如何获取所有 Subversion 提交作者用户名的列表?

发布于 2024-08-26 07:20:06 字数 530 浏览 1 评论 0原文

我正在寻找一种有效的方法来获取整个 SVN 存储库或给定资源路径的唯一提交作者列表。我还没有找到专门为此目的的 SVN 命令(并且不希望有),但我希望可能有一种比我迄今为止在终端(在 OS X 上)中尝试过的更好的方法

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

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

:其中每行都会给我一个作者姓名,但它们都需要过滤掉相当多的额外信息。它们也不处理同一作者姓名的重复项,因此对于少数作者的大量提交,网络上会存在大量冗余。通常我只想查看唯一的作者用户名。 (实际上,有时可以很方便地推断每个作者的提交计数,但即使在这些情况下,如果发送聚合数据会更好。)

我通常与客户合作-only 访问,因此 svnadmin 命令不太有用,但如果有必要,如果绝对必要或更有效的话,我可能可以请求存储库管理员的特别帮助。我正在使用的存储库有数以万计的提交和许多活跃用户,我不想给任何人带来不便。

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.)

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

笨死的猪 2024-09-02 07:20:06

要过滤掉重复项,请获取输出并通过管道:sort |唯一性。因此:

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

如果这是做你所要求的事情的方法,我不会感到惊讶。 Unix 工具通常期望用户使用其他工具进行奇特的处理和分析。

PS 想想看,您可以合并 grepawk...

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

PPS Per Kevin Reid...

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

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

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

为了提高效率,您可以使用 Perl 单行代码。我不太了解 Perl,所以我最终会用 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

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

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

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. 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...

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

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

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)

Or, if you wanted counts:

#!/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])

Then you'd run:

svn log --quiet | ./authorfilter.py
九局 2024-09-02 07:20:06

在 PowerShell 中,将您的位置设置为工作副本并使用此命令。

svn.exe log --quiet |
? { $_ -notlike '-*' } |
% { ($_ -split ' \| ')[1] } |
Sort -Unique

svn.exe log --quiet 的输出格式如下所示:

r20209 | tinkywinky | 2013-12-05 08:56:29 +0000 (Thu, 05 Dec 2013)
------------------------------------------------------------------------
r20208 | dispy | 2013-12-04 16:33:53 +0000 (Wed, 04 Dec 2013)
------------------------------------------------------------------------
r20207 | lala | 2013-12-04 16:28:15 +0000 (Wed, 04 Dec 2013)
------------------------------------------------------------------------
r20206 | po | 2013-12-04 14:34:32 +0000 (Wed, 04 Dec 2013)
------------------------------------------------------------------------
r20205 | tinkywinky | 2013-12-04 14:07:54 +0000 (Wed, 04 Dec 2013)

过滤掉水平规则? { $_ - 不像 '-*' }

r20209 | tinkywinky | 2013-12-05 08:56:29 +0000 (Thu, 05 Dec 2013)
r20208 | dispy | 2013-12-04 16:33:53 +0000 (Wed, 04 Dec 2013)
r20207 | lala | 2013-12-04 16:28:15 +0000 (Wed, 04 Dec 2013)
r20206 | po | 2013-12-04 14:34:32 +0000 (Wed, 04 Dec 2013)
r20205 | tinkywinky | 2013-12-04 14:07:54 +0000 (Wed, 04 Dec 2013)

' \| 分割' 将记录转换为数组。

$ 'r20209 | tinkywinky | 2013-12-05 08:56:29 +0000 (Thu, 05 Dec 2013)' -split ' \| '
r20209
tinkywinky
2013-12-05 08:56:29 +0000 (Thu, 05 Dec 2013)

第二个元素是名称。

将每一行创建一个数组,并使用 % { ($_ -split ' \| ')[1] } 选择第二个元素。

tinkywinky
dispy
lala
po
tinkywinky

使用 Sort -Unique 返回唯一出现的情况。这会将输出排序作为副作用。

dispy
lala
po
tinkywinky

In PowerShell, set your location to the working copy and use this command.

svn.exe log --quiet |
? { $_ -notlike '-*' } |
% { ($_ -split ' \| ')[1] } |
Sort -Unique

The output format of svn.exe log --quiet looks like this:

r20209 | tinkywinky | 2013-12-05 08:56:29 +0000 (Thu, 05 Dec 2013)
------------------------------------------------------------------------
r20208 | dispy | 2013-12-04 16:33:53 +0000 (Wed, 04 Dec 2013)
------------------------------------------------------------------------
r20207 | lala | 2013-12-04 16:28:15 +0000 (Wed, 04 Dec 2013)
------------------------------------------------------------------------
r20206 | po | 2013-12-04 14:34:32 +0000 (Wed, 04 Dec 2013)
------------------------------------------------------------------------
r20205 | tinkywinky | 2013-12-04 14:07:54 +0000 (Wed, 04 Dec 2013)

Filter out the horizontal rules with ? { $_ -notlike '-*' }.

r20209 | tinkywinky | 2013-12-05 08:56:29 +0000 (Thu, 05 Dec 2013)
r20208 | dispy | 2013-12-04 16:33:53 +0000 (Wed, 04 Dec 2013)
r20207 | lala | 2013-12-04 16:28:15 +0000 (Wed, 04 Dec 2013)
r20206 | po | 2013-12-04 14:34:32 +0000 (Wed, 04 Dec 2013)
r20205 | tinkywinky | 2013-12-04 14:07:54 +0000 (Wed, 04 Dec 2013)

Split by ' \| ' to turn a record into an array.

$ 'r20209 | tinkywinky | 2013-12-05 08:56:29 +0000 (Thu, 05 Dec 2013)' -split ' \| '
r20209
tinkywinky
2013-12-05 08:56:29 +0000 (Thu, 05 Dec 2013)

The second element is the name.

Make an array of each line and select the second element with % { ($_ -split ' \| ')[1] }.

tinkywinky
dispy
lala
po
tinkywinky

Return unique occurrences with Sort -Unique. This sorts the output as a side effect.

dispy
lala
po
tinkywinky
梦冥 2024-09-02 07:20:06

我必须在 Windows 中执行此操作,因此我使用 Super Sed 的 Windows 端口 ( http://www.pement. org/sed/ ) - 并替换了 AWK & GREP 命令:

svn log --quiet --xml | sed -n -e "s/<\/\?author>//g" -e "/[<>]/!p" | sort | sed "$!N; /^\(.*\)\n\1$/!P; D" > USERS.txt

这使用可能并非所有计算机上都存在的窗口“排序”。

I had to do this in Windows, so I used the Windows port of Super Sed ( http://www.pement.org/sed/ ) - and replaced the AWK & GREP commands:

svn log --quiet --xml | sed -n -e "s/<\/\?author>//g" -e "/[<>]/!p" | sort | sed "$!N; /^\(.*\)\n\1$/!P; D" > USERS.txt

This uses windows "sort" that might not be present on all machines.

醉生梦死 2024-09-02 07:20:06

您可以使用一个远程存储库:

 svn log --quiet https://url/svn/project/ | grep "^r" | awk '{print $3}' | sort | uniq

One a remote repository you can use:

 svn log --quiet https://url/svn/project/ | grep "^r" | awk '{print $3}' | sort | uniq
余罪 2024-09-02 07:20:06
svn log  path-to-repo | grep '^r' | grep '|' | awk '{print $3}' | sort | uniq > committers.txt

该命令具有额外的 grep '|' 来消除错误值。
否则,将包含以 'r' 开头的随机提交,从而返回提交消息中的单词。

svn log  path-to-repo | grep '^r' | grep '|' | awk '{print $3}' | sort | uniq > committers.txt

This command has the additional grep '|' that eliminates false values.
Otherwise, Random commits starting with 'r' get included and thus words from commit messages get returned.

千纸鹤带着心事 2024-09-02 07:20:06

Powershell 支持 XML,无需解析字符串输出。

这是我在 Mac 上使用的一个快速脚本,用于跨多个存储库获取唯一的用户列表。

#!/usr/bin/env pwsh

$repos = @(
    'Common/'
    'Database/'
    'Integration/'
    'Reporting/'
    'Tools/'
    'Web/'
    'Webservices/'
)

foreach ($repo in $repos) {
    $url = "https://svn.example.com:8443/svn/$repo"
    $users += ([Xml](svn log $url --xml)).log.logentry.author | Sort-Object -Unique
}

$users | Sort-Object -Unique

Powershell has support for XML which eliminates the need for parsing string output.

Here's a quick script I used on a mac to get a unique list of users across multiple repositories.

#!/usr/bin/env pwsh

$repos = @(
    'Common/'
    'Database/'
    'Integration/'
    'Reporting/'
    'Tools/'
    'Web/'
    'Webservices/'
)

foreach ($repo in $repos) {
    $url = "https://svn.example.com:8443/svn/$repo"
    $users += ([Xml](svn log $url --xml)).log.logentry.author | Sort-Object -Unique
}

$users | Sort-Object -Unique
时光病人 2024-09-02 07:20:06

Windows 10的解决方案。

  1. 创建一个批处理文件printAllAuthor.bat
@echo off
for /f "tokens=3" %%a in ('svn log --quiet ^|findstr /r "^r"') do echo %%a
@echo on
  1. 使用sort命令运行bat文件
printAllAuthor.bat | sort /unique >author.txt

PS:

  • 步骤2需要使用正确的路径运行批处理文件。在 %PATH% 中设置路径或使用正确的操作系统路径格式。
  • 步骤2也可以根据您的需要制作成批处理文件。

A solution for windows 10.

  1. create a batch file printAllAuthor.bat
@echo off
for /f "tokens=3" %%a in ('svn log --quiet ^|findstr /r "^r"') do echo %%a
@echo on
  1. run bat file with sort command
printAllAuthor.bat | sort /unique >author.txt

PS:

  • The step 2 need run the batch file with right path. either set path in %PATH% or use the right OS path format.
  • The step 2 can be made into a batch file as well according to your needs.
鹿港巷口少年归 2024-09-02 07:20:06

一个更简单的替代方案:

find . -name "*cpp" -exec svn log -q {} \;|grep -v "\-\-"|cut -d "|" -f 2|sort|uniq -c|sort -n

A simpler alternative:

find . -name "*cpp" -exec svn log -q {} \;|grep -v "\-\-"|cut -d "|" -f 2|sort|uniq -c|sort -n
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文