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 Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tao Klerks <tao@xxxxxxxxxx> 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.




[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