Browse Source

golden version; handle git log output; update README

Matthew Wang 11 years ago
parent
commit
00bd330f7c
2 changed files with 36 additions and 3 deletions
  1. 31
    2
      README.md
  2. 5
    1
      src/cdiff.py

+ 31
- 2
README.md View File

@@ -1,7 +1,36 @@
1 1
 ## About
2 2
 
3
-Diff viewer.
3
+Diff viewer, side-by-side, auto pager with `less`.
4 4
 
5
+## Install
6
+
7
+Just download the `src/cdiff.py` and save to whatever directory which in your
8
+`$PATH`, for example, `$HOME/bin` is in my `$PATH`, so I save the script there
9
+and name as `cdiff`.
10
+
11
+    curl -ksS https://raw.github.com/ymattw/cdiff/master/src/cdiff.py > ~/bin/cdiff
12
+    
5 13
 ## Usage
14
+    
15
+Read diff from svn, use option `-s` for side-by-side view, use option `-w` to
16
+use text width other than default `80`.  You don't need `less`, it's automatic:
17
+
18
+    svn diff | cdiff
19
+    svn diff | cdiff -s
20
+    svn diff | cdiff -s -w 90
21
+    
22
+Read diff from git:
23
+
24
+    git diff | cdiff -s
25
+    git log -p -2 | cdiff -s
26
+    git show <commit> | cdiff -s
27
+
28
+View a diff (patch) file:
29
+
30
+    cdiff foo.patch
31
+    cdiff foo.patch -s
32
+    cdiff foo.patch -s -w 90
33
+
34
+Redirect output to another patch file is safe:
6 35
 
7
-TODO
36
+    svn diff | cdiff -s > my.patch

+ 5
- 1
src/cdiff.py View File

@@ -330,7 +330,11 @@ class DiffParser(object):
330 330
         hunk = None
331 331
 
332 332
         while stream:
333
-            if Udiff.is_header(stream[0]):
333
+            # 'common' line occurs before 'old_path' is considered as header
334
+            # too, this happens with `git log -p` and `git show <commit>`
335
+            #
336
+            if Udiff.is_header(stream[0]) or \
337
+                    (Udiff.is_common(stream[0]) and old_path is None):
334 338
                 if headers and old_path:
335 339
                     # Encounter a new header
336 340
                     assert new_path is not None