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