xml 如何将 Subversion 日志导出到电子表格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11436214/
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 export the Subversion log to spreadsheet
提问by lamcro
Is there a way to export the Subversion log messages to a spreadsheet(excel, csv, etc.) format?
有没有办法将 Subversion 日志消息导出为电子表格(excel、csv 等)格式?
When copying from the Log Messages window in TortoiseSVN, it pastes text in the following format:
从 TortoiseSVN 中的日志消息窗口复制时,它会以以下格式粘贴文本:
Revision: 174
Author: CARDINALHEALTH\enrique.colon
Date: Wednesday, July 11, 2012 9:37:02 AM
Message: CR #58514
----
Modified : /trunk/ob_progs/utility/connect_peek
I could create a script to reformat this to CSV, if necessary. But I really don't want to :(
如有必要,我可以创建一个脚本将其重新格式化为 CSV。但我真的不想:(
回答by lamcro
Use the following Subversion command to create an xml file out of the repository's log:
svn log -v --xml > repository_log.xml
Import the xml file into an Excelspreadsheet (not sure if it will work with LibreOffice/OpenOffice), e.g. from cmd:
start excel repository_log.xml
You can then save it as a spreadsheet.
使用以下 Subversion 命令从存储库的日志中创建一个 xml 文件:
svn log -v --xml > repository_log.xml
将 xml 文件导入Excel电子表格(不确定它是否适用于 LibreOffice/OpenOffice),例如从 cmd:
启动excel repository_log.xml
然后您可以将其另存为电子表格。
That's it!
就是这样!
回答by Michael Sorens
Since you are using TortoiseSVN and are thus on Windows, a straightforward way to do this is with PowerShell. Start with this function to convert svn log data to PowerShell objects:
由于您使用的是 TortoiseSVN 并且因此在 Windows 上,执行此操作的一种直接方法是使用 PowerShell。从这个函数开始将 svn 日志数据转换为 PowerShell 对象:
Function Get-SvnLogData()
{
([xml](svn log -v --xml)).log.logentry | % {
$nestedEntry = $_
$_.paths.path | % {
$path = $_
$nestedEntry | Select-Object -Property `
Author, `
@{n='Revision'; e={([int]$_.Revision)}}, `
@{n='Date'; e={Get-Date $_.Date }}, `
@{n='Action'; e={$path.action }}, `
@{n='Path'; e={$path.InnerText }}`
}
}
}
The default output is a list, e.g.:
默认输出是一个列表,例如:
author : smith
Revision : 29091
Date : 6/26/2012 7:30:44 AM
Action : M
Path : /Utility/trunk/Distribution/file1.txt
author : jones
Revision : 28987
Date : 6/21/2012 3:56:51 PM
Action : M
Path : /Utility/trunk/Distribution/file2.txt
author : msorens
Revision : 28934
Date : 6/21/2012 8:22:17 AM
Action : M
Path : /Utility/trunk/Distribution/file3.txt
author : jones
Revision : 28835
Date : 6/19/2012 8:56:08 AM
Action : A
Path : /Utility/trunk/DAL/stuff.txt
. . .
With this command, however...
但是,有了这个命令...
Get-SvnLogData | Format-Table -AutoSize
...you can tell PowerShell to give you a table instead of a list, e.g.:
...你可以告诉 PowerShell 给你一个表格而不是一个列表,例如:
author Revision Date Action Path
------ -------- ---- ------ ----
smith 29091 6/26/2012 7:30:44 AM M /Utility/trunk/Distribution/file1.txt
jones 28987 6/21/2012 3:56:51 PM M /Utility/trunk/Distribution/file2.txt
msorens 28934 6/21/2012 8:22:17 AM M /Utility/trunk/Distribution/file3.txt
jones 28835 6/19/2012 8:56:08 AM A /Utility/trunk/DAL/stuff.txt
. . .
And to actually answer your question :-) you can just as easily convert the output to CSV and send it to a file with a command like this:
并实际回答您的问题:-)您可以轻松地将输出转换为 CSV 并使用如下命令将其发送到文件:
Get-SvnLogData | Export-Csv -Path temp.csv
Double-clicking on the resultant file opens it up in Excel:
双击生成的文件在 Excel 中打开它:


