git/list[1] front-page[2] threads[3] people[4] search[5] about
 

fuzzy patch application

From
NDNick Desaulniers <ndesaulniers@google.com>
Date
Feb 10, 2017, 19:20 UTC
Message-ID
<CAKwvOdn9j=_Ob=xq4ucN6Ar1G537zNiU9ox4iF6o1qO7kPY41A@mail.gmail.com>

I frequently need to backport patches from the Linux kernel to older kernel versions (Android Security). My usual workflow for simple patches is:

1. try `git am patch.txt`.
2. if that fails try `git apply -v patch.txt` then add commit message
manually.
3. if that fails try `patch -p1 < patch.txt` then add commit message
manually.
4. if that fails, manually fix bug based on patch.

My question is, why does `patch` seem to do a better job at applying patches than `git am`? It's almost like the `git` tools don't try to fuzz the offsets. Is there a way to tell git to try fuzzing offsets when applying patches?

From the output of `patch` I ran recently (for a patch that `git apply` would not apply):

patching file <filename.c> Hunk #1 succeeded at 113 (offset -1 lines). Hunk #2 succeeded at 435 (offset -3 lines). Hunk #3 succeeded at 693 (offset 2 lines). Hunk #4 succeeded at 1535 (offset -41 lines). Hunk #5 succeeded at 1551 (offset -41 lines). Hunk #6 succeeded at 1574 with fuzz 2 (offset -42 lines). Hunk #7 succeeded at 1614 (offset -42 lines).

In fact, `git apply -v` errors for hunk #6.

I would guess maybe that there's an upper limit on the offset searched? Also, I'm not sure what the `fuzz 2` part means exactly, but it seems like `git apply` chokes when fuzzing is needed to properly apply a patch.

http://stackoverflow.com/q/6336440/1027966
-- 
Thanks,
~Nick Desaulniers
Next: Junio C Hamano
Message 1 of 9 in “fuzzy patch application”
  1. Nick DesaulniersFeb 10, 2017
  2. Junio C HamanoFeb 10, 2017
  3. Jeff KingFeb 10, 2017
  4. Stefan BellerFeb 10, 2017
  5. Jeff KingFeb 10, 2017
  6. Junio C HamanoFeb 10, 2017
  7. Junio C HamanoFeb 10, 2017
  8. Nick DesaulniersFeb 10, 2017
  9. Junio C HamanoFeb 11, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.