Git development
 help / color / mirror / Atom feed
* Re: git-filehistory (3rd try at detecting renames)
@ 2005-10-20 21:23 David Ho
  2005-10-20 23:32 ` Johannes Schindelin
  0 siblings, 1 reply; 2+ messages in thread
From: David Ho @ 2005-10-20 21:23 UTC (permalink / raw)
  To: git

Sorry, once again, this calls git-diff-tree once per commit.

[davidho@penguin git-tutorial]$ cat git-filehistory.perl
#!/usr/bin/perl

use warnings;
use strict;

sub usage($);

# Sanity checks:
my $GIT_DIR = $ENV{'GIT_DIR'} || ".git";

unless ( -d $GIT_DIR && -d $GIT_DIR . "/objects" &&
        -d $GIT_DIR . "/objects/" && -d $GIT_DIR . "/refs") {
        usage("Git repository not found.");
}

usage("") if scalar @ARGV != 1;

my ($file) = @ARGV;

unless (-f $file) {
        usage("git filehistory: '$file' does not exist");
}

open(F,"-|","git-rev-parse",,"--default","HEAD","--revs-only",$file);
my $git_rev_args = <F>;
chomp ($git_rev_args);
close (F);

open(F,"-|","git-rev-list", $git_rev_args);
my @commits = <F>;
close (F);

my $nextname = $file;
my (@renamecommit, @renamecomment, @renameentry);
for (my $i=0; $i < scalar @commits; $i++)
{
        my $commit = $commits[$i];
        chomp ($commit);
        open (F, "-|","git-diff-tree","-r","-M","--pretty=medium",$commit);
        @renamecommit = <F>;
        close(F);
        @renamecomment = grep /^[^:]/, @renamecommit;
        @renameentry = grep /$nextname/, @renamecommit;
        push @renamecomment, @renameentry;
        if (scalar @renameentry) {
                if ($renameentry[0] =~ /\t$nextname$/) {
                        foreach (@renamecomment) {
                                print;
                        }
                }
                if ($renameentry[0] =~ /R\d{3}\t(.+)\t(.+)/) {
                        #The file is renamed
                        $nextname = $1;
                }
        }
}

sub usage($) {
        my $s = shift;
        print $s, "\n" if (length $s != 0);
        print <<EOT;
$0 <file>
This script traces renames to find the origin of the file
EOT
        exit(1);
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-10-20 23:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-20 21:23 git-filehistory (3rd try at detecting renames) David Ho
2005-10-20 23:32 ` Johannes Schindelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox