Selaa lähdekoodia

Support pseudo headers in patches.

Jelmer Vernooij 14 vuotta sitten
vanhempi
commit
c92929e140
2 muutettua tiedostoa jossa 36 lisäystä ja 8 poistoa
  1. 12 8
      dulwich/patch.py
  2. 24 0
      dulwich/tests/test_patch.py

+ 12 - 8
dulwich/patch.py

@@ -18,7 +18,7 @@
 
 """Classes for dealing with git am-style patches.
 
-These patches are basically unified diffs with some extra metadata tacked 
+These patches are basically unified diffs with some extra metadata tacked
 on.
 """
 
@@ -46,7 +46,7 @@ def write_commit_patch(f, commit, contents, progress, version=None):
     f.write("\n")
     f.write("---\n")
     try:
-        p = subprocess.Popen(["diffstat"], stdout=subprocess.PIPE, 
+        p = subprocess.Popen(["diffstat"], stdout=subprocess.PIPE,
                              stdin=subprocess.PIPE)
     except OSError, e:
         pass # diffstat not available?
@@ -65,7 +65,7 @@ def write_commit_patch(f, commit, contents, progress, version=None):
 
 def get_summary(commit):
     """Determine the summary line for use in a filename.
-    
+
     :param commit: Commit
     :return: Summary string
     """
@@ -102,7 +102,7 @@ def unified_diff(a, b, fromfile='', tofile='', n=3):
                     yield '+' + line
 
 
-def write_blob_diff(f, (old_path, old_mode, old_blob), 
+def write_blob_diff(f, (old_path, old_mode, old_blob),
                        (new_path, new_mode, new_blob)):
     """Write diff file header.
 
@@ -133,14 +133,14 @@ def write_blob_diff(f, (old_path, old_mode, old_blob),
         if new_mode is not None:
             if old_mode is not None:
                 f.write("old mode %o\n" % old_mode)
-            f.write("new mode %o\n" % new_mode) 
+            f.write("new mode %o\n" % new_mode)
         else:
             f.write("deleted mode %o\n" % old_mode)
     f.write("index %s..%s %o\n" % (
         blob_id(old_blob), blob_id(new_blob), new_mode))
     old_contents = lines(old_blob)
     new_contents = lines(new_blob)
-    f.writelines(unified_diff(old_contents, new_contents, 
+    f.writelines(unified_diff(old_contents, new_contents,
         old_path, new_path))
 
 
@@ -167,9 +167,13 @@ def git_am_patch_split(f):
         if l == "---\n":
             break
         if first:
-            c.message += "\n"
+            if l.startswith("From: "):
+                c.author = l[len("From: "):].rstrip()
+            else:
+                c.message += "\n" + l
             first = False
-        c.message += l
+        else:
+            c.message += l
     diff = ""
     for l in f:
         if l == "-- \n":

+ 24 - 0
dulwich/tests/test_patch.py

@@ -111,3 +111,27 @@ Subject:  [Dulwich-users] [PATCH] Added unit tests for
 """
         c, diff, version = git_am_patch_split(StringIO(text))
         self.assertEquals('Added unit tests for dulwich.object_store.tree_lookup_path.\n\n* dulwich/tests/test_object_store.py\n  (TreeLookupPathTests): This test case contains a few tests that ensure the\n   tree_lookup_path function works as expected.\n', c.message)
+
+    def test_extract_pseudo_from_header(self):
+        text = """From ff643aae102d8870cac88e8f007e70f58f3a7363 Mon Sep 17 00:00:00 2001
+From: Jelmer Vernooij <jelmer@samba.org>
+Date: Thu, 15 Apr 2010 15:40:28 +0200
+Subject:  [Dulwich-users] [PATCH] Added unit tests for
+ dulwich.object_store.tree_lookup_path.
+
+From: Jelmer Vernooy <jelmer@debian.org>
+
+* dulwich/tests/test_object_store.py
+  (TreeLookupPathTests): This test case contains a few tests that ensure the
+   tree_lookup_path function works as expected.
+---
+ pixmaps/prey.ico |  Bin 9662 -> 9662 bytes
+ 1 files changed, 0 insertions(+), 0 deletions(-)
+ mode change 100755 => 100644 pixmaps/prey.ico
+
+-- 
+1.7.0.4
+"""
+        c, diff, version = git_am_patch_split(StringIO(text))
+        self.assertEquals("Jelmer Vernooy <jelmer@debian.org>", c.author)
+        self.assertEquals('Added unit tests for dulwich.object_store.tree_lookup_path.\n\n* dulwich/tests/test_object_store.py\n  (TreeLookupPathTests): This test case contains a few tests that ensure the\n   tree_lookup_path function works as expected.\n', c.message)