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

Re: looking for example of following code across files

From
Jakub Narebski <jnareb@gmail.com>
Date
Feb 16, 2008, 09:16 UTC
Message-ID
<m3pruxb6rh.fsf@localhost.localdomain>
In-Reply-To
<57E76010-D0F8-420C-A11D-8884832FD00D@gmail.com>
"Rhodes, Kate" <masukomi@gmail.com> writes:
Show 12 quoted lines
> I seem to remember that when Linus was giving the tech-talk to the
> folks at Google he mentioned Git being able to follow a block of code
> as it was moved from file to file, but I'm having a hard time finding
> an actual example of how that plays out. I'd love to be able to
> demonstrate this to people but I'm not quite sure of the steps I'd
> need to do to accomplish this.
> 
> I've gotten as far as using git ls-tree to track down the sha1 of the
> blob I want to follow, which I'm assuming is the key to making this
> happen but I'm not sure where to go from there. :(
> 
> Can someone please point me to an example showing how to go about this?

For example in git.git repository, try "git gui blame revision.c". The 9th fragment, the 'path_name' function, was moved there from the file "rev-list.c".

This is the commit that added the code:
  commit e646de0d14bac20ef6e156c1742b9e62fb0b9020
  Author:	Junio C Hamano <junkio@cox.net>  czw lut 23 07:10:24 2006
  Committer:	Junio C Hamano <junkio@cox.net>  pi? lut 24 08:44:42 2006
  Original File:	rev-list.c
  rev-list --objects: use full pathname to help hashing.
  This helps to group the same files from different revs together,
  while spreading files with the same basename in different
  directories, to help pack-object.
  Signed-off-by: Junio C Hamano <junkio@cox.net>
This is the commit that moved the code
  commit ae563542bf10fa8c33abd2a354e4b28aca4264d7
  Author:	Linus Torvalds <torvalds@osdl.org>  nie lut 26 01:19:46 2006
  Committer:	Junio C Hamano <junkio@cox.net>  pon lut 27 00:33:27 2006
  First cut at libifying revlist generation
  This really just splits things up partially, and creates the
  interface to set things up by parsing the command line.
  No real code changes so far, although the parsing of filenames is a bit
  stricter. In particular, if there is a "--", then we do not accept any
  filenames before it, and if there isn't any "--", then we check that _all_
  paths listed are valid, not just the first one.
  The new argument parsing automatically also gives us "--default" and
  "--not" handling as in git-rev-parse.
  Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  Signed-off-by: Junio C Hamano <junkio@cox.net>

You can check the commits using gitweb; unfortunately blame in gitweb is usually disabled, and it dies not have fancy "git gui blame" showing of code movements.

P.S. Sorry, I've just noticed that the dates are in my locale...
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: Rhodes, KateNext: Rhodes, Kate
Message 2 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.