water has asked for the wisdom of the Perl Monks concerning the following question:

Hi --

I am looking for a way from w/in a perl program to determine, for a given file in a subversion repository, the last person who committed a change to that file. Any suggestions or module recommendations much appreciated.



Replies are listed 'Best First'.
Re: Subversion: last change author
by brian_d_foy (Abbot) on Oct 27, 2006 at 05:10 UTC

    I have this little script, although it shells out to svn log to ask it about the file. It's good enough for the rare times when I need it and don't want to look at svn log directly.

    #!/usr/bin/perl foreach $f (@ARGV) { open F, "svn log $f |"; while(<F>) { next unless /^r/; /^(r\d+)\s+\|\s+(.*?)\s+\|/; print "$f $1 $2\n"; last } close F or do { $! = $? >> 8; warn "Could not read $f: $!" }; }

    The output shows me the file, last revision where the file was changed, and who changed it. With a little more work I could get the date (or just print the entire second line from svn log).

    $ svn-who Chap*/*.pod ... Chapters/16.tied_variables.pod r137 brian Chapters/17.modulinos.pod r130 brian Chapters/18.bit_vectors.pod r137 brian Chapters/19.foriegn_relations.pod r137 brian
    brian d foy <brian@stonehenge.com>
    Subscribe to The Perl Review
Re: Subversion: last change author
by imp (Priest) on Oct 27, 2006 at 02:19 UTC

      SVNLook seems to take a version perspective on the tree -- how get a file perspective?

      Rather than "which author made the last revision to the repository, and which files were involved", I'm looking to determine "which author made the most recent change to file 'x', and when was that change made".

      Can SVNLook do that, or did I misread the docs?


Re: Subversion: last change author
by Fletch (Chancellor) on Oct 27, 2006 at 12:25 UTC

    An svn ls -v file should show the last author and revision of the last commit for a given file (among other things; see svn help ls). You can run that through a piped open or backticks, or see if the module referenced previously gives a way to do that.