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

Re: yet better rename approach?: (was RE: rename overwrites code: this a reasonable interim solution?)

From: Justin Johnson <justinjohnson_at_gmail.com>
Date: 2007-04-27 18:35:37 CEST

On 4/27/07, lsuvkne@onemodel.org <lsuvkne@onemodel.org> wrote:
> >>> On Fri, Apr 27, 2007 at 9:30 am, justinjohnson@gmail.com wrote:
> > Wrapping up client commands isn't really an option for me. There are
> > too many clients to make this feasible (command line, TortoiseSVN, IDE
> > plugins).
>
> If we do that we'll have to train our people
> to use the command line only for merges; in our case this seems
> possible.
>
> > I wrote a script that parses revisions from the log and determines if
> > a rename happened. It seems like svnmerge.py should be able to detect
> > when something was renamed and make sure changes aren't lost. It may
> > require asking the user which file/directory should be kept (i.e. what
> > history to preserve) and then it can merge the lost changes into that
> > file/directory.
>
> What is the reliable logic to determine if a rename happened? Like
> if a directory (java package) is renamed, or if there are other adds
> & deletes at the same time? I didn't see a way but if it works, then
> modifying svnmerge.py sounds attractive.

Here is sample log output for clarification.

C:\work\testwc2>svn log -v -r 14
------------------------------------------------------------------------
r14 | jjohn53 | 2007-04-26 13:46:33 -0500 (Thu, 26 Apr 2007) | 1 line
Changed paths:
   A /trunk/foo.txt (from /trunk/new_file.txt:12)
   D /trunk/new_file.txt

------------------------------------------------------------------------

From the log output I parse for:

1) " A NEW_PATH (from OLD_PATH:REV)" saving OLD_PATH
2) " D OLD_PATH"

Here is the quick and dirty perl script.

# Run while in a working copy.

# Get single revision or revision range
my $revs = $ARGV[0];

# Get the repository root from the working copy
my $repos_url = "";
my @info_output = `svn info`;
foreach (@info_output)
{
   if (/Repository Root: (.+)$/)
   {
      $repos_url = $1;
      last;
   }
}

# Get log for all revisions. If none specified, get all revisions.
my @log_output = ();
if ($revs)
{
   @log_output = `svn log $repos_url -v -r $revs`;
}
else
{
   @log_output = `svn log $repos_url -v`;
}

# Parse log output into each revision
# Shift off the first one since we know we're starting a new revision.
my $line = shift @log_output;
while (@log_output)
{
   # New revision starts here
   if ($line =~ /^\-\-\-/)
   {
      my $rev = "";
      my %copied_from = ();
      my %deleted = ();
      $line = shift @log_output;
      while ($line !~ /^\-\-\-/)
      {
         if ($line =~ /^r(\d+)/)
         {
            $rev = $1;
         }
         if ($line =~ / A (.+) \(from (.+)\:\d+\)$/)
         {
            $copied_from{$1} = "$2";
         }
         if ($line =~ / D (.+)$/)
         {
            $deleted{$1} = 1;
         }
         $line = shift @log_output;
      }

      # Display results
      foreach my $c (keys %copied_from)
      {
         my $old_file = $copied_from{$c};
         if (defined $deleted{"$old_file"})
         {
            print "r$rev\t Renamed '$old_file' to '$c'\n";
         }
      }
   }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Fri Apr 27 18:36:07 2007

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

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