1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/scripts/chg-len.py Mon Sep 22 08:12:44 2008 +0100
1.3 @@ -0,0 +1,39 @@
1.4 +#! /usr/bin/env python
1.5 +
1.6 +import sys
1.7 +import os
1.8 +
1.9 +if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
1.10 + print """
1.11 +This utility just prints the length of the longest path
1.12 +in the revision graph from revison 0 to the current one.
1.13 +"""
1.14 + exit(0)
1.15 +plist = os.popen("hg parents --template='{rev}\n'").readlines()
1.16 +if len(plist)>1:
1.17 + print "You are in the process of merging"
1.18 + exit(1)
1.19 +PAR = int(plist[0])
1.20 +
1.21 +f = os.popen("hg log -r 0:tip --template='{rev} {parents}\n'").readlines()
1.22 +REV = -1
1.23 +lengths=[]
1.24 +for l in f:
1.25 + REV+=1
1.26 + s = l.split()
1.27 + rev = int(s[0])
1.28 + if REV != rev:
1.29 + print "Something is seriously wrong"
1.30 + exit(1)
1.31 + if len(s) == 1:
1.32 + par1 = par2 = rev - 1
1.33 + elif len(s) == 2:
1.34 + par1 = par2 = int(s[1].split(":")[0])
1.35 + else:
1.36 + par1 = int(s[1].split(":")[0])
1.37 + par2 = int(s[2].split(":")[0])
1.38 + if rev == 0:
1.39 + lengths.append(0)
1.40 + else:
1.41 + lengths.append(max(lengths[par1],lengths[par2])+1)
1.42 +print lengths[PAR]