Rev 3923: (Adeodato Simo) Update patience_diff.unified_diff so that it doesn't in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Jan 6 17:15:24 GMT 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3923
revision-id: pqm at pqm.ubuntu.com-20090106171520-9pzjoqa7m74hvhht
parent: pqm at pqm.ubuntu.com-20090106073252-m4c72a1m7004nqmz
parent: john at arbash-meinel.com-20090106162002-06xtt1n1qbzs8hw3
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2009-01-06 17:15:20 +0000
message:
  (Adeodato Simo) Update patience_diff.unified_diff so that it doesn't
  	add trailing whitespace when you don't supply datestamps.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/diff.py                 diff.py-20050309040759-26944fbbf2ebbf36
  bzrlib/patiencediff.py         patiencediff.py-20070721205536-jz8gaykeb7xtampk-1
  bzrlib/tests/test_diff.py      testdiff.py-20050727164403-d1a3496ebb12e339
    ------------------------------------------------------------
    revno: 3922.1.5
    revision-id: john at arbash-meinel.com-20090106162002-06xtt1n1qbzs8hw3
    parent: john at arbash-meinel.com-20090106161652-mmiu620z0uwuq659
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: jam-integration
    timestamp: Tue 2009-01-06 10:20:02 -0600
    message:
      Add a NEWS entry
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3922.1.4
    revision-id: john at arbash-meinel.com-20090106161652-mmiu620z0uwuq659
    parent: john at arbash-meinel.com-20090106151157-1eb23rpqw10hal27
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: jam-integration
    timestamp: Tue 2009-01-06 10:16:52 -0600
    message:
      It turns out that internal_diff worked around the trailing whitespace problem
      from unified_diff, so we have to remove that workaround.
      Also, the filename should be separated from the date by a tab character, not by a blank
      space.
    modified:
      bzrlib/diff.py                 diff.py-20050309040759-26944fbbf2ebbf36
      bzrlib/patiencediff.py         patiencediff.py-20070721205536-jz8gaykeb7xtampk-1
      bzrlib/tests/test_diff.py      testdiff.py-20050727164403-d1a3496ebb12e339
    ------------------------------------------------------------
    revno: 3922.1.3
    revision-id: john at arbash-meinel.com-20090106151157-1eb23rpqw10hal27
    parent: john at arbash-meinel.com-20090106150929-2z675mps5t1p1t5g
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: jam-integration
    timestamp: Tue 2009-01-06 09:11:57 -0600
    message:
      fix some odd spacing.
    modified:
      bzrlib/tests/test_diff.py      testdiff.py-20050727164403-d1a3496ebb12e339
    ------------------------------------------------------------
    revno: 3922.1.2
    revision-id: john at arbash-meinel.com-20090106150929-2z675mps5t1p1t5g
    parent: john at arbash-meinel.com-20090106150242-frp82yhowbro6t1a
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: jam-integration
    timestamp: Tue 2009-01-06 09:09:29 -0600
    message:
      Update the test cases for the new patience diff code.
    modified:
      bzrlib/tests/test_diff.py      testdiff.py-20050727164403-d1a3496ebb12e339
    ------------------------------------------------------------
    revno: 3922.1.1
    revision-id: john at arbash-meinel.com-20090106150242-frp82yhowbro6t1a
    parent: pqm at pqm.ubuntu.com-20090106073252-m4c72a1m7004nqmz
    author: Adeodato Simo <dato at net.com.org.es>
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: jam-integration
    timestamp: Tue 2009-01-06 09:02:42 -0600
    message:
      Change the patience_diff.unified_diff code to not add trailing whitespace when no timestamp is supplied.
    modified:
      bzrlib/patiencediff.py         patiencediff.py-20070721205536-jz8gaykeb7xtampk-1
=== modified file 'NEWS'
--- a/NEWS	2008-12-29 13:51:19 +0000
+++ b/NEWS	2009-01-06 16:20:02 +0000
@@ -136,6 +136,11 @@
       cost of not preserving the 'active' set as well as an ``LRUCache``.
       (John Arbash Meinel)
 
+    * ``bzrlib.patience_diff.unified_diff`` now properly uses a tab
+      character to separate the filename from the date stamp, and doesn't
+      add trailing whitespace when a date stamp is not supplied.
+      (Adeodato Simó, John Arbash Meinel)
+
     * ``DirStateWorkingTree`` and ``DirStateWorkingTreeFormat`` added
       as base classes of ``WorkingTree4`` and ``WorkingTreeFormat4``
       respectively. (Ian Clatworthy)

=== modified file 'bzrlib/diff.py'
--- a/bzrlib/diff.py	2008-10-01 05:40:45 +0000
+++ b/bzrlib/diff.py	2009-01-06 16:16:52 +0000
@@ -99,9 +99,6 @@
         ud[2] = ud[2].replace('-1,0', '-0,0')
     elif not newlines:
         ud[2] = ud[2].replace('+1,0', '+0,0')
-    # work around for difflib emitting random spaces after the label
-    ud[0] = ud[0][:-2] + '\n'
-    ud[1] = ud[1][:-2] + '\n'
 
     for line in ud:
         to_file.write(line)

