开发者

SVN List of files changed exclusively by 1 user

开发者 https://www.devze.com 2023-03-16 23:56 出处:网络
Our company has 7 developers working on a project for which we use SVN as the VCS. I am not sure if this is possible, but is there a way to find out the list of files in the repository which have be

Our company has 7 developers working on a project for which we use SVN as the VCS.

I am not sure if this is possible, but is there a way to find out the list of files in the repository which have been changed exclusively by a specific user throughout the history of the repository.

For example:

  • There are 3 users - user1, user2, user3
  • Also, there are 3 files - "folder1/file1", "folder1/file2" and "folder2/file1"

The repository has 10 commits -

  • "folder1/file1" has changes only by user1.
  • "folder1/file2" has changes by user2 and user3.
  • "folder2/fil开发者_Python百科e1" has changes by user1, user2 and user3.

Essentially, in above case, if searching for files changed exclusively by user1, the result will be "folder1/file1", since other files have changes from multiple authors.

I have tried Google and SO Search but couldn't find any solution for this. Will be really grateful if there is a way to achieve this.

Regards


Hmmm. Interesting question.

If you're only interested in files visible in the latest revision, you could do something like this:

$ svn --recursive list 

That'll give you a listing of all the files in Subversion (at least the ones that are currently in the HEAD of branches and trunk)

From there, you could pipe that into the Subversion log command for each file to see which users had modified that file in that file's life time.

$ svn -R $URL | while read file
do
     echo "FILE = $file"
     svn log $URL/$file
done

Now, things will get a bit tricky (at least doing this in the shell). You'll have to parse the output of the svn log command which means you're reading from STDIN again. To get around that, you'll have to open another device number for that output and do your while read from that...

Okay, let's do this in Perl...

# Bunch of Pragmas that don't mean much
use strict;
use warnings;
use feature qw(say);

# Defining some constants for svn command and url
use constant {
    URL =>  "svn://localhost",
    SVN =>  "svn",
};
my $cmd;

# This creates the svn list command to list all files
# I'm opening this command as if it's a file
$cmd = SVN . " list -R " . URL;
open (FILE_LIST, "$cmd|")
    or die "Can't open command '$cmd' for reading\n";

# Looping through the output of the "svn list -R URL"
# and setting "$file" to the name of the file
while (my $file = <FILE_LIST>) {
    chomp $file;

    # Now opening the "svn log URL/$file" command as a file
    $cmd = SVN . " log " . URL . "/$file";
    open(FILE_LOG, "$cmd|")
        or die "Can't open command '$cmd' for reading\n";
    my $initialChanger = undef;
    my $changer;

    # Looping through the output of the "svn log" command
    while (my $log = <FILE_LOG>) {
        chomp $log;

        # Skipping all lines that don't start with a revision number.
        # I don't care about the commit log, I want the name of the
        # user who is in the next section over between two pipes
        next unless ($log =~ /^\s*r\d+\s+\|\s*([^|]+)/);

        # The previous RegEx actually caught the name of the changer
        # in the parentheses, and now just setting the changer
        $changer = $1;

        # If there is no initialChanger, I set the changer to be initial
        $initialChanger = $changer if (not defined $initialChanger);

        # And if the changer isn't the same as the initial, I know at least
        # two people edited this file. Get the next file
        if ($initialChanger ne $changer)
        {
            close FILE_LOG;
            next;
        }
    }
    # Finished with file log, if we're down here, there was only
    # one person who edited the file.
    close FILE_LOG;
    say qq(Sole Changer of "$file" is "$changer");
}

Quick and dirty and not well tested. I tested it on my repository, but then I'm the sole changer in my repository. I know you didn't ask for Perl, but I tried my best to explain what I was doing. It's a tool I know how to use. When you have a hammer, everything looks like a nail. Even if that's a big ugly old obsolete hammer you happen to have.


Given a filename you can find out how many people have submitted changes to it with

svn log --xml filename | grep "<author>" | sort -u | wc -l

You could modify that to see whether or not the file has been edited by a specific username

svn log --xml filename | grep "<author>" | sort -u | grep username | wc -l


I don't know SVN command line commands too well, but I do know that using TortoiseSVN on Windows I can view the log, shove my name in the search box and set the date range from the beginning of time to now, select all of the commits that come back in the search and then see all of the files I have every comitted in the file list.

Probably not too helpful if you don't use something like TortoiseSVN, but at least if that can do it then it must be possible!

Edit: added example image so you can see what I mean

SVN List of files changed exclusively by 1 user

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号