From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Ho Subject: Re: git-filehistory (first cut at detecting renames) Date: Thu, 20 Oct 2005 16:19:15 -0400 Message-ID: <4dd15d180510201319k6beeb1f3j89eae34322d12c90@mail.gmail.com> References: <4dd15d180510201251p57bea756s18b2e77d4be4ec35@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7BIT X-From: git-owner@vger.kernel.org Thu Oct 20 22:21:41 2005 Return-path: Received: from vger.kernel.org ([209.132.176.167]) by ciao.gmane.org with esmtp (Exim 4.43) id 1ESgsj-0002Gn-Fj for gcvg-git@gmane.org; Thu, 20 Oct 2005 22:19:21 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932522AbVJTUTS (ORCPT ); Thu, 20 Oct 2005 16:19:18 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S932523AbVJTUTS (ORCPT ); Thu, 20 Oct 2005 16:19:18 -0400 Received: from qproxy.gmail.com ([72.14.204.193]:31402 "EHLO qproxy.gmail.com") by vger.kernel.org with ESMTP id S932522AbVJTUTR convert rfc822-to-8bit (ORCPT ); Thu, 20 Oct 2005 16:19:17 -0400 Received: by qproxy.gmail.com with SMTP id v40so402046qbe for ; Thu, 20 Oct 2005 13:19:15 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=RVOD92ACwbsdamuoaYyFBJyvZhqgBeGmvKBlm60ltkqRfO9VvFZ4vCM1Jg3H+PQNfjsOHzPatOOuwkh5NiVCufUGsz+OkH6lbjWJLWIJ5yfyIpzvTBgeJmCAzDAiW/sSsm0eijFF+ffrx5eWhIWEgmHZE14ypwF5aDfL4KQsdRs= Received: by 10.65.192.13 with SMTP id u13mr1841847qbp; Thu, 20 Oct 2005 13:19:15 -0700 (PDT) Received: by 10.65.22.3 with HTTP; Thu, 20 Oct 2005 13:19:15 -0700 (PDT) To: git@vger.kernel.org In-Reply-To: <4dd15d180510201251p57bea756s18b2e77d4be4ec35@mail.gmail.com> Content-Disposition: inline Sender: git-owner@vger.kernel.org Precedence: bulk X-Mailing-List: git@vger.kernel.org Archived-At: Actually, just tried it on the git repository. It is very slow. Maybe because I'm doing a complete diff-tree on each commit. Mmm... maybe there is a better way to detect renames when walking up the file history. David On 10/20/05, David Ho wrote: > Hi all, > > This is my stupid perl script to detect renames all the way to it's > origin. This is my first attempt at writing a perl script so it looks > a bit awful. It's not perfect, if a file is renamed, the entire > commit is dumped out. Maybe if git-diff-tree -M does post > processing to output changes relevant to then it will work > quite well. > > 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 = ; > chomp ($git_rev_args); > close (F); > > open(F,"-|","git-rev-list", $git_rev_args); > my @commits = ; > close (F); > > my $nextname = $file; > 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/, ; > close(F); > if (scalar @lines >=1) { > #The file is renamed! > my $rc = system > ("git-diff-tree","-r","-M","-p","--pretty=medium",$commit); > die "git-diff-tree failed" if $rc; > print "\n"; > if ($lines[0] =~ /R\d{3}\t(.+)\t(.+)/) { > $nextname = $1; > } > } > else { > #Not renamed > my $rc = system > ("git-diff-tree","-r","-m","-p","--pretty=medium",$commit, $nextname); > die "git-diff-tree failed" if $rc; > print "\n"; > } > } > > sub usage($) { > my $s = shift; > print $s, "\n" if (length $s != 0); > print < $0 > This script traces renames to find the origin of the file > EOT > exit(1); > } >