2011-07-20 30 views
0

我們已經使用了一段時間的mercurial,現在一切正常。Mercurial - 記錄執行的命令

我們遇到的唯一問題是有人運行「壞命令」。

一個例子是,在穩定的主幹合併的不穩定分支或拉過完全無關覆蓋了一堆東西的東西類似命名的分支...

你有汞日誌,但你總是弄人那不會相信產出會說「我沒有那樣做」......現在爲了公衆羞辱:)並給予「你打破了帽子」的合法特權,我想知道,有沒有辦法有水銀日誌的每一個命令它給,這將使我們像一個文本文件:

hg pull -b something 
hg merge TotallyWrongBranch 
hg ci -m "I didn't do it!" -u bsimpson 
+0

那麼,你總是可以通過運行''history |當你等待一個答案時,你會少一些。 – Troy

+0

這會工作,但這是非常耗時的,特別是如果提交語句很模糊,那麼您會比較大量的轉速編號。但是,它可以工作:) – jfrobishow

+0

您可以在中央存儲庫掛鉤中添加日誌記錄功能。像'mercurial-server'一樣 – zerkms

回答

0

好吧,我有幾分鐘我的手所以我寫了一個exe文件並命名爲hg.exe,並將Mercurial的原始exe文件重命名爲real_hg ...

一個醜陋的黑客不介意代碼質量請IT作品!

public static StreamWriter sw; 

static void Main(string[] args) 
{ 
    sw = new StreamWriter("hgCommandLog.txt", true); 
    StringBuilder sbArguments = new StringBuilder(); 
    if (args.Length > 0) 
    { 
     for (int i = 0; i < args.Length; i++) 
     { 
      sbArguments.Append(args[i]); 
      sbArguments.Append(" "); 
     } 
    } 
    //Console.WriteLine("arg:" + sbArguments.ToString()); 
    //Console.WriteLine("Session ID = " + System.Diagnostics.Process.GetCurrentProcess().SessionId.ToString()); 
    //Console.WriteLine("hello ->"+Environment.GetEnvironmentVariable("CLIENTNAME")); 

    string sessionID = System.Diagnostics.Process.GetCurrentProcess().SessionId.ToString(); 
    string clientName = Environment.GetEnvironmentVariable("CLIENTNAME"); 

    //log the command to sw 
    sw.WriteLine(DateTime.Now.ToString() + "\t" + clientName + "("+sessionID+")\t" + "hg " + sbArguments.ToString()); 
    sw.Flush(); 

    // Start the child process. 
    Process p = new Process(); 
    // Redirect the output stream of the child process. 
    p.StartInfo.UseShellExecute = false; 
    p.StartInfo.RedirectStandardOutput = true; 
    p.StartInfo.FileName = "real_hg"; 
    p.StartInfo.Arguments = sbArguments.ToString(); 

    p.StartInfo.CreateNoWindow = true; 
    p.ErrorDataReceived += outputReceived; 
    p.OutputDataReceived += outputReceived; 
    p.EnableRaisingEvents = true; 

    p.Start(); 
    // Do not wait for the child process to exit before 
    // reading to the end of its redirected stream. 
    p.BeginOutputReadLine(); 
    //p.BeginErrorReadLine(); 
    p.WaitForExit(); 

    sw.Close(); 
} 

static void outputReceived(object sender, DataReceivedEventArgs e) 
{ 
    sw.WriteLine("\t"+e.Data); 
    Console.WriteLine(e.Data); 
} 
+1

如果你的合作開發者如此嚴厲的紀律以至於他們不會承擔自己所犯的錯誤,你認爲他們會想要運行一個可以記錄他們每個命令的mercurial「版本」?另外,如果您使用TortoiseHg,則不會記錄任何內容。 –

+0

@Lasse V. Karlsen:不會經常使用hg.exe嗎? – zerkms

+1

對於許多函數,它直接與Python代碼進行交流,以避免啓動第二個Python解釋器。請記住,TortoiseHg也是用Python編寫的。 –