Mercurial > hg
changeset 34964:7ebf850d3166
patch: improve heuristics to not take the word "diff" as header (issue1879)
The word "diff" is likely to appear in a commit message. Let's make it less
likely by requiring "diff -" for "diff -r" or "diff --git".
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 21 Oct 2017 16:50:57 +0900 |
parents | ddf37b6b8c3d |
children | d8c2db6167b3 |
files | mercurial/patch.py tests/test-import.t |
diffstat | 2 files changed, 88 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/patch.py Sat Oct 21 17:01:20 2017 +0900 +++ b/mercurial/patch.py Sat Oct 21 16:50:57 2017 +0900 @@ -203,7 +203,7 @@ # attempt to detect the start of a patch # (this heuristic is borrowed from quilt) - diffre = re.compile(br'^(?:Index:[ \t]|diff[ \t]|RCS file: |' + diffre = re.compile(br'^(?:Index:[ \t]|diff[ \t]-|RCS file: |' br'retrieving revision [0-9]+(\.[0-9]+)*$|' br'---[ \t].*?^\+\+\+[ \t]|' br'\*\*\*[ \t].*?^---[ \t])',
--- a/tests/test-import.t Sat Oct 21 17:01:20 2017 +0900 +++ b/tests/test-import.t Sat Oct 21 16:50:57 2017 +0900 @@ -1346,6 +1346,93 @@ $ cd .. +commit message that looks like a diff header (issue1879) + + $ hg init headerlikemsg + $ cd headerlikemsg + $ touch empty + $ echo nonempty >> nonempty + $ hg ci -qAl - <<EOF + > blah blah + > diff blah + > blah blah + > EOF + $ hg --config diff.git=1 log -pv + changeset: 0:c6ef204ef767 + tag: tip + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + files: empty nonempty + description: + blah blah + diff blah + blah blah + + + diff --git a/empty b/empty + new file mode 100644 + diff --git a/nonempty b/nonempty + new file mode 100644 + --- /dev/null + +++ b/nonempty + @@ -0,0 +1,1 @@ + +nonempty + + + (without --git, empty file is lost, but commit message should be preserved) + + $ hg init plain + $ hg export 0 | hg -R plain import - + applying patch from stdin + $ hg --config diff.git=1 -R plain log -pv + changeset: 0:60a2d231e71f + tag: tip + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + files: nonempty + description: + blah blah + diff blah + blah blah + + + diff --git a/nonempty b/nonempty + new file mode 100644 + --- /dev/null + +++ b/nonempty + @@ -0,0 +1,1 @@ + +nonempty + + + (with --git, patch contents should be fully preserved) + + $ hg init git + $ hg --config diff.git=1 export 0 | hg -R git import - + applying patch from stdin + $ hg --config diff.git=1 -R git log -pv + changeset: 0:c6ef204ef767 + tag: tip + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + files: empty nonempty + description: + blah blah + diff blah + blah blah + + + diff --git a/empty b/empty + new file mode 100644 + diff --git a/nonempty b/nonempty + new file mode 100644 + --- /dev/null + +++ b/nonempty + @@ -0,0 +1,1 @@ + +nonempty + + + $ cd .. + no segfault while importing a unified diff which start line is zero but chunk size is non-zero