如何在svn日志中显示特定用户的提交?

发布于 2024-10-09 05:54:05 字数 44 浏览 1 评论 0原文

如何在svn中显示特定用户的提交?我没有找到 svn log 的任何开关。

How to display a specific user's commits in svn? I didn't find any switches for that for svn log.

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

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

发布评论

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

评论(11

岁月苍老的讽刺 2024-10-16 05:54:06

svn 没有为此提供内置选项。它确实有一个 svn log --xml 选项,允许您自己解析输出并获取有趣的部分。

您可以编写一个脚本来解析它,例如,在 Python 2.6 中:

import sys
from xml.etree.ElementTree import iterparse, dump

author = sys.argv[1]
iparse = iterparse(sys.stdin, ['start', 'end'])

for event, elem in iparse:
    if event == 'start' and elem.tag == 'log':
        logNode = elem
        break

logentries = (elem for event, elem in iparse
                   if event == 'end' and elem.tag == 'logentry')

for logentry in logentries:
    if logentry.find('author').text == author:
        dump(logentry)
    logNode.remove(logentry)

如果将上述内容保存为 svnLogStripByAuthor.py,则可以将其调用为:

svn log --xml other-options | svnLogStripByAuthor.py user

svn doesn't come with built-in options for this. It does have an svn log --xml option, to allow you to parse the output yourself, and get the interesting parts.

You can write a script to parse it, for example, in Python 2.6:

import sys
from xml.etree.ElementTree import iterparse, dump

author = sys.argv[1]
iparse = iterparse(sys.stdin, ['start', 'end'])

for event, elem in iparse:
    if event == 'start' and elem.tag == 'log':
        logNode = elem
        break

logentries = (elem for event, elem in iparse
                   if event == 'end' and elem.tag == 'logentry')

for logentry in logentries:
    if logentry.find('author').text == author:
        dump(logentry)
    logNode.remove(logentry)

If you save the above as svnLogStripByAuthor.py, you could call it as:

svn log --xml other-options | svnLogStripByAuthor.py user
情话难免假 2024-10-16 05:54:06

由于每个人似乎都倾向于 Linux(等):以下是 Windows 的等效版本:

svn log [SVNPath]|find "USERNAME"

Since everyone seems to be leaning toward linux (et al): Here is the Windows equivalent:

svn log [SVNPath]|find "USERNAME"
风轻花落早 2024-10-16 05:54:06
svn log | grep user

大部分工作。

或者更准确地说:

svn log | egrep 'r[0-9]+ \| user \|'
svn log | grep user

works for the most part.

Or to be more accurate:

svn log | egrep 'r[0-9]+ \| user \|'
ぃ弥猫深巷。 2024-10-16 05:54:06

虽然 yvoyer 的解决方案工作正常,但这里是一个利用 SVN 的 XML 输出,并使用 xmlstarlet 解析它的解决方案。

svn log --xml | xmlstarlet sel -t -m 'log/logentry' \
  --if "author = '<AUTHOR>'" \
  -v "concat('Revision ', @revision, ' ', date)" -n -v msg -n -n

从这里您可以进入更高级的 XML 查询。

While yvoyer's solution works fine, here is one making use of SVN's XML output, parsing it with xmlstarlet.

svn log --xml | xmlstarlet sel -t -m 'log/logentry' \
  --if "author = '<AUTHOR>'" \
  -v "concat('Revision ', @revision, ' ', date)" -n -v msg -n -n

From here you could go into more advanced XML queries.

数理化全能战士 2024-10-16 05:54:06

这是我使用 xslt 的解决方案。但不幸的是,xsltproc 不是流处理器,因此您必须给 log 一个限制。用法示例:

svn log -v --xml --limit=500  | xsltproc --stringparam author yonran /path/to/svnLogFilter.xslt  - | xsltproc /path/to/svnLogText.xslt  - | less

svnLogFilter.xslt

<!--
svnLogFilter.xslt

Usage: (note: use double dashes; I can't do double dashes in a XML comment)
svn log -xml | xsltproc -stringparam author yonran svnLogFilter.xslt -
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:param name="author" select="''"/>
  <xsl:strip-space elements="log"/>
  <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
  <xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
  <xsl:variable name="lowercaseAuthor" select="translate($author, $uppercase, $lowercase)"/>

<xsl:template match="/log">
  <xsl:copy>
    <xsl:apply-templates name="entrymatcher"/>
  </xsl:copy>
</xsl:template>

<xsl:template name="entrymatcher" match="logentry">
  <xsl:variable name="lowercaseChangeAuthor" select="translate(author, $uppercase, $lowercase)"/>
  <xsl:choose>
    <xsl:when test="contains($lowercaseChangeAuthor, $lowercaseAuthor)">
      <xsl:call-template name="insideentry"/>
    </xsl:when>
    <!--Filter out-->
    <xsl:otherwise/>
  </xsl:choose>
</xsl:template>


<xsl:template name="insideentry" match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

svnLogText.xslt

<!--
svnLogText.xslt

Usage: (note: use double dashes; I can't do double dashes in a XML comment)
svn log -xml -limit=1000 | xsltproc svnLogText.xslt -
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:param name="author" select="''"/>
  <xsl:param name="xml" select="false()"/>
  <xsl:output method="text"/>

<xsl:template match="/log">
  <xsl:apply-templates name="entrymatcher"/>
  <xsl:text>------------------------------------------------------------------------
</xsl:text>
</xsl:template>

<xsl:template name="entrymatcher" match="logentry">
  <xsl:text>------------------------------------------------------------------------
</xsl:text>
  <xsl:text>r</xsl:text><xsl:value-of select="@revision"/>
  <xsl:text> | </xsl:text>
  <xsl:value-of select="author"/>
  <xsl:text> | </xsl:text>
  <xsl:value-of select="date"/>
  <xsl:text>

</xsl:text>
  <xsl:if test="paths">
    <xsl:text>Changed paths:
</xsl:text>
    <xsl:for-each select="paths/path">
      <xsl:text>   </xsl:text>
      <xsl:value-of select="@action"/>
      <xsl:text> </xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>
</xsl:text>
    </xsl:for-each>
  </xsl:if>
  <xsl:text>
</xsl:text>
  <xsl:value-of select="msg"/>
  <xsl:text>
</xsl:text>
</xsl:template>

</xsl:stylesheet>

Here’s my solution using xslt. Unfortunately, though, xsltproc is not a streaming processor, so you have to give log a limit. Example usage:

svn log -v --xml --limit=500  | xsltproc --stringparam author yonran /path/to/svnLogFilter.xslt  - | xsltproc /path/to/svnLogText.xslt  - | less

svnLogFilter.xslt

<!--
svnLogFilter.xslt

Usage: (note: use double dashes; I can't do double dashes in a XML comment)
svn log -xml | xsltproc -stringparam author yonran svnLogFilter.xslt -
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:param name="author" select="''"/>
  <xsl:strip-space elements="log"/>
  <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
  <xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
  <xsl:variable name="lowercaseAuthor" select="translate($author, $uppercase, $lowercase)"/>

<xsl:template match="/log">
  <xsl:copy>
    <xsl:apply-templates name="entrymatcher"/>
  </xsl:copy>
</xsl:template>

<xsl:template name="entrymatcher" match="logentry">
  <xsl:variable name="lowercaseChangeAuthor" select="translate(author, $uppercase, $lowercase)"/>
  <xsl:choose>
    <xsl:when test="contains($lowercaseChangeAuthor, $lowercaseAuthor)">
      <xsl:call-template name="insideentry"/>
    </xsl:when>
    <!--Filter out-->
    <xsl:otherwise/>
  </xsl:choose>
</xsl:template>


<xsl:template name="insideentry" match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

svnLogText.xslt

<!--
svnLogText.xslt

Usage: (note: use double dashes; I can't do double dashes in a XML comment)
svn log -xml -limit=1000 | xsltproc svnLogText.xslt -
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:param name="author" select="''"/>
  <xsl:param name="xml" select="false()"/>
  <xsl:output method="text"/>

<xsl:template match="/log">
  <xsl:apply-templates name="entrymatcher"/>
  <xsl:text>------------------------------------------------------------------------
</xsl:text>
</xsl:template>

<xsl:template name="entrymatcher" match="logentry">
  <xsl:text>------------------------------------------------------------------------
</xsl:text>
  <xsl:text>r</xsl:text><xsl:value-of select="@revision"/>
  <xsl:text> | </xsl:text>
  <xsl:value-of select="author"/>
  <xsl:text> | </xsl:text>
  <xsl:value-of select="date"/>
  <xsl:text>

</xsl:text>
  <xsl:if test="paths">
    <xsl:text>Changed paths:
</xsl:text>
    <xsl:for-each select="paths/path">
      <xsl:text>   </xsl:text>
      <xsl:value-of select="@action"/>
      <xsl:text> </xsl:text>
      <xsl:value-of select="."/>
      <xsl:text>
</xsl:text>
    </xsl:for-each>
  </xsl:if>
  <xsl:text>
</xsl:text>
  <xsl:value-of select="msg"/>
  <xsl:text>
</xsl:text>
</xsl:template>

</xsl:stylesheet>
土豪我们做朋友吧 2024-10-16 05:54:06

从 Subversion 1.8 开始,您可以使用 --search--search-and 命令行选项,带有 svn log 命令

所以它应该像运行 svn log --search JohnDoe 一样简单。

Beginning with Subversion 1.8, you can use --search and --search-and command-line options with svn log command.

So it should be as simple as running svn log --search JohnDoe.

孤独患者 2024-10-16 05:54:06

您可以使用 Perl 按用户名过滤日志维护提交消息。只需设置 $/ 变量即可决定 Perl 中“行”的构成。如果您将其设置为 SVN 日志条目的分隔符,Perl 将一次读取一条记录,然后您应该能够匹配整条记录中的用户名。见下文:

svn log | perl -ne 'BEGIN{$/="------------------------------------------------------------------------"} print if /USERNAME/'

You can use Perl to filter the log by username and maintain the commit messages. Just set the $/ variable which decides what constitutes a "line" in Perl. If you set this to the separator of the entries of the SVN log, Perl will read one record at a time and then you should be able to match the the username in the entire record. See below:

svn log | perl -ne 'BEGIN{$/="------------------------------------------------------------------------"} print if /USERNAME/'
一袭水袖舞倾城 2024-10-16 05:54:06

获取差异以及签入。

将修订号放入文件中:

svn log | sed -n '/USERNAME/,/-----$/ p'| grep "^r" 

现在通读文件并查看版本号。为每个修订版执行 diff:

while read p; do   svn log -v"$p" --diff ; done < Revisions.txt 

To GET diffs along with the checkin.

Get the revision numbers into a file:

svn log | sed -n '/USERNAME/,/-----$/ p'| grep "^r" 

Now read through the file & executing diff for each revision:

while read p; do   svn log -v"$p" --diff ; done < Revisions.txt 
泪之魂 2024-10-16 05:54:06

我用Python编写了一个脚本:

#!/usr/bin/python
# coding:utf-8

import sys

argv_len = len(sys.argv)


def help():
    print 'Filter svnlog by user or date!       '
    print 'USEAGE: svnlog [ARGs]                '
    print 'ARGs:                                '
    print '    -n[=name]:                       '
    print '      filter by the special [=name]\n'
    print '    -t[=date]:                       '
    print '      filter by the special [=date]  '
    print 'EXP:                                 '
    print '1. Filter ruikye\'s commit log       \n'
    print '     svn log -l 50 | svnlog -n=ruikye\n'


if not argv_len - 1:
    help()
    quit()

author = ''
date = ''

for index in range(1, argv_len):
    argv = sys.argv[index]
    if argv.startswith('-n='):
        author = argv.replace('-n=', '')
    elif argv.startswith('-t='):
        date = argv.replace('-t=', '')
    else:
        help()
        quit()

if author == '' and date == '':
    help()
    quit()


SPLIT_LINE =
    '------------------------------------------------------------------------'
src = ''.join(sys.stdin.readlines()).replace('\n\n', '\n')
lines = src.split(SPLIT_LINE)

for line in lines:
    if author in line and date in line:
        print SPLIT_LINE, line

if len(lines):
    print SPLIT_LINE

并使用:

$ mv svnlog.py svnlog          

$ chmod a+x svnlog             

$ cd /usr/local/bin
$ ln -s ~/mycmd/svnlog filter 

$ svn log | filter -n=ruikye -t=2015-03-04

I had write a script by Python:

#!/usr/bin/python
# coding:utf-8

import sys

argv_len = len(sys.argv)


def help():
    print 'Filter svnlog by user or date!       '
    print 'USEAGE: svnlog [ARGs]                '
    print 'ARGs:                                '
    print '    -n[=name]:                       '
    print '      filter by the special [=name]\n'
    print '    -t[=date]:                       '
    print '      filter by the special [=date]  '
    print 'EXP:                                 '
    print '1. Filter ruikye\'s commit log       \n'
    print '     svn log -l 50 | svnlog -n=ruikye\n'


if not argv_len - 1:
    help()
    quit()

author = ''
date = ''

for index in range(1, argv_len):
    argv = sys.argv[index]
    if argv.startswith('-n='):
        author = argv.replace('-n=', '')
    elif argv.startswith('-t='):
        date = argv.replace('-t=', '')
    else:
        help()
        quit()

if author == '' and date == '':
    help()
    quit()


SPLIT_LINE =
    '------------------------------------------------------------------------'
src = ''.join(sys.stdin.readlines()).replace('\n\n', '\n')
lines = src.split(SPLIT_LINE)

for line in lines:
    if author in line and date in line:
        print SPLIT_LINE, line

if len(lines):
    print SPLIT_LINE

and use:

$ mv svnlog.py svnlog          

$ chmod a+x svnlog             

$ cd /usr/local/bin
$ ln -s ~/mycmd/svnlog filter 

$ svn log | filter -n=ruikye -t=2015-03-04
他不在意 2024-10-16 05:54:05

您可以使用它:

svn log | sed -n '/USERNAME/,/-----$/ p' 

它将显示指定用户(USERNAME)所做的每一次提交。

更新

按照@bahrep的建议,subversion 1.8 带有一个 --search 选项。

You could use this:

svn log | sed -n '/USERNAME/,/-----$/ p' 

It will show you every commit made by the specified user (USERNAME).

UPDATE

As suggested by @bahrep, subversion 1.8 comes with a --search option.

烟若柳尘 2024-10-16 05:54:05

对于 Subversion 1.8 或更高版本:

svn log --search johnsmith77 -l 50

除了作者匹配之外,这还会出现在提交消息中包含该用户名的 SVN 提交,如果您的用户名不是常用单词,则不会发生这种情况。

-l 50 将搜索限制为最新 50 个条目。

--搜索 ARG

过滤日志消息以仅显示与搜索模式 ARG 匹配的日志消息。

仅当提供的搜索模式与作者、日期、日志消息文本中的任何一个匹配时,才会显示日志消息(除非使用 --quiet),或者,如果 --verbose还提供了 选项,更改路径。

如果提供了多个 --search 选项,如果它与任何提供的搜索模式匹配,则会显示一条日志消息。

如果使用--limit,它会限制搜索的日志消息数量,而不是将输出限制为特定数量的匹配日志消息。

http://svnbook.red-bean.com /en/1.8/svn.ref.svn.html#svn.ref.svn.sw.search

With Subversion 1.8 or later:

svn log --search johnsmith77 -l 50

Besides author matches, this will also turn up SVN commits that contain that username in the commit message, which shouldn't happen if your username is not a common word.

The -l 50 will limit the search to the latest 50 entries.

--search ARG

Filters log messages to show only those that match the search pattern ARG.

Log messages are displayed only if the provided search pattern matches any of the author, date, log message text (unless --quiet is used), or, if the --verbose option is also provided, a changed path.

If multiple --search options are provided, a log message is shown if it matches any of the provided search patterns.

If --limit is used, it restricts the number of log messages searched, rather than restricting the output to a particular number of matching log messages.

http://svnbook.red-bean.com/en/1.8/svn.ref.svn.html#svn.ref.svn.sw.search

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文