scripts/chg-len.py
 author Alpar Juttner Tue, 16 Sep 2008 08:51:02 +0100 changeset 272 e63a95b68827 child 284 a16cc721259e permissions -rwxr-xr-x
Python script for computing the longest path in the revision tree
 alpar@272 1 #! /usr/bin/env python alpar@272 2 alpar@272 3 import sys alpar@272 4 import os alpar@272 5 alpar@272 6 if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]: alpar@272 7 print """ alpar@272 8 This utility just prints the length of the longest path alpar@272 9 in the revision graph from revison 0 to the current one. alpar@272 10 """ alpar@272 11 exit(0) alpar@272 12 plist = os.popen("hg parents --template='{rev}\n'").readlines() alpar@272 13 if len(plist)>1: alpar@272 14 print "You are in the process of merging" alpar@272 15 exit(1) alpar@272 16 PAR = int(plist[0]) alpar@272 17 alpar@272 18 f = os.popen("hg log -r 0:tip --template='{rev} {parents}\n'").readlines() alpar@272 19 REV = -1 alpar@272 20 lengths=[] alpar@272 21 for l in f: alpar@272 22 REV+=1 alpar@272 23 s = l.split() alpar@272 24 rev = int(s[0]) alpar@272 25 if REV != rev: alpar@272 26 print "Something is seriously wrong" alpar@272 27 exit(1) alpar@272 28 if len(s) == 1: alpar@272 29 par1 = par2 = rev - 1 alpar@272 30 elif len(s) == 2: alpar@272 31 par1 = par2 = int(s[1].split(":")[0]) alpar@272 32 else: alpar@272 33 par1 = int(s[1].split(":")[0]) alpar@272 34 par2 = int(s[2].split(":")[0]) alpar@272 35 if rev == 0: alpar@272 36 lengths.append(0) alpar@272 37 else: alpar@272 38 lengths.append(max(lengths[par1],lengths[par2])+1) alpar@272 39 print lengths[PAR]