bugGNU patch - Bugs: bug #33065, Allow idempotent patching


bug #33065: Allow idempotent patching

Submitted by:  Philip Prindeville <pprindeville>
Submitted on:  Wed Apr 13 16:54:02 2011  
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Wont Fix
Privacy: PublicAssigned to: None
Open/Closed: Closed

Add a New Comment (Rich MarkupRich Markup):

You are not logged in

Please log in, so followups can be emailed to you.


Mon Aug 8 11:59:33 2016, comment #5:

Really, the only thing patch can tell you is if a patch can be reverse applied. From that you may want to assume that the patch was already applied, but there is no guarantee: there are cases where the same patch can be reverse as well as forward applied. There is no such thing as idempotent patching as long as the patch doesn't contain both files in their entirety (i.e., with infinite context).

Andreas Gruenbacher <agruen>
Project Administrator
Mon Aug 8 11:25:23 2016, comment #4:

I'd strongly recommend to reconsider this issue.

Idempotent patching would be really appreciated in my use cases.

Consider the following, I'm building a specific software for all released versions. Since version 3 and on a specific feature was added.

If now one wants to build all software versions (also 1 and 2) with that features, applying the patch to them would work out. For version 1 and 2 it would apply cleanly, but for 3 and on it would be ignored as it was already applied.

"already applied" is a very different outcome in this case than "patch didn't cleanly apply".

Domen Ko┼żar <ielectric>
Thu Jan 3 21:27:20 2013, comment #3:

The description of the --forward option in the man page isn't very clear. Here is a better version:

When a patch does not apply, patch usually checks if the patch
looks like it has been reversed. The --forward option prevents

Patch doesn't ignore (or "silently apply") patches like three-way merge usually does. The result wouldn't be reliable enough with the information available. If you insist on ignoring patches that look like they have already been applied, do so by checking if they can be reverse applied.

Andreas Gruenbacher <agruen>
Project Administrator
Thu Jan 3 11:03:33 2013, comment #2:

Consider the following in bash:
$patch -s --forward -i mypatch.txt myfile.txt
$echo $?
$patch -s --forward -i mypatch.txt myfile.txt
Reversed (or previously applied) patch detected! Skipping patch.
1 out of 1 hunk ignored -- saving rejects to file myfile.txt.rej
$echo $?

(i.e. patching one file twice with the same patch)

If I read the manual page correctly, '-s --forward' should silently apply a forward patch, and just drop it if applied already. It does this, but prints a warning and returns non-zero, which is not what one wants when writing shell scripts.

This was tried with patch v. 2.6.1

Kalle Raiskila <kraiskil>
Wed Apr 13 18:17:14 2011, comment #1:

I am not sure what you mean. A patch that has already been applied can be reverse applied, which reverts it. (This may fail if the patch modifies the same file more than once though.)

Also note that patch uses a heuristic to determine if a patch has already been applied, and that this heuristic can fail. Trying to revert the patch with --reverse --dry-run is safer. This can also fail if a patch file modifies the same file more than once though.

Andreas Gruenbacher <agruen>
Project Administrator
Wed Apr 13 16:54:02 2011, original submission:

Software projects building their own patched kernel are often the source of kernel fixes. This patches will appear in the project tree and be submitted upstream, eventually appearing in kernel releases.

This creates scenarios where a patch might be attempted on a kernel release that's already been applied.

The --forward flag enables two separate and orthogonal conditions: already applied patches and reversed patches.

Separate options are needed to control reversed and already applied patches. The --forward option partially overlaps with --reverse.

I'm proposing an option called --idempotent that allows already applied patches to be quietly ignored.

Philip Prindeville <pprindeville>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by ielectric (Posted a comment)
  • -unavailable- added by kraiskil (Posted a comment)
  • -unavailable- added by agruen (Posted a comment)
  • -unavailable- added by pprindeville (Submitted the item)
  • -unavailable- added by pprindeville

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu Jan 3 21:27:20 2013agruenStatusNeed Info=>Wont Fix
    Wed Apr 13 18:17:14 2011agruenStatusNone=>Need Info
    Wed Apr 13 16:54:02 2011pprindevilleCarbon-Copy-=>Added pprindeville

    Back to the top

    Powered by Savane 3.1-cleanup1