如何获得所有Subversion提交作者用户名的列表? [英] How to get a list of all Subversion commit author usernames?

查看:119
本文介绍了如何获得所有Subversion提交作者用户名的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种有效的方法来获取整个SVN存储库或给定资源路径的唯一提交作者列表.我还没有找到专门用于此的SVN命令(并且不要指望一个),但是我希望有一种更好的方法可以解决到目前为止我在Terminal(在OS X上)尝试过的方法:

I'm looking for an efficient way to get the list of unique commit authors for an SVN repository as a whole, or for a given resource path. I haven't been able to find an SVN command specifically for this (and don't expect one) but I'm hoping there may be a better way that what I've tried so far in Terminal (on OS X):

svn log --quiet | grep "^r" | awk '{print $3}'

svn log --quiet --xml | grep author | sed -E "s:</?author>::g"

这两种方法每行都会给我一个作者名,但是它们都需要过滤掉大量的额外信息.他们也不会处理同一作者姓名的重复副本,因此,对于很少有作者进行的大量提交工作,网络上存在大量冗余.通常,我只是想看到唯一的作者用户名.

Either of these will give me one author name per line, but they both require filtering out a fair amount of extra information. They also don't handle duplicates of the same author name, so for lots of commits by few authors, there's tons of redundancy flowing over the wire. More often than not I just want to see the unique author usernames. (It actually might be handy to infer the commit count for each author on occasion, but even in these cases it would be better if the aggregated data were sent across instead.)

我通常使用仅客户端访问,因此svnadmin命令用处不大,但是如果有必要,我可以向存储库管理员提出特别的要求,如果严格需要或更有效的话.我正在使用的存储库具有成千上万的提交和许多活跃的用户,我不想给任何人带来不便.

I'm generally working with client-only access, so svnadmin commands are less useful, but if necessary, I might be able to ask a special favor of the repository admin if strictly necessary or much more efficient. The repositories I'm working with have tens of thousands of commits and many active users, and I don't want to inconvenience anyone.

推荐答案

要过滤出重复项,请获取输出并通过以下管道进行传递:sort | uniq.因此:

To filter out duplicates, take your output and pipe through: sort | uniq. Thus:

svn log --quiet | grep "^r" | awk '{print $3}' | sort | uniq

如果这是您要求的方式,我不会感到惊讶. Unix工具通常希望用户与其他工具一起进行精美的处理和分析.

I woud not be surprised if this is the way to do what you ask. Unix tools often expect the user to do fancy processing and analysis with other tools.

P.S.想一想,您可以合并grepawk ...

P.S. Come to think of it, you can merge the grep and awk...

svn log --quiet | awk '/^r/ {print $3}' | sort | uniq

P.P.S. Per Kevin Reid ...

P.P.S. Per Kevin Reid...

svn log --quiet | awk '/^r/ {print $3}' | sort -u

P 3 .S. kan,使用竖线而不是空格作为字段分隔符,以正确处理带有空格的名称(也更新了Python示例)...

P3.S. Per kan, using the vertical bars instead of spaces as field separators, to properly handle names with spaces (also updated the Python examples)...

svn log --quiet | awk -F ' \\\\|' '/^r/ {print $2}' | sort -u

要获得更高的效率,您可以执行Perl一线操作.我不太了解Perl,所以我最终会在Python中做到这一点:

For more efficient, you could do a Perl one-liner. I don't know Perl that well, so I'd wind up doing it in Python:

#!/usr/bin/env python
import sys
authors = set()
for line in sys.stdin:
    if line[0] == 'r':
        authors.add(line.split('|')[1].strip())
for author in sorted(authors):
    print(author)

或者,如果您想计数:

#!/usr/bin/env python
from __future__ import print_function # Python 2.6/2.7
import sys
authors = {}
for line in sys.stdin:
    if line[0] != 'r':
        continue
    author = line.split('|')[1].strip()
    authors.setdefault(author, 0)
    authors[author] += 1
for author in sorted(authors):
    print(author, authors[author])

然后您将运行:

svn log --quiet | ./authorfilter.py

这篇关于如何获得所有Subversion提交作者用户名的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