Permalink
Browse files

document update; images

  • Loading branch information...
ymattw committed Feb 1, 2013
1 parent 00bd330 commit f362c08766ea25ad4ff653c62f2a4ce234ba3389
Showing with 110 additions and 166 deletions.
  1. +7 −10 Makefile
  2. +25 −12 README.md
  3. BIN img/default.png
  4. BIN img/side-by-side.png
  5. +47 −0 tests/git.diff
  6. +0 −30 tests/multi.udiff
  7. +0 −114 tests/single.udiff
  8. +31 −0 tests/svn.diff
View
@@ -1,21 +1,18 @@
# Makefile for testing
-.PHONY: dogfood test single-udiff multi-udiff
+.PHONY: dogfood test git svn
dogfood:
git diff | src/cdiff.py
git diff | src/cdiff.py -s
git diff | src/cdiff.py -s -w 60
- git diff | src/cdiff.py -s -w 100
+ git diff | src/cdiff.py -s -w 90
-test: single-udiff multi-udiff
+test: git svn
-single-udiff:
- src/cdiff.py tests/single.udiff
- src/cdiff.py tests/single.udiff | diff -u tests/single.udiff -
-
-multi-udiff:
- src/cdiff.py tests/multi.udiff
- src/cdiff.py tests/multi.udiff | diff -u tests/multi.udiff -
+git svn:
+ src/cdiff.py tests/$@.diff
+ src/cdiff.py tests/$@.diff -s
+ src/cdiff.py tests/$@.diff | diff -u tests/$@.diff -
# vim:set noet ts=8 sw=8:
View
@@ -1,19 +1,33 @@
## About
-Diff viewer, side-by-side, auto pager with `less`.
+View **colored** diff in unified-diff format or **side-by-side** with **auto
+pager**. Requires Python (>= 2.5.0) and `less`.
+
+![Default](img/default.png)
+![Side-by-side](img/side-by-side.png)
## Install
-Just download the `src/cdiff.py` and save to whatever directory which in your
-`$PATH`, for example, `$HOME/bin` is in my `$PATH`, so I save the script there
-and name as `cdiff`.
+Save [src/cdiff.py](https://raw.github.com/ymattw/cdiff/master/src/cdiff.py) to
+whatever directory which is in your `$PATH`, for example, `$HOME/bin` is in my
+`$PATH`, so I save the script there and name as `cdiff`.
curl -ksS https://raw.github.com/ymattw/cdiff/master/src/cdiff.py > ~/bin/cdiff
+ chmod +x ~/bin/cdiff
## Usage
-Read diff from svn, use option `-s` for side-by-side view, use option `-w` to
-use text width other than default `80`. You don't need `less`, it's automatic:
+Just give it a diff (patch) file or pipe a diff to it. Use option `-s` for
+side-by-side view, and option `-w` to use text width other than default `80`.
+See examples below
+
+View a diff (patch) file:
+
+ cdiff foo.patch # view colored udiff
+ cdiff foo.patch -s # side-by-side
+ cdiff foo.patch -s -w 90 # use text width 90 other than default 80
+
+Read diff from svn:
svn diff | cdiff
svn diff | cdiff -s
@@ -25,12 +39,11 @@ Read diff from git:
git log -p -2 | cdiff -s
git show <commit> | cdiff -s
-View a diff (patch) file:
-
- cdiff foo.patch
- cdiff foo.patch -s
- cdiff foo.patch -s -w 90
-
Redirect output to another patch file is safe:
svn diff | cdiff -s > my.patch
+
+## Known issue
+
+- Only support unified format for input diff
+- Side-by-side mode has alignment problem for wide chars
View
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,47 @@
+commit 15bfa564b9db08fb277a343a3d0a01d377800606
+Author: Matthew Wang <XXXXXXX@gmail.com>
+Date: Thu Jan 31 15:27:17 2013 +0800
+
+ Default width is now 80
+
+diff --git a/src/cdiff.py b/src/cdiff.py
+index 13f725f..bf15ef1 100755
+--- a/src/cdiff.py
++++ b/src/cdiff.py
+@@ -128,9 +128,7 @@ class Diff(object):
+ yield self._markup_common(' ' + old[1])
+
+ def markup_side_by_side(self, width):
+- """width of 0 means infinite width, None means auto detect. Returns a
+- generator
+- """
++ """Returns a generator"""
+ def _normalize(line):
+ return line.replace('\t', ' ' * 8).replace('\n', '')
+
+@@ -147,7 +145,8 @@ class Diff(object):
+ return markup
+
+ # Setup line width and number width
+- if not width: width = 80
++ if width <= 0:
++ width = 80
+ (start, offset) = self._hunks[-1].get_old_addr()
+ max1 = start + offset - 1
+ (start, offset) = self._hunks[-1].get_new_addr()
+@@ -430,13 +429,10 @@ if __name__ == '__main__':
+ parser = optparse.OptionParser(usage)
+ parser.add_option('-s', '--side-by-side', action='store_true',
+ help=('show in side-by-side mode'))
+- parser.add_option('-w', '--width', type='int', default=None,
+- help='set line width (side-by-side mode only)')
++ parser.add_option('-w', '--width', type='int', default=80,
++ help='set line width (side-by-side mode only), default is 80')
+ opts, args = parser.parse_args()
+
+- if opts.width and opts.width < 0:
+- opts.width = 0
+-
+ if len(args) >= 1:
+ diff_hdl = open(args[0], 'r')
+ elif sys.stdin.isatty():
View
@@ -1,30 +0,0 @@
-diff --git a/Makefile b/Makefile
-index 2dc65aa..4d698fc 100644
---- a/Makefile
-+++ b/Makefile
-@@ -2,9 +2,12 @@
-
- .PHONY: test single
-
--test: single
-+test: single multi
-
- single:
- src/diffview.py -t tests/single.diff
-
-+multi:
-+ src/diffview.py -t tests/multi.diff
-+
- # vim:set noet ts=8 sw=8:
-diff --git a/README.md b/README.md
-index 39b5c84..1da3039 100644
---- a/README.md
-+++ b/README.md
-@@ -1,3 +1,7 @@
- ## About
-
-+Diff viewer.
-+
- ## Usage
-+
-+TODO
View
@@ -1,114 +0,0 @@
-diff --git a/src/cdiff.py b/src/cdiff.py
-index 1db7807..c17032f 100755
---- a/src/cdiff.py
-+++ b/src/cdiff.py
-@@ -17,7 +17,7 @@ COLORS = {
- 'lightred' : '\x1b[1;31m',
- 'lightgreen' : '\x1b[1;32m',
- 'lightyellow' : '\x1b[1;33m',
-- 'lightblue ' : '\x1b[1;34m',
-+ 'lightblue' : '\x1b[1;34m',
- 'lightmagenta' : '\x1b[1;35m',
- 'lightcyan' : '\x1b[1;36m',
- }
-@@ -31,23 +31,13 @@ def colorize(text, start_color, end_color='reset'):
-
- class Hunk(object):
-
-- def __init__(self, hunk_header, old_addr, old_offset, new_addr, new_offset):
-+ def __init__(self, hunk_header):
- self._hunk_header = hunk_header
-- self._old_addr = old_addr
-- self._old_offset = old_offset
-- self._new_addr = new_addr
-- self._new_offset = new_offset
- self._hunk_list = [] # 2-element group (attr, line)
-
- def get_header(self):
- return self._hunk_header
-
-- def get_old_addr(self):
-- return (self._old_addr, self._old_offset)
--
-- def get_new_addr(self):
-- return (self._new_addr, self._new_offset)
--
- def append(self, attr, line):
- """attr: '-': old, '+': new, ' ': common"""
- self._hunk_list.append((attr, line))
-@@ -117,10 +107,10 @@ class Diff(object):
- line = from_info[1].strip('\x00\x01')
- out.append(self._markup_old(line))
- else:
-- out.append(self._markup_old('-' +
-- self._markup_old_mix(from_info[1])))
-- out.append(self._markup_new('+' +
-- self._markup_new_mix(to_info[1])))
-+ out.append(self._markup_old('-') +
-+ self._markup_old_mix(from_info[1]))
-+ out.append(self._markup_new('+') +
-+ self._markup_new_mix(to_info[1]))
- else:
- out.append(self._markup_common(' ' + from_info[1]))
- return ''.join(out)
-@@ -139,7 +129,7 @@ class Diff(object):
- return colorize(line, 'yellow')
-
- def _markup_hunk_header(self, line):
-- return colorize(line, 'blue')
-+ return colorize(line, 'lightblue')
-
- def _markup_common(self, line):
- return colorize(line, 'reset')
-@@ -150,18 +140,20 @@ class Diff(object):
- def _markup_new(self, line):
- return colorize(line, 'lightgreen')
-
-- def _markup_mix(self, line, end_color):
-- line = line.replace('\x00-', ansi_code('red'))
-- line = line.replace('\x00+', ansi_code('green'))
-- line = line.replace('\x00^', ansi_code('lightyellow'))
-- line = line.replace('\x01', ansi_code(end_color))
-- return colorize(line, end_color)
-+ def _markup_mix(self, line, base_color, del_color, add_color, chg_color):
-+ line = line.replace('\x00-', ansi_code(del_color))
-+ line = line.replace('\x00+', ansi_code(add_color))
-+ line = line.replace('\x00^', ansi_code(chg_color))
-+ line = line.replace('\x01', ansi_code(base_color))
-+ return colorize(line, base_color)
-
- def _markup_old_mix(self, line):
-- return self._markup_mix(line, 'red')
-+ return self._markup_mix(line, 'cyan', 'lightred', 'lightgreen',
-+ 'yellow')
-
- def _markup_new_mix(self, line):
-- return self._markup_mix(line, 'green')
-+ return self._markup_mix(line, 'lightcyan', 'lightred', 'lightgreen',
-+ 'lightyellow')
-
-
- class Udiff(Diff):
-@@ -278,21 +270,7 @@ class DiffParser(object):
- hunks.append(hunk)
- hunk = None
- else:
-- # @@ -3,7 +3,6 @@
-- hunk_header = stream.pop(0)
--
-- addr_info = hunk_header.split()[1]
-- assert addr_info.startswith('-')
-- old_addr = addr_info.split(',')[0]
-- old_offset = addr_info.split(',')[1]
--
-- addr_info = hunk_header.split()[2]
-- assert addr_info.startswith('+')
-- new_addr = addr_info.split(',')[0]
-- new_offset = addr_info.split(',')[1]
--
-- hunk = Hunk(hunk_header, old_addr, old_offset, new_addr,
-- new_offset)
-+ hunk = Hunk(stream.pop(0))
-
- elif Udiff.is_old(stream[0]) or Udiff.is_new(stream[0]) or \
- Udiff.is_common(stream[0]):
View
@@ -0,0 +1,31 @@
+Index: README.md
+===================================================================
+--- README.md (revision 41)
++++ README.md (working copy)
+@@ -3,7 +3,6 @@
+ ## About
+
+ Coderev is a toolkit generates static side-by-side html pages for code review.
+-Typical use case is to generate diff pages for local modification in svn/cvs
+ workspace and send page link to teammates for code review.
+
+ See [joyus.org/pub/coderev-demo](http://joyus.org/pub/coderev-demo) for a demo.
+@@ -18,9 +17,10 @@
+
+ ## Usage of coderev.sh
+
+-Just type `./coderev.sh -h` to see the usage.
++Just type `./coderev.sh --help` to see the usage.
+
+ Usage:
++
+ coderev.sh [-r revision] [-w width] [-o outdir] [-y] [-d name] \
+ [-F comment-file | -m 'comment...'] [file...]
+
+@@ -145,3 +145,5 @@
+ specify column number where lines are broken and
+ wrapped for sdiff, default is no line wrapping
+ -y, --yes do not prompt for overwriting
++
++# EOF
+\ No newline at end of file

0 comments on commit f362c08

Please sign in to comment.