Skip to content

Commit 3ec4f86

Browse files
authored
add processing for empty file adds in git (#21)
* add processing for empty file adds in git * 80 char linter rule is dumb * prefer 100 len lines and expand travis matrix * flatten test matrix * use xenial dist to get python 3.7 * fix README line * flip hunk order so any tuple access is still compatible * addressing PR comments * move pipenv installed packages to be dev-only
1 parent 951d601 commit 3ec4f86

File tree

10 files changed

+365
-74
lines changed

10 files changed

+365
-74
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ env/
33
env2/
44
env3/
55

6+
.vscode/
7+
68
*.py[cod]
79
.ropeproject
810

.travis.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1+
dist: xenial
12
sudo: false
23
language: python
3-
python: "3.5"
4-
env:
5-
- TOX_ENV=py27
6-
- TOX_ENV=py34
7-
- TOX_ENV=py35
84
matrix:
95
include:
6+
- python: 3.4
7+
env: TOX_ENV=py34
8+
9+
- python: 3.5
10+
env: TOX_ENV=py35
11+
1012
- python: 3.6
1113
env: TOX_ENV=py36
12-
include:
14+
1315
- python: 3.7
1416
env: TOX_ENV=py37
15-
include:
1617
- python: 3.7
1718
env: TOX_ENV=lint
18-
include:
19+
20+
- python: 2.7
21+
env: TOX_ENV=py27
1922
- python: 2.7
2023
env: TOX_ENV=lint
2124
addons:
22-
apt:
23-
packages:
24-
- ed
25+
apt:
26+
packages:
27+
- ed
2528
install: pip install tox
2629
script: tox -e $TOX_ENV
2730
cache: pip

Pipfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
nose = "*"
8+
flake8 = "*"
9+
tox = "*"
10+
twine = "*"
11+
12+
[packages]
13+
14+
[requires]
15+
python_version = "3.7"

Pipfile.lock

Lines changed: 216 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.rst

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,21 @@ each diff in the patch:
8282
old_version='2013-01-05 16:56:19.000000000 -0600',
8383
new_path='tzu',
8484
new_version='2013-01-05 16:56:35.000000000 -0600'),
85-
changes=[Change(old=1, new=None, hunk=1, line='The Way that can be told of is not the eternal Way;'),
86-
Change(old=2, new=None, hunk=1, line='The name that can be named is not the eternal name.'),
87-
Change(old=3, new=1, hunk=1, line='The Nameless is the origin of Heaven and Earth;'),
88-
Change(old=4, new=None, hunk=1, line='The Named is the mother of all things.'),
89-
Change(old=None, new=2, hunk=1, line='The named is the mother of all things.'),
90-
Change(old=None, new=3, hunk=1, line=''), Change(old=5, new=4, hunk=1, line='Therefore let there always be non-being,'),
91-
Change(old=6, new=5, hunk=1, line=' so we may see their subtlety,'),
92-
Change(old=7, new=6, hunk=1, line='And let there always be being,'),
93-
Change(old=9, new=8, hunk=2, line='The two are the same,'),
94-
Change(old=10, new=9, hunk=2, line='But after they are produced,'),
95-
Change(old=11, new=10, hunk=2, line=' they have different names.'),
96-
Change(old=None, new=11, hunk=2, line='They both may be called deep and profound.'),
97-
Change(old=None, new=12, hunk=2, line='Deeper and more profound,'),
98-
Change(old=None, new=13, hunk=2, line='The door of all subtleties!')],
85+
changes=[Change(old=1, new=None, line='The Way that can be told of is not the eternal Way;', hunk=1),
86+
Change(old=2, new=None, line='The name that can be named is not the eternal name.', hunk=1),
87+
Change(old=3, new=1, line='The Nameless is the origin of Heaven and Earth;', hunk=1),
88+
Change(old=4, new=None, line='The Named is the mother of all things.', hunk=1),
89+
Change(old=None, new=2, line='The named is the mother of all things.', hunk=1),
90+
Change(old=None, new=3, line='', hunk=1),
91+
Change(old=5, new=4, line='Therefore let there always be non-being,', hunk=1),
92+
Change(old=6, new=5, line=' so we may see their subtlety,', hunk=1),
93+
Change(old=7, new=6, line='And let there always be being,', hunk=1),
94+
Change(old=9, new=8, line='The two are the same,', hunk=2),
95+
Change(old=10, new=9, line='But after they are produced,', hunk=2),
96+
Change(old=11, new=10, line=' they have different names.', hunk=2),
97+
Change(old=None, new=11, line='They both may be called deep and profound.', hunk=2),
98+
Change(old=None, new=12, line='Deeper and more profound,', hunk=2),
99+
Change(old=None, new=13, line='The door of all subtleties!', hunk=2)],
99100
text='...')
100101
101102
The changes are listed as they are in the patch, but instead of the +/- syntax
@@ -106,7 +107,7 @@ What these numbers indicate are as follows:
106107
#. ``( old=None, new=2, ... )`` indicates line 2 of the file tzu was **inserted**.
107108
#. ``( old=5, new=4, ... )`` indicates that line 5 of lao and line 4 of tzu are **equal**.
108109

109-
Please note that not all patch formats provide the actual lines modified, so some
110+
Please note that not all patch formats provide the actual lines modified, so some
110111
results will have the text portion of the tuple set to ``None``.
111112

112113
Applying

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
setup(
1313
name='whatthepatch',
14-
version='0.0.5',
15-
description='A patch parsing library.',
16-
long_description=readme,
14+
version='0.0.6',
1715
author='Christopher S. Corley',
1816
author_email='[email protected]',
17+
description='A patch parsing and application library.',
18+
long_description=readme,
19+
long_description_content_type="text/markdown",
1920
url='https://github.com/cscorley/whatthepatch',
2021
license='MIT',
2122
packages=['whatthepatch'],
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
diff --git a/somefile.txt b/somefile.txt
2+
new file mode 100644
3+
index 0000000..e69de29

tests/test_patch.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def _process_change(c):
9797
return (c.old, c.new, c.line)
9898

9999
def _process_diffobj(d):
100-
return d._replace(changes=[_process_change(c) for c in d.changes])
100+
changes = d.changes or []
101+
return d._replace(changes=[_process_change(c) for c in changes])
101102

102103
def _process(d_or_c):
103104
if isinstance(d_or_c, list):
@@ -579,6 +580,29 @@ def test_git_oneline_rm(self):
579580
results = list(wtp.parse_patch(text))
580581
self.assert_diffs_equal(results, expected)
581582

583+
def test_git_new_empty_file(self):
584+
with open('tests/casefiles/git-new-empty-file.diff') as f:
585+
text = f.read()
586+
587+
lines = text.splitlines()
588+
589+
expected = [
590+
diffobj(
591+
header=headerobj(
592+
index_path=None,
593+
old_path='/dev/null',
594+
old_version='0000000',
595+
new_path='somefile.txt',
596+
new_version='e69de29',
597+
),
598+
changes=[],
599+
text='\n'.join(lines[:34]) + '\n'
600+
)
601+
]
602+
603+
results = list(wtp.parse_patch(text))
604+
self.assert_diffs_equal(results, expected)
605+
582606
def test_git_header(self):
583607
with open('tests/casefiles/git-header.diff') as f:
584608
text = f.read()

0 commit comments

Comments
 (0)