Browse Source

Rename to ydiff (version 1.1)

Matt Wang 6 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
 Change log
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
 Version 1.0 (2016-12-31)
11
 Version 1.0 (2016-12-31)
6
 
12
 
7
   - Use environment variable ``CDIFF_OPTIONS`` to hold default options
13
   - Use environment variable ``CDIFF_OPTIONS`` to hold default options

+ 3
- 3
LICENSE View File

1
 Software License Agreement (BSD-3 License)
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
 All rights reserved.
4
 All rights reserved.
5
 
5
 
6
 Redistribution and use in source and binary forms, with or without modification,
6
 Redistribution and use in source and binary forms, with or without modification,
8
 
8
 
9
     1. Redistributions of source code must retain the above copyright notice,
9
     1. Redistributions of source code must retain the above copyright notice,
10
        this list of conditions and the following disclaimer.
10
        this list of conditions and the following disclaimer.
11
-    
11
+
12
     2. Redistributions in binary form must reproduce the above copyright notice,
12
     2. Redistributions in binary form must reproduce the above copyright notice,
13
        this list of conditions and the following disclaimer in the documentation
13
        this list of conditions and the following disclaimer in the documentation
14
        and/or other materials provided with the distribution.
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
        to endorse or promote products derived from this software without
17
        to endorse or promote products derived from this software without
18
        specific prior written permission.
18
        specific prior written permission.
19
 
19
 

+ 9
- 9
Makefile View File

7
 	test test3 cov cov3 html reg reg3 profile profile3
7
 	test test3 cov cov3 html reg reg3 profile profile3
8
 
8
 
9
 dogfood:
9
 dogfood:
10
-	./cdiff.py
11
-	git diff | ./cdiff.py -s
10
+	./ydiff.py
11
+	git diff | ./ydiff.py -s
12
 
12
 
13
 lint:
13
 lint:
14
 	pep8 --ignore=E203 *.py tests/*.py
14
 	pep8 --ignore=E203 *.py tests/*.py
27
 test3: lint doc-check cov3 reg3
27
 test3: lint doc-check cov3 reg3
28
 
28
 
29
 cov:
29
 cov:
30
-	coverage run tests/test_cdiff.py
30
+	coverage run tests/test_ydiff.py
31
 	coverage report --show-missing
31
 	coverage report --show-missing
32
 
32
 
33
 cov3:
33
 cov3:
34
-	python3 `which coverage` run tests/test_cdiff.py
34
+	python3 `which coverage` run tests/test_ydiff.py
35
 	python3 `which coverage` report --show-missing
35
 	python3 `which coverage` report --show-missing
36
 
36
 
37
 html:
37
 html:
52
 
52
 
53
 clean:
53
 clean:
54
 	rm -f MANIFEST profile*.tmp* .coverage
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
 build:
57
 build:
58
 	./setup.py build sdist
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
 	rm -f ~/.pypirc
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
 	rm -f ~/.pypirc
66
 	rm -f ~/.pypirc
67
 
67
 
68
 # vim:set noet ts=8 sw=8:
68
 # vim:set noet ts=8 sw=8:

+ 55
- 55
README.rst View File

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
    :alt: Build status
6
    :alt: Build status
7
 
7
 
8
 Term based tool to view *colored*, *incremental* diff in a *Git/Mercurial/Svn*
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
    :alt: default
13
    :alt: default
14
    :align: center
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
    :alt: side by side
17
    :alt: side by side
18
    :align: center
18
    :align: center
19
    :width: 900 px
19
    :width: 900 px
24
 Install with pip
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
 the tool.
28
 the tool.
29
 
29
 
30
-.. _PyPI: http://pypi.python.org/pypi/cdiff
30
+.. _PyPI: http://pypi.python.org/pypi/ydiff
31
 
31
 
32
 .. code-block:: bash
32
 .. code-block:: bash
33
 
33
 
34
-    pip install --upgrade cdiff
34
+    pip install --upgrade ydiff
35
 
35
 
36
 Install with setup.py
36
 Install with setup.py
37
 ~~~~~~~~~~~~~~~~~~~~~
37
 ~~~~~~~~~~~~~~~~~~~~~
40
 
40
 
41
 .. code-block:: bash
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
     ./setup.py install
45
     ./setup.py install
46
 
46
 
47
 Install with Homebrew
47
 Install with Homebrew
55
 .. _`@bfontaine`: https://github.com/bfontaine
55
 .. _`@bfontaine`: https://github.com/bfontaine
56
 .. _`@hivehand`: https://github.com/hivehand
56
 .. _`@hivehand`: https://github.com/hivehand
57
 .. _`@nijikon`: https://github.com/nijikon
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
 .. code-block:: bash
60
 .. code-block:: bash
61
 
61
 
62
-    brew install cdiff
62
+    brew install ydiff
63
 
63
 
64
 Download directly
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
 example, ``$HOME/bin`` is in my ``$PATH``, so I save the script there and name
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
 .. code-block:: bash
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
 Usage
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
     View colored, incremental diff in a workspace or from stdin, with side by side
86
     View colored, incremental diff in a workspace or from stdin, with side by side
87
     and auto pager support
87
     and auto pager support
99
 
99
 
100
       Note:
100
       Note:
101
         Option parser will stop on first unknown option and pass them down to
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
         used to specify default options that will be placed at the beginning
103
         used to specify default options that will be placed at the beginning
104
         of the argument list.
104
         of the argument list.
105
 
105
 
109
 .. code-block:: bash
109
 .. code-block:: bash
110
 
110
 
111
     cd proj-workspace
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
 Read log with changes in a *Git/Mercurial/Svn* workspace (output from e.g.
123
 Read log with changes in a *Git/Mercurial/Svn* workspace (output from e.g.
124
 ``git log -p``, ``svn log --diff``), note *--diff* option is new in svn 1.7.0:
124
 ``git log -p``, ``svn log --diff``), note *--diff* option is new in svn 1.7.0:
126
 .. code-block:: bash
126
 .. code-block:: bash
127
 
127
 
128
     cd proj-workspace
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
 that will be placed at the beginning of the argument list, for example:
135
 that will be placed at the beginning of the argument list, for example:
136
 
136
 
137
 .. code-block:: bash
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
 as follows:
144
 as follows:
145
 
145
 
146
 .. code-block:: bash
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
 Pipe in a diff:
151
 Pipe in a diff:
152
 
152
 
153
 .. code-block:: bash
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
     # View diff in a GitHub pull request, side by side
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
     # View a patch file in unified or context format, the latter depends on
164
     # View a patch file in unified or context format, the latter depends on
165
     # command `filterdiff` from package `patchutils` which is available in
165
     # command `filterdiff` from package `patchutils` which is available in
166
     # major Linux distros and MacPorts.
166
     # major Linux distros and MacPorts.
167
     #
167
     #
168
-    cdiff -s < foo.patch
168
+    ydiff -s < foo.patch
169
 
169
 
170
 Redirect output to another patch file is safe:
170
 Redirect output to another patch file is safe:
171
 
171
 
172
 .. code-block:: bash
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
 Notes
176
 Notes
177
 -----
177
 -----
178
 
178
 
179
-Cdiff has following known issues:
179
+Ydiff has following known issues:
180
 
180
 
181
 - Does not recognize `normal` diff, and depends on ``filterdiff`` (patchutils)
181
 - Does not recognize `normal` diff, and depends on ``filterdiff`` (patchutils)
182
   to read `context` diff
182
   to read `context` diff
188
 be installed with ``pip install coverage``).  Also watch out `travis build`_
188
 be installed with ``pip install coverage``).  Also watch out `travis build`_
189
 after push, make sure it passes as well.
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
 See also
193
 See also
194
 --------
194
 --------
195
 
195
 
196
 I have another tool `coderev`_ which generates side-by-side diff pages for code
196
 I have another tool `coderev`_ which generates side-by-side diff pages for code
197
 review from two given files or directories, I found it's not easy to extend to
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
 project `colordiff`_.
199
 project `colordiff`_.
200
 
200
 
201
 .. _coderev: https://github.com/ymattw/coderev
201
 .. _coderev: https://github.com/ymattw/coderev

+ 5
- 5
setup.py View File

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

+ 4
- 4
tests/README View File

1
 # To generate expected output, chdir to a subdir and use following command, then
1
 # To generate expected output, chdir to a subdir and use following command, then
2
 # review with `less -R`
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
 OUTPUT=${1:?"output file required"}
3
 OUTPUT=${1:?"output file required"}
4
 
4
 
5
 SELF_DIR=$(cd $(dirname $0) && pwd) || exit 1
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
 # To test with py3k: PYTHON=python3 make test
8
 # To test with py3k: PYTHON=python3 make test
9
 PYTHON=${PYTHON:-python}
9
 PYTHON=${PYTHON:-python}
12
 STATS="stats.$$.tmp"
12
 STATS="stats.$$.tmp"
13
 
13
 
14
 for i in {1..100}; do cat "tests/svn/in.diff"; done \
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
     > /dev/null
16
     > /dev/null
17
 
17
 
18
 $PYTHON -c "import pstats;  p = pstats.Stats('$STATS'); \
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
     | tee $OUTPUT
20
     | tee $OUTPUT
21
 
21
 
22
 rm -f $STATS
22
 rm -f $STATS

+ 3
- 3
tests/regression.sh View File

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

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

1
 #!/usr/bin/env python
1
 #!/usr/bin/env python
2
 # -*- coding: utf-8 -*-
2
 # -*- coding: utf-8 -*-
3
 
3
 
4
-"""Unit test for cdiff"""
4
+"""Unit test for ydiff"""
5
 
5
 
6
 import sys
6
 import sys
7
 import unittest
7
 import unittest
10
 import os
10
 import os
11
 
11
 
12
 sys.path.insert(0, '')
12
 sys.path.insert(0, '')
13
-import cdiff  # nopep8
13
+import ydiff  # nopep8
14
 
14
 
15
 
15
 
16
 class Sequential(object):
16
 class Sequential(object):
41
 class PatchStreamTest(unittest.TestCase):
41
 class PatchStreamTest(unittest.TestCase):
42
 
42
 
43
     def test_is_empty(self):
43
     def test_is_empty(self):
44
-        stream = cdiff.PatchStream(Sequential([]))
44
+        stream = ydiff.PatchStream(Sequential([]))
45
         self.assertTrue(stream.is_empty())
45
         self.assertTrue(stream.is_empty())
46
 
46
 
47
-        stream = cdiff.PatchStream(Sequential(['hello', 'world']))
47
+        stream = ydiff.PatchStream(Sequential(['hello', 'world']))
48
         self.assertFalse(stream.is_empty())
48
         self.assertFalse(stream.is_empty())
49
 
49
 
50
     def test_read_stream_header(self):
50
     def test_read_stream_header(self):
51
-        stream = cdiff.PatchStream(Sequential([]))
51
+        stream = ydiff.PatchStream(Sequential([]))
52
         self.assertEqual(stream.read_stream_header(1), [])
52
         self.assertEqual(stream.read_stream_header(1), [])
53
 
53
 
54
         items = ['hello', 'world', 'again']
54
         items = ['hello', 'world', 'again']
55
 
55
 
56
-        stream = cdiff.PatchStream(Sequential(items))
56
+        stream = ydiff.PatchStream(Sequential(items))
57
         self.assertEqual(stream.read_stream_header(2), items[:2])
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
         self.assertEqual(stream.read_stream_header(4), items[:])
60
         self.assertEqual(stream.read_stream_header(4), items[:])
61
 
61
 
62
     def test_iter_after_read_stream_header(self):
62
     def test_iter_after_read_stream_header(self):
63
         items = ['hello', 'world', 'again', 'and', 'again']
63
         items = ['hello', 'world', 'again', 'and', 'again']
64
-        stream = cdiff.PatchStream(Sequential(items))
64
+        stream = ydiff.PatchStream(Sequential(items))
65
 
65
 
66
         _ = stream.read_stream_header(2)
66
         _ = stream.read_stream_header(2)
67
         out = list(stream)
67
         out = list(stream)
72
 
72
 
73
     def test_normal(self):
73
     def test_normal(self):
74
         utext = 'hello'.encode('utf-8')
74
         utext = 'hello'.encode('utf-8')
75
-        self.assertEqual('hello', cdiff.decode(utext))
75
+        self.assertEqual('hello', ydiff.decode(utext))
76
 
76
 
77
     def test_latin_1(self):
77
     def test_latin_1(self):
78
         text = '\x80\x02q\x01(U'
78
         text = '\x80\x02q\x01(U'
80
             decoded_text = text.decode('latin-1')
80
             decoded_text = text.decode('latin-1')
81
         else:
81
         else:
82
             decoded_text = text
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
 class HunkTest(unittest.TestCase):
86
 class HunkTest(unittest.TestCase):
87
 
87
 
88
     def test_get_old_text(self):
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
         hunk.append(('-', 'foo\n'))
90
         hunk.append(('-', 'foo\n'))
91
         hunk.append(('+', 'bar\n'))
91
         hunk.append(('+', 'bar\n'))
92
         hunk.append((' ', 'common\n'))
92
         hunk.append((' ', 'common\n'))
93
         self.assertEqual(hunk._get_old_text(), ['foo\n', 'common\n'])
93
         self.assertEqual(hunk._get_old_text(), ['foo\n', 'common\n'])
94
 
94
 
95
     def test_get_new_text(self):
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
         hunk.append(('-', 'foo\n'))
97
         hunk.append(('-', 'foo\n'))
98
         hunk.append(('+', 'bar\n'))
98
         hunk.append(('+', 'bar\n'))
99
         hunk.append((' ', 'common\n'))
99
         hunk.append((' ', 'common\n'))
120
             + spaced
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
                           (1, 5), (1, 5))
124
                           (1, 5), (1, 5))
125
         hunk.append(('-', 'hhello\n'))
125
         hunk.append(('-', 'hhello\n'))
126
         hunk.append(('+', 'helloo\n'))
126
         hunk.append(('+', 'helloo\n'))
131
         hunk.append(('-', '	tabbed\n'))
131
         hunk.append(('-', '	tabbed\n'))
132
         hunk.append(('+', 'again\n'))
132
         hunk.append(('+', 'again\n'))
133
         hunk.append(('+', ' spaced\n'))
133
         hunk.append(('+', ' spaced\n'))
134
-        diff = cdiff.UnifiedDiff(
134
+        diff = ydiff.UnifiedDiff(
135
             ['header\n'], '--- old\n', '+++ new\n', [hunk])
135
             ['header\n'], '--- old\n', '+++ new\n', [hunk])
136
         return diff
136
         return diff
137
 
137
 
138
     def test_markup_traditional_hunk_header(self):
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
         out = list(marker.markup(diff))
143
         out = list(marker.markup(diff))
144
         self.assertEqual(len(out), 4)
144
         self.assertEqual(len(out), 4)
149
         self.assertEqual(out[3], '\x1b[1;34m@@ -0 +0 @@\n\x1b[0m')
149
         self.assertEqual(out[3], '\x1b[1;34m@@ -0 +0 @@\n\x1b[0m')
150
 
150
 
151
     def test_markup_traditional_old_changed(self):
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
         hunk.append(('-', 'spam\n'))
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
         out = list(marker.markup(diff))
157
         out = list(marker.markup(diff))
158
         self.assertEqual(len(out), 4)
158
         self.assertEqual(len(out), 4)
163
         self.assertEqual(out[3], '\x1b[1;31m-spam\n\x1b[0m')
163
         self.assertEqual(out[3], '\x1b[1;31m-spam\n\x1b[0m')
164
 
164
 
165
     def test_markup_traditional_new_changed(self):
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
         hunk.append(('+', 'spam\n'))
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
         out = list(marker.markup(diff))
171
         out = list(marker.markup(diff))
172
         self.assertEqual(len(out), 4)
172
         self.assertEqual(len(out), 4)
177
         self.assertEqual(out[3], '\x1b[32m+spam\n\x1b[0m')
177
         self.assertEqual(out[3], '\x1b[32m+spam\n\x1b[0m')
178
 
178
 
179
     def test_markup_traditional_both_changed(self):
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
         hunk.append(('-', 'hella\n'))
181
         hunk.append(('-', 'hella\n'))
182
         hunk.append(('+', 'hello\n'))
182
         hunk.append(('+', 'hello\n'))
183
         hunk.append((' ', 'common\n'))
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
         out = list(marker.markup(diff))
187
         out = list(marker.markup(diff))
188
         self.assertEqual(len(out), 6)
188
         self.assertEqual(len(out), 6)
202
 
202
 
203
     def test_markup_side_by_side_padded(self):
203
     def test_markup_side_by_side_padded(self):
204
         diff = self._init_diff()
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
         out = list(marker.markup(diff))
207
         out = list(marker.markup(diff))
208
         self.assertEqual(len(out), 11)
208
         self.assertEqual(len(out), 11)
256
     # This test is not valid anymore
256
     # This test is not valid anymore
257
     def __test_markup_side_by_side_neg_width(self):
257
     def __test_markup_side_by_side_neg_width(self):
258
         diff = self._init_diff()
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
         out = list(marker.markup(diff))
260
         out = list(marker.markup(diff))
261
         self.assertEqual(len(out), 11)
261
         self.assertEqual(len(out), 11)
262
 
262
 
300
 
300
 
301
     def test_markup_side_by_side_off_by_one(self):
301
     def test_markup_side_by_side_off_by_one(self):
302
         diff = self._init_diff()
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
         out = list(marker.markup(diff))
304
         out = list(marker.markup(diff))
305
         self.assertEqual(len(out), 11)
305
         self.assertEqual(len(out), 11)
306
 
306
 
351
 
351
 
352
     def test_markup_side_by_side_wrapped(self):
352
     def test_markup_side_by_side_wrapped(self):
353
         diff = self._init_diff()
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
         out = list(marker.markup(diff))
355
         out = list(marker.markup(diff))
356
         self.assertEqual(len(out), 11)
356
         self.assertEqual(len(out), 11)
357
 
357
 
403
 
403
 
404
     def test_markup_side_by_side_tabbed(self):
404
     def test_markup_side_by_side_tabbed(self):
405
         diff = self._init_diff()
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
         out = list(marker.markup(diff))
407
         out = list(marker.markup(diff))
408
         self.assertEqual(len(out), 11)
408
         self.assertEqual(len(out), 11)
409
 
409
 
456
 
456
 
457
 class UnifiedDiffTest(unittest.TestCase):
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
     def test_is_hunk_meta_normal(self):
461
     def test_is_hunk_meta_normal(self):
462
         self.assertTrue(self.diff.is_hunk_meta('@@ -1 +1 @@'))
462
         self.assertTrue(self.diff.is_hunk_meta('@@ -1 +1 @@'))
518
 @@ -1,2 +1,2 @@
518
 @@ -1,2 +1,2 @@
519
 """
519
 """
520
         items = patch.splitlines(True)
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
         self.assertEqual(parser._type, 'unified')
523
         self.assertEqual(parser._type, 'unified')
524
 
524
 
525
     def test_type_detect_context(self):
525
     def test_type_detect_context(self):
533
   This part of the
533
   This part of the
534
 """
534
 """
535
         items = patch.splitlines(True)
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
         self.assertEqual(parser._type, 'context')
538
         self.assertEqual(parser._type, 'context')
539
 
539
 
540
     def test_type_detect_neg(self):
540
     def test_type_detect_neg(self):
546
 
546
 
547
 """
547
 """
548
         items = patch.splitlines(True)
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
         self.assertEqual(parser._type, 'unified')
551
         self.assertEqual(parser._type, 'unified')
552
 
552
 
553
     def test_parse_invalid_hunk_meta(self):
553
     def test_parse_invalid_hunk_meta(self):
559
 @@ -a,a +0 @@
559
 @@ -a,a +0 @@
560
 """
560
 """
561
         items = patch.splitlines(True)
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
         self.assertRaises(RuntimeError, list, parser.get_diff_generator())
564
         self.assertRaises(RuntimeError, list, parser.get_diff_generator())
565
 
565
 
566
     def test_parse_dangling_header(self):
566
     def test_parse_dangling_header(self):
574
 spam
574
 spam
575
 """
575
 """
576
         items = patch.splitlines(True)
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
         out = list(parser.get_diff_generator())
580
         out = list(parser.get_diff_generator())
581
         self.assertEqual(len(out), 2)
581
         self.assertEqual(len(out), 2)
596
 --- c
596
 --- c
597
 """
597
 """
598
         items = patch.splitlines(True)
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
         self.assertRaises(AssertionError, list, parser.get_diff_generator())
601
         self.assertRaises(AssertionError, list, parser.get_diff_generator())
602
 
602
 
603
     def test_parse_missing_hunk_meta(self):
603
     def test_parse_missing_hunk_meta(self):
612
 +++ d
612
 +++ d
613
 """
613
 """
614
         items = patch.splitlines(True)
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
         out = list(parser.get_diff_generator())
618
         out = list(parser.get_diff_generator())
619
         self.assertEqual(len(out), 2)
619
         self.assertEqual(len(out), 2)
635
 @@ -1,2 +1,2 @@
635
 @@ -1,2 +1,2 @@
636
 """
636
 """
637
         items = patch.splitlines(True)
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
         self.assertRaises(AssertionError, list, parser.get_diff_generator())
640
         self.assertRaises(AssertionError, list, parser.get_diff_generator())
641
 
641
 
642
     def test_parse_only_in_dir(self):
642
     def test_parse_only_in_dir(self):
656
  common
656
  common
657
 """
657
 """
658
         items = patch.splitlines(True)
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
         out = list(parser.get_diff_generator())
662
         out = list(parser.get_diff_generator())
663
         self.assertEqual(len(out), 3)
663
         self.assertEqual(len(out), 3)
677
 Only in foo: foo
677
 Only in foo: foo
678
 """
678
 """
679
         items = patch.splitlines(True)
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
         out = list(parser.get_diff_generator())
683
         out = list(parser.get_diff_generator())
684
         self.assertEqual(len(out), 2)
684
         self.assertEqual(len(out), 2)
702
  common
702
  common
703
 """
703
 """
704
         items = patch.splitlines(True)
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
         out = list(parser.get_diff_generator())
708
         out = list(parser.get_diff_generator())
709
         self.assertEqual(len(out), 3)
709
         self.assertEqual(len(out), 3)
738
  common
738
  common
739
 """
739
 """
740
         items = patch.splitlines(True)
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
         out = list(parser.get_diff_generator())
744
         out = list(parser.get_diff_generator())
745
         self.assertEqual(len(out), 3)
745
         self.assertEqual(len(out), 3)
764
 +Id
764
 +Id
765
 """
765
 """
766
         items = patch.splitlines(True)
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
         out = list(parser.get_diff_generator())
769
         out = list(parser.get_diff_generator())
770
         self.assertEqual(len(out), 1)
770
         self.assertEqual(len(out), 1)
771
         self.assertEqual(len(out[0]._hunks), 2)
771
         self.assertEqual(len(out[0]._hunks), 2)
779
 
779
 
780
     def setUp(self):
780
     def setUp(self):
781
         self._cwd = os.getcwd()
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
         cmd = ('cd %s; git init; git config user.name me; '
784
         cmd = ('cd %s; git init; git config user.name me; '
785
                'git config user.email me@example.org') % self._ws
785
                'git config user.email me@example.org') % self._ws
786
         subprocess.call(cmd, shell=True, stdout=subprocess.PIPE)
786
         subprocess.call(cmd, shell=True, stdout=subprocess.PIPE)
802
         subprocess.call(cmd, stdout=subprocess.PIPE)
802
         subprocess.call(cmd, stdout=subprocess.PIPE)
803
 
803
 
804
     def test_preset_options(self):
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
     def test_read_diff(self):
809
     def test_read_diff(self):
810
         sys.argv = sys.argv[:1]
810
         sys.argv = sys.argv[:1]
811
         self._change_file('read_diff')
811
         self._change_file('read_diff')
812
 
812
 
813
         os.chdir(self._ws)
813
         os.chdir(self._ws)
814
-        ret = cdiff.main()
814
+        ret = ydiff.main()
815
         os.chdir(self._cwd)
815
         os.chdir(self._cwd)
816
         self.assertEqual(ret, 0)
816
         self.assertEqual(ret, 0)
817
 
817
 
823
         self._commit_file()
823
         self._commit_file()
824
 
824
 
825
         os.chdir(self._ws)
825
         os.chdir(self._ws)
826
-        ret = cdiff.main()
826
+        ret = ydiff.main()
827
         os.chdir(self._cwd)
827
         os.chdir(self._cwd)
828
         self.assertEqual(ret, 0)
828
         self.assertEqual(ret, 0)
829
 
829
 
830
     def _test_read_diff_neg(self):
830
     def _test_read_diff_neg(self):
831
         sys.argv = sys.argv[:1]
831
         sys.argv = sys.argv[:1]
832
         os.chdir(self._non_ws)
832
         os.chdir(self._non_ws)
833
-        ret = cdiff.main()
833
+        ret = ydiff.main()
834
         os.chdir(self._cwd)
834
         os.chdir(self._cwd)
835
         self.assertNotEqual(ret, 0)
835
         self.assertNotEqual(ret, 0)
836
 
836
 
837
     def _test_read_log_neg(self):
837
     def _test_read_log_neg(self):
838
         sys.argv = [sys.argv[0], '--log']
838
         sys.argv = [sys.argv[0], '--log']
839
         os.chdir(self._non_ws)
839
         os.chdir(self._non_ws)
840
-        ret = cdiff.main()
840
+        ret = ydiff.main()
841
         os.chdir(self._cwd)
841
         os.chdir(self._cwd)
842
         self.assertNotEqual(ret, 0)
842
         self.assertNotEqual(ret, 0)
843
 
843
 

cdiff → ydiff View File

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

cdiff.py → ydiff.py View File

16
 import difflib
16
 import difflib
17
 
17
 
18
 META_INFO = {
18
 META_INFO = {
19
-    'version'     : '1.0',
19
+    'version'     : '1.1',
20
     'license'     : 'BSD-3',
20
     'license'     : 'BSD-3',
21
     'author'      : 'Matthew Wang',
21
     'author'      : 'Matthew Wang',
22
     'email'       : 'mattwyl(@)gmail(.)com',
22
     'email'       : 'mattwyl(@)gmail(.)com',
23
-    'url'         : 'https://github.com/ymattw/cdiff',
23
+    'url'         : 'https://github.com/ymattw/ydiff',
24
     'keywords'    : 'colored incremental side-by-side diff',
24
     'keywords'    : 'colored incremental side-by-side diff',
25
     'description' : ('View colored, incremental diff in a workspace or from '
25
     'description' : ('View colored, incremental diff in a workspace or from '
26
                      'stdin, with side by side and auto pager support')
26
                      'stdin, with side by side and auto pager support')
372
                 break
372
                 break
373
         else:
373
         else:
374
             # `filterdiff` translates unknown diff to nothing, fall through to
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
             sys.stderr.write("*** unknown format, fall through to 'unified'\n")
377
             sys.stderr.write("*** unknown format, fall through to 'unified'\n")
378
             self._type = 'unified'
378
             self._type = 'unified'
712
     ended), most likely python bug 12607 (http://bugs.python.org/issue12607)
712
     ended), most likely python bug 12607 (http://bugs.python.org/issue12607)
713
     which was fixed in python 2.7.3.
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
     information.
716
     information.
717
     """
717
     """
718
     pager_cmd = ['less']
718
     pager_cmd = ['less']
770
         except UnicodeDecodeError:
770
         except UnicodeDecodeError:
771
             pass
771
             pass
772
 
772
 
773
-    return '*** cdiff: undecodable bytes ***\n'
773
+    return '*** ydiff: undecodable bytes ***\n'
774
 
774
 
775
 
775
 
776
 def terminal_size():
776
 def terminal_size():
845
     option_group = OptionGroup(
845
     option_group = OptionGroup(
846
         parser, 'Note', ('Option parser will stop on first unknown option '
846
         parser, 'Note', ('Option parser will stop on first unknown option '
847
                          'and pass them down to underneath revision control. '
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
                          'specify default options that will be placed at the '
849
                          'specify default options that will be placed at the '
850
                          'beginning of the argument list.'))
850
                          'beginning of the argument list.'))
851
     parser.add_option_group(option_group)
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
     if opts.log:
867
     if opts.log:
858
         diff_hdl = revision_control_log(args)
868
         diff_hdl = revision_control_log(args)