回答by Brandon
Chris West came up with a pretty simple and yet effective solution: http://gotochriswest.com/blog/2012/10/02/svn-log-to-csv-converter/Actually the page seems to be moved here:
http://cwestblog.com/2012/10/02/svn-log-to-csv-converter/
Chris West 提出了一个非常简单但有效的解决方案:http: //gotochriswest.com/blog/2012/10/02/svn-log-to-csv-converter/实际上页面似乎移到这里:
http: //cwestblog.com/2012/10/02/svn-log-to-csv-converter/
He listed two solutions on that page. The first is a Java program which will output a CSV. The second is a JSBin page which will convert the pasted SVN log into a CSV.
他在该页面上列出了两个解决方案。第一个是将输出 CSV 的 Java 程序。第二个是 JSBin 页面,它将粘贴的 SVN 日志转换为 CSV。
回答by SherlockSpreadsheets
The answer by Michael Sorens is awesome and this is how I extract SVN log data. I am posting a supplemental answer which shows you how to apply his solution into a script file that can be run in an instant.
Michael Sorens 的回答很棒,这就是我提取 SVN 日志数据的方式。我发布了一个补充答案,向您展示了如何将他的解决方案应用到可以立即运行的脚本文件中。
Create and save the script seen below to .PS1 file. Open and view the file in basic Notepad program. Then pin the file. Now all you have to do is right click my Notepad task bar icon, hover of the file, right-click the file, from the fly out window choose "Run with PowerShell". In an instance the CSV data file pops up, and for me it opens in Excel.
创建和保存下面看到的脚本到 .PS1 文件。在基本的记事本程序中打开并查看文件。然后固定文件。现在您要做的就是右键单击我的记事本任务栏图标,将鼠标悬停在文件上,右键单击该文件,从弹出窗口中选择“使用 PowerShell 运行”。在一个实例中,CSV 数据文件弹出,对我来说它在 Excel 中打开。
About the script file that you may want to review and revise.
关于您可能想要查看和修改的脚本文件。
- My repo has tons of commits so I retrieved only the last 20
- Update the filepaths
- Used the Invoke-Item cmdlet to Opening the output file automatically
- As suggested in this thread you could add
@{n='Message'; e={$_.msg }}
- 我的仓库有大量提交,所以我只检索了最后 20 个
- 更新文件路径
- 使用 Invoke-Item cmdlet自动打开输出文件
- 正如此线程中所建议的,您可以添加
@{n='Message'; e={$_.msg }}
Get-SvnLogData.ps1
获取-SvnLogData.ps1
# Get-SvnLogData | sort-Object @{Expression="Date"; Descending=$true} | Select-Object -first 20 | Export-Csv -Path temp.csv
#############################################################
# <STEP 1: MUST FIRST CREATE THIS FUNCTION.....>
Function Get-SvnLogData()
{
([xml](svn log -v --xml)).log.logentry | % {
$nestedEntry = $_
$_.paths.path | % {
$path = $_
$nestedEntry | Select-Object -Property `
Author, `
@{n='Revision'; e={([int]$_.Revision)}}, `
@{n='Date'; e={Get-Date $_.Date }}, `
@{n='Action'; e={$path.action }}, `
@{n='Path'; e={$path.InnerText }}`
}
}
}
# <\STEP 1>
# <STEP 2: NAVIGATE TO THE DIRECTORY.....>
cd \
cd SVN\BusinessAnalysts\SSRSReports\ssrs2016_solution
# <\STEP 2>
# <STEP 3: EXTRACT THE LOGDATA TO CSV; OPEN THE FILE.....>
Get-SvnLogData | sort-Object @{Expression="Date"; Descending=$true} | Select-Object -first 20 | Export-Csv -Path temp.csv
#REM https://social.technet.microsoft.com/Forums/windowsserver/en-US/399abe9a-195c-4362-9081-6fd9d79b88ad/need-help-converting-getlocation-info-to-string?forum=winserverpowershell
$CurrentDirectory= get-location
$path = $CurrentDirectory.tostring() + "\"
Invoke-Item $path"temp.csv"
# <\STEP 3>
#############################################################
TUTORIAL: PS1 file - Run with PowerShell
教程:PS1 文件 - 使用 PowerShell 运行

