Browse Source

Fall through unknown format to 'unified', fixed #18

Matthew Wang 11 years ago
parent
commit
2e49a7eb3f

+ 12
- 10
cdiff.py View File

377
 
377
 
378
     def is_hunk_meta(self, line):
378
     def is_hunk_meta(self, line):
379
         """Minimal valid hunk meta is like '@@ -1 +1 @@', note extra chars
379
         """Minimal valid hunk meta is like '@@ -1 +1 @@', note extra chars
380
-        might occur after the ending @@, e.g. in git log.  '## ' uaually
380
+        might occur after the ending @@, e.g. in git log.  '## ' usually
381
         indicates svn property changes in output from `svn log --diff`
381
         indicates svn property changes in output from `svn log --diff`
382
         """
382
         """
383
         return (line.startswith('@@ -') and line.find(' @@') >= 8) or \
383
         return (line.startswith('@@ -') and line.find(' @@') >= 8) or \
484
                           header[3].startswith('*** ') and
484
                           header[3].startswith('*** ') and
485
                           header[3].rstrip().endswith(' ****')):
485
                           header[3].rstrip().endswith(' ****')):
486
             self._type = 'context'
486
             self._type = 'context'
487
+
488
+            # For context diff, try use `filterdiff` to translate it to unified
489
+            # format and provide a new stream
490
+            #
491
+            # TODO
492
+
487
             return
493
             return
488
 
494
 
489
         for n in range(size):
495
         for n in range(size):
492
                 self._type = 'unified'
498
                 self._type = 'unified'
493
                 break
499
                 break
494
         else:
500
         else:
495
-            if size < 5:
496
-                # It's safe to consider as udiff if patch stream contains no
497
-                # more than 4 lines. happens with `git diff` on a file that
498
-                # only has perm bits changes or `svn diff` with property
499
-                # changes.
500
-                #
501
-                self._type = 'unified'
502
-            else:
503
-                raise RuntimeError('unknown diff type')
501
+            # `filterdiff` translate unknown diff to nothing, fall through to
502
+            # unified diff give cdiff a chance to show everything as headers
503
+            #
504
+            sys.stderr.write("*** unknown format, fall through to 'unified'\n")
505
+            self._type = 'unified'
504
 
506
 
505
     def get_diff_generator(self):
507
     def get_diff_generator(self):
506
         """parse all diff lines, construct a list of Diff objects"""
508
         """parse all diff lines, construct a list of Diff objects"""

+ 6
- 3
tests/git-perm/in.diff View File

1
-diff --git a/CHANGES b/CHANGES
2
-old mode 100644
3
-new mode 100755
1
+diff --git a/cdiff b/cdiff
2
+old mode 100755
3
+new mode 100644
4
+diff --git a/cdiff.py b/cdiff.py
5
+old mode 100755
6
+new mode 100644

+ 6
- 3
tests/git-perm/out.normal View File

1
-diff --git a/CHANGES b/CHANGES
2
-old mode 100644
3
-new mode 100755
1
+diff --git a/cdiff b/cdiff
2
+old mode 100755
3
+new mode 100644
4
+diff --git a/cdiff.py b/cdiff.py
5
+old mode 100755
6
+new mode 100644
4
 
7
 

+ 6
- 3
tests/git-perm/out.side-by-side View File

1
-diff --git a/CHANGES b/CHANGES
2
-old mode 100644
3
-new mode 100755
1
+diff --git a/cdiff b/cdiff
2
+old mode 100755
3
+new mode 100644
4
+diff --git a/cdiff.py b/cdiff.py
5
+old mode 100755
6
+new mode 100644
4
 
7
 

+ 6
- 3
tests/git-perm/out.w70 View File

1
-diff --git a/CHANGES b/CHANGES
2
-old mode 100644
3
-new mode 100755
1
+diff --git a/cdiff b/cdiff
2
+old mode 100755
3
+new mode 100644
4
+diff --git a/cdiff.py b/cdiff.py
5
+old mode 100755
6
+new mode 100644
4
 
7
 

+ 1
- 1
tests/regression.sh View File

33
     local cdiff_opt=${3:-""}
33
     local cdiff_opt=${3:-""}
34
     local cmd
34
     local cmd
35
 
35
 
36
-    cmd=$(printf "%-8s $CDIFF %-18s < %-25s " $PYTHON "$cdiff_opt" "$input")
36
+    cmd=$(printf "%-8s $CDIFF %-18s <  %-30s " $PYTHON "$cdiff_opt" "$input")
37
     printf "$cmd"
37
     printf "$cmd"
38
     if eval $cmd 2>/dev/null | diff -ubq $expected_out - >& /dev/null; then
38
     if eval $cmd 2>/dev/null | diff -ubq $expected_out - >& /dev/null; then
39
         pass
39
         pass

+ 2
- 1
tests/test_cdiff.py View File

460
 """
460
 """
461
         items = patch.splitlines(True)
461
         items = patch.splitlines(True)
462
         stream = cdiff.PatchStream(Sequential(items))
462
         stream = cdiff.PatchStream(Sequential(items))
463
-        self.assertRaises(RuntimeError, cdiff.DiffParser, stream)
463
+        parser = cdiff.DiffParser(stream)
464
+        self.assertEqual(parser._type, 'unified')
464
 
465
 
465
     def test_parse_invalid_hunk_meta(self):
466
     def test_parse_invalid_hunk_meta(self):
466
         patch = """\
467
         patch = """\