Procházet zdrojové kódy

golden version; handle git log output; update README

Matthew Wang před 11 roky
rodič
revize
00bd330f7c
2 změnil soubory, kde provedl 36 přidání a 3 odebrání
  1. 31
    2
      README.md
  2. 5
    1
      src/cdiff.py

+ 31
- 2
README.md Zobrazit soubor

1
 ## About
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
 ## Usage
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 Zobrazit soubor

330
         hunk = None
330
         hunk = None
331
 
331
 
332
         while stream:
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
                 if headers and old_path:
338
                 if headers and old_path:
335
                     # Encounter a new header
339
                     # Encounter a new header
336
                     assert new_path is not None
340
                     assert new_path is not None