Skip to content

Commit

Permalink
document update; images
Browse files Browse the repository at this point in the history
  • Loading branch information
ymattw committed Feb 1, 2013
1 parent 00bd330 commit f362c08
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 166 deletions.
17 changes: 7 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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:
37 changes: 25 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Binary file added img/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/side-by-side.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions tests/git.diff
Original file line number Diff line number Diff line change
@@ -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():
30 changes: 0 additions & 30 deletions tests/multi.udiff

This file was deleted.

114 changes: 0 additions & 114 deletions tests/single.udiff

This file was deleted.

31 changes: 31 additions & 0 deletions tests/svn.diff
Original file line number Diff line number Diff line change
@@ -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.