version control - Mercurial - log the command executed -
we've been using mercurial while , working fine.
the problem encounter when runs "bad command".
an example be, merging unstable branch in stable trunk or pulling named branch on unrelated overwriting bunch of stuff...
you've got hg log people won't believe output saying "i didn't that"...now in interest of public shaming :) , giving rightful priviledges "you broke built hat", i'm wondering, there way have mercurial log every command given text file give like:
hg pull -b hg merge totallywrongbranch hg ci -m "i didn't it!" -u bsimpson
ok, had few minutes on hand wrote exe , named hg.exe , renamed mercurial's original exe real_hg...
an ugly hack don't mind code quality please works!
public static streamwriter sw; static void main(string[] args) { sw = new streamwriter("hgcommandlog.txt", true); stringbuilder sbarguments = new stringbuilder(); if (args.length > 0) { (int = 0; < 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 command sw sw.writeline(datetime.now.tostring() + "\t" + clientname + "("+sessionid+")\t" + "hg " + sbarguments.tostring()); sw.flush(); // start child process. process p = new process(); // redirect output stream of 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(); // not wait child process exit before // reading end of 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); }
Comments
Post a Comment