Browse Source

Merge branch 'old-new-path-recogonize'

Matthew Wang 9 years ago
parent
commit
40a2c47d02
5 changed files with 90 additions and 9 deletions
  1. 23
    9
      cdiff.py
  2. 18
    0
      tests/evil-udiff/in.diff
  3. 19
    0
      tests/evil-udiff/out.normal
  4. 15
    0
      tests/evil-udiff/out.side-by-side
  5. 15
    0
      tests/evil-udiff/out.w70

+ 23
- 9
cdiff.py View File

132
                 out.append(line)
132
                 out.append(line)
133
         return out
133
         return out
134
 
134
 
135
+    def is_completed(self):
136
+        old_completed = self._old_addr[1] == len(self._get_old_text())
137
+        new_completed = self._new_addr[1] == len(self._get_new_text())
138
+        return old_completed and new_completed
139
+
135
 
140
 
136
 class UnifiedDiff(object):
141
 class UnifiedDiff(object):
137
 
142
 
162
             old_addr = (int(a[0][1:]), int(a[1]))
167
             old_addr = (int(a[0][1:]), int(a[1]))
163
         else:
168
         else:
164
             # @@ -1 +1,2 @@
169
             # @@ -1 +1,2 @@
165
-            old_addr = (int(a[0][1:]), 0)
170
+            old_addr = (int(a[0][1:]), 1)
166
 
171
 
167
         b = hunk_meta.split()[2].split(',')   # +3 6
172
         b = hunk_meta.split()[2].split(',')   # +3 6
168
         if len(b) > 1:
173
         if len(b) > 1:
169
             new_addr = (int(b[0][1:]), int(b[1]))
174
             new_addr = (int(b[0][1:]), int(b[1]))
170
         else:
175
         else:
171
             # @@ -0,0 +1 @@
176
             # @@ -0,0 +1 @@
172
-            new_addr = (int(b[0][1:]), 0)
177
+            new_addr = (int(b[0][1:]), 1)
173
 
178
 
174
         return (old_addr, new_addr)
179
         return (old_addr, new_addr)
175
 
180
 
321
             line = decode(line)
326
             line = decode(line)
322
 
327
 
323
             if diff.is_old_path(line):
328
             if diff.is_old_path(line):
324
-                # FIXME: '--- ' breaks here, better to probe next line
325
-                if diff._old_path and diff._new_path and diff._hunks:
326
-                    # See a new diff, yield previous diff if exists
327
-                    yield diff
328
-                diff = UnifiedDiff(headers, line, None, [])
329
-                headers = []
329
+                # This is a new diff when current hunk is not yet genreated or
330
+                # is completed.  We yield previous diff if exists and construct
331
+                # a new one for this case.  Otherwise it's acutally an 'old'
332
+                # line starts with '--- '.
333
+                #
334
+                if (not diff._hunks or diff._hunks[-1].is_completed()):
335
+                    if diff._old_path and diff._new_path and diff._hunks:
336
+                        yield diff
337
+                    diff = UnifiedDiff(headers, line, None, [])
338
+                    headers = []
339
+                else:
340
+                    diff._hunks[-1].append(diff.parse_hunk_line(line))
330
 
341
 
331
             elif diff.is_new_path(line) and diff._old_path:
342
             elif diff.is_new_path(line) and diff._old_path:
332
-                diff._new_path = line
343
+                if not diff._new_path:
344
+                    diff._new_path = line
345
+                else:
346
+                    diff._hunks[-1].append(diff.parse_hunk_line(line))
333
 
347
 
334
             elif diff.is_hunk_meta(line):
348
             elif diff.is_hunk_meta(line):
335
                 hunk_meta = line
349
                 hunk_meta = line

+ 18
- 0
tests/evil-udiff/in.diff View File

1
+--- evil.orig   2013-06-01 16:36:29.676003599 -0500
2
++++ evil.new    2013-06-01 16:36:28.280056137 -0500
3
+@@ -1,12 +1,12 @@
4
+ blah blah blah
5
+-humbug
6
++bah humbug
7
+ one two three
8
+ four five six
9
+--- vim73/src/ui.c      2013-06-01 14:48:45.012467754 -0500
10
++++ vim73/src/ui.c      2013-06-01 14:48:45.012467754 -0500
11
+ @@ -1,6 +1,6 @@
12
+ blah blah blah
13
+ humbug
14
+ one two three
15
+ four five six
16
+-eight nine ten
17
++seven eight nine ten
18
+ zero

+ 19
- 0
tests/evil-udiff/out.normal View File

1
+--- evil.orig   2013-06-01 16:36:29.676003599 -0500
2
++++ evil.new    2013-06-01 16:36:28.280056137 -0500
3
+@@ -1,12 +1,12 @@
4
+ blah blah blah
5
+-humbug
6
++bah humbug
7
+ one two three
8
+ four five six
9
+--- vim73/src/ui.c      2013-06-01 14:48:45.012467754 -0500
10
++++ vim73/src/ui.c      2013-06-01 14:48:45.012467754 -0500
11
+ @@ -1,6 +1,6 @@
12
+ blah blah blah
13
+ humbug
14
+ one two three
15
+ four five six
16
+-eight nine ten
17
++seven eight nine ten
18
+ zero
19
+

+ 15
- 0
tests/evil-udiff/out.side-by-side View File

1
+--- evil.orig   2013-06-01 16:36:29.676003599 -0500
2
++++ evil.new    2013-06-01 16:36:28.280056137 -0500
3
+@@ -1,12 +1,12 @@
4
+ 1 blah blah blah                                                                    1 blah blah blah
5
+ 2 humbug                                                                            2 bah humbug
6
+ 3 one two three                                                                     3 one two three
7
+ 4 four five six                                                                     4 four five six
8
+ 5 -- vim73/src/ui.c      2013-06-01 14:48:45.012467754 -0500                        5 ++ vim73/src/ui.c      2013-06-01 14:48:45.012467754 -0500
9
+ 6 @@ -1,6 +1,6 @@                                                                   6 @@ -1,6 +1,6 @@
10
+ 7 blah blah blah                                                                    7 blah blah blah
11
+ 8 humbug                                                                            8 humbug
12
+ 9 one two three                                                                     9 one two three
13
+10 four five six                                                                    10 four five six
14
+11 eight nine ten                                                                   11 seven eight nine ten
15
+12 zero                                                                             12 zero

+ 15
- 0
tests/evil-udiff/out.w70 View File

1
+--- evil.orig   2013-06-01 16:36:29.676003599 -0500
2
++++ evil.new    2013-06-01 16:36:28.280056137 -0500
3
+@@ -1,12 +1,12 @@
4
+ 1 blah blah blah                                                          1 blah blah blah
5
+ 2 humbug                                                                  2 bah humbug
6
+ 3 one two three                                                           3 one two three
7
+ 4 four five six                                                           4 four five six
8
+ 5 -- vim73/src/ui.c      2013-06-01 14:48:45.012467754 -0500              5 ++ vim73/src/ui.c      2013-06-01 14:48:45.012467754 -0500
9
+ 6 @@ -1,6 +1,6 @@                                                         6 @@ -1,6 +1,6 @@
10
+ 7 blah blah blah                                                          7 blah blah blah
11
+ 8 humbug                                                                  8 humbug
12
+ 9 one two three                                                           9 one two three
13
+10 four five six                                                          10 four five six
14
+11 eight nine ten                                                         11 seven eight nine ten
15
+12 zero                                                                   12 zero