Browse Source

Rename to ydiff (version 1.1)

Matt Wang 5 years ago
parent
commit
ba7dea407c
11 changed files with 176 additions and 160 deletions
  1. 6
    0
      CHANGES.rst
  2. 3
    3
      LICENSE
  3. 9
    9
      Makefile
  4. 55
    55
      README.rst
  5. 5
    5
      setup.py
  6. 4
    4
      tests/README
  7. 3
    3
      tests/profile.sh
  8. 3
    3
      tests/regression.sh
  9. 67
    67
      tests/test_ydiff.py
  10. 2
    2
      ydiff
  11. 19
    9
      ydiff.py

+ 6
- 0
CHANGES.rst View File

@@ -2,6 +2,12 @@
2 2
 Change log
3 3
 ==========
4 4
 
5
+Version 1.1 (2018-06-05)
6
+
7
+  - Rename from ``cdiff`` to ``ydiff`` to avoid binary name conflict on major
8
+    distributions, ``CDIFF_OPTIONS`` still works but will be deprepated soon
9
+  - New option ``--wrap`` to wrap long lines in side-by-side view
10
+
5 11
 Version 1.0 (2016-12-31)
6 12
 
7 13
   - Use environment variable ``CDIFF_OPTIONS`` to hold default options

+ 3
- 3
LICENSE View File

@@ -1,6 +1,6 @@
1 1
 Software License Agreement (BSD-3 License)
2 2
 
3
-Copyright (c) 2013, Matthew Wang <mattwyl(@)gmail(.)com>
3
+Copyright (c) 2013-2018, Matt Wang <mattwyl(@)gmail(.)com>
4 4
 All rights reserved.
5 5
 
6 6
 Redistribution and use in source and binary forms, with or without modification,
@@ -8,12 +8,12 @@ are permitted provided that the following conditions are met:
8 8
 
9 9
     1. Redistributions of source code must retain the above copyright notice,
10 10
        this list of conditions and the following disclaimer.
11
-    
11
+
12 12
     2. Redistributions in binary form must reproduce the above copyright notice,
13 13
        this list of conditions and the following disclaimer in the documentation
14 14
        and/or other materials provided with the distribution.
15 15
 
16
-    3. Neither the name of cdiff nor the names of its contributors may be used
16
+    3. Neither the name of ydiff nor the names of its contributors may be used
17 17
        to endorse or promote products derived from this software without
18 18
        specific prior written permission.
19 19
 

+ 9
- 9
Makefile View File

@@ -7,8 +7,8 @@ PYPI = pypi
7 7
 	test test3 cov cov3 html reg reg3 profile profile3
8 8
 
9 9
 dogfood:
10
-	./cdiff.py
11
-	git diff | ./cdiff.py -s
10
+	./ydiff.py
11
+	git diff | ./ydiff.py -s
12 12
 
13 13
 lint:
