簡體   English   中英

如何使用Mercurial導出所選變更集的報告?

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

我想以類似“報告”的格式導出變更集列表,其中作者,注釋和文件都已更改(只是文件名而不是內容)。

我在Windows上使用TortoiseHg。 我該怎么做?

您想要哪種格式? hg log與模板一起使用。 Mercurial對定制輸出提供了廣泛的支持,並且在Mercurial手冊中有很好的記錄

因此,我使用Powershell解決了這個問題(與其他許多問題一樣)。 我基於Mercurial可以導出的補丁文件生成了HTML報告。

它當然不是完美的,但是效果很好。 適用典型的免責聲明,使用此風險自擔風險,如果您運行此行為,我將不承擔任何責任,等等。

這是代碼:

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