From: Mike Hommey <mh@glandium.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: Should notes handle replace commits?
Date: Sat, 9 Jan 2016 09:32:58 +0900 [thread overview]
Message-ID: <20160109003258.GA31415@glandium.org> (raw)
In-Reply-To: <xmqqvb73zk35.fsf@gitster.mtv.corp.google.com>
On Fri, Jan 08, 2016 at 04:13:02PM -0800, Junio C Hamano wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
> > Perhaps you would see what is going on more clearly if you replace
> > your "git log" with "git rev-list".
> >
> > If your pre-graft/pre-replace histories were
> >
> > A (first) <--- B (second) <--- C (third) master
> > X (rFirst) <--- Y (rSecond) <--- Z (rThird) old
> >
> > then your "graft" tells Git "B's parent is Z, not A. If you run
> > "rev-list master", it will give you "C B Z Y X". The discrepancy
> > (relative to the true history) brought in by "grafting" is that
> > nowhere in "cat-file commit B" you would find Z, even though "log"
> > and "rev-list" pretends as if Z is a (and the) parent of B.
> >
> > Your "replace" tells Git "A records what Z records". If you run
> > "rev-list master", it will give you "C B A Y X".
> >
> > A fake history made by "replace" does not have the same discrepancy
> > as "grafting"; "cat-file commit B" names A as its parent, and asking
> > what A is gives what actually is in Z, i.e. "cat-file commit A"
> > shows what "cat-file commit Z" would give you. The discrepancy with
> > the reality "replacing" gives you is that hashing what you got from
> > "cat-file commit A" does not hash to A (it obviously has to hash to
> > Z).
> >
> >> From my POV, replace is more about
> >> "telling Git that this commit (and its parents) is really that one (and
> >> its parents)".
> >
> > Your "POV" does not match reality; replace is about telling Git to
> > give contents recorded for object Z when anybody asks the contents
> > recorded for object A.
>
> To put it differently, what you did in your two examples with graft
> and replace are not equivalent. With graft, you told commit B that
> its parent is not commit A but commit Z. If you wanted to do the
> equivalent with replace, you would have replaced commit B with an
> otherwise identical commit B' that records Z as its parent. But you
> didn't; instead, you replaced commit A with Z.
>
> And if you did the equivalent with "replace", your "git rev-list"
> would have shown "C B Z Y X" (instead of "C B A Y X"), and when "git
> log" showed the second commit, it would have shown the contents of B'
> _and_ because Git still thinks it is showing the original B, it
> would have shown the notes for B.
>
> Something like this (totally untested) would let you replace B with
> an otherwise identical B' that has Z instead of A as its parent:
>
> $ Bprime=$(git cat-file commit master~ |
> sed -e "s/^parent .*/parent $(git rev-parse old)/" |
> git hash-object -w --stdin -t commit)
>
> $ git update-ref refs/replace/$(git rev-parse master~) $Bprime
git replace --graft does that automatically. But my contention is not
really about graft vs. replace. I should just have skipped that part,
it's largely irrelevant.
Mike
next prev parent reply other threads:[~2016-01-09 0:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-08 1:28 Should notes handle replace commits? Mike Hommey
2016-01-08 20:09 ` Junio C Hamano
2016-01-08 21:49 ` Mike Hommey
2016-01-08 23:51 ` Junio C Hamano
2016-01-09 0:13 ` Junio C Hamano
2016-01-09 0:32 ` Mike Hommey [this message]
2016-01-09 0:25 ` Mike Hommey
2016-01-09 1:04 ` Junio C Hamano
2016-01-09 1:25 ` Mike Hommey
2016-01-11 16:09 ` Junio C Hamano
2016-01-09 17:39 ` Philip Oakley
2016-01-11 16:50 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160109003258.GA31415@glandium.org \
--to=mh@glandium.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).