Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3-unidiff: fix for UnidiffParseError #45

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
From de89a8e941da89258c736b887ba2f3b983d8a877 Mon Sep 17 00:00:00 2001
From: Chris Packham <[email protected]>
Date: Tue, 7 Jun 2022 12:09:39 +1200
Subject: [PATCH] Remove newline from RE_DIFF_GIT_{DELETED,NEW}_FILE

RE_DIFF_GIT_DELETED_FILE and RE_DIFF_GIT_NEW_FILE match on a complete
line pattern 'r^$' so including `\n` in the pattern leads to the pattern
not matching. Remove the `\n`.

Upstream-Status: Backport
---
tests/samples/git_delete.diff | 16 ++++++++++++++++
tests/test_parser.py | 10 ++++++++++
unidiff/constants.py | 4 ++--
3 files changed, 28 insertions(+), 2 deletions(-)
create mode 100644 tests/samples/git_delete.diff

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/test_parser.py b/tests/test_parser.py
index 25cf129..3fc76b7 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -313,6 +313,16 @@ def test_parse_diff_git_no_prefix(self):
self.assertTrue(res[2].is_added_file)
self.assertEqual(res[2].path, 'file3')

+ 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/constants.py b/unidiff/constants.py
index 9601cd5..68c70aa 100644
--- a/unidiff/constants.py
+++ b/unidiff/constants.py
@@ -40,10 +40,10 @@
r'^diff --git (?P<source>(a/)?[^\t\n]+) (?P<target>(b/)?[^\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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ---------------------------------------------------------------------------------------------------------------------
# SPDX-License-Identifier: MIT
# ---------------------------------------------------------------------------------------------------------------------

FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"

# Fix for https://github.com/matiasb/python-unidiff/pull/97
SRC_URI += "file://97.patch"