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

Re: [PATCH v2] unpack-trees: do not abort when overwriting an existing file with the same content

From
Jeff King <peff@peff.net>
Date
Jan 22, 2013, 20:19 UTC
Message-ID
<20130122201929.GB23521@sigill.intra.peff.net>
In-Reply-To
<7vwqv6c7oe.fsf@alter.siamese.dyndns.org>
On Mon, Jan 21, 2013 at 05:45:05PM -0800, Junio C Hamano wrote:
Show 12 quoted lines
> Duy Nguyen <pclouds@gmail.com> writes:
> 
> > On Tue, Jan 22, 2013 at 6:15 AM, Jeff King <peff@peff.net> wrote:
> >> Can you elaborate on when this code is triggered?
> >>
> >> In the general case, shouldn't we already know the sha1 of what's on
> >> disk in the index, and be able to just compare the hashes? And if we
> >> don't, because the entry is start-dirty, should we be updating it
> >> (possibly earlier, so we do not even get into the "need to write" code
> >> path) instead of doing this ad-hoc byte comparison?
> 
> If the index knows what is in the working tree, I think I agree.

Right. I was wondering why it didn't (and if it doesn't, why we are not saving the information there).

But I think I was letting my inaccurate mental model of the index get in the way. I tend to think of the stat information as "if the file matches this stat info, then it has sha1 X". But that is not true. The sha1 we store is the actual index entry, and if it does not match what is in the working tree, we do not know or store the sha1 of what is in the working tree. We cannot just "refresh" that value and compare it, which is what I was implying.

So I think I was just confused. That is what I get for not actually doing low-level index stuff enough.

> > git reset HEAD~10
> > # blah that was a mistake, undo it
> > git checkout HEAD@{1}
It seems like
  git reset HEAD@{1}

would be the correct undo, as the original never touched the working tree.

-Peff
Previous: Duy Nguyen
Message 9 of 9 in “unpack-trees: do not abort when overwriting an existing file with the same content”
  1. unpack-trees: do not abort when overwriting an existing file with the same contentNguyễn Thái Ngọc Duy, Jan 19, 2013
  2. Junio C HamanoJan 20, 2013
  3. Duy NguyenJan 21, 2013
  4. unpack-trees: do not abort when overwriting an existing file with the same contentNguyễn Thái Ngọc Duy, Jan 21, 2013
  5. Jeff KingJan 21, 2013
  6. Duy NguyenJan 22, 2013
  7. Junio C HamanoJan 22, 2013
  8. Duy NguyenJan 22, 2013
  9. Jeff KingJan 22, 2013

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.