comparison mercurial/patch.py @ 18830:6b827d84d286

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
author Sean Farley <sean.michael.farley@gmail.com>
date Fri, 22 Mar 2013 17:27:06 -0500
parents f0d55e1b4855
children 0b3689a08df5
comparison
equal deleted inserted replaced
18829:8843182f3514 18830:6b827d84d286
312 # Filter patch for git information 312 # Filter patch for git information
313 gp = None 313 gp = None
314 gitpatches = [] 314 gitpatches = []
315 for line in lr: 315 for line in lr:
316 line = line.rstrip(' \r\n') 316 line = line.rstrip(' \r\n')
317 if line.startswith('diff --git'): 317 if line.startswith('diff --git a/'):
318 m = gitre.match(line) 318 m = gitre.match(line)
319 if m: 319 if m:
320 if gp: 320 if gp:
321 gitpatches.append(gp) 321 gitpatches.append(gp)
322 dst = m.group(2) 322 dst = m.group(2)
1209 hunknum += 1 1209 hunknum += 1
1210 if emitfile: 1210 if emitfile:
1211 emitfile = False 1211 emitfile = False
1212 yield 'file', (afile, bfile, h, gp and gp.copy() or None) 1212 yield 'file', (afile, bfile, h, gp and gp.copy() or None)
1213 yield 'hunk', h 1213 yield 'hunk', h
1214 elif x.startswith('diff --git'): 1214 elif x.startswith('diff --git a/'):
1215 m = gitre.match(x.rstrip(' \r\n')) 1215 m = gitre.match(x.rstrip(' \r\n'))
1216 if not m: 1216 if not m:
1217 continue 1217 continue
1218 if gitpatches is None: 1218 if gitpatches is None:
1219 # scan whole input for git metadata 1219 # scan whole input for git metadata
1813 for line in lines: 1813 for line in lines:
1814 if line.startswith('diff'): 1814 if line.startswith('diff'):
1815 addresult() 1815 addresult()
1816 # set numbers to 0 anyway when starting new file 1816 # set numbers to 0 anyway when starting new file
1817 adds, removes, isbinary = 0, 0, False 1817 adds, removes, isbinary = 0, 0, False
1818 if line.startswith('diff --git'): 1818 if line.startswith('diff --git a/'):
1819 filename = gitre.search(line).group(1) 1819 filename = gitre.search(line).group(1)
1820 elif line.startswith('diff -r'): 1820 elif line.startswith('diff -r'):
1821 # format: "diff -r ... -r ... filename" 1821 # format: "diff -r ... -r ... filename"
1822 filename = diffre.search(line).group(1) 1822 filename = diffre.search(line).group(1)
1823 elif line.startswith('+') and not line.startswith('+++ '): 1823 elif line.startswith('+') and not line.startswith('+++ '):