我们公司有 7 名开发人员在从事一个我们使用 SVN 作为 VCS 的项目。
我不确定这是否可行,但是有没有办法找出存储库中的文件列表,这些文件在存储库的整个历史记录中已由特定用户专门更改。
例如:
存储库有 10 次提交 -
本质上,在上述情况下,如果搜索仅由 更改的文件用户 1 ,结果将是 “文件夹 1/文件 1” ,因为其他文件有来自多个作者的更改。
我尝试过 Google 和 SO Search,但找不到任何解决方案。如果有办法实现这一点,将不胜感激。
问候
最佳答案
嗯。有趣的问题。
如果您只对最新版本中可见的文件感兴趣,您可以执行以下操作:
$ svn --recursive list
这将为您提供 Subversion 中所有文件的列表(至少是当前位于分支和主干 HEAD 中的文件)
从那里,您可以将其通过管道传输到 Subversion
log
每个文件的命令以查看哪些用户在该文件的生命周期内修改了该文件。$ svn -R $URL | while read file
do
echo "FILE = $file"
svn log $URL/$file
done
现在,事情会变得有点棘手(至少在 shell 中这样做)。您必须解析
svn log
的输出命令,这意味着您正在再次从 STDIN 读取。要解决这个问题,您必须为该输出打开另一个设备编号,然后从该输出中读取...好的,让我们用 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");
}
又快又脏,而且没有经过很好的测试。我在我的存储库中对其进行了测试,但随后我是存储库中唯一的更改者。我知道你没有要求 Perl,但我尽力解释我在做什么。这是我知道如何使用的工具。当你有锤子时,一切看起来都像钉子。即使那是你碰巧拥有的又大又丑又旧的过时锤子。
关于SVN 由 1 个用户专门更改的文件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6572728/