=== modified file 'bzrlib/patiencediff.py'
--- a/bzrlib/patiencediff.py	2007-09-04 09:10:35 +0000
+++ b/bzrlib/patiencediff.py	2009-01-06 16:16:52 +0000
@@ -76,11 +76,16 @@
         import difflib
         sequencematcher = difflib.SequenceMatcher
 
+    if fromfiledate:
+        fromfiledate = '\t' + str(fromfiledate)
+    if tofiledate:
+        tofiledate = '\t' + str(tofiledate)
+
     started = False
     for group in sequencematcher(None,a,b).get_grouped_opcodes(n):
         if not started:
-            yield '--- %s %s%s' % (fromfile, fromfiledate, lineterm)
-            yield '+++ %s %s%s' % (tofile, tofiledate, lineterm)
+            yield '--- %s%s%s' % (fromfile, fromfiledate, lineterm)
+            yield '+++ %s%s%s' % (tofile, tofiledate, lineterm)
             started = True
         i1, i2, j1, j2 = group[0][1], group[-1][2], group[0][3], group[-1][4]
         yield "@@ -%d,%d +%d,%d @@%s" % (i1+1, i2-i1, j1+1, j2-j1, lineterm)

=== modified file 'bzrlib/tests/test_diff.py'
--- a/bzrlib/tests/test_diff.py	2008-09-01 14:03:34 +0000
+++ b/bzrlib/tests/test_diff.py	2009-01-06 16:16:52 +0000
@@ -1083,8 +1083,8 @@
                  'how are you today?\n']
         unified_diff = bzrlib.patiencediff.unified_diff
         psm = self._PatienceSequenceMatcher
-        self.assertEquals([ '---  \n',
-                           '+++  \n',
+        self.assertEquals(['--- \n',
+                           '+++ \n',
                            '@@ -1,3 +1,2 @@\n',
                            ' hello there\n',
                            '-world\n',
@@ -1095,8 +1095,8 @@
         txt_a = map(lambda x: x+'\n', 'abcdefghijklmnop')
         txt_b = map(lambda x: x+'\n', 'abcdefxydefghijklmnop')
         # This is the result with LongestCommonSubstring matching
-        self.assertEquals(['---  \n',
-                           '+++  \n',
+        self.assertEquals(['--- \n',
+                           '+++ \n',
                            '@@ -1,6 +1,11 @@\n',
                            ' a\n',
                            ' b\n',
@@ -1111,8 +1111,8 @@
                            ' f\n']
                           , list(unified_diff(txt_a, txt_b)))
         # And the patience diff
-        self.assertEquals(['---  \n',
-                           '+++  \n',
+        self.assertEquals(['--- \n',
+                           '+++ \n',
                            '@@ -4,6 +4,11 @@\n',
                            ' d\n',
                            ' e\n',
@@ -1129,6 +1129,27 @@
                           , list(unified_diff(txt_a, txt_b,
                                  sequencematcher=psm)))
 
+    def test_patience_unified_diff_with_dates(self):
+        txt_a = ['hello there\n',
+                 'world\n',
+                 'how are you today?\n']
+        txt_b = ['hello there\n',
+                 'how are you today?\n']
+        unified_diff = bzrlib.patiencediff.unified_diff
+        psm = self._PatienceSequenceMatcher
+        self.assertEquals(['--- a\t2008-08-08\n',
+                           '+++ b\t2008-09-09\n',
+                           '@@ -1,3 +1,2 @@\n',
+                           ' hello there\n',
+                           '-world\n',
+                           ' how are you today?\n'
+                          ]
+                          , list(unified_diff(txt_a, txt_b,
+                                 fromfile='a', tofile='b',
+                                 fromfiledate='2008-08-08',
+                                 tofiledate='2008-09-09',
+                                 sequencematcher=psm)))
+
 
 class TestPatienceDiffLib_c(TestPatienceDiffLib):
 
@@ -1174,8 +1195,8 @@
 
         unified_diff_files = bzrlib.patiencediff.unified_diff_files
         psm = self._PatienceSequenceMatcher
-        self.assertEquals(['--- a1 \n',
-                           '+++ b1 \n',
+        self.assertEquals(['--- a1\n',
+                           '+++ b1\n',
                            '@@ -1,3 +1,2 @@\n',
                            ' hello there\n',
                            '-world\n',
@@ -1190,8 +1211,8 @@
         open('b2', 'wb').writelines(txt_b)
 
         # This is the result with LongestCommonSubstring matching
-        self.assertEquals(['--- a2 \n',
-                           '+++ b2 \n',
+        self.assertEquals(['--- a2\n',
+                           '+++ b2\n',
                            '@@ -1,6 +1,11 @@\n',
                            ' a\n',
                            ' b\n',
@@ -1207,8 +1228,8 @@
                           , list(unified_diff_files('a2', 'b2')))
 
         # And the patience diff
-        self.assertEquals(['--- a2 \n',
-                           '+++ b2 \n',
+        self.assertEquals(['--- a2\n',
+                           '+++ b2\n',
                            '@@ -4,6 +4,11 @@\n',
                            ' d\n',
                            ' e\n',




More information about the bazaar-commits mailing list