/Examples/012 - Graphviz example.linq

# · Unknown · 45 lines · 37 code · 8 blank · 0 comment · 0 complexity · 21dadff9090673c344eafd449b20f8c9 MD5 · raw file

  1. <Query Kind="Program">
  2. <Reference Relative="..\Mercurial.Net\bin\Debug\Mercurial.NET.dll">C:\Dev\VS.NET\Mercurial.Net\Mercurial.Net\bin\Debug\Mercurial.NET.dll</Reference>
  3. <Namespace>Mercurial</Namespace>
  4. </Query>
  5. // *****************************************************
  6. // *
  7. // * Visualize a random bitbucket-project through Graphviz
  8. // * The project was chosen because it had relatively few
  9. // * changesets, and a couple of parallel branches.
  10. // *
  11. // ***********************
  12. const string repoPath = @"C:\Temp\repo";
  13. const string repoSource = @"http://bitbucket.org/ventor3000/iup.net";
  14. const string tempFile = @"C:\Temp\test.dot";
  15. void Main()
  16. {
  17. if (Directory.Exists(repoPath))
  18. Directory.Delete(repoPath, true);
  19. Directory.CreateDirectory(repoPath);
  20. var repo = new Repository(repoPath);
  21. repo.Init();
  22. var log = repo.Incoming(repoSource, new IncomingCommand().WithTimeout(240));
  23. List<string> lines = new List<string>();
  24. lines.Add("digraph G {");
  25. lines.Add(" rankdir = LR;");
  26. foreach (var changeset in log)
  27. {
  28. if (changeset.LeftParentRevision >= 0)
  29. lines.Add(" \"" + changeset.LeftParentRevision + "\" -> \"" + changeset.RevisionNumber + "\"");
  30. if (changeset.RightParentRevision >= 0)
  31. lines.Add(" \"" + changeset.RightParentRevision + "\" -> \"" + changeset.RevisionNumber + "\"");
  32. }
  33. lines.Add("}");
  34. File.WriteAllLines(tempFile, lines.ToArray());
  35. Util.Cmd("dot " + tempFile + " -Tpng -O");
  36. Util.Cmd("\"" + tempFile + ".png\"");
  37. }