+static char *git_header_name(char *line)
+{
+ int len;
+ char *name, *second;
+
+ /*
+ * Find the first '/'
+ */
+ name = line;
+ for (;;) {
+ char c = *name++;
+ if (c == '\n')
+ return NULL;
+ if (c == '/')
+ break;
+ }
+
+ /*
+ * We don't accept absolute paths (/dev/null) as possibly valid
+ */
+ if (name == line+1)
+ return NULL;
+
+ /*
+ * Accept a name only if it shows up twice, exactly the same
+ * form.
+ */
+ for (len = 0 ; ; len++) {
+ char c = name[len];
+
+ switch (c) {
+ default:
+ continue;
+ case '\n':
+ break;
+ case '\t': case ' ':
+ second = name+len;
+ for (;;) {
+ char c = *second++;
+ if (c == '\n')
+ return NULL;
+ if (c == '/')
+ break;
+ }
+ if (!memcmp(name, second, len)) {
+ char *ret = xmalloc(len + 1);
+ memcpy(ret, name, len);
+ ret[len] = 0;
+ return ret;
+ }
+ }
+ }
+ return NULL;
+}
+