Patchwork patch: match 'diff --git a/' instead of 'diff --git'

login
register
mail settings
Submitter Sean Farley
Date March 22, 2013, 10:46 p.m.
Message ID <8e1fe4a88e89f8aff8d7.1363992385@laptop.local>
Download mbox | patch
Permalink /patch/1168/
State Accepted
Commit 6b827d84d286bf299ede4c677d56727f991e2111
Headers show

Comments

Sean Farley - March 22, 2013, 10:46 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@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
Brendan Cully - March 22, 2013, 10:50 p.m.
On Friday, 22 March 2013 at 17:46, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley@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

What happens if the description contains a line starting with

diff --git a/

?
Sean Farley - March 23, 2013, 1:45 a.m.
Brendan Cully writes:

> On Friday, 22 March 2013 at 17:46, Sean Farley wrote:
>> # HG changeset patch
>> # User Sean Farley <sean.michael.farley@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
>
> What happens if the description contains a line starting with
>
> diff --git a/
>
> ?

It would most definitely give the same traceback I saw. I think fixing
this bug for the general case would require using the regex already in
the file (gitre) but since this is a vital piece of code (and one I'm
not too familiar with), I took the path of least number of lines
changed.

I could feasibly look into going the regex route but didn't feel that I
had the time to look at it in-depth. Of course, with enough nagging I
would get around to it ;-)
Bryan O'Sullivan - March 26, 2013, 5:45 p.m.
On Fri, Mar 22, 2013 at 3:46 PM, Sean Farley
<sean.michael.farley@gmail.com>wrote:

> 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:
>

I've applied this patch, but I changed "fixes a traceback" to "reduces the
likelihood of a traceback", since it's not quite really a fix.
Sean Farley - March 26, 2013, 7:45 p.m.
Bryan O'Sullivan writes:

> On Fri, Mar 22, 2013 at 3:46 PM, Sean Farley
> <sean.michael.farley@gmail.com>wrote:
>
>> 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:
>>
>
> I've applied this patch, but I changed "fixes a traceback" to "reduces the
> likelihood of a traceback", since it's not quite really a fix.

Thanks! Your message is much more descriptive; much appreciated :-)

Patch

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('+++ '):