# HG changeset patch # User wenzelm # Date 1494767233 -7200 # Node ID ff3dc9325eaada4c49e92e01028b653878070030 # Parent 94cad759001592ed0dadca3bbdab18436f9d63df explore repository structure, with minimal assumptions about "hg log" output; diff -r 94cad7590015 -r ff3dc9325eaa src/Pure/General/mercurial.scala --- a/src/Pure/General/mercurial.scala Sun May 14 12:50:55 2017 +0200 +++ b/src/Pure/General/mercurial.scala Sun May 14 15:07:13 2017 +0200 @@ -137,5 +137,26 @@ hg.command("update", opt_rev(rev) + opt_flag("--clean", clean) + opt_flag("--check", check), options).check } + + def length(): Int = + identify(options = "-n") match { + case Value.Int(n) => n + 1 + case s => error("Cannot determine repository length from " + quote(s)) + } + + def graph(): Graph[String, Unit] = + { + val Node = """^node: (\w{12}) (\w{12}) (\w{12})""".r + val log_result = + log(template = """node: {node|short} {p1node|short} {p2node|short}\n""", + options = "-l " + length()) + (Graph.string[Unit] /: split_lines(log_result)) { + case (graph, Node(x, y, z)) => + val deps = List(y, z).filterNot(s => s.forall(_ == '0')) + val graph1 = (graph /: (x :: deps))(_.default_node(_, ())) + (graph1 /: deps)({ case (g, dep) => g.add_edge(dep, x) }) + case (graph, _) => graph + } + } } }