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

Re: `git diff`/`git apply` can generate/apply ambiguous hunks (ie. in the wrong place) (just like gnu diff/patch)

From
ECEmanuel Attila Czirai <corre.a.buscar@gmail.com>
Date
Jul 3, 2024, 16:22 UTC
Message-ID
<CAFjaU5vvk-nNLvCyXAgU9C3ScKBNRPFB7=1PXejmLZi+r7EbNQ@mail.gmail.com>
In-Reply-To
<082b01dacd61$81174a80$8345df80$@nexbridge.com>
Show 16 quoted lines
> >I consider that I don't know enough to understand how `git diff`/`git apply` works
> >internally (and similarly, gnu `diff`/`patch`) to actually change them and make them
> >generate unambiguous hunks where only the hunks that would've been ambiguous
> >have increased context size, instead of the whole patch have increased context size
> >for all hunks(which is what I did for `diffy` too so far, in that proof of concept patch),
> >therefore if a "fix" is deemed necessary(it may not be, as I might've missed
> >something and I'm unaware of it, so a fix may be messing other things up, who
> >knows?!) then I hope someone much more knowledgeable could implement
> >it(maybe even for gnu diff/patch too), and while I don't think that a "please" would
> >be enough, I'm still gonna say it: please do so, if so inclined.
> >
> >Thank you for your time and consideration.
>
> You make good points, but Rust code should not be put into the main git code base as it will break many non-GNU platforms. Perhaps rewriting it is C to be compatible with the git code-base.
> --Randall
>

Ah, definitely whoever writes the fix would do it in C for the git code base, I didn't mean to imply it would be or should be done in rust, therefore please excuse my failure to communicate that clearly. The `diffy` proof-of-concept patch, is just for `diffy`, in rust, and it's just to show a way this could be done and that "it works" that way. It was easier for me to do it for `diffy` in rust, than in C for git diff/apply or gnu diff/patch. If a fix is to be implemented for `git diff/apply`, it would definitely not be in rust by any means, but C, as you mentioned. Thank you for your reply.

Also, I notice that I made a mistake when pasting the patch with the context length of 4, it was a real patch not the one I used in the examples, here's the corrected unambiguous patch: ```diff --- original +++ modified

@@ -1114,8 +1114,12 @@
                     self.config.shell().warn(msg)?
                 }
             }
         }
+        if seen_any_warnings {
+            //comment
+            bail!("reasons");
+        }
         Ok(())
     }

     pub fn set_target_dir(&mut self, target_dir: Filesystem) {
```

Cheers, have a great day everyone!
Previous: rsbecker@nexbridge.comNext: Johannes Sixt
Message 3 of 8 in “`git diff`/`git apply` can generate/apply ambiguous hunks (ie. in the wrong place) (just like gnu diff/patch)”
  1. Emanuel CziraiJul 3, 2024
  2. rsbecker@nexbridge.comJul 3, 2024
  3. Emanuel Attila CziraiJul 3, 2024
  4. Johannes SixtJul 3, 2024
  5. Emanuel CziraiJul 4, 2024
  6. Elijah NewrenJul 4, 2024
  7. Emanuel CziraiJul 4, 2024
  8. Junio C HamanoJul 6, 2024

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.