From 0186b8740962603473351e6f19729697dedca99b Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Sun, 8 Jun 2025 10:58:27 -0400 Subject: [PATCH 1/2] repro --- testdata/empty/left/__init__.py | 1 + testdata/empty/right/__init__.py | 0 2 files changed, 1 insertion(+) create mode 100644 testdata/empty/left/__init__.py create mode 100644 testdata/empty/right/__init__.py diff --git a/testdata/empty/left/__init__.py b/testdata/empty/left/__init__.py new file mode 100644 index 0000000..63f3c56 --- /dev/null +++ b/testdata/empty/left/__init__.py @@ -0,0 +1 @@ +print('something here') diff --git a/testdata/empty/right/__init__.py b/testdata/empty/right/__init__.py new file mode 100644 index 0000000..e69de29 From f53d2ff7743f1d65555935a8798b1214dbc0babd Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Sun, 8 Jun 2025 11:00:03 -0400 Subject: [PATCH 2/2] bug fix --- webdiff/diff.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webdiff/diff.py b/webdiff/diff.py index 869d35f..9ef568f 100644 --- a/webdiff/diff.py +++ b/webdiff/diff.py @@ -42,7 +42,12 @@ def fast_num_lines(path: str) -> int: # See https://stackoverflow.com/q/9629179/388951 for the idea to use a Unix command. # Unfortunately `wc -l` ignores the last line if there is no trailing newline. So # instead, see https://stackoverflow.com/a/38870057/388951 - return int(subprocess.check_output(['grep', '-c', '', path])) + try: + return int(subprocess.check_output(['grep', '-c', '', path])) + except subprocess.CalledProcessError as e: + if e.returncode == 1: + return 0 # grep -c returns an error code if there are no matches + raise def get_diff_ops(