Gource for Plastic SCM

Thursday, April 08, 2010 1 Comments

David just sent me the following code to make gource work with Plastic.

Build it and create a pgource.exe and then type (all in one line)


$ cm log -f=0 --allbranches
--csFormat="{items}"
--itemformat=
"{date}|{owner}|{shortstatus}
|{path}{newline}"
| pgource.exe > p.log


Now you've a gource ready log! Just play it and enjoy


$ gource p.log





using System;
using System.Collections;
using System.Globalization;

namespace pgource
{
class Class1
{
private static string mCulture = "en-us";
private static Stack mReversedLines = new Stack();

[STAThread]
static void Main(string[] args)
{
ProcessArgs(args);
ReadInput();
PrintOutput();
}

private static void ProcessArgs(string[] args)
{
if (args.Length == 1) mCulture = args[0];
}

private static void ReadInput()
{
string line;

while ( (line = Console.ReadLine()) != null)
{
ProcessLine(line);
}
}

private static void ProcessLine(string line)
{
if (line == string.Empty) return;

string[] parts = line.Split('|');

if (parts.Length != 4) return;

ProcessParts(parts);
}

private static void ProcessParts(string[] parts)
{
// 3/28/2010 9:10:22 PM|dave|C|c:\develop\Form1.resx

mReversedLines.Push(string.Format("{0}|{1}|{2}|{3}",
GetUnixDate(parts[0]),
parts[1],
GetStatus(parts[2]),
GetPath(parts[3])));
}

private static int GetUnixDate(string date)
{
CultureInfo c = new CultureInfo(mCulture);

DateTime parsedDate = DateTime.Parse(date, c, DateTimeStyles.None);

return (int)((parsedDate - new DateTime(1970, 1, 1)).TotalSeconds);
}

private static string GetStatus(string status)
{
switch (status)
{
case "A": return "A";
case "R": return "D";
default: return "M";
}
}

private static string GetPath(string path)
{
return path.Replace('\\', '/').Replace(':', '_');
}

private static void PrintOutput()
{
while (mReversedLines.Count > 0)
{
Console.WriteLine(mReversedLines.Pop() as string);
}
}
}
}



1 comment:

  1. Wow, cool, nice effects!
    "source control made alive!" ;-)

    ReplyDelete