[PATCH] patch: match 'diff --git a/' instead of 'diff --git'

Sean Farley sean.michael.farley at gmail.com
Fri Mar 22 17:46:25 CDT 2013


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1363991226 18000
#      Fri Mar 22 17:27:06 2013 -0500
# Node ID 8e1fe4a88e89f8aff8d781b787c2d02053ef6bcc
# Parent  ac0336471ba766cc3c1234473e75d4478819e50d
patch: match 'diff --git a/' instead of 'diff --git'

This fixes 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

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -312,11 +312,11 @@
     # Filter patch for git information
     gp = None
     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:
                     gitpatches.append(gp)
                 dst = m.group(2)
@@ -1209,11 +1209,11 @@
             hunknum += 1
             if emitfile:
                 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
             if gitpatches is None:
                 # scan whole input for git metadata
@@ -1811,11 +1811,11 @@
     for line in lines:
         if line.startswith('diff'):
             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"
                 filename = diffre.search(line).group(1)
         elif line.startswith('+') and not line.startswith('+++ '):


More information about the Mercurial-devel mailing list