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

Re: looking for example of following code across files

From
Jeff King <peff@peff.net>
Date
Feb 16, 2008, 17:54 UTC
Message-ID
<20080216175445.GA19506@sigill.intra.peff.net>
In-Reply-To
<44F74AD0-CD8E-4715-BA88-4355F4513AB0@gmail.com>
On Sat, Feb 16, 2008 at 12:10:11PM -0500, Rhodes, Kate wrote:
> In order to find the original commit of each block is the system looking 
> up the commit for each block via it's SHA1, then following its parent 
> commits until it finds another commit that affected the same block or runs 
> out of commits?

Not exactly. You don't have a sha1 for each block, you have a sha1 for the whole file. So you walk the parent tree looking for the first time a particular chunk showed up. The basic idea is sketched out here:

http://article.gmane.org/gmane.comp.version-control.git/28826
> I'm thinking that while this would be possible to do manually it would  
> way too many lookups to be practical. Or, is there a simpler way to do it 
> on the command line?

You could do it manually, but it would be horribly slow. An overly simplified version of the algorithm is:

  1. Assume I'm interesed in a line that says "int foo() {"
  2. Check whether my parent has that line
     2a. If yes, then pass blame to parent, starting at '1'.
     2b. If no, then I introduced the line. Accept blame.

[When you talk about content movement, it gets a little trickier. See Junio's original explanation for more details.]

So you would end up pass blame for some lines through many commits that didn't touch those lines. I don't think you would want to do that by hand.

-Peff
Previous: Rhodes, Kate
Message 4 of 4 in “looking for example of following code across files”
  1. Rhodes, KateFeb 16, 2008
  2. Jakub NarebskiFeb 16, 2008
  3. Rhodes, KateFeb 16, 2008
  4. Jeff KingFeb 16, 2008

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.