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
19 changes: 18 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,24 @@ TESTS = tests/newline1/run-test \
tests/patch-ignore-whitespace/run-test \
tests/whitespace-w/run-test \
tests/filterdiff-inplace1/run-test \
tests/rediff-inplace1/run-test
tests/rediff-inplace1/run-test \
tests/git-rename-issue22/run-test \
tests/git-binary-issue57/run-test \
tests/git-binary-formats/run-test \
tests/git-mode-issue59/run-test \
tests/git-exclude-issue27/run-test \
tests/git-prefixes-option/run-test \
tests/git-prefixes-with-strip/run-test \
tests/git-diff-duplication/run-test \
tests/git-complex-mixed/run-test \
tests/git-error-handling/run-test \
tests/git-copy-operations/run-test \
tests/git-extended-headers/run-test \
tests/git-lsdiff-status/run-test \
tests/git-deleted-file/run-test \
tests/git-pure-rename/run-test \
tests/git-diff-edge-cases/run-test \
tests/malformed-diff-headers/run-test

# These ones don't work yet.
# Feel free to send me patches. :-)
Expand Down
11 changes: 11 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ Patchutils news

0.4.4 (stable)

Enhanced Git diff format support in filterdiff/lsdiff/grepdiff.
Improved handling of Git diffs without traditional hunks,
including proper support for file renames, binary file changes,
and permission mode changes. Fixed exclusion filtering (-x) for
multi-file Git diffs to prevent orphaned headers. Enhanced filename
extraction to properly strip Git's a/ and b/ prefixes for consistent
output. Added --git-prefixes=strip|keep option to control handling
of Git filename prefixes, with 'keep' as default for backward
compatibility (will change to 'strip' in version 0.5.0).
Addresses GitHub issues #22, #27, #59, and #68.

Code improvements and build system enhancements. Added redirectfd()
utility function to redirect stdout without reassignment. Enhanced
CI testing with musl support for better compatibility testing.
Expand Down
18 changes: 17 additions & 1 deletion bash-completion-patchutils
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _patchutils_common_opts() {
}

_patchutils_filter_opts() {
echo "--exclude -x --exclude-from-file -X --include -i --include-from-file -I --hunks -# --lines --files -F --annotate --as-numbered-lines --format --remove-timestamps --clean --in-place --decompress -z --strip-match -p --strip --addprefix --addoldprefix --addnewprefix"
echo "--exclude -x --exclude-from-file -X --include -i --include-from-file -I --hunks -# --lines --files -F --annotate --as-numbered-lines --format --remove-timestamps --clean --in-place --decompress -z --strip-match -p --strip --addprefix --addoldprefix --addnewprefix --git-prefixes"
}

_patchutils_list_opts() {
Expand Down Expand Up @@ -74,6 +74,10 @@ _filterdiff() {
# Prefix completion - no specific completion
return 0
;;
--git-prefixes)
COMPREPLY=($(compgen -W "strip keep" -- "$cur"))
return 0
;;
esac

if [[ ${cur} == -* ]]; then
Expand Down Expand Up @@ -110,6 +114,10 @@ _lsdiff() {
--addprefix|--addoldprefix|--addnewprefix)
return 0
;;
--git-prefixes)
COMPREPLY=($(compgen -W "strip keep" -- "$cur"))
return 0
;;
esac

if [[ ${cur} == -* ]]; then
Expand Down Expand Up @@ -162,6 +170,10 @@ _grepdiff() {
--addprefix|--addoldprefix|--addnewprefix)
return 0
;;
--git-prefixes)
COMPREPLY=($(compgen -W "strip keep" -- "$cur"))
return 0
;;
esac

if [[ ${cur} == -* ]]; then
Expand Down Expand Up @@ -374,6 +386,10 @@ _patchview() {
--addprefix|--addoldprefix|--addnewprefix)
return 0
;;
--git-prefixes)
COMPREPLY=($(compgen -W "strip keep" -- "$cur"))
return 0
;;
esac

if [[ ${cur} == -* ]]; then
Expand Down
118 changes: 109 additions & 9 deletions doc/patchutils.xml
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@
<arg>--strip-match=<replaceable>n</replaceable></arg>
</group>
<arg choice="opt">--strip=<replaceable>n</replaceable></arg>
<arg choice="opt">--git-prefixes=<replaceable>strip|keep</replaceable></arg>
<arg choice="opt">--addprefix=<replaceable>PREFIX</replaceable></arg>
<arg choice="opt">--addoldprefix=<replaceable>PREFIX</replaceable></arg>
<arg choice="opt">--addnewprefix=<replaceable>PREFIX</replaceable></arg>
Expand Down Expand Up @@ -724,6 +725,10 @@

