The fix in ca53c3f (Fix diff parsing for lines starting with "--" or "++",
2008-09-05) got a bug report from Johannes Sixt, that new files in the
index now looks like:
new file mode 100644
--- /dev/null+++ b/foo
@@ -0,0 +1 @@+foo
The introduced problem was that the 'in-diff-header'-flag was unconditially
disabled. Now it is only disabled when a hunk line is detected. And also
re-enabled when we encounter a new diff header.
The second part solves also the issue reported by me for diffs with file
type changes (i.e. the ''error: Unhandled 2 way diff marker: {d}"', which
comes from the second 'diff --git' line).
Reported-by: Johannes Sixt <redacted>
Reported-by: Bert Wesarg <redacted>
Signed-off-by: Bert Wesarg <redacted>
---
Cc: Johannes Sixt <redacted>
---
foo | 1 +
lib/diff.tcl | 18 +++++++++++++++---
2 files changed, 16 insertions(+), 3 deletions(-)
create mode 100644 foo
@@ -382,23 +382,35 @@ proc read_diff {fd conflict_size cont_info} {foreach{linemarkup}[parse_color_line$line]breaksetline[stringmap{\033^}$line]-# -- Cleanup uninteresting diff header lines.+# -- Check for start of diff header.+if{[stringmatch{diff--git*}$line]+||[stringmatch{diff--cc*}$line]+||[stringmatch{diff--combined*}$line]}{+set::current_diff_inheader1+}++# -- Check for end of diff header (any hunk line will do this).#+if{[regexp{^@@+}$line]}{set::current_diff_inheader0}+if{$::current_diff_inheader}{+appendcurrent_diff_header$line"\n"++# -- Cleanup uninteresting diff header lines.+#if{[stringmatch{diff--git*}$line]||[stringmatch{diff--cc*}$line]||[stringmatch{diff--combined*}$line]||[stringmatch{---*}$line]||[stringmatch{+++*}$line]}{-appendcurrent_diff_header$line"\n"continue}}+if{[stringmatch{index*}$line]}continueif{$lineeq{deletedfilemode120000}}{setline"deleted symlink"}-set::current_diff_inheader0# -- Automatically detect if this is a 3 way diff.#
@@ -423,14 +423,9 @@ proc read_diff {fd conflict_size cont_info} {# -- Name it symlink, not 120000# Note, that the original line is in $current_diff_headerregsub{^(deleted|new)filemode120000}$line{\1symlink}line-}-if{[stringmatch{newfile*}$line]-||[regexp{^(old|new)mode*}$line]-||[stringmatch{deletedfile*}$line]-||[stringmatch{deletedsymlink}$line]-||[stringmatch{newsymlink}$line]-||$lineeq{\Nonewlineatendoffile}}{+}elseif{$lineeq{\Nonewlineatendoffile}}{+# -- Handle some special lines}elseif{$is_3way_diff}{setop[stringrange$line01]switch--$op{
@@ -400,7 +400,14 @@ proc read_diff {fd conflict_size cont_info} {if{[stringmatch{@@@*}$line]}{setis_3way_diff1}if{$::current_diff_inheader}{-appendcurrent_diff_header$line"\n"++# -- These two lines stop a diff header and shouldn't be in there+if{[stringmatch{Binaryfiles*and*differ}$line]+||[regexp{^\*Unmergedpath}$line]}{+set::current_diff_inheader0+}else{+appendcurrent_diff_header$line"\n"+}# -- Cleanup uninteresting diff header lines.#
and rename them only in the diff header
Signed-off-by: Bert Wesarg <redacted>
---
lib/diff.tcl | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
@@ -406,12 +406,13 @@ proc read_diff {fd conflict_size cont_info} {||[stringmatch{index*}$line]}{continue}-}-if{$lineeq{deletedfilemode120000}}{-setline"deleted symlink"+# -- Name it symlink, not 120000+# Note, that the original line is in $current_diff_header+regsub{^(deleted|new)filemode120000}$line{\1symlink}line}+# -- Automatically detect if this is a 3 way diff.#if{[stringmatch{@@@*}$line]}{setis_3way_diff1}
@@ -393,6 +393,10 @@ proc read_diff {fd conflict_size cont_info} {#if{[regexp{^@@+}$line]}{set::current_diff_inheader0}+# -- Automatically detect if this is a 3 way diff.+#+if{[stringmatch{@@@*}$line]}{setis_3way_diff1}+if{$::current_diff_inheader}{appendcurrent_diff_header$line"\n"
@@ -413,9 +417,6 @@ proc read_diff {fd conflict_size cont_info} {}-# -- Automatically detect if this is a 3 way diff.-#-if{[stringmatch{@@@*}$line]}{setis_3way_diff1}if{[stringmatch{newfile*}$line]||[regexp{^(old|new)mode*}$line]