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
Johannes Sixt <j6t@kdbg.org>
Date
Jul 3, 2024, 21:01 UTC
Message-ID
<772a1bd2-dd21-459a-8b95-7605fd7f52dc@kdbg.org>
In-Reply-To
<CAFjaU5sAVaNHZ0amPXJcbSvsnaijo+3X5Otg_Mntkx2GbikZMA@mail.gmail.com>
Am 03.07.24 um 17:24 schrieb Emanuel Czirai:
Show 22 quoted lines
> With the aforementioned `diffy` patch, the generated diff would actually be
> with a context of 4, to make it unambiguous, so it would've been this:
> ```diff
> --- original
> +++ modified
> @@ -1186,8 +1186,12 @@
>                      self.gctx.shell().warn(msg)?
>                  }
>              }
>          }
> +        if seen_any_warnings {
> +            //use anyhow::bail;
> +            bail!("reasons");
> +        }
>          Ok(())
>      }
> 
>      pub fn emit_lints(&self, pkg: &Package, path: &Path) ->
> CargoResult<()> {
> ```
> this hunk is now unambiguous because it cannot be applied in more than 1
> place in the original file,

This assertion is wrong, assuming that the patch is to be applied to a modified version of 'original'. There is nothing that can be done at the time when a patch is generated to make it unambiguous, not even if the entire file becomes context. The reason is that the modified 'original' could now have the part duplicated that is the context in the patch, and it would be possible to apply the patch any one of the duplicates. Which one?

-- Hannes
Previous: Emanuel Attila CziraiNext: Emanuel Czirai
Message 4 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.