Skip to content
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
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
18 changes: 16 additions & 2 deletions src/filterdiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down
36 changes: 36 additions & 0 deletions tests/filterdiff-binary-filtering/run-test
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions tests/lsdiff-binary-numbering/run-test
Original file line number Diff line number Diff line change
@@ -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