[PATCH RFC] import: tweak diff line detection in patch header regex (issue1879)
Levi Bard
taktaktaktaktaktaktaktaktaktak at gmail.com
Sun May 13 10:13:29 CDT 2012
# HG changeset patch
# User Levi Bard <levi at unity3d.com>
# Date 1336921918 -7200
# Node ID 03e0651bf4c3d7a8515d79cc222be905b8073bbd
# Parent 0a176990243c9b4753039867164cfed560806fb7
import: tweak diff line detection in patch header regex (issue1879)
diff -r 0a176990243c -r 03e0651bf4c3 mercurial/patch.py
--- a/mercurial/patch.py Sun May 13 14:29:05 2012 +0200
+++ b/mercurial/patch.py Sun May 13 17:11:58 2012 +0200
@@ -160,10 +160,12 @@
# attempt to detect the start of a patch
# (this heuristic is borrowed from quilt)
- diffre = re.compile(r'^(?:Index:[ \t]|diff[ \t]|RCS file: |'
- r'retrieving revision [0-9]+(\.[0-9]+)*$|'
- r'---[ \t].*?^\+\+\+[ \t]|'
- r'\*\*\*[ \t].*?^---[ \t])', re.MULTILINE|re.DOTALL)
+ diffre = re.compile(r'^(?:Index:[ \t]|'
+ r'diff[ \t]+(--?[\w][-\w]*[ \t]+(\S+)?[ \t]*)*' # diff -x y --z-1 2
+ r'(\S+[ \t]*){0,2}[ \t\r]*$' # zero to two non-option args (a/a b/a)
+ r'|RCS file: |retrieving revision \d+(\.\d+)*$|'
+ r'---[ \t].*?^\+\+\+[ \t]|\*\*\*[ \t].*?^---[ \t])',
+ re.MULTILINE|re.DOTALL)
fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
tmpfp = os.fdopen(fd, 'w')
diff -r 0a176990243c -r 03e0651bf4c3 tests/test-import.t
--- a/tests/test-import.t Sun May 13 14:29:05 2012 +0200
+++ b/tests/test-import.t Sun May 13 17:11:58 2012 +0200
@@ -167,6 +167,36 @@
[255]
$ rm -r b
+ $ cat > spurious-diff-line.diff <<EOF
+ > summary line
+ >
+ > this is a message containing the word
+ > diff in a strategic place
+ >
+ > diff --git a/test.txt b/test.txt
+ > new file mode 100644
+ >
+ > EOF
+ $ hg clone -r0 a b
+ adding changesets
+ adding manifests
+ adding file changes
+ added 1 changesets with 2 changes to 2 files
+ updating to branch default
+ 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ $ hg --cwd b import ../spurious-diff-line.diff
+ applying ../spurious-diff-line.diff
+ $ hg --cwd b log --template '===\n{desc}\n===\n'
+ ===
+ summary line
+
+ this is a message containing the word
+ diff in a strategic place
+ ===
+ ===
+ a
+ ===
+ $ rm -r b
hg -R repo import
put the clone in a subdir - having a directory named "a"
More information about the Mercurial-devel
mailing list