[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: The "follow copy history" initiative

From: Martin Tomes <lists_at_tomes.org>
Date: 2004-04-02 22:59:18 CEST

Branko Čibej wrote:
> C. Michael Pilato wrote:
>>Greg Hudson <ghudson@MIT.EDU> writes:
>>
>>>I'm not saying it's never useful to know what copies of a node were made
>>>in the past or the future.

The attached perl program finds copy points on a file. It isn't
desperately efficient but it does do the job.

-- 
Martin

#!/usr/bin/perl

use strict;
use SVN::Client;

die "usage: findcopies repository path" if ($#ARGV < 1);
my $repo = $ARGV[0];
my $path = $ARGV[1];
$path =~ s/\//\\\//g;
my %copies;

my $ctx = new SVN::Client(
    auth => [SVN::Client::get_simple_provider(),
             SVN::Client::get_simple_prompt_provider(\&simple_prompt, 2),
             SVN::Client::get_username_provider()]
          );

sub simple_prompt {
 my $cred = shift;
 my $realm = shift;
 my $default_username = shift;
 my $may_save = shift;
 my $pool = shift;
 $cred->username('xxx');
 $cred->password('xxx');
}

sub show_log {
 my $changed_paths = shift;
 my $revision = shift;
 my $author = shift;
 my $date = shift;
 my $message = shift;
 my $pool = shift;

 $author = '(no author)' if (!defined($author));
 $date = '(no date)' if (!defined($date));
 $message = '' if (!defined($message));

 foreach my $key (sort keys %$changed_paths) {
   my $frompath = $changed_paths->{$key}->copyfrom_path();
   if ($frompath && ($frompath =~ /^$path/)) {
     $copies{$revision} = [ $date,
                            $author,
                            $key,
                            $frompath,
                            $changed_paths->{$key}->copyfrom_rev(),
                            $message ];
   }
 }
}

sub max {
  my ($a, $b) = @_;
  if ($a < $b) {
    return $b;
  } else {
    return $a;
  }
}

$ctx->log($repo . '/',
          'HEAD',
          1,
          1,
          0,
          \&show_log);

my @sortedkeys = sort keys %copies;
if ($#sortedkeys >= 0) {
  my $fromwidth=4;
  my $towidth=2;
  foreach my $revision (@sortedkeys) {
    my $info = $copies{$revision};
    $fromwidth = max($fromwidth, length($info->[3].':'.$info->[4]));
    $towidth = max($towidth, length($info->[2]));
  }
  my $fmt = '%5s %' . $fromwidth . 's->%-'. $towidth . 's' . "\n";
  printf $fmt, 'Rev.', 'From', 'To';
  foreach my $revision (@sortedkeys) {
    my $info = $copies{$revision};
    printf $fmt, $revision, $info->[3].':'.$info->[4], $info->[2];
  }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Apr 2 23:00:06 2004

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.