From patchwork Thu Nov 2 13:32:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: patch: improve heuristics to not take the word "diff" as header (issue1879) From: Yuya Nishihara X-Patchwork-Id: 25344 Message-Id: <6798568fe43dc1e28a0c.1509629573@mimosa> To: mercurial-devel@mercurial-scm.org Date: Thu, 02 Nov 2017 22:32:53 +0900 # HG changeset patch # User Yuya Nishihara # Date 1508572257 -32400 # Sat Oct 21 16:50:57 2017 +0900 # Node ID 6798568fe43dc1e28a0c66c54217b563e1f2d5de # Parent a7e49a5b3e6f38338660c0d98f9c593f70064e95 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". diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -203,7 +203,7 @@ def extract(ui, fileobj): # 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])', diff --git a/tests/test-import.t b/tests/test-import.t --- a/tests/test-import.t +++ b/tests/test-import.t @@ -1346,6 +1346,93 @@ import a unified diff with no lines of c $ cd .. +commit message that looks like a diff header (issue1879) + + $ hg init headerlikemsg + $ cd headerlikemsg + $ touch empty + $ echo nonempty >> nonempty + $ hg ci -qAl - < 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