{"thread":{"id":"2168","subject":"Re: git-filehistory (2nd try at detecting renames)","startedAt":"2005-10-20T20:52:13Z","lastAt":"2005-10-20T20:52:13Z","messageCount":1,"participants":["David Ho"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"10372","messageId":"4dd15d180510201352m754e70afycc580b0daf66c6d0@mail.gmail.com","threadId":"2168","inReplyTo":null,"subject":"Re: git-filehistory (2nd try at detecting renames)","fromName":"David Ho","fromEmail":"davidkwho@gmail.com","sentAt":"2005-10-20T20:52:13Z","receivedAt":"2005-10-20T20:52:13Z","isPatch":false,"sender":{"key":"davidkwho@gmail.com","avatar":"https://gravatar.com/avatar/1596ca9708bdd00a5c237f15af1011d65b6ef49a3bd9e9152e0bf09e7577fb5a?d=mp&s=160"},"body":"The output is a bit more manageable with this, but still a bit slow.\nI tried it on git-commit.sh\n\nDavid\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\n        open(F,\"-|\",\"git-diff-tree\",\"-r\",\"-M\", $commit)\n                or die \"Failed to open pipe from git-diff-tree: \" . $!;\n        my @lines = grep /R\\d{3}.+$nextname/, <F>;\n        close(F);\n        if (scalar @lines >=1) {\n                #The file is renamed!\n                #my $rc = system\n(\"git-diff-tree\",\"-r\",\"-M\",\"-p\",\"--pretty=medium\",$commit);\n                open (F,\n\"-|\",\"git-diff-tree\",\"-r\",\"-M\",\"--pretty=medium\",$commit);\n                        @renamecommit = <F>;\n                        @renamecomment = grep /^[^:]/, @renamecommit;\n                        @renameentry = grep /R\\d{3}.+$nextname/, @renamecommit;\n                        push @renamecomment, @renameentry;\n                        foreach (@renamecomment) {\n                                print;\n                        }\n                if ($lines[0] =~ /R\\d{3}\\t(.+)\\t(.+)/) {\n                        $nextname = $1;\n                }\n                close(F);\n        }\n        else {\n                #Not renamed\n                #my $rc = system\n(\"git-diff-tree\",\"-r\",\"-m\",\"-p\",\"--pretty=medium\",$commit, $nextname);\n                my $rc = system\n(\"git-diff-tree\",\"-r\",\"--pretty=medium\",$commit, $nextname);\n                die \"git-diff-tree failed\" if $rc;\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"}]}