[Lemon-commits] Alpar Juttner: Python script for computing the l...

Lemon HG hg at lemon.cs.elte.hu
Mon Sep 22 09:40:00 CEST 2008


details:   http://lemon.cs.elte.hu/hg/lemon/rev/e63a95b68827
changeset: 272:e63a95b68827
user:      Alpar Juttner <alpar [at] cs.elte.hu>
date:      Tue Sep 16 08:51:02 2008 +0100
description:
	Python script for computing the longest path in the revision tree

diffstat:

1 file changed, 39 insertions(+)
scripts/chg-len.py |   39 +++++++++++++++++++++++++++++++++++++++

diffs (43 lines):

diff -r c691064dfd4f -r e63a95b68827 scripts/chg-len.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/chg-len.py	Tue Sep 16 08:51:02 2008 +0100
@@ -0,0 +1,39 @@
+#! /usr/bin/env python
+
+import sys
+import os
+
+if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
+    print """
+This utility just prints the length of the longest path
+in the revision graph from revison 0 to the current one.
+"""
+    exit(0)
+plist = os.popen("hg parents --template='{rev}\n'").readlines()
+if len(plist)>1:
+    print "You are in the process of merging"
+    exit(1)
+PAR = int(plist[0])
+
+f = os.popen("hg log -r 0:tip --template='{rev} {parents}\n'").readlines()
+REV = -1
+lengths=[]
+for l in f:
+    REV+=1
+    s = l.split()
+    rev = int(s[0])
+    if REV != rev:
+        print "Something is seriously wrong"
+        exit(1)
+    if len(s) == 1:
+        par1 = par2 = rev - 1
+    elif len(s) == 2:
+        par1 = par2 = int(s[1].split(":")[0])
+    else:
+        par1 = int(s[1].split(":")[0])
+        par2 = int(s[2].split(":")[0])
+    if rev == 0:
+        lengths.append(0)
+    else:
+        lengths.append(max(lengths[par1],lengths[par2])+1)
+print lengths[PAR]



More information about the Lemon-commits mailing list