diff --git a/Makefile.am b/Makefile.am index 79b41f1c..e2657bb5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -209,6 +209,7 @@ TESTS = tests/newline1/run-test \ tests/lsdiff-exclusion-combined/run-test \ tests/lsdiff-verbose-levels/run-test \ tests/lsdiff-range-exclude/run-test \ + tests/lsdiff-binary-numbering/run-test \ tests/patchview1/run-test \ tests/patchview2/run-test \ tests/fuzz1/run-test \ @@ -306,6 +307,7 @@ TESTS = tests/newline1/run-test \ tests/patch-ignore-whitespace/run-test \ tests/whitespace-w/run-test \ tests/filterdiff-inplace1/run-test \ + tests/filterdiff-binary-filtering/run-test \ tests/rediff-inplace1/run-test \ tests/rediff-empty-hunk/run-test \ tests/git-rename-issue22/run-test \ diff --git a/src/filterdiff.c b/src/filterdiff.c index 9e70c19d..4f8a6956 100644 --- a/src/filterdiff.c +++ b/src/filterdiff.c @@ -1324,6 +1324,9 @@ static int filterdiff (FILE *f, const char *patchname) /* Extract filenames from git headers */ if (extract_git_filenames (header, num_headers, &git_old_name, &git_new_name, git_prefix_mode) == 0) { + /* Increment file count for this git diff without hunks */ + filecount++; + /* Use the best name for filtering */ char *names[2] = { git_old_name, git_new_name }; p = best_name (2, names); @@ -1334,7 +1337,11 @@ static int filterdiff (FILE *f, const char *patchname) if (match && pat_include != NULL) match = patlist_match(pat_include, p_stripped); - /* Print filename if in list mode and matches */ + /* Apply file number filter */ + if (match) + match = file_matches(); + + /* Print filename if in list mode and matches */ if (match && !show_status && mode == mode_list) display_filename (start_linenum, status, p, patchname); @@ -1400,6 +1407,9 @@ static int filterdiff (FILE *f, const char *patchname) goto flush_continue; } + /* Increment file count for this git diff without hunks */ + filecount++; + /* Use the best name for filtering */ char *names[2] = { git_old_name, git_new_name }; p = best_name (2, names); @@ -1410,7 +1420,11 @@ static int filterdiff (FILE *f, const char *patchname) if (match && pat_include != NULL) match = patlist_match(pat_include, p_stripped); - /* Process the git diff (it will handle filename display) */ + /* Apply file number filter */ + if (match) + match = file_matches(); + + /* Process the git diff (it will handle filename display) */ result = do_git_diff_no_hunks (f, header, num_headers, match, &line, &linelen, &linenum, start_linenum, status, p, patchname, diff --git a/tests/filterdiff-binary-filtering/run-test b/tests/filterdiff-binary-filtering/run-test new file mode 100755 index 00000000..2052aaa0 --- /dev/null +++ b/tests/filterdiff-binary-filtering/run-test @@ -0,0 +1,36 @@ +#!/bin/sh + +# GitHub issue #157: Binary files should be filtered by file number + +. ${top_srcdir-.}/tests/common.sh + +cat << 'EOF' > diff +diff --git a/file1.txt b/file1.txt +new file mode 100644 +--- /dev/null ++++ b/file1.txt +@@ -0,0 +1 @@ ++a +diff --git a/file1.bin b/file1.bin +new file mode 100644 +Binary files /dev/null and b/file1.bin differ +diff --git a/file2.txt b/file2.txt +new file mode 100644 +--- /dev/null ++++ b/file2.txt +@@ -0,0 +1 @@ ++b +diff --git a/file2.bin b/file2.bin +new file mode 100644 +Binary files /dev/null and b/file2.bin differ +EOF + +# Test -F2: should only show file #2 (file1.bin), NOT file2.bin +${FILTERDIFF} -F2 diff 2>errors >output || exit 1 +[ -s errors ] && exit 1 + +cat << 'EOF' | cmp - output || exit 1 +diff --git a/file1.bin b/file1.bin +new file mode 100644 +Binary files /dev/null and b/file1.bin differ +EOF diff --git a/tests/lsdiff-binary-numbering/run-test b/tests/lsdiff-binary-numbering/run-test new file mode 100755 index 00000000..30578878 --- /dev/null +++ b/tests/lsdiff-binary-numbering/run-test @@ -0,0 +1,22 @@ +#!/bin/sh + +# GitHub issue #157: Binary files should be numbered sequentially + +. ${top_srcdir-.}/tests/common.sh + +cat << 'EOF' > diff +diff --git a/file1.bin b/file1.bin +new file mode 100644 +Binary files /dev/null and b/file1.bin differ +diff --git a/file2.bin b/file2.bin +new file mode 100644 +Binary files /dev/null and b/file2.bin differ +EOF + +${LSDIFF} -N diff 2>errors >output || exit 1 +[ -s errors ] && exit 1 + +cat << 'EOF' | cmp - output || exit 1 +File #1 a/file1.bin +File #2 a/file2.bin +EOF