Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Tao Klerks <tao@klerks.biz>
Cc: git <git@vger.kernel.org>,  Derrick Stolee <stolee@gmail.com>
Subject: Re: Can git log be made to "follow" in the same way as git blame? Why / in what way is "--follow" broken or limited?
Date: Mon, 26 Aug 2024 12:43:55 -0700	[thread overview]
Message-ID: <xmqqa5gzhxxg.fsf@gitster.g> (raw)
In-Reply-To: <CAPMMpogApZ6VN9sYxgmtHCickkstM6HZq1teeAa+a2t1_BY0sQ@mail.gmail.com> (Tao Klerks's message of "Mon, 26 Aug 2024 21:00:24 +0200")

Tao Klerks <tao@klerks.biz> writes:

> What seems weird and interesting to me, is that whatever is going
> "wrong" in "git log --follow" doesn't happen in "git blame".

Yes, because log.follow was done as a checkbox item but blame was
done as a real feature ;-)

In tree-diff.c:try_to_follow_renames(), you'll notice that it only
has a space to remember a single path in .single_follow member in
the diff_opts.  That member is the hack.

Imagine that the original commit had paths A and B, and over time,
the history diverged and in one fork A got renamed to C while
another fork B got renamed to C.  Eventually these two forks merge.
Now you want to "follow" C, so .single_follow member will have C.


  ----1----3----5(rename A to C)----7---9---10---11
       \                               /
        2----4----6(rename B to C)----8

You follow the history of one fork and notice that C came from A at
commit #5.  Great.  Your .pathspec member will be _switched_ to A
and you keep following the history of A.

Imagine further that your history traversal didn't follow one fork
fully before following the other fork, but dug commits from newer to
older, so your traversal jumps around between two forks.  What
happens when your "git log --follow HEAD -- C" that has internally
switched to follow A already jumps back to follow the other fork at
this point?  It does see that A exists (maybe unchanged), and you
see A's history, but that is not a releavant history---what ended up
in the final C from that fork was in B, not A.

Unlike the above checkbox hack, "git blame" uses a real data
structure to keep track of what came from where.  Instead of a
global "this single path is what interests us now", it knows "in
this commit, this is the path we are looking at", and when it looks
at the parents of that commit, it checks where that path the child
was interested in came from each different parent, and records a
similar "in this commit (which is parent of the commit we were
looking at), this path is what we are interested in".

To equip "git log --follow" with similar "correctness" as "git
blame", you'd need to somehow stop using that single .pathspec thing
for the purpose of keeping track of "which path are we following
now?" and instead use "this is the path we are following" that is
per history traversal path.

  reply	other threads:[~2024-08-26 19:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-26 19:00 Can git log be made to "follow" in the same way as git blame? Why / in what way is "--follow" broken or limited? Tao Klerks
2024-08-26 19:43 ` Junio C Hamano [this message]
2024-08-26 22:52   ` 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=xmqqa5gzhxxg.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=stolee@gmail.com \
    --cc=tao@klerks.biz \
    /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