Commits

Anonymous committed cbbafde

Support --git-style diffs.

Comments (0)

Files changed (1)

scripts/addpatchsets

     patches = []
     filename = None
     for line in data.splitlines(True):
-        if line.startswith('diff -r'):
+        if line.startswith('diff '):
             if filename:
                 chunks = patching.ParsePatchToChunks(diff)
                 if not chunks:
                 patches.append((filename, ''.join(diff), chunks))
             diff = []
             filename = line.split()[-1]
+            if filename.startswith("b/"):
+                # git style
+                filename = filename[2:]
             continue
         if filename:
             diff.append(line)
     return patches
 
 def find_bases(data):
-    if not data.startswith("diff -r "):
+    if not data.startswith("diff "):
         # this should only be called if there is actually is a diff in the file
-        head, tail = data.split("\ndiff -r ", 1)
-        data = "diff -r "+tail
-    first, second, rev = data.split()[:3]
-    if first != 'diff' or second != '-r' or len(rev) != 12:
-        return None, None
+        head, tail = data.split("\ndiff ", 1)
+        data = "diff "+tail
+    # default to default branch if no revision is found
+    rev = 'default'
+    if data.startswith("diff -r "):
+        first, second, rev = data.split()[:3]
     c = connection.cursor()
     pieces = hg_splitpatch(data)
     if not pieces:
         print filename,"not found"
         continue
     data = open(filename).read()
-    if not data.startswith('diff -r ') and data.find('\ndiff -r ')==-1:
+    if not data.startswith('diff ') and data.find('\ndiff ')==-1:
         if verbose:
             print filename, "is not a patch"
         continue