<screen>filterdiff message-with-diff-in-the-body > patch</screen></para>

<para>Filterdiff supports unified, context, and Git format diffs.
Git format includes support for binary files, file renames,
permission mode changes, and other Git-specific diff features.</para>

<para>Note that the interpretation of the shell wildcard
pattern does not count slash characters or periods as
special (in other words, no flags are given to
Expand Down Expand Up @@ -860,6 +865,23 @@
</listitem>
</varlistentry>

<varlistentry>
<term><option>--git-prefixes</option>=<replaceable>strip|keep</replaceable></term>
<listitem>
<para>How to handle <literal>a/</literal> and <literal>b/</literal>
prefixes in Git diff filenames. With <literal>strip</literal>, removes
the prefixes both for filename matching (when using <option>-i</option>
and <option>-x</option> options) and for filename output (similar to
<option>--strip</option>). With <literal>keep</literal> (default),
preserves existing behavior. Applies to both Git-specific diffs (binary files,
renames, mode changes) and traditional diffs when part of a Git patch.
Note: Git rename operations use <literal>rename from/to</literal> headers
that contain literal filenames without <literal>a/</literal> or
<literal>b/</literal> prefixes, so this option does not affect renamed
filenames. The default will change to <literal>strip</literal> in version 0.5.0.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--addprefix</option>=<replaceable>PREFIX</replaceable></term>
<listitem>
Expand Down Expand Up @@ -1039,6 +1061,12 @@ patch.file]]></screen></para>
and context format diffs:

<screen><![CDATA[filterdiff -v --format=unified context.diff]]></screen></para>

<para>Git format diffs are fully supported, including binary files,
file renames, and permission mode changes. For example, to extract
only the renames from a git diff:

<screen><![CDATA[filterdiff -i '*/newname' git-patch-with-renames.patch]]></screen></para>
</refsect1>

<refsect1>
Expand Down Expand Up @@ -1182,6 +1210,7 @@ patch.file]]></screen></para>
<arg>--strip-match=<replaceable>n</replaceable></arg>
</group>
<arg choice="opt">--strip=<replaceable>n</replaceable></arg>
<arg choice="opt">--git-prefixes=<replaceable>strip|keep</replaceable></arg>
<arg choice="opt">--addprefix=<replaceable>PREFIX</replaceable></arg>
<group choice="opt">
<arg>-s</arg>
Expand Down Expand Up @@ -1243,8 +1272,10 @@ patch.file]]></screen></para>

<para>List the files modified by a patch.</para>

<para>You can use both unified and context format diffs with
this program.</para>
<para>You can use unified, context, and Git format diffs with
this program. Git format includes support for binary files,
file renames, permission mode changes, and other Git-specific
diff features.</para>

</refsect1>

Expand Down Expand Up @@ -1354,6 +1385,23 @@ patch.file]]></screen></para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--git-prefixes</option>=<replaceable>strip|keep</replaceable></term>
<listitem>
<para>How to handle <literal>a/</literal> and <literal>b/</literal>
prefixes in Git diff filenames. With <literal>strip</literal>, removes
the prefixes both for filename matching (when using <option>-i</option>
and <option>-x</option> options) and for filename output (similar to
<option>--strip</option>). With <literal>keep</literal> (default),
preserves existing behavior. Applies to both Git-specific diffs (binary files,
renames, mode changes) and traditional diffs when part of a Git patch.
Note: Git rename operations use <literal>rename from/to</literal> headers
that contain literal filenames without <literal>a/</literal> or
<literal>b/</literal> prefixes, so this option does not affect renamed
filenames. The default will change to <literal>strip</literal> in version 0.5.0.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--addprefix</option>=<replaceable>PREFIX</replaceable></term>
<listitem>
Expand Down Expand Up @@ -1534,6 +1582,7 @@ done)]]></screen></para>
<arg>--strip-match=<replaceable>n</replaceable></arg>
</group>
<arg choice="opt">--strip=<replaceable>n</replaceable></arg>
<arg choice="opt">--git-prefixes=<replaceable>strip|keep</replaceable></arg>
<arg choice="opt">--addprefix=<replaceable>PREFIX</replaceable></arg>
<group choice="opt">
<arg>-s</arg>
Expand Down Expand Up @@ -1597,13 +1646,13 @@ done)]]></screen></para>

<screen>patchview</screen>
(without args)

is equivalent to: lsdiff --number
</para>
<para>
<screen>patchview -F2-</screen>
(or with any other args)