14 14
 	pep8 --ignore=E203 *.py tests/*.py
@@ -27,11 +27,11 @@ test: lint doc-check cov reg
27 27
 test3: lint doc-check cov3 reg3
28 28
 
29 29
 cov:
30
-	coverage run tests/test_cdiff.py
30
+	coverage run tests/test_ydiff.py
31 31
 	coverage report --show-missing
32 32
 
33 33
 cov3:
34
-	python3 `which coverage` run tests/test_cdiff.py
34
+	python3 `which coverage` run tests/test_ydiff.py
35 35
 	python3 `which coverage` report --show-missing
36 36
 
37 37
 html:
@@ -52,17 +52,17 @@ profile3:
52 52
 
53 53
 clean:
54 54
 	rm -f MANIFEST profile*.tmp* .coverage
55
-	rm -rf build/ cdiff.egg-info/ dist/ __pycache__/ htmlcov/
55
+	rm -rf build/ ydiff.egg-info/ dist/ __pycache__/ htmlcov/
56 56
 
57 57
 build:
58 58
 	./setup.py build sdist
59 59
 
60
-dist-test:
61
-	./setup.py build sdist register upload -r $(TESTPYPI)
60
+dist-test: clean build
61
+	twine upload --repository-url https://test.pypi.org/legacy/ dist/*
62 62
 	rm -f ~/.pypirc
63 63
 
64
-dist:
65
-	./setup.py build sdist register upload -r $(PYPI)
64
+dist: clean build
65
+	twine upload dist/*
66 66
 	rm -f ~/.pypirc
67 67
 
68 68
 # vim:set noet ts=8 sw=8:

+ 55
- 55
README.rst View File

@@ -1,19 +1,19 @@
1
-Cdiff
1
+Ydiff
2 2
 =====
3 3
 
4
-.. image:: https://travis-ci.org/ymattw/cdiff.png?branch=master
5
-   :target: https://travis-ci.org/ymattw/cdiff
4
+.. image:: https://travis-ci.org/ymattw/ydiff.png?branch=master
5
+   :target: https://travis-ci.org/ymattw/ydiff
6 6
    :alt: Build status
7 7
 
8 8
 Term based tool to view *colored*, *incremental* diff in a *Git/Mercurial/Svn*
9
-workspace or from stdin, with *side by side* and *auto pager* support. Requires
10
-python (>= 2.5.0) and ``less``.
9
+workspace or from stdin, with *side by side* (similar to ``diff -y``) and *auto
10
+pager* support. Requires python (>= 2.5.0) and ``less``.
11 11
 
12
-.. image:: https://raw.github.com/ymattw/cdiff/gh-pages/img/default.png
12
+.. image:: https://raw.github.com/ymattw/ydiff/gh-pages/img/default.png
13 13
    :alt: default
14 14
    :align: center
15 15
 
16
-.. image:: https://raw.github.com/ymattw/cdiff/gh-pages/img/side-by-side.png
16
+.. image:: https://raw.github.com/ymattw/ydiff/gh-pages/img/side-by-side.png
17 17
    :alt: side by side
18 18
    :align: center
19 19
    :width: 900 px
@@ -24,14 +24,14 @@ Installation
24 24
 Install with pip
25 25
 ~~~~~~~~~~~~~~~~
26 26
 
27
-Cdiff is already listed on `PyPI`_, you can install with ``pip`` if you have
27
+Ydiff is already listed on `PyPI`_, you can install with ``pip`` if you have
28 28
 the tool.
29 29
 
30
-.. _PyPI: http://pypi.python.org/pypi/cdiff
30
+.. _PyPI: http://pypi.python.org/pypi/ydiff
31 31
 
32 32
 .. code-block:: bash
33 33
 
34
-    pip install --upgrade cdiff
34
+    pip install --upgrade ydiff
35 35
 
36 36
 Install with setup.py
37 37
 ~~~~~~~~~~~~~~~~~~~~~
@@ -40,8 +40,8 @@ You can also run the setup.py from the source if you don't have ``pip``.
40 40
 
41 41
 .. code-block:: bash
42 42
 
43
-    git clone https://github.com/ymattw/cdiff.git
44
-    cd cdiff
43
+    git clone https://github.com/ymattw/ydiff.git
44
+    cd ydiff
45 45
     ./setup.py install
46 46
 
47 47
 Install with Homebrew
@@ -55,33 +55,33 @@ You can also install with Homebrew on Mac. (Thanks to `@josa42`_,
55 55
 .. _`@bfontaine`: https://github.com/bfontaine
56 56
 .. _`@hivehand`: https://github.com/hivehand
57 57
 .. _`@nijikon`: https://github.com/nijikon
58
-.. _`Formula`: https://github.com/Homebrew/homebrew-core/blob/master/Formula/cdiff.rb
58
+.. _`Formula`: https://github.com/Homebrew/homebrew-core/blob/master/Formula/ydiff.rb
59 59
 
60 60
 .. code-block:: bash
61 61
 
62
-    brew install cdiff
62
+    brew install ydiff
63 63
 
64 64
 Download directly
65 65
 ~~~~~~~~~~~~~~~~~
66 66
 
67
-Just save `cdiff.py`_ to whatever directory which is in your ``$PATH``, for
67
+Just save `ydiff.py`_ to whatever directory which is in your ``$PATH``, for
68 68
 example, ``$HOME/bin`` is in my ``$PATH``, so I save the script there and name
69
-as ``cdiff``.
69
+as ``ydiff``.
70 70
 
71
-.. _`cdiff.py`: https://raw.github.com/ymattw/cdiff/master/cdiff.py
71
+.. _`ydiff.py`: https://raw.github.com/ymattw/ydiff/master/ydiff.py
72 72
 
73 73
 .. code-block:: bash
74 74
 
75
-    curl -ksSL https://raw.github.com/ymattw/cdiff/master/cdiff.py > ~/bin/cdiff
76
-    chmod +x ~/bin/cdiff
75
+    curl -ksSL https://raw.github.com/ymattw/ydiff/master/ydiff.py > ~/bin/ydiff
76
+    chmod +x ~/bin/ydiff
77 77
 
78 78
 Usage
79 79
 -----
80 80
 
81
-Type ``cdiff -h`` to show usage::
81
+Type ``ydiff -h`` to show usage::
82 82
 
83
-    $ cdiff -h
84
-    Usage: cdiff [options] [file|dir ...]
83
+    $ ydiff -h
84
+    Usage: ydiff [options] [file|dir ...]
85 85
 
86 86
     View colored, incremental diff in a workspace or from stdin, with side by side
87 87
     and auto pager support
@@ -99,7 +99,7 @@ Type ``cdiff -h`` to show usage::
99 99
 
100 100
       Note:
101 101
         Option parser will stop on first unknown option and pass them down to
102
-        underneath revision control. Environment variable CDIFF_OPTIONS may be
102
+        underneath revision control. Environment variable YDIFF_OPTIONS may be
103 103
         used to specify default options that will be placed at the beginning
104 104
         of the argument list.
105 105
 
@@ -109,16 +109,16 @@ from e.g. ``git diff``, ``svn diff``):
109 109
 .. code-block:: bash
110 110
 
111 111
     cd proj-workspace
112
-    cdiff                         # view colored incremental diff
113
-    cdiff -s                      # view side by side, use default text width 80
114
-    cdiff -s -w 90                # use text width 90 other than default 80
115
-    cdiff -s -w 0                 # auto set text width based on terminal size
116
-    cdiff -s -w 0 --wrap          # same as before, but also wrap long lines
117
-    cdiff -s file1 dir2           # view modification of given files/dirs only
118
-    cdiff -s -w90 --wrap -- -U10  # pass '-U10' to underneath revision diff tool
119
-    cdiff -s -w90 --wrap -U10     # '--' is optional as it's unknown to cdiff
120
-    cdiff -s --cached             # show git staged diff (git diff --cached)
121
-    cdiff -s -r1234               # show svn diff to revision 1234
112
+    ydiff                         # view colored incremental diff
113
+    ydiff -s                      # view side by side, use default text width 80
114
+    ydiff -s -w 90                # use text width 90 other than default 80
115
+    ydiff -s -w 0                 # auto set text width based on terminal size
116
+    ydiff -s -w 0 --wrap          # same as before, but also wrap long lines
117
+    ydiff -s file1 dir2           # view modification of given files/dirs only
118
+    ydiff -s -w90 --wrap -- -U10  # pass '-U10' to underneath revision diff tool
119
+    ydiff -s -w90 --wrap -U10     # '--' is optional as it's unknown to ydiff
120
+    ydiff -s --cached             # show git staged diff (git diff --cached)
121
+    ydiff -s -r1234               # show svn diff to revision 1234
122 122
 
123 123
 Read log with changes in a *Git/Mercurial/Svn* workspace (output from e.g.
124 124
 ``git log -p``, ``svn log --diff``), note *--diff* option is new in svn 1.7.0:
@@ -126,57 +126,57 @@ Read log with changes in a *Git/Mercurial/Svn* workspace (output from e.g.
126 126
 .. code-block:: bash
127 127
 
128 128
     cd proj-workspace
129
-    cdiff -l                    # read log along with changes
130
-    cdiff -ls                   # equivalent to cdiff -l -s, view side by side
131
-    cdiff -ls -w90 --wrap       # set text width 90 and enable wrapping as well
132
-    cdiff -ls file1 dir2        # see log with changes of given files/dirs only
129
+    ydiff -l                    # read log along with changes
130
+    ydiff -ls                   # equivalent to ydiff -l -s, view side by side
131
+    ydiff -ls -w90 --wrap       # set text width 90 and enable wrapping as well
132
+    ydiff -ls file1 dir2        # see log with changes of given files/dirs only
133 133
 
134
-Environment variable ``CDIFF_OPTIONS`` may be used to specify default options
134
+Environment variable ``YDIFF_OPTIONS`` may be used to specify default options
135 135
 that will be placed at the beginning of the argument list, for example:
136 136
 
137 137
 .. code-block:: bash
138 138
 
139
-    export CDIFF_OPTIONS='-s -w0 --wrap'
140
-    cdiff foo                   # equivalent to "cdiff -s -w0 --wrap foo"
139
+    export YDIFF_OPTIONS='-s -w0 --wrap'
140
+    ydiff foo                   # equivalent to "ydiff -s -w0 --wrap foo"
141 141
 
142
-If you feel more comfortable with a command such as ``git cdiff`` to trigger
143
-the cdiff command, you may symlink the executable to one named ``git-cdiff``
142
+If you feel more comfortable with a command such as ``git ydiff`` to trigger
143
+the ydiff command, you may symlink the executable to one named ``git-ydiff``
144 144
 as follows:
145 145
 
146 146
 .. code-block:: bash
147 147
 
148
-    cdiff_dir=$(dirname $(which cdiff))
149
-    ln -s "${cdiff_dir}/cdiff" "${cdiff_dir}/git-cdiff"
148
+    ydiff_dir=$(dirname $(which ydiff))
149
+    ln -s "${ydiff_dir}/ydiff" "${ydiff_dir}/git-ydiff"
150 150
 
151 151
 Pipe in a diff:
152 152
 
153 153
 .. code-block:: bash
154 154
 
155
-    git log -p -2 | cdiff       # view git log with changes of last 2 commits
156
-    git show 15bfa | cdiff -s   # view a given git commit, side by side
157
-    svn diff -r1234 | cdiff -s  # view svn diff comparing to given revision
158
-    diff -u file1 file2 | cdiff # view diff between two files (note the '-u')
159
-    diff -ur dir1 dir2 | cdiff  # view diff between two dirs
155
+    git log -p -2 | ydiff       # view git log with changes of last 2 commits
156
+    git show 15bfa | ydiff -s   # view a given git commit, side by side
157
+    svn diff -r1234 | ydiff -s  # view svn diff comparing to given revision
158
+    diff -u file1 file2 | ydiff # view diff between two files (note the '-u')
159
+    diff -ur dir1 dir2 | ydiff  # view diff between two dirs
160 160
 
161 161
     # View diff in a GitHub pull request, side by side
162
-    curl https://github.com/ymattw/cdiff/pull/11.diff | cdiff -s
162
+    curl https://github.com/ymattw/ydiff/pull/11.diff | ydiff -s
163 163
 
164 164
     # View a patch file in unified or context format, the latter depends on
165 165
     # command `filterdiff` from package `patchutils` which is available in
166 166
     # major Linux distros and MacPorts.
167 167
     #
168
-    cdiff -s < foo.patch
168
+    ydiff -s < foo.patch
169 169
 
170 170
 Redirect output to another patch file is safe:
171 171
 
172 172
 .. code-block:: bash
173 173
 
174
-    svn diff -r PREV | cdiff -s > my.patch
174
+    svn diff -r PREV | ydiff -s > my.patch
175 175
 
176 176
 Notes
177 177
 -----
178 178
 
179
-Cdiff has following known issues:
179
+Ydiff has following known issues:
180 180
 
181 181
 - Does not recognize `normal` diff, and depends on ``filterdiff`` (patchutils)
182 182
   to read `context` diff
@@ -188,14 +188,14 @@ tests and regression tests by run ``make test`` (required tool *coverage* can
188 188
 be installed with ``pip install coverage``).  Also watch out `travis build`_
189 189
 after push, make sure it passes as well.
190 190
 
191
-.. _`travis build`: https://travis-ci.org/ymattw/cdiff/pull_requests
191
+.. _`travis build`: https://travis-ci.org/ymattw/ydiff/pull_requests
192 192
 
193 193
 See also
194 194
 --------
195 195
 
196 196
 I have another tool `coderev`_ which generates side-by-side diff pages for code
197 197
 review from two given files or directories, I found it's not easy to extend to
198
-support git so invented `cdiff`.  Idea of ansi color markup is also from
198
+support git so invented `ydiff`.  Idea of ansi color markup is also from
199 199
 project `colordiff`_.
200 200
 
201 201
 .. _coderev: https://github.com/ymattw/coderev

+ 5
- 5
setup.py View File

@@ -4,7 +4,7 @@
4 4
 from __future__ import with_statement
5 5
 import sys
6 6
 from distutils.core import setup
7
-from cdiff import META_INFO as _meta
7
+from ydiff import META_INFO as _meta
8 8
 
9 9
 if sys.hexversion < 0x02050000:
10 10
     raise SystemExit("*** Requires python >= 2.5.0")
@@ -15,10 +15,10 @@ with open('CHANGES.rst') as changes:
15 15
     long_description += changes.read()
16 16
 
17 17
 setup(
18
-    name='cdiff',
18
+    name='ydiff',
19 19
     version=_meta['version'],
20 20
     author=_meta['author'],
21
-    author_email=_meta['email'],
21
+    author_email=_meta['email'].replace('(', '').replace(')', ''),
22 22
     license=_meta['license'],
23 23
     description=_meta['description'],
24 24
     long_description=long_description,
@@ -38,8 +38,8 @@ setup(
38 38
         'Programming Language :: Python :: 2',
39 39
         'Programming Language :: Python :: 3',
40 40
     ],
41
-    py_modules=['cdiff'],
42
-    scripts=['cdiff'],
41
+    py_modules=['ydiff'],
42
+    scripts=['ydiff'],
43 43
 )
44 44
 
45 45
 # vim:set et sts=4 sw=4 tw=79:

+ 4
- 4
tests/README View File

@@ -1,7 +1,7 @@
1 1
 # To generate expected output, chdir to a subdir and use following command, then
2 2
 # review with `less -R`
3 3
 #
4
-../../cdiff.py -c always < in.diff > out.normal
5
-../../cdiff.py -c always -s < in.diff > out.side-by-side
6
-../../cdiff.py -c always -s < in.diff -w70 > out.w70
7
-../../cdiff.py -c always -s < in.diff -w70 --wrap > out.w70.wrap
4
+../../ydiff.py -c always < in.diff > out.normal
5
+../../ydiff.py -c always -s < in.diff > out.side-by-side
6
+../../ydiff.py -c always -s < in.diff -w70 > out.w70
7
+../../ydiff.py -c always -s < in.diff -w70 --wrap > out.w70.wrap

+ 3
- 3
tests/profile.sh View File

@@ -3,7 +3,7 @@
3 3
 OUTPUT=${1:?"output file required"}
4 4
 
5 5
 SELF_DIR=$(cd $(dirname $0) && pwd) || exit 1
6
-CDIFF_PY=$SELF_DIR/../cdiff.py
6
+YDIFF_PY=$SELF_DIR/../ydiff.py
7 7
 
8 8
 # To test with py3k: PYTHON=python3 make test
9 9
 PYTHON=${PYTHON:-python}
@@ -12,11 +12,11 @@ set -o errexit
12 12
 STATS="stats.$$.tmp"
13 13
 
14 14
 for i in {1..100}; do cat "tests/svn/in.diff"; done \
15
-    | $PYTHON -m cProfile -o $STATS $CDIFF_PY -c always -s -w 60 \
15
+    | $PYTHON -m cProfile -o $STATS $YDIFF_PY -c always -s -w 60 \
16 16
     > /dev/null
17 17
 
18 18
 $PYTHON -c "import pstats;  p = pstats.Stats('$STATS'); \
19
-    p.strip_dirs().sort_stats('time').print_stats('cdiff')" \
19
+    p.strip_dirs().sort_stats('time').print_stats('ydiff')" \
20 20
     | tee $OUTPUT
21 21
 
22 22
 rm -f $STATS

+ 3
- 3
tests/regression.sh View File

@@ -3,7 +3,7 @@
3 3
 TOP_DIR=$(cd $(dirname $0)/.. && pwd) || exit 1
4 4
 cd $TOP_DIR || exit 1
5 5
 
6
-CDIFF=./cdiff
6
+YDIFF=./ydiff
7 7
 
8 8
 # To test with py3k: PYTHON=python3 make test
9 9
 PYTHON=${PYTHON:-python}
@@ -30,10 +30,10 @@ function cmp_output()
30 30
 {
31 31
     local input=${1:?}
32 32
     local expected_out=${2:?}
33
-    local cdiff_opt=${3:-""}
33
+    local ydiff_opt=${3:-""}
34 34
     local cmd
35 35
 
36
-    cmd=$(printf "%-7s $CDIFF %-24s < %-30s " $PYTHON "$cdiff_opt" "$input")
36
+    cmd=$(printf "%-7s $YDIFF %-24s < %-30s " $PYTHON "$ydiff_opt" "$input")
37 37
     printf "$cmd"
38 38
     if eval $cmd 2>/dev/null | cmp --silent $expected_out -; then
39 39
         pass

tests/test_cdiff.py → tests/test_ydiff.py View File

@@ -1,7 +1,7 @@
1 1
 #!/usr/bin/env python
2 2
 # -*- coding: utf-8 -*-
3 3
 
4
-"""Unit test for cdiff"""
4
+"""Unit test for ydiff"""
5 5
 
6 6
 import sys
7 7
 import unittest
@@ -10,7 +10,7 @@ import subprocess
10 10
 import os
11 11
 
12 12
 sys.path.insert(0, '')
13
-import cdiff  # nopep8
13
+import ydiff  # nopep8
14 14
 
15 15
 
16 16
 class Sequential(object):
@@ -41,27 +41,27 @@ class Sequential(object):
41 41
 class PatchStreamTest(unittest.TestCase):
42 42
 
43 43
     def test_is_empty(self):
44
-        stream = cdiff.PatchStream(Sequential([]))
44
+        stream = ydiff.PatchStream(Sequential([]))
45 45
         self.assertTrue(stream.is_empty())
46 46
 
47
-        stream = cdiff.PatchStream(Sequential(['hello', 'world']))
47
+        stream = ydiff.PatchStream(Sequential(['hello', 'world']))
48 48
         self.assertFalse(stream.is_empty())
49 49
 
50 50
     def test_read_stream_header(self):
51
-        stream = cdiff.PatchStream(Sequential([]))
51
+        stream = ydiff.PatchStream(Sequential([]))
52 52
         self.assertEqual(stream.read_stream_header(1), [])
53 53
 
54 54
         items = ['hello', 'world', 'again']
55 55
 
56
-        stream = cdiff.PatchStream(Sequential(items))
56
+        stream = ydiff.PatchStream(Sequential(items))
57 57
         self.assertEqual(stream.read_stream_header(2), items[:2])
58 58
 
59
-        stream = cdiff.PatchStream(Sequential(items))
59
+        stream = ydiff.PatchStream(Sequential(items))
60 60
         self.assertEqual(stream.read_stream_header(4), items[:])
61 61
 
62 62
     def test_iter_after_read_stream_header(self):
63 63
         items = ['hello', 'world', 'again', 'and', 'again']
64
-        stream = cdiff.PatchStream(Sequential(items))
64
+        stream = ydiff.PatchStream(Sequential(items))
65 65
 
66 66
         _ = stream.read_stream_header(2)
67 67
         out = list(stream)
@@ -72,7 +72,7 @@ class DecodeTest(unittest.TestCase):
72 72
 
73 73
     def test_normal(self):
74 74
         utext = 'hello'.encode('utf-8')
75
-        self.assertEqual('hello', cdiff.decode(utext))
75
+        self.assertEqual('hello', ydiff.decode(utext))
76 76
 
77 77
     def test_latin_1(self):
78 78
         text = '\x80\x02q\x01(U'
@@ -80,20 +80,20 @@ class DecodeTest(unittest.TestCase):
80 80
             decoded_text = text.decode('latin-1')
81 81
         else:
82 82
             decoded_text = text
83
-        self.assertEqual(decoded_text, cdiff.decode(text))
83
+        self.assertEqual(decoded_text, ydiff.decode(text))
84 84
 
85 85
 
86 86
 class HunkTest(unittest.TestCase):
87 87
 
88 88
     def test_get_old_text(self):
89
-        hunk = cdiff.Hunk([], '@@ -1,2 +1,2 @@', (1, 2), (1, 2))
89
+        hunk = ydiff.Hunk([], '@@ -1,2 +1,2 @@', (1, 2), (1, 2))
90 90
         hunk.append(('-', 'foo\n'))
91 91
         hunk.append(('+', 'bar\n'))
92 92
         hunk.append((' ', 'common\n'))
93 93
         self.assertEqual(hunk._get_old_text(), ['foo\n', 'common\n'])
94 94
 
95 95
     def test_get_new_text(self):
96
-        hunk = cdiff.Hunk([], '@@ -1,2 +1,2 @@', (1, 2), (1, 2))
96
+        hunk = ydiff.Hunk([], '@@ -1,2 +1,2 @@', (1, 2), (1, 2))
97 97
         hunk.append(('-', 'foo\n'))
98 98
         hunk.append(('+', 'bar\n'))
99 99
         hunk.append((' ', 'common\n'))
@@ -120,7 +120,7 @@ class DiffMarkupTest(unittest.TestCase):
120 120
             + spaced
121 121
         """
122 122
 
123
-        hunk = cdiff.Hunk(['hunk header\n'], '@@ -1,5 +1,5 @@\n',
123
+        hunk = ydiff.Hunk(['hunk header\n'], '@@ -1,5 +1,5 @@\n',
124 124
                           (1, 5), (1, 5))
125 125
         hunk.append(('-', 'hhello\n'))
126 126
         hunk.append(('+', 'helloo\n'))
@@ -131,14 +131,14 @@ class DiffMarkupTest(unittest.TestCase):
131 131
         hunk.append(('-', '	tabbed\n'))
132 132
         hunk.append(('+', 'again\n'))
133 133
         hunk.append(('+', ' spaced\n'))
134
-        diff = cdiff.UnifiedDiff(
134
+        diff = ydiff.UnifiedDiff(
135 135
             ['header\n'], '--- old\n', '+++ new\n', [hunk])
136 136
         return diff
137 137
 
138 138
     def test_markup_traditional_hunk_header(self):
139
-        hunk = cdiff.Hunk(['hunk header\n'], '@@ -0 +0 @@\n', (0, 0), (0, 0))
140
-        diff = cdiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk])
141
-        marker = cdiff.DiffMarker()
139
+        hunk = ydiff.Hunk(['hunk header\n'], '@@ -0 +0 @@\n', (0, 0), (0, 0))
140
+        diff = ydiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk])
141
+        marker = ydiff.DiffMarker()
142 142
 
143 143
         out = list(marker.markup(diff))
144 144
         self.assertEqual(len(out), 4)
@@ -149,10 +149,10 @@ class DiffMarkupTest(unittest.TestCase):
149 149
         self.assertEqual(out[3], '\x1b[1;34m@@ -0 +0 @@\n\x1b[0m')
150 150
 
151 151
     def test_markup_traditional_old_changed(self):
152
-        hunk = cdiff.Hunk([], '@@ -1 +0,0 @@\n', (1, 0), (0, 0))
152
+        hunk = ydiff.Hunk([], '@@ -1 +0,0 @@\n', (1, 0), (0, 0))
153 153
         hunk.append(('-', 'spam\n'))
154
-        diff = cdiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk])
155
-        marker = cdiff.DiffMarker()
154
+        diff = ydiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk])
155
+        marker = ydiff.DiffMarker()
156 156
 
157 157
         out = list(marker.markup(diff))
158 158
         self.assertEqual(len(out), 4)
@@ -163,10 +163,10 @@ class DiffMarkupTest(unittest.TestCase):
163 163
         self.assertEqual(out[3], '\x1b[1;31m-spam\n\x1b[0m')
164 164
 
165 165
     def test_markup_traditional_new_changed(self):
166
-        hunk = cdiff.Hunk([], '@@ -0,0 +1 @@\n', (0, 0), (1, 0))
166
+        hunk = ydiff.Hunk([], '@@ -0,0 +1 @@\n', (0, 0), (1, 0))
167 167
         hunk.append(('+', 'spam\n'))
168
-        diff = cdiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk])
169
-        marker = cdiff.DiffMarker()
168
+        diff = ydiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk])
169
+        marker = ydiff.DiffMarker()
170 170
 
171 171
         out = list(marker.markup(diff))
172 172
         self.assertEqual(len(out), 4)
@@ -177,12 +177,12 @@ class DiffMarkupTest(unittest.TestCase):
177 177
         self.assertEqual(out[3], '\x1b[32m+spam\n\x1b[0m')
178 178
 
179 179
     def test_markup_traditional_both_changed(self):
180
-        hunk = cdiff.Hunk([], '@@ -1,2 +1,2 @@\n', (1, 2), (1, 2))
180
+        hunk = ydiff.Hunk([], '@@ -1,2 +1,2 @@\n', (1, 2), (1, 2))
181 181
         hunk.append(('-', 'hella\n'))
182 182
         hunk.append(('+', 'hello\n'))
183 183
         hunk.append((' ', 'common\n'))
184
-        diff = cdiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk])
185
-        marker = cdiff.DiffMarker()
184
+        diff = ydiff.UnifiedDiff([], '--- old\n', '+++ new\n', [hunk])
185
+        marker = ydiff.DiffMarker()
186 186
 
187 187
         out = list(marker.markup(diff))
188 188
         self.assertEqual(len(out), 6)
@@ -202,7 +202,7 @@ class DiffMarkupTest(unittest.TestCase):
202 202
 
203 203
     def test_markup_side_by_side_padded(self):
204 204
         diff = self._init_diff()
205
-        marker = cdiff.DiffMarker(side_by_side=True, width=7)
205
+        marker = ydiff.DiffMarker(side_by_side=True, width=7)
206 206
 
207 207
         out = list(marker.markup(diff))
208 208
         self.assertEqual(len(out), 11)
@@ -256,7 +256,7 @@ class DiffMarkupTest(unittest.TestCase):
256 256
     # This test is not valid anymore
257 257
     def __test_markup_side_by_side_neg_width(self):
258 258
         diff = self._init_diff()
259
-        marker = cdiff.DiffMarker(side_by_side=True, width=-1)
259
+        marker = ydiff.DiffMarker(side_by_side=True, width=-1)
260 260
         out = list(marker.markup(diff))
261 261
         self.assertEqual(len(out), 11)
262 262
 
@@ -300,7 +300,7 @@ class DiffMarkupTest(unittest.TestCase):
300 300
 
301 301
     def test_markup_side_by_side_off_by_one(self):
302 302
         diff = self._init_diff()
303
-        marker = cdiff.DiffMarker(side_by_side=True, width=6)
303
+        marker = ydiff.DiffMarker(side_by_side=True, width=6)
304 304
         out = list(marker.markup(diff))
305 305
         self.assertEqual(len(out), 11)
306 306
 
@@ -351,7 +351,7 @@ class DiffMarkupTest(unittest.TestCase):
351 351
 
352 352
     def test_markup_side_by_side_wrapped(self):
353 353
         diff = self._init_diff()
354
-        marker = cdiff.DiffMarker(side_by_side=True, width=5)
354
+        marker = ydiff.DiffMarker(side_by_side=True, width=5)
355 355
         out = list(marker.markup(diff))
356 356
         self.assertEqual(len(out), 11)
357 357
 
@@ -403,7 +403,7 @@ class DiffMarkupTest(unittest.TestCase):
403 403
 
404 404
     def test_markup_side_by_side_tabbed(self):
405 405
         diff = self._init_diff()
406
-        marker = cdiff.DiffMarker(side_by_side=True, width=8, tab_width=2)
406
+        marker = ydiff.DiffMarker(side_by_side=True, width=8, tab_width=2)
407 407
         out = list(marker.markup(diff))
408 408
         self.assertEqual(len(out), 11)
409 409
 
@@ -456,7 +456,7 @@ class DiffMarkupTest(unittest.TestCase):
456 456
 
457 457
 class UnifiedDiffTest(unittest.TestCase):
458 458
 
459
-    diff = cdiff.UnifiedDiff(None, None, None, None)
459
+    diff = ydiff.UnifiedDiff(None, None, None, None)
460 460
 
461 461
     def test_is_hunk_meta_normal(self):
462 462
         self.assertTrue(self.diff.is_hunk_meta('@@ -1 +1 @@'))
@@ -518,8 +518,8 @@ spam
518 518
 @@ -1,2 +1,2 @@
519 519
 """
520 520
         items = patch.splitlines(True)
521
-        stream = cdiff.PatchStream(Sequential(items))
522
-        parser = cdiff.DiffParser(stream)
521
+        stream = ydiff.PatchStream(Sequential(items))
522
+        parser = ydiff.DiffParser(stream)
523 523
         self.assertEqual(parser._type, 'unified')
524 524
 
525 525
     def test_type_detect_context(self):
@@ -533,8 +533,8 @@ spam
533 533
   This part of the
534 534
 """
535 535
         items = patch.splitlines(True)
536
-        stream = cdiff.PatchStream(Sequential(items))
537
-        parser = cdiff.DiffParser(stream)
536
+        stream = ydiff.PatchStream(Sequential(items))
537
+        parser = ydiff.DiffParser(stream)
538 538
         self.assertEqual(parser._type, 'context')
539 539
 
540 540
     def test_type_detect_neg(self):
@@ -546,8 +546,8 @@ spam
546 546
 
547 547
 """
548 548
         items = patch.splitlines(True)
549
-        stream = cdiff.PatchStream(Sequential(items))
550
-        parser = cdiff.DiffParser(stream)
549
+        stream = ydiff.PatchStream(Sequential(items))
550
+        parser = ydiff.DiffParser(stream)
551 551
         self.assertEqual(parser._type, 'unified')
552 552
 
553 553
     def test_parse_invalid_hunk_meta(self):
@@ -559,8 +559,8 @@ spam
559 559
 @@ -a,a +0 @@
560 560
 """
561 561
         items = patch.splitlines(True)
562
-        stream = cdiff.PatchStream(Sequential(items))
563
-        parser = cdiff.DiffParser(stream)
562
+        stream = ydiff.PatchStream(Sequential(items))
563
+        parser = ydiff.DiffParser(stream)
564 564
         self.assertRaises(RuntimeError, list, parser.get_diff_generator())
565 565
 
566 566
     def test_parse_dangling_header(self):
@@ -574,8 +574,8 @@ spam
574 574
 spam
575 575
 """
576 576
         items = patch.splitlines(True)
577
-        stream = cdiff.PatchStream(Sequential(items))
578
-        parser = cdiff.DiffParser(stream)
577
+        stream = ydiff.PatchStream(Sequential(items))
578
+        parser = ydiff.DiffParser(stream)
579 579
 
580 580
         out = list(parser.get_diff_generator())
581 581
         self.assertEqual(len(out), 2)
@@ -596,8 +596,8 @@ spam
596 596
 --- c
597 597
 """
598 598
         items = patch.splitlines(True)
599
-        stream = cdiff.PatchStream(Sequential(items))
600
-        parser = cdiff.DiffParser(stream)
599
+        stream = ydiff.PatchStream(Sequential(items))
600
+        parser = ydiff.DiffParser(stream)
601 601
         self.assertRaises(AssertionError, list, parser.get_diff_generator())
602 602
 
603 603
     def test_parse_missing_hunk_meta(self):
@@ -612,8 +612,8 @@ spam
612 612
 +++ d
613 613
 """
614 614
         items = patch.splitlines(True)
615
-        stream = cdiff.PatchStream(Sequential(items))
616
-        parser = cdiff.DiffParser(stream)
615
+        stream = ydiff.PatchStream(Sequential(items))
616
+        parser = ydiff.DiffParser(stream)
617 617
 
618 618
         out = list(parser.get_diff_generator())
619 619
         self.assertEqual(len(out), 2)
@@ -635,8 +635,8 @@ spam
635 635
 @@ -1,2 +1,2 @@
636 636
 """
637 637
         items = patch.splitlines(True)
638
-        stream = cdiff.PatchStream(Sequential(items))
639
-        parser = cdiff.DiffParser(stream)
638
+        stream = ydiff.PatchStream(Sequential(items))
639
+        parser = ydiff.DiffParser(stream)
640 640
         self.assertRaises(AssertionError, list, parser.get_diff_generator())
641 641
 
642 642
     def test_parse_only_in_dir(self):
@@ -656,8 +656,8 @@ Only in foo: foo
656 656
  common
657 657
 """
658 658
         items = patch.splitlines(True)
659
-        stream = cdiff.PatchStream(Sequential(items))
660
-        parser = cdiff.DiffParser(stream)
659
+        stream = ydiff.PatchStream(Sequential(items))
660
+        parser = ydiff.DiffParser(stream)
661 661
 
662 662
         out = list(parser.get_diff_generator())
663 663
         self.assertEqual(len(out), 3)
@@ -677,8 +677,8 @@ Only in foo: foo
677 677
 Only in foo: foo
678 678
 """
679 679
         items = patch.splitlines(True)
680
-        stream = cdiff.PatchStream(Sequential(items))
681
-        parser = cdiff.DiffParser(stream)
680
+        stream = ydiff.PatchStream(Sequential(items))
681
+        parser = ydiff.DiffParser(stream)
682 682
 
683 683
         out = list(parser.get_diff_generator())
684 684
         self.assertEqual(len(out), 2)
@@ -702,8 +702,8 @@ Binary files a/1.pdf and b/1.pdf differ
702 702
  common
703 703
 """
704 704
         items = patch.splitlines(True)
705
-        stream = cdiff.PatchStream(Sequential(items))
706
-        parser = cdiff.DiffParser(stream)
705
+        stream = ydiff.PatchStream(Sequential(items))
706
+        parser = ydiff.DiffParser(stream)
707 707
 
708 708
         out = list(parser.get_diff_generator())
709 709
         self.assertEqual(len(out), 3)
@@ -738,8 +738,8 @@ index 529e8a3..ad71921 100755
738 738
  common
739 739
 """
740 740
         items = patch.splitlines(True)
741
-        stream = cdiff.PatchStream(Sequential(items))
742
-        parser = cdiff.DiffParser(stream)
741
+        stream = ydiff.PatchStream(Sequential(items))
742
+        parser = ydiff.DiffParser(stream)
743 743
 
744 744
         out = list(parser.get_diff_generator())
745 745
         self.assertEqual(len(out), 3)
@@ -764,8 +764,8 @@ Added: svn:keywords
764 764
 +Id
765 765
 """
766 766
         items = patch.splitlines(True)
767
-        stream = cdiff.PatchStream(Sequential(items))
768
-        parser = cdiff.DiffParser(stream)
767
+        stream = ydiff.PatchStream(Sequential(items))
768
+        parser = ydiff.DiffParser(stream)
769 769
         out = list(parser.get_diff_generator())
770 770
         self.assertEqual(len(out), 1)
771 771
         self.assertEqual(len(out[0]._hunks), 2)
@@ -779,8 +779,8 @@ class MainTest(unittest.TestCase):
779 779
 
780 780
     def setUp(self):
781 781
         self._cwd = os.getcwd()
782
-        self._ws = tempfile.mkdtemp(prefix='test_cdiff')
783
-        self._non_ws = tempfile.mkdtemp(prefix='test_cdiff')
782
+        self._ws = tempfile.mkdtemp(prefix='test_ydiff')
783
+        self._non_ws = tempfile.mkdtemp(prefix='test_ydiff')
784 784
         cmd = ('cd %s; git init; git config user.name me; '
785 785
                'git config user.email me@example.org') % self._ws
786 786
         subprocess.call(cmd, shell=True, stdout=subprocess.PIPE)
@@ -802,16 +802,16 @@ class MainTest(unittest.TestCase):
802 802
         subprocess.call(cmd, stdout=subprocess.PIPE)
803 803
 
804 804
     def test_preset_options(self):
805
-        os.environ['CDIFF_OPTIONS'] = '--help'
806
-        self.assertRaises(SystemExit, cdiff.main)
807
-        os.environ.pop('CDIFF_OPTIONS', None)
805
+        os.environ['YDIFF_OPTIONS'] = '--help'
806
+        self.assertRaises(SystemExit, ydiff.main)
807
+        os.environ.pop('YDIFF_OPTIONS', None)
808 808
 
809 809
     def test_read_diff(self):
810 810
         sys.argv = sys.argv[:1]
811 811
         self._change_file('read_diff')
812 812
 
813 813
         os.chdir(self._ws)
814
-        ret = cdiff.main()
814
+        ret = ydiff.main()
815 815
         os.chdir(self._cwd)
816 816
         self.assertEqual(ret, 0)
817 817
 
@@ -823,21 +823,21 @@ class MainTest(unittest.TestCase):
823 823
         self._commit_file()
824 824
 
825 825
         os.chdir(self._ws)
826
-        ret = cdiff.main()
826
+        ret = ydiff.main()
827 827
         os.chdir(self._cwd)
828 828
         self.assertEqual(ret, 0)
829 829
 
830 830
     def _test_read_diff_neg(self):
831 831
         sys.argv = sys.argv[:1]
832 832
         os.chdir(self._non_ws)
833
-        ret = cdiff.main()
833
+        ret = ydiff.main()
834 834
         os.chdir(self._cwd)
835 835
         self.assertNotEqual(ret, 0)
836 836
 
837 837
     def _test_read_log_neg(self):
838 838
         sys.argv = [sys.argv[0], '--log']
839 839
         os.chdir(self._non_ws)
840
-        ret = cdiff.main()
840
+        ret = ydiff.main()
841 841
         os.chdir(self._cwd)
842 842
         self.assertNotEqual(ret, 0)
843 843
 

cdiff → ydiff View File

@@ -2,8 +2,8 @@
2 2
 # -*- coding: utf-8 -*-
3 3
 
4 4
 import sys
5
-import cdiff
5
+import ydiff
6 6
 
7
-sys.exit(cdiff.main())
7
+sys.exit(ydiff.main())
8 8
 
9 9
 # vim:set et sts=4 sw=4 tw=79:

cdiff.py → ydiff.py View File

@@ -16,11 +16,11 @@ import select
16 16
 import difflib
17 17
 
18 18
 META_INFO = {
19
-    'version'     : '1.0',
19
+    'version'     : '1.1',
20 20
     'license'     : 'BSD-3',
21 21
     'author'      : 'Matthew Wang',
22 22
     'email'       : 'mattwyl(@)gmail(.)com',
23
-    'url'         : 'https://github.com/ymattw/cdiff',
23
+    'url'         : 'https://github.com/ymattw/ydiff',
24 24
     'keywords'    : 'colored incremental side-by-side diff',
25 25
     'description' : ('View colored, incremental diff in a workspace or from '
26 26
                      'stdin, with side by side and auto pager support')
@@ -372,7 +372,7 @@ class DiffParser(object):
372 372
                 break
373 373
         else:
374 374
             # `filterdiff` translates unknown diff to nothing, fall through to
375
-            # unified diff give cdiff a chance to show everything as headers
375
+            # unified diff give ydiff a chance to show everything as headers
376 376
             #
377 377
             sys.stderr.write("*** unknown format, fall through to 'unified'\n")
378 378
             self._type = 'unified'
@@ -712,7 +712,7 @@ def markup_to_pager(stream, opts):
712 712
     ended), most likely python bug 12607 (http://bugs.python.org/issue12607)
713 713
     which was fixed in python 2.7.3.
714 714
 
715
-    See issue #30 (https://github.com/ymattw/cdiff/issues/30) for more
715
+    See issue #30 (https://github.com/ymattw/ydiff/issues/30) for more
716 716
     information.
717 717
     """
718 718
     pager_cmd = ['less']
@@ -770,7 +770,7 @@ def decode(line):
770 770
         except UnicodeDecodeError:
771 771
             pass
772 772
 
773
-    return '*** cdiff: undecodable bytes ***\n'
773
+    return '*** ydiff: undecodable bytes ***\n'
774 774
 
775 775
 
776 776
 def terminal_size():
@@ -845,14 +845,24 @@ def main():
845 845
     option_group = OptionGroup(
846 846
         parser, 'Note', ('Option parser will stop on first unknown option '
847 847
                          'and pass them down to underneath revision control. '
848
-                         'Environment variable CDIFF_OPTIONS may be used to '
848
+                         'Environment variable YDIFF_OPTIONS may be used to '
849 849
                          'specify default options that will be placed at the '
850 850
                          'beginning of the argument list.'))
851 851
     parser.add_option_group(option_group)
852 852
 
853
-    # Place possible options defined in CDIFF_OPTIONS at the beginning of argv
854
-    cdiff_opts = [x for x in os.getenv('CDIFF_OPTIONS', '').split(' ') if x]
855
-    opts, args = parser.parse_args(cdiff_opts + sys.argv[1:])
853
+    # Place possible options defined in YDIFF_OPTIONS at the beginning of argv
854
+    ydiff_opts = [x for x in os.getenv('YDIFF_OPTIONS', '').split(' ') if x]
855
+
856
+    # TODO: Deprecate CDIFF_OPTIONS. Fall back to it and warn (for now).
857
+    if not ydiff_opts:
858
+        cdiff_opts = [x for x in os.getenv('CDIFF_OPTIONS', '').split(' ')
859
+                      if x]
860
+        if cdiff_opts:
861
+            sys.stderr.write('*** CDIFF_OPTIONS will be depreated soon, '
862
+                             'please use YDIFF_OPTIONS instead\n')
863
+            ydiff_opts = cdiff_opts
864
+
865
+    opts, args = parser.parse_args(ydiff_opts + sys.argv[1:])
856 866
 
857 867
     if opts.log:
858 868
         diff_hdl = revision_control_log(args)