简体   繁体   English

如何使用Mercurial导出所选变更集的报告?

[英]How can I export a report of selected changesets with Mercurial?

I would like to export a list of changesets in a "report"-like format, with the author, comment, and files changed (just the filenames, not the contents). 我想以类似“报告”的格式导出变更集列表,其中作者,注释和文件都已更改(只是文件名而不是内容)。

I'm using TortoiseHg on Windows. 我在Windows上使用TortoiseHg。 How can I accomplish this? 我该怎么做?

What kind of format do you want? 您想要哪种格式? Use hg log with a template. hg log与模板一起使用。 Mercurial has extensive support for customizing output, and it's very nicely documented in the mercurial book. Mercurial对定制输出提供了广泛的支持,并且在Mercurial手册中有很好的记录

So I solved this problem (like many others) with Powershell. 因此,我使用Powershell解决了这个问题(与其他许多问题一样)。 I generated an HTML report based on the patch files that Mercurial can export. 我基于Mercurial可以导出的补丁文件生成了HTML报告。

It's certainly not perfect, but it works well enough. 它当然不是完美的,但是效果很好。 The typical disclaimer applies, use this at your own risk, I am not responsible for what happens if you run this, etc etc. 适用典型的免责声明,使用此风险自担风险,如果您运行此行为,我将不承担任何责任,等等。

Here's the code: 这是代码:

function Generate-PatchReport([string]$loc)
{
    $patchFiles = ls $loc -Filter "*.patch"

    $html = @()
    $html += "<html><head><title>Diff Report</title><style type=`"text/css`">body,table{font-family:Verdana;font-size:10pt}
table{border-collapse:collapse;margin:10px}
p{margin:0}
thead{font-weight:700}
td{border:1px solid gray;padding:5px}
.bin{background-color:#eee}
.add{background-color:#dfd}
.chg{background-color:#ffd}
.rem{background-color:#fdd}
hr{height:1px;background-color:#999;border:none;margin-top:15px;margin-bottom:15px}</style></head><body>"

    foreach($patch in $patchFiles)
    {
        $lines = gc $patch.FullName;

        # Get checkin notes
        $null, $null, $username = $lines[1].Split(' ')
        $datestamp = $lines[2].Split(' ')[2]

        $date = Get-Date -Year 1970 -Month 1 -Day 1 -Minute 0 -Hour 0 -Second 0 -Millisecond 0
        $date = $date.AddSeconds($datestamp)

        foreach($l in $lines)
        {
            if(!$l.StartsWith('#'))
            {
                $note = $l
                break;
            }
        }

        $html += '<p><strong>Note:</strong> ' + $note + '</p>'
        $html += "<p><strong>User:</strong> $username</p>"
        $html += "<p><strong>Timestamp:</strong> $($date.ToString("MM/dd/yyyy hh:mm tt")) UTC</p>"

        # Generate file reports
        $html += "<table><thead><td>Operation</td><td>File</td></thead>"
        for($i = 0; $i -lt $lines.Length; $i++)
        {
            if($lines[$i].StartsWith('diff'))
            {
                $html += "<tr>"
                $null, $null, $null, $null, $null, $filename = $lines[$i].Split(' ')

                if($lines[$i+1].Contains('Binary file'))
                {
                    $html += '<td class="bin">% Binary</td>'
                }
                elseif($lines[$i+1].Contains('/dev/null'))
                {
                    $html += '<td class="add">+ Add</td>'
                }
                elseif($lines[$i+2].Contains('/dev/null'))
                {
                    $html += '<td class="rem">- Remove</td>'
                }
                else
                {
                    $html += '<td class="chg">&bull; Change</td>'
                }
                $html += "<td>$filename</td>"
                $html += "</tr>"
            }
        }

        $html += "</table><hr />"
    }

    # Finalize HTML
    $html += "</body></html>"

    # Write the file to the same folder
    sc $html -Path ([System.IO.Path]::Combine($loc, "PatchReport.html"))
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM