28

I have a user that has, up until today, been called foo.bar. Now that user will be known as fb instead from here on. But I would like to update all the old commits to reflect this username instead of the old one for statistical reasons etc. How can this be done?

I know about the syntax

svn propset --revprop -r revision_number svn:author your_username

But that would require a lot of manual labor. Is there an existing function or script that just takes the name to replace and the name to replace it with?

Update:

Here is a small script I made to handle this since I will be doing this on a lot of repos for a lot of users :) Just run it in the checked out repository folder of your choice. Note that error handling is at a minimum in the script.

https://github.com/inquam/svn-rename-author

inquam
  • 12,664
  • 15
  • 61
  • 101
  • 1
    +1 for the script which works just as expected (just had to add the path to my repo(s) at the end of each `svn` command). Note: the `pre-revprop-change` hook must be activated and return 0 on the `revprop` command – Bruno Grieder Mar 02 '13 at 11:50

4 Answers4

22

You can build a command to get the revisions in the log which old_username has committed with:

svn log | grep "^r[0-9]* | old_username |" | cut -c 2- | awk '{print $1}'

This command gets the logs, searches for lines that appear at the start of each revision, drops the first character (i.e. the r) from those lines and then takes the first remaining part of the line, which is the revision.

You can use this information in a variety of ways. In bash you could make it produce the sequence of svn propset commands with:

for f in `svn log | grep "^r[0-9]* | old_username |" | cut -c 2- | awk '{print $1}'`
do
svn propset --revprop -r $f svn:author your_username
done

which iterates over the values created by the first expression (now in backquotes) and uses those values for your svn propset command, replacing the $f with the appropriate revision value.

iron9
  • 397
  • 2
  • 12
borrible
  • 17,120
  • 7
  • 53
  • 75
3

Insert the following into your pre-revprop-change.bat (by opening it in notepad) in a folder called something like this (depending on your configuration) C:\ASP.NET Projecten\ProjectX\hooks

set magProperyWijzigen = false;
:: Only allow the log message and author to be changed.
if("%propertyName%" == "svn:author") magProperyWijzigen = true;
if("%propertyName%" == "svn:log") magProperyWijzigen = true;

if "%magProperyWijzigen%" == "false" goto ERROR_PROPNAME
asmit
  • 39
  • 1
1

I've tested this until the last system command. (I didn't want to change my repository), but this Perl program should work:

#! /usr/bin/env perl
#

use strict;
use warnings;
use feature qw(say);
use autodie;   #Don't have to test if open fails

use constant {
    SVN      => "svn",
    REPOS    => "http://source/src/myrepo",
    OLD_NAME => "dbrown",
    NEW_NAME => "db",
};

open (my $log, "-|", LOG_CMD);

while (my $line = <$log>) {
    chomp $line;

    #
    # Is this a revision line?
    #

while (my $line = <$log>) {
    chomp $line;
    next unless $line =~ /^r       #Line starts with an "r"
                         (\d+)     #Followed by digits (Capture)
                         \s\|\s    #And a "|" separator
                         ([^\|]+)  #This should be the name (Capture)
                         \s+\|     #And another separator
                         /x;
    my $revision = $1;
    my $author = $2;
    next unless $author eq OLD_NAME;

    #
    # Found the Author
    #
    my $command = qq(@{[SVN]} -r $revision pset --revprop svn:author @{[NEW_NAME]});
    my $error = system $command;
    say STDERR qq(Couldn't modify revision $revision) if $error;
}
David W.
  • 105,218
  • 39
  • 216
  • 337
-6
  1. svnadmin dump
  2. Edit dump-file
  3. Kill old repo
  4. Create new and svnadmin load edited data
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
  • borrible's method is much safer and easier than fiddling around with bulky dumpfiles. Also editing dumpfiles is not supported in terms of subversion toolchain. why using a risky method if there is a tool fitting for the job? – Peter Parker Feb 13 '12 at 22:06
  • How do you edit the dump file? Do you do this manually, or is there an automated way to do this? The OP knows how to change the author without taking the repo down and manually editing the dump (which is not recommended since a bad change can destroy the whole repo). The author simply wants a way to automate the process. – David W. Feb 13 '12 at 22:07