+
+ name = xmalloc(len + 1);
+ memcpy(name, start, len);
+ name[len] = 0;
+ free(def);
+ return name;
+}
+
+/*
+ * Get the name etc info from the --/+++ lines of a traditional patch header
+ *
+ * NOTE! This hardcodes "-p1" behaviour in filename detection.
+ */
+static int parse_traditional_patch(const char *first, const char *second)
+{
+ int p_value = 1;
+ char *name;
+
+ first += 4; // skip "--- "
+ second += 4; // skip "+++ "
+ if (is_dev_null(first)) {
+ is_new = 1;
+ name = find_name(second, def_name, p_value);
+ } else if (is_dev_null(second)) {
+ is_delete = 1;
+ name = find_name(first, def_name, p_value);
+ } else {
+ name = find_name(first, def_name, p_value);
+ name = find_name(second, name, p_value);
+ }
+ if (!name)
+ die("unable to find filename in patch at line %d", linenr);
+ old_name = name;
+ new_name = name;
+}
+
+static int gitdiff_hdrend(const char *line)
+{
+ return -1;
+}
+
+static int gitdiff_oldname(const char *line)
+{
+ if (!old_name)
+ old_name = find_name(line, NULL, 1);
+ return 0;
+}
+
+static int gitdiff_newname(const char *line)
+{
+ if (!new_name)
+ new_name = find_name(line, NULL, 1);
+ return 0;
+}
+
+static int gitdiff_oldmode(const char *line)
+{
+ old_mode = strtoul(line, NULL, 8);
+ return 0;
+}
+
+static int gitdiff_newmode(const char *line)
+{
+ new_mode = strtoul(line, NULL, 8);
+ return 0;
+}
+
+static int gitdiff_delete(const char *line)
+{
+ is_delete = 1;
+ return gitdiff_oldmode(line);
+}
+
+static int gitdiff_newfile(const char *line)
+{
+ is_new = 1;
+ return gitdiff_newmode(line);
+}
+
+static int gitdiff_copysrc(const char *line)
+{
+ is_copy = 1;
+ old_name = find_name(line, NULL, 0);
+ return 0;
+}
+
+static int gitdiff_copydst(const char *line)
+{
+ is_copy = 1;
+ new_name = find_name(line, NULL, 0);
+ return 0;
+}
+
+static int gitdiff_renamesrc(const char *line)
+{
+ is_rename = 1;
+ old_name = find_name(line, NULL, 0);
+ return 0;
+}
+
+static int gitdiff_renamedst(const char *line)
+{
+ is_rename = 1;
+ new_name = find_name(line, NULL, 0);
+ return 0;
+}
+
+static int gitdiff_similarity(const char *line)
+{
+ return 0;