{"thread":{"id":"12125","subject":"looking for example of following code across files","startedAt":"2008-02-16T04:41:20Z","lastAt":"2008-02-16T17:54:45Z","messageCount":4,"participants":["Rhodes, Kate","Jakub Narebski","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"68864","messageId":"57E76010-D0F8-420C-A11D-8884832FD00D@gmail.com","threadId":"12125","inReplyTo":null,"subject":"looking for example of following code across files","fromName":"Rhodes, Kate","fromEmail":"masukomi@gmail.com","sentAt":"2008-02-16T04:41:20Z","receivedAt":"2008-02-16T04:41:20Z","isPatch":false,"sender":{"key":"masukomi@gmail.com","avatar":null},"body":"I seem to remember that when Linus was giving the tech-talk to the  \nfolks at Google he mentioned Git being able to follow a block of code  \nas it was moved from file to file, but I'm having a hard time finding  \nan actual example of how that plays out. I'd love to be able to  \ndemonstrate this to people but I'm not quite sure of the steps I'd  \nneed to do to accomplish this.\n\nI've gotten as far as using git ls-tree to track down the sha1 of the  \nblob I want to follow, which I'm assuming is the key to making this  \nhappen but I'm not sure where to go from there. :(\n\nCan someone please point me to an example showing how to go about this?\n\n\n-Kate=masukomi\n"},{"id":"68890","messageId":"m3pruxb6rh.fsf@localhost.localdomain","threadId":"12125","inReplyTo":"57E76010-D0F8-420C-A11D-8884832FD00D@gmail.com","subject":"Re: looking for example of following code across files","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-02-16T09:16:56Z","receivedAt":"2008-02-16T09:16:56Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"\"Rhodes, Kate\" <masukomi@gmail.com> writes:\n\n> I seem to remember that when Linus was giving the tech-talk to the\n> folks at Google he mentioned Git being able to follow a block of code\n> as it was moved from file to file, but I'm having a hard time finding\n> an actual example of how that plays out. I'd love to be able to\n> demonstrate this to people but I'm not quite sure of the steps I'd\n> need to do to accomplish this.\n> \n> I've gotten as far as using git ls-tree to track down the sha1 of the\n> blob I want to follow, which I'm assuming is the key to making this\n> happen but I'm not sure where to go from there. :(\n> \n> Can someone please point me to an example showing how to go about this?\n\nFor example in git.git repository, try \"git gui blame revision.c\".\nThe 9th fragment, the 'path_name' function, was moved there from the\nfile \"rev-list.c\".\n\nThis is the commit that added the code:\n\n  commit e646de0d14bac20ef6e156c1742b9e62fb0b9020\n  Author:\tJunio C Hamano <junkio@cox.net>  czw lut 23 07:10:24 2006\n  Committer:\tJunio C Hamano <junkio@cox.net>  pi? lut 24 08:44:42 2006\n  Original File:\trev-list.c\n\n  rev-list --objects: use full pathname to help hashing.\n\n  This helps to group the same files from different revs together,\n  while spreading files with the same basename in different\n  directories, to help pack-object.\n\n  Signed-off-by: Junio C Hamano <junkio@cox.net>\n\nThis is the commit that moved the code\n\n  commit ae563542bf10fa8c33abd2a354e4b28aca4264d7\n  Author:\tLinus Torvalds <torvalds@osdl.org>  nie lut 26 01:19:46 2006\n  Committer:\tJunio C Hamano <junkio@cox.net>  pon lut 27 00:33:27 2006\n\n  First cut at libifying revlist generation\n\n  This really just splits things up partially, and creates the\n  interface to set things up by parsing the command line.\n\n  No real code changes so far, although the parsing of filenames is a bit\n  stricter. In particular, if there is a \"--\", then we do not accept any\n  filenames before it, and if there isn't any \"--\", then we check that _all_\n  paths listed are valid, not just the first one.\n\n  The new argument parsing automatically also gives us \"--default\" and\n  \"--not\" handling as in git-rev-parse.\n\n  Signed-off-by: Linus Torvalds <torvalds@osdl.org>\n  Signed-off-by: Junio C Hamano <junkio@cox.net>\n\nYou can check the commits using gitweb; unfortunately blame in gitweb\nis usually disabled, and it dies not have fancy \"git gui blame\"\nshowing of code movements.\n\nP.S. Sorry, I've just noticed that the dates are in my locale...\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"68905","messageId":"44F74AD0-CD8E-4715-BA88-4355F4513AB0@gmail.com","threadId":"12125","inReplyTo":"m3pruxb6rh.fsf@localhost.localdomain","subject":"Re: looking for example of following code across files","fromName":"Rhodes, Kate","fromEmail":"masukomi@gmail.com","sentAt":"2008-02-16T17:10:11Z","receivedAt":"2008-02-16T17:10:11Z","isPatch":false,"sender":{"key":"masukomi@gmail.com","avatar":null},"body":"\nOn Feb 16, 2008, at 4:16 AM, Jakub Narebski wrote:\n\n> \"Rhodes, Kate\" <masukomi@gmail.com> writes:\n>\n>> I seem to remember that when Linus was giving the tech-talk to the\n>> folks at Google he mentioned Git being able to follow a block of code\n>> as it was moved from file to file, but I'm having a hard time finding\n>> an actual example of how that plays out.\n[snip]\n>>\n>> Can someone please point me to an example showing how to go about  \n>> this?\n>\n> For example in git.git repository, try \"git gui blame revision.c\".\n> The 9th fragment, the 'path_name' function, was moved there from the\n> file \"rev-list.c\".\n>\n> This is the commit that added the code:\n>\n>  commit e646de0d14bac20ef6e156c1742b9e62fb0b9020\n[snip]\n>\n> This is the commit that moved the code\n>\n>  commit ae563542bf10fa8c33abd2a354e4b28aca4264d7\n[snip]\n>\n> You can check the commits using gitweb; unfortunately blame in gitweb\n> is usually disabled, and it dies not have fancy \"git gui blame\"\n> showing of code movements.\n>\n> P.S. Sorry, I've just noticed that the dates are in my locale...\n\nThank you Jakub. I really appreciate it.\nIn order to find the original commit of each block is the system  \nlooking up the commit for each block via it's SHA1, then following its  \nparent commits until it finds another commit that affected the same  \nblock or runs out of commits?\n\nI'm thinking that while this would be possible to do manually it would  \nway too many lookups to be practical. Or, is there a simpler way to do  \nit on the command line?\n\nI'm just trying to get my head around how the pieces of git fit  \ntogether.\n\n-Kate=masukomi\n"},{"id":"68909","messageId":"20080216175445.GA19506@sigill.intra.peff.net","threadId":"12125","inReplyTo":"44F74AD0-CD8E-4715-BA88-4355F4513AB0@gmail.com","subject":"Re: looking for example of following code across files","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-02-16T17:54:45Z","receivedAt":"2008-02-16T17:54:45Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Feb 16, 2008 at 12:10:11PM -0500, Rhodes, Kate wrote:\n\n> In order to find the original commit of each block is the system looking \n> up the commit for each block via it's SHA1, then following its parent \n> commits until it finds another commit that affected the same block or runs \n> out of commits?\n\nNot exactly. You don't have a sha1 for each block, you have a sha1 for\nthe whole file. So you walk the parent tree looking for the first time a\nparticular chunk showed up. The basic idea is sketched out here:\n\nhttp://article.gmane.org/gmane.comp.version-control.git/28826\n\n> I'm thinking that while this would be possible to do manually it would  \n> way too many lookups to be practical. Or, is there a simpler way to do it \n> on the command line?\n\nYou could do it manually, but it would be horribly slow. An overly\nsimplified version of the algorithm is:\n\n  1. Assume I'm interesed in a line that says \"int foo() {\"\n  2. Check whether my parent has that line\n     2a. If yes, then pass blame to parent, starting at '1'.\n     2b. If no, then I introduced the line. Accept blame.\n\n[When you talk about content movement, it gets a little trickier. See\nJunio's original explanation for more details.]\n\nSo you would end up pass blame for some lines through many commits that\ndidn't touch those lines. I don't think you would want to do that by\nhand.\n\n-Peff\n"}]}