is equivalent to: filterdiff -F2- (or whatever arguments are supplied)
</para>
<para>
Expand All @@ -1612,19 +1661,19 @@ There are two scripts for working with git (gitdiff and gitdiffview) and two for
<screen>svndiff</screen>
<screen>gitdiff</screen>
(without args)

will give the list of files modified
</para>
<para>
<screen>svndiff -F1</screen>
<screen>gitdiff -F1</screen>

will show the patch of file #1
</para>
<para>
<screen>svndiffview</screen>
<screen>gitdiffview</screen>

pipe all patches through filterdiff to vim - -R (in read-only mode, easy to quit), showing complete patch with color.
</para>
<para>
Expand Down Expand Up @@ -1743,6 +1792,23 @@ will pipe patch of file #2 to vim - -R
</listitem>
</varlistentry>

<varlistentry>
<term><option>--git-prefixes</option>=<replaceable>strip|keep</replaceable></term>
<listitem>
<para>How to handle <literal>a/</literal> and <literal>b/</literal>
prefixes in Git diff filenames. With <literal>strip</literal>, removes
the prefixes both for filename matching (when using <option>-i</option>
and <option>-x</option> options) and for filename output (similar to
<option>--strip</option>). With <literal>keep</literal> (default),
preserves existing behavior. Applies to both Git-specific diffs (binary files,
renames, mode changes) and traditional diffs when part of a Git patch.
Note: Git rename operations use <literal>rename from/to</literal> headers
that contain literal filenames without <literal>a/</literal> or
<literal>b/</literal> prefixes, so this option does not affect renamed
filenames. The default will change to <literal>strip</literal> in version 0.5.0.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--addprefix</option>=<replaceable>PREFIX</replaceable></term>
<listitem>
Expand Down Expand Up @@ -2193,6 +2259,7 @@ will pipe patch of file #2 to vim - -R
<arg>--strip-match=<replaceable>n</replaceable></arg>
</group>
<arg choice="opt">--strip=<replaceable>n</replaceable></arg>
<arg choice="opt">--git-prefixes=<replaceable>strip|keep</replaceable></arg>
<arg choice="opt">--addprefix=<replaceable>PREFIX</replaceable></arg>
<arg choice="opt">--addoldprefix=<replaceable>PREFIX</replaceable></arg>
<arg choice="opt">--addnewprefix=<replaceable>PREFIX</replaceable></arg>
Expand Down Expand Up @@ -2291,8 +2358,10 @@ will pipe patch of file #2 to vim - -R
<screen><![CDATA[grepdiff pf_gfp_mask my.patch | \
xargs -rn1 filterdiff my.patch -i]]></screen></para>

<para>You can use both unified and context format diffs with
this program.</para>
<para>You can use unified, context, and Git format diffs with
this program. Git format includes support for binary files,
file renames, permission mode changes, and other Git-specific
diff features.</para>

</refsect1>

Expand Down Expand Up @@ -2342,6 +2411,23 @@ will pipe patch of file #2 to vim - -R
</listitem>
</varlistentry>

<varlistentry>
<term><option>--git-prefixes</option>=<replaceable>strip|keep</replaceable></term>
<listitem>
<para>How to handle <literal>a/</literal> and <literal>b/</literal>
prefixes in Git diff filenames. With <literal>strip</literal>, removes
the prefixes both for filename matching (when using <option>-i</option>
and <option>-x</option> options) and for filename output (similar to
<option>--strip</option>). With <literal>keep</literal> (default),
preserves existing behavior. Applies to both Git-specific diffs (binary files,
renames, mode changes) and traditional diffs when part of a Git patch.
Note: Git rename operations use <literal>rename from/to</literal> headers
that contain literal filenames without <literal>a/</literal> or
<literal>b/</literal> prefixes, so this option does not affect renamed
filenames. The default will change to <literal>strip</literal> in version 0.5.0.</para>
</listitem>
</varlistentry>

<varlistentry>
<term><option>--addprefix</option>=<replaceable>PREFIX</replaceable></term>
<listitem>
Expand Down Expand Up @@ -2603,6 +2689,20 @@ will pipe patch of file #2 to vim - -R
</variablelist>
</refsect1>

<refsect1>
<title>Examples</title>

<para>Git format diffs are fully supported. For example, to find
files in a git patch that contain changes to malloc calls:

<screen><![CDATA[grepdiff "malloc" git-patch.patch]]></screen></para>

<para>Note that grepdiff searches in the hunk content (the actual
code changes), not in Git metadata like rename headers. Files with
only renames or mode changes (no content hunks) won't be found
even if the pattern appears in the Git headers.</para>
</refsect1>

<refsect1>
<title>See also</title>

Expand Down
Loading