18

When my team first started out with SVN we all just used our first names when committing to the repository, however, now that our team has grown, we are running into issues because we just hired a second Mike.

What we would like to do is change everybody's usernames to be the same as the username on their computer (first name initial + last name). The issue that I'm seeing is that the SVN history will still show the old usernames on commits.

Is there a tool out there for changing usernames throughout the entire history of a repository?

For example, I would like every commit that is currently attributed to Mike to change to msmith, all the way back to revision 1.

My first thought is that I'll have to do some parsing and processing on a dump file, but a tool would be nice.

4
  • 3
    Have you tried renaming Mike?
    – Draemon
    Jul 28, 2009 at 16:53
  • 6
    We have actually, for a short time we were referring to him as Phil... Jul 29, 2009 at 12:36
  • 2
    You're welcome, if only it was a joke... Jan 25, 2013 at 1:52
  • 1
    Could you accept Greg's answer? The question is still actual, and that answer gives the easiest way to do it for a Linux server, as it doesn't require any repo outage or tweaks. It would be really helpful if people looking for an answer saw it first. Nov 28, 2019 at 6:23

7 Answers 7

21

You can use svndumptool:

svnadmin dump path/to/my/repo > repo.dump

svndumptool transform-revprop svn:author originalregexp newvalue repo.dump newrepo.dump

1
  • I was moving a package from a private repo to community repo where the users had different author names. I used svndumptool and it worked perfectly.
    – claytron
    Aug 24, 2010 at 15:18
13

TortoiseSVN has excellent support for this functionality: within its Revision Log Dialog one can filter by author (even via regular expressions), select revisions from the filtered list as desired (usually all like in this question) and select 'Edit author' from the context menu.

The pre condition of having a pre-revprop-change hook in place as mentioned in jeroenhs answer does still apply, of course.

The processing is rather slow, but depending on ones needs this might still be much faster and/or more convenient then having to dump an entire repository and process these potentially huge dump file(s) with scripts.

12

yes there is:

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

However, svn does not allow changing revision properties by default. You need to set up a pre-revprop-change hook script for that. On windows, it suffices to put a bat-file in the hooks folder of your repository that simply contains one line:

exit 0

If that is set up, you should be able to write a script for your needs.

EDIT: I didn't test this through, but I think this should do the trick in PowerShell:

([xml] ( svn log --xml )).log.logentry 
   | ? {$_.author -eq "Mike"} 
   | foreach {svn propset --revprop -r $_.revision svn:author msmith}
1
  • 2
    svnadmin gets around the hook problem
    – Greg
    Aug 1, 2012 at 21:00
7

On the repository server, you can:

echo -n "msmith" > msmith.txt
svn log /svn -q | grep '^r[0-9]* | Mike |' | cut -f 1 -d' ' | xargs -n1 svnadmin setrevprop /svn svn:author msmith.txt -r

Here's what that's doing:

  1. Store the new username in a file with no newline at the end (echo -n)
  2. Get the full log for the repository in /svn, displaying only the summary info (not the log message) (svn log -q)
  3. Find lines with Mike (grep). Note: in most cases, something like grep Mike would do just fine, but if you had a user named Jul, you risk updating every commit made in July (more or less risk depending on your locale)
  4. Filter out everything except the first field (the revision #) (cut)
  5. Run a svnadmin command on every revision found in step 4 (xargs). Only pass one revision per execution of the command (-n1). That will replace the svn:author property with the contents of the msmith.txt file.
1
  • This is the best answer!
    – gecco
    Apr 3, 2014 at 13:45
3

In Thunder Below, the story of the USS Barb in WWII, a new officer comes aboard. The Captain asks him his name. "Mike", he responds. "Nope, we already have a Mike", says the Captain. "We'll call you Robert. In combat, when I call out orders, there can be no confusion about who I'm talking to."

What I'm getting at is that there's precedent for making your new Mike choose another name.

2

It took a lot of looking but I eventually found a perl script that works against an SVN dump file.

I tried it this morning on a dump of my repository and it worked flawlessly.

Here is the direct link

-2

From memory, the standard SVN answer to change anything in the history is to do a text dump of the database, search-replace through it and re-create the database from that.

But I haven't really looked at the internals of SVN since its 0.x-days, so I might be off...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.