patch: match 'diff --git a/' instead of 'diff --git'
authorSean Farley <sean.michael.farley@gmail.com>
Fri, 22 Mar 2013 17:27:06 -0500
changeset 18830 6b827d84d286
parent 18829 8843182f3514
child 18831 17f6644a2fbc
patch: match 'diff --git a/' instead of 'diff --git' This reduces the likelihood of a traceback when trying to email a patch that happens to have 'diff --git' at the beginning of a line in the description, as this patch did: http://markmail.org/message/wxpgowxd7ucxygwe
mercurial/patch.py
--- a/mercurial/patch.py	Thu Mar 21 18:16:49 2013 +0100
+++ b/mercurial/patch.py	Fri Mar 22 17:27:06 2013 -0500
@@ -314,7 +314,7 @@
     gitpatches = []
     for line in lr:
         line = line.rstrip(' \r\n')
-        if line.startswith('diff --git'):
+        if line.startswith('diff --git a/'):
             m = gitre.match(line)
             if m:
                 if gp:
@@ -1211,7 +1211,7 @@
                 emitfile = False
                 yield 'file', (afile, bfile, h, gp and gp.copy() or None)
             yield 'hunk', h
-        elif x.startswith('diff --git'):
+        elif x.startswith('diff --git a/'):
             m = gitre.match(x.rstrip(' \r\n'))
             if not m:
                 continue
@@ -1815,7 +1815,7 @@
             addresult()
             # set numbers to 0 anyway when starting new file
             adds, removes, isbinary = 0, 0, False
-            if line.startswith('diff --git'):
+            if line.startswith('diff --git a/'):
                 filename = gitre.search(line).group(1)
             elif line.startswith('diff -r'):
                 # format: "diff -r ... -r ... filename"