{"thread":{"id":"2169","subject":"Re: git-filehistory (3rd try at detecting renames)","startedAt":"2005-10-20T21:23:09Z","lastAt":"2005-10-20T23:32:42Z","messageCount":2,"participants":["David Ho","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"10373","messageId":"4dd15d180510201423y5e200b68xec32bffec0f0cf84@mail.gmail.com","threadId":"2169","inReplyTo":null,"subject":"Re: git-filehistory (3rd try at detecting renames)","fromName":"David Ho","fromEmail":"davidkwho@gmail.com","sentAt":"2005-10-20T21:23:09Z","receivedAt":"2005-10-20T21:23:09Z","isPatch":false,"sender":{"key":"davidkwho@gmail.com","avatar":"https://gravatar.com/avatar/1596ca9708bdd00a5c237f15af1011d65b6ef49a3bd9e9152e0bf09e7577fb5a?d=mp&s=160"},"body":"Sorry, once again, this calls git-diff-tree once per commit.\n\n[davidho@penguin git-tutorial]$ cat git-filehistory.perl\n#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\nsub usage($);\n\n# Sanity checks:\nmy $GIT_DIR = $ENV{'GIT_DIR'} || \".git\";\n\nunless ( -d $GIT_DIR && -d $GIT_DIR . \"/objects\" &&\n        -d $GIT_DIR . \"/objects/\" && -d $GIT_DIR . \"/refs\") {\n        usage(\"Git repository not found.\");\n}\n\nusage(\"\") if scalar @ARGV != 1;\n\nmy ($file) = @ARGV;\n\nunless (-f $file) {\n        usage(\"git filehistory: '$file' does not exist\");\n}\n\nopen(F,\"-|\",\"git-rev-parse\",,\"--default\",\"HEAD\",\"--revs-only\",$file);\nmy $git_rev_args = <F>;\nchomp ($git_rev_args);\nclose (F);\n\nopen(F,\"-|\",\"git-rev-list\", $git_rev_args);\nmy @commits = <F>;\nclose (F);\n\nmy $nextname = $file;\nmy (@renamecommit, @renamecomment, @renameentry);\nfor (my $i=0; $i < scalar @commits; $i++)\n{\n        my $commit = $commits[$i];\n        chomp ($commit);\n        open (F, \"-|\",\"git-diff-tree\",\"-r\",\"-M\",\"--pretty=medium\",$commit);\n        @renamecommit = <F>;\n        close(F);\n        @renamecomment = grep /^[^:]/, @renamecommit;\n        @renameentry = grep /$nextname/, @renamecommit;\n        push @renamecomment, @renameentry;\n        if (scalar @renameentry) {\n                if ($renameentry[0] =~ /\\t$nextname$/) {\n                        foreach (@renamecomment) {\n                                print;\n                        }\n                }\n                if ($renameentry[0] =~ /R\\d{3}\\t(.+)\\t(.+)/) {\n                        #The file is renamed\n                        $nextname = $1;\n                }\n        }\n}\n\nsub usage($) {\n        my $s = shift;\n        print $s, \"\\n\" if (length $s != 0);\n        print <<EOT;\n$0 <file>\nThis script traces renames to find the origin of the file\nEOT\n        exit(1);\n}\n"},{"id":"10376","messageId":"Pine.LNX.4.63.0510210130480.10503@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2169","inReplyTo":"4dd15d180510201423y5e200b68xec32bffec0f0cf84@mail.gmail.com","subject":"Re: git-filehistory (3rd try at detecting renames)","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-10-20T23:32:42Z","receivedAt":"2005-10-20T23:32:42Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 20 Oct 2005, David Ho wrote:\n\n> Sorry, once again, this calls git-diff-tree once per commit.\n\nHow about detecting renames only when the tree does not have an object of \nthe same name? You could even use the pathspec optimizations to track just \nthat file through history, and do a git-diff-tree on the last commit \ncontaining that file.\n\nCiao,\nDscho\n"}]}