bash 如何在 svn 日志中显示特定用户的提交?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4499910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to display a specific user's commits in svn log?
提问by mimrock
How to display a specific user's commits in svn? I didn't find any switches for that for svn log.
如何在 svn 中显示特定用户的提交?我没有为 svn log 找到任何开关。
回答by yvoyer
You could use this:
你可以用这个:
svn log | sed -n '/USERNAME/,/-----$/ p'
It will show you every commit made by the specified user (USERNAME).
它将显示指定用户 (USERNAME) 所做的每次提交。
UPDATE
更新
As suggested by @bahrep, subversion 1.8comes with a --search
option.
正如@bahrep 所建议的,subversion 1.8带有一个--search
选项。
回答by Michael Butler
With Subversion 1.8 or later:
使用 Subversion 1.8 或更高版本:
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.
除了作者匹配之外,这还会在提交消息中显示包含该用户名的 SVN 提交,如果您的用户名不是常用词,则不会发生这种情况。
The -l 50
will limit the search to the latest 50 entries.
在-l 50
将搜索范围限制为最新的50个条目。
--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.
--search ARG
过滤日志消息以仅显示与搜索模式 ARG 匹配的消息。
仅当提供的搜索模式与作者、日期、日志消息文本(除非
--quiet
使用)中的任何一个匹配时才会显示日志消息,或者,如果--verbose
还提供了该选项,则显示更改的路径。如果
--search
提供了多个选项,则在匹配任何提供的搜索模式时会显示一条日志消息。如果
--limit
使用,它会限制搜索的日志消息的数量,而不是将输出限制为特定数量的匹配日志消息。
http://svnbook.red-bean.com/en/1.8/svn.ref.svn.html#svn.ref.svn.sw.search
http://svnbook.red-bean.com/en/1.8/svn.ref.svn.html#svn.ref.svn.sw.search
回答by Avi
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.
svn 没有为此提供内置选项。它确实有一个svn log --xml
选项,允许您自己解析输出,并获得有趣的部分。
You can write a script to parse it, for example, in Python 2.6:
您可以编写一个脚本来解析它,例如,在 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:
如果将上述内容另存为 svnLogStripByAuthor.py,则可以将其命名为:
svn log --xml other-options | svnLogStripByAuthor.py user
回答by user2197169
Since everyone seems to be leaning toward linux (et al): Here is the Windows equivalent:
由于每个人似乎都倾向于 linux (et al):这是 Windows 等价的:
svn log [SVNPath]|find "USERNAME"
回答by moinudin
svn log | grep user
works for the most part.
大部分工作。
Or to be more accurate:
或者更准确地说:
svn log | egrep 'r[0-9]+ \| user \|'
回答by mxgr
While yvoyer's solution works fine, here is one making use of SVN's XML output, parsing it with xmlstarlet
.
虽然 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
From here you could go into more advanced XML queries.
从这里您可以进入更高级的 XML 查询。
回答by bahrep
Beginning with Subversion 1.8, you can use --search
and --search-and
command-line options with svn log
command.
与Subversion 1.8开始,你可以使用--search
和--search-and
使用命令行选项svn log
命令。
So it should be as simple as running svn log --search JohnDoe
.
所以它应该像运行一样简单svn log --search JohnDoe
。
回答by yonran
Here's my solution using xslt. Unfortunately, though, xsltproc is not a streaming processor, so you have to give log a limit. Example usage:
这是我使用 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
<!--
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
<!--
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>
回答by user668958
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
回答by Stathis Sideris
You can use Perl to filter the log by username andmaintain 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:
您可以使用 Perl 按用户名过滤日志并维护提交消息。只需设置 $/ 变量,该变量决定了 Perl 中“行”的构成。如果您将其设置为 SVN 日志条目的分隔符,Perl 将一次读取一条记录,然后您应该能够匹配整个记录中的用户名。见下文:
svn log | perl -ne 'BEGIN{$/="------------------------------------------------------------------------"} print if /USERNAME/'