From: David Ho <davidkwho@gmail.com>
To: git@vger.kernel.org
Subject: Re: git-filehistory (2nd try at detecting renames)
Date: Thu, 20 Oct 2005 16:52:13 -0400 [thread overview]
Message-ID: <4dd15d180510201352m754e70afycc580b0daf66c6d0@mail.gmail.com> (raw)
The output is a bit more manageable with this, but still a bit slow.
I tried it on git-commit.sh
David
[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", $commit)
or die "Failed to open pipe from git-diff-tree: " . $!;
my @lines = grep /R\d{3}.+$nextname/, <F>;
close(F);
if (scalar @lines >=1) {
#The file is renamed!
#my $rc = system
("git-diff-tree","-r","-M","-p","--pretty=medium",$commit);
open (F,
"-|","git-diff-tree","-r","-M","--pretty=medium",$commit);
@renamecommit = <F>;
@renamecomment = grep /^[^:]/, @renamecommit;
@renameentry = grep /R\d{3}.+$nextname/, @renamecommit;
push @renamecomment, @renameentry;
foreach (@renamecomment) {
print;
}
if ($lines[0] =~ /R\d{3}\t(.+)\t(.+)/) {
$nextname = $1;
}
close(F);
}
else {
#Not renamed
#my $rc = system
("git-diff-tree","-r","-m","-p","--pretty=medium",$commit, $nextname);
my $rc = system
("git-diff-tree","-r","--pretty=medium",$commit, $nextname);
die "git-diff-tree failed" if $rc;
}
}
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);
}
reply other threads:[~2005-10-20 20:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4dd15d180510201352m754e70afycc580b0daf66c6d0@mail.gmail.com \
--to=davidkwho@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox