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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 03.07.24 um 17:24 schrieb Emanuel Czirai:
> 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





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux