{"thread":{"id":"62508","subject":"[BUG] Apply patches failed without any changes","startedAt":"2024-11-17T12:40:20Z","lastAt":"2024-11-18T10:15:22Z","messageCount":2,"participants":["Ylarod","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"507437","messageId":"CAGtHOOFutv6wHgoFnkZoETJwq6FDkbbBgGqzSXT9V7ESXQswCg@mail.gmail.com","threadId":"62508","inReplyTo":null,"subject":"[BUG] Apply patches failed without any changes","fromName":"Ylarod","fromEmail":"ylarod9@gmail.com","sentAt":"2024-11-17T12:40:06Z","receivedAt":"2024-11-17T12:40:20Z","isPatch":false,"sender":{"key":"ylarod9@gmail.com","avatar":null},"body":"Thank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\n1. Clone the repo\n\n```bash\ngit clone https://github.com/Ylarod/frida-core\n```\n\n2. Generate patches from 36a8ffbb to ed039c9f\n\ned039c9f Florida: memfd-name-jit-cache\nf5f61669 Florida: pool-frida\n7d4ada2d Florida: update python script\nbbe4ebb1 Florida: protocol_unexpected_command\nbedd2337 Florida: thread_gmain\ne251174c Florida: thread_gum_js_loop\n357374cf Florida: symbol_frida_agent_main\nda9110f5 Florida: frida_agent_so\n351d9c1e Florida: string_frida_rpc\n36a8ffbb subprojects: Prepare for release\n\n```bash\ngit format-patch -N 36a8ffbb\n```\n\nThere will be 9 patches:\n\n0001-Florida-string_frida_rpc.patch\n0002-Florida-frida_agent_so.patch\n0003-Florida-symbol_frida_agent_main.patch\n0004-Florida-thread_gum_js_loop.patch\n0005-Florida-thread_gmain.patch\n0006-Florida-protocol_unexpected_command.patch\n0007-Florida-update-python-script.patch\n0008-Florida-pool-frida.patch\n0009-Florida-memfd-name-jit-cache.patch\n\n3. Apply these patches to 36a8ffbb\n\n```bash\ngit reset --hard 36a8ffbb\n\ngit am 000*\n```\n\nThe bug happens:\n\n```\nApplying: Florida: string_frida_rpc\nApplying: Florida: frida_agent_so\nApplying: Florida: symbol_frida_agent_main\n.git/rebase-apply/patch:126: trailing whitespace.\n\nerror: patch failed: lib/agent/frida-agent.def:1\nerror: lib/agent/frida-agent.def: patch does not apply\nerror: patch failed: tests/labrats/agent.def:1\nerror: tests/labrats/agent.def: patch does not apply\nPatch failed at 0003 Florida: symbol_frida_agent_main\nhint: Use 'git am --show-current-patch=diff' to see the failed patch\nhint: When you have resolved this problem, run \"git am --continue\".\nhint: If you prefer to skip this patch, run \"git am --skip\" instead.\nhint: To restore the original branch and stop patching, run \"git am --abort\".\nhint: Disable this message with \"git config advice.mergeConflict false\"\n```\n\nWhat did you expect to happen? (Expected behavior)\n\nApply these patches correctly\n\nWhat happened instead? (Actual behavior)\n\nApply patch failed\n\nWhat's different between what you expected and what actually happened?\n\nAnything else you want to add:\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.47.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nlibcurl: 8.10.1\nOpenSSL: OpenSSL 3.3.2 3 Sep 2024\nzlib: 1.3.1\nuname: Linux 6.11.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 01 Nov 2024\n03:30:41 +0000 x86_64\ncompiler info: gnuc: 14.2\nlibc info: glibc: 2.40\n$SHELL (typically, interactive shell): /usr/bin/zsh\n\n\n[Enabled Hooks]\n"},{"id":"507489","messageId":"20241118101521.GB3991628@coredump.intra.peff.net","threadId":"62508","inReplyTo":"CAGtHOOFutv6wHgoFnkZoETJwq6FDkbbBgGqzSXT9V7ESXQswCg@mail.gmail.com","subject":"Re: [BUG] Apply patches failed without any changes","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2024-11-18T10:15:21Z","receivedAt":"2024-11-18T10:15:22Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Nov 17, 2024 at 08:40:06PM +0800, Ylarod wrote:\n\n> ```\n> Applying: Florida: string_frida_rpc\n> Applying: Florida: frida_agent_so\n> Applying: Florida: symbol_frida_agent_main\n> .git/rebase-apply/patch:126: trailing whitespace.\n> \n> error: patch failed: lib/agent/frida-agent.def:1\n> error: lib/agent/frida-agent.def: patch does not apply\n> error: patch failed: tests/labrats/agent.def:1\n> error: tests/labrats/agent.def: patch does not apply\n> Patch failed at 0003 Florida: symbol_frida_agent_main\n> hint: Use 'git am --show-current-patch=diff' to see the failed patch\n> hint: When you have resolved this problem, run \"git am --continue\".\n> hint: If you prefer to skip this patch, run \"git am --skip\" instead.\n> hint: To restore the original branch and stop patching, run \"git am --abort\".\n> hint: Disable this message with \"git config advice.mergeConflict false\"\n> ```\n\nYour .def files have CRLF line endings:\n\n  $ git show --oneline 357374cfbbcb '*/frida-agent.def' | cat -A\n  357374cf Florida: symbol_frida_agent_main$\n  diff --git a/lib/agent/frida-agent.def b/lib/agent/frida-agent.def$\n  index 7634e3fd..dc297d6f 100644$\n  --- a/lib/agent/frida-agent.def$\n  +++ b/lib/agent/frida-agent.def$\n  @@ -1,2 +1,2 @@$\n   EXPORTS^M$\n  -^Ifrida_agent_main^M$\n  +^Imain^M$\n\nThe email format created by format-patch puts the diff inline in a\ntext/plain email part. And since emails use CRLF as the line terminator,\nthey are stripped when it is read back in by git-am. So it tries to\napply the change above _without_ the extra CR, and we fail to find the\ncontext.\n\nYou can use \"git am --keep-cr\" to retain the literal line endings on the\ndiff. This would work for the commands you showed above, but I suspect\nwould be a problem if you were actually sending the emails to somebody\nelse (since the mail transport would probably normalize everything to\nCRLF).\n\nTo robustly send them you'd either have to:\n\n  - send a binary patch. I don't think there's an easy way to ask for\n    this for a particular format-patch invocation. You'd probably have\n    to mark them with .gitattributes which would also suppress diffs,\n    etc.\n\n  - store the files in the repository with regular LF endings. If it's\n    important that they have CRLF in the working tree, you can use\n    attributes to convert them on checkout. See \"End-of-line conversion\"\n    in \"git help attributes\".\n\n-Peff\n"}]}