New Upstream Release - python-unidiff
Ready changes
Summary
Merged new upstream version: 0.7.4 (was: 0.7.3).
Resulting package
Built on 2022-12-30T15:23 (took 6m3s)
The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:
apt install -t fresh-releases python3-unidiff
Lintian Result
Diff
diff --git a/AUTHORS b/AUTHORS
index 5b54cd5..d3e357d 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -30,3 +30,5 @@ Contributors
* (`@huichen-cs`)
* Mikhail f. Shiryaev (`@Felixoid`)
* Ronuk Raval (`@rraval`)
+ * anthony sottile (`@asottile-sentry`)
+ * (`@cpackham-atlnz`)
diff --git a/HISTORY b/HISTORY
index e9d39dc..f06cdf2 100644
--- a/HISTORY
+++ b/HISTORY
@@ -1,6 +1,11 @@
History
-------
+0.7.4 - 2022-06-26
+------------------
+
+* Fixed git diff parsing issues (filename with spaces, only one added/deleted file).
+
0.7.3 - 2022-02-06
------------------
diff --git a/debian/changelog b/debian/changelog
index 411f12b..92e6a51 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+python-unidiff (0.7.4-1) UNRELEASED; urgency=low
+
+ * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk> Fri, 30 Dec 2022 15:17:26 -0000
+
python-unidiff (0.7.3-1) unstable; urgency=medium
* Team upload
diff --git a/tests/samples/git_delete.diff b/tests/samples/git_delete.diff
new file mode 100644
index 0000000..f412c06
--- /dev/null
+++ b/tests/samples/git_delete.diff
@@ -0,0 +1,16 @@
+diff --git a/somefile.c b/somefile.c
+deleted file mode 100644
+index abcdefbbb8..0000000000
+--- a/somefile.c
++++ /dev/null
+@@ -1,10 +0,0 @@
+-/**
+- * @file somefile.c
+- */
+-#include <stdio.h>
+-
+-int main(int argc, cahr *argv[])
+-{
+- printf("Hello World\n");
+- return 0;
+-}
diff --git a/tests/samples/git_filenames_with_spaces.diff b/tests/samples/git_filenames_with_spaces.diff
new file mode 100644
index 0000000..0d1866a
--- /dev/null
+++ b/tests/samples/git_filenames_with_spaces.diff
@@ -0,0 +1,7 @@
+diff --git a/has spaces/t.sql b/has spaces/t.sql
+new file mode 100644
+index 0000000..8a9b485
+--- /dev/null
++++ b/has spaces/t.sql
+@@ -0,0 +1 @@
++select * FROM t;
diff --git a/tests/test_parser.py b/tests/test_parser.py
index 25cf129..9eaa722 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -313,6 +313,28 @@ class TestUnidiffParser(unittest.TestCase):
self.assertTrue(res[2].is_added_file)
self.assertEqual(res[2].path, 'file3')
+ def test_parse_filename_with_spaces(self):
+ filename = os.path.join(self.samples_dir, 'samples/git_filenames_with_spaces.diff')
+ with open(filename) as f:
+ res = PatchSet(f)
+
+ self.assertEqual(len(res), 1)
+
+ self.assertEqual(res[0].source_file, '/dev/null')
+ self.assertEqual(res[0].target_file, 'b/has spaces/t.sql')
+ self.assertTrue(res[0].is_added_file)
+ self.assertEqual(res[0].path, 'has spaces/t.sql')
+
+ def test_deleted_file(self):
+ filename = os.path.join(self.samples_dir, 'samples/git_delete.diff')
+ with open(filename) as f:
+ res = PatchSet(f)
+
+ self.assertEqual(len(res), 1)
+ self.assertEqual(res[0].source_file, 'a/somefile.c')
+ self.assertEqual(res[0].target_file, '/dev/null')
+ self.assertTrue(res[0].is_removed_file)
+
def test_diff_lines_linenos(self):
with open(self.sample_file, 'rb') as diff_file:
res = PatchSet(diff_file, encoding='utf-8')
diff --git a/unidiff/__version__.py b/unidiff/__version__.py
index e1e30c2..0448fe8 100644
--- a/unidiff/__version__.py
+++ b/unidiff/__version__.py
@@ -21,4 +21,4 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
# OR OTHER DEALINGS IN THE SOFTWARE.
-__version__ = '0.7.3'
+__version__ = '0.7.4'
diff --git a/unidiff/constants.py b/unidiff/constants.py
index 9601cd5..72073b7 100644
--- a/unidiff/constants.py
+++ b/unidiff/constants.py
@@ -37,13 +37,15 @@ RE_TARGET_FILENAME = re.compile(
# check diff git line for git renamed files support
RE_DIFF_GIT_HEADER = re.compile(
- r'^diff --git (?P<source>(a/)?[^\t\n]+) (?P<target>(b/)?[^\t\n]+)')
+ r'^diff --git (?P<source>a/[^\t\n]+) (?P<target>b/[^\t\n]+)')
+RE_DIFF_GIT_HEADER_NO_PREFIX = re.compile(
+ r'^diff --git (?P<source>[^\t\n]+) (?P<target>[^\t\n]+)')
# check diff git new file marker `deleted file mode 100644`
-RE_DIFF_GIT_DELETED_FILE = re.compile(r'^deleted file mode \d+\n$')
+RE_DIFF_GIT_DELETED_FILE = re.compile(r'^deleted file mode \d+$')
# check diff git new file marker `new file mode 100644`
-RE_DIFF_GIT_NEW_FILE = re.compile(r'^new file mode \d+\n$')
+RE_DIFF_GIT_NEW_FILE = re.compile(r'^new file mode \d+$')
# @@ (source offset, length) (target offset, length) @@ (section header)
diff --git a/unidiff/patch.py b/unidiff/patch.py
index 62aab80..ff671dc 100644
--- a/unidiff/patch.py
+++ b/unidiff/patch.py
@@ -40,6 +40,7 @@ from unidiff.constants import (
LINE_VALUE_NO_NEWLINE,
RE_DIFF_GIT_DELETED_FILE,
RE_DIFF_GIT_HEADER,
+ RE_DIFF_GIT_HEADER_NO_PREFIX,
RE_DIFF_GIT_NEW_FILE,
RE_HUNK_BODY_LINE,
RE_HUNK_EMPTY_BODY_LINE,
@@ -478,7 +479,7 @@ class PatchSet(list):
line = line.decode(encoding)
# check for a git file rename
- is_diff_git_header = RE_DIFF_GIT_HEADER.match(line)
+ is_diff_git_header = RE_DIFF_GIT_HEADER.match(line) or RE_DIFF_GIT_HEADER_NO_PREFIX.match(line)
if is_diff_git_header:
patch_info = PatchInfo()
source_file = is_diff_git_header.group('source')
Debdiff
[The following lists of changes regard files as different if they have different names, permissions or owners.]
Files in second set of .debs but not in first
-rw-r--r-- root/root /usr/lib/python3/dist-packages/unidiff-0.7.4.egg-info/PKG-INFO -rw-r--r-- root/root /usr/lib/python3/dist-packages/unidiff-0.7.4.egg-info/dependency_links.txt -rw-r--r-- root/root /usr/lib/python3/dist-packages/unidiff-0.7.4.egg-info/top_level.txt
Files in first set of .debs but not in second
-rw-r--r-- root/root /usr/lib/python3/dist-packages/unidiff-0.7.3.egg-info/PKG-INFO -rw-r--r-- root/root /usr/lib/python3/dist-packages/unidiff-0.7.3.egg-info/dependency_links.txt -rw-r--r-- root/root /usr/lib/python3/dist-packages/unidiff-0.7.3.egg-info/top_level.txt
No differences were encountered in the control files