Cope with missing newlines in patches.
authorJelmer Vernooij <jelmer@samba.org>
Tue, 11 May 2010 08:17:54 +0000 (10:17 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Tue, 11 May 2010 08:17:54 +0000 (10:17 +0200)
dulwich/patch.py

index d922168fa000271be3b5603c4d4d6af899fa98d1..7c20b1e3ff4425af14558bc56fcd3c5c39fade3c 100644 (file)
@@ -72,13 +72,13 @@ def get_summary(commit):
     return commit.message.splitlines()[0].replace(" ", "-")
 
 
-def unified_diff(a, b, fromfile='', tofile='', n=3, lineterm='\n'):
+def unified_diff(a, b, fromfile='', tofile='', n=3):
     """difflib.unified_diff that doesn't write any dates or trailing spaces.
 
     Based on the same function in Python2.6.5-rc2's difflib.py
     """
     started = False
-    for group in SequenceMatcher(None, a, b).get_grouped_opcodes(3):
+    for group in SequenceMatcher(None, a, b).get_grouped_opcodes(n):
         if not started:
             yield '--- %s\n' % fromfile
             yield '+++ %s\n' % tofile
@@ -92,9 +92,13 @@ def unified_diff(a, b, fromfile='', tofile='', n=3, lineterm='\n'):
                 continue
             if tag == 'replace' or tag == 'delete':
                 for line in a[i1:i2]:
+                    if not line[-1] == '\n':
+                        line += '\n\\ No newline at end of file\n'
                     yield '-' + line
             if tag == 'replace' or tag == 'insert':
                 for line in b[j1:j2]:
+                    if not line[-1] == '\n':
+                        line += '\n\\ No newline at end of file\n'
                     yield '+' + line