scripts/chg-len.py
changeset 417 6ff53afe98b5
parent 284 a16cc721259e
child 422 62c1ed05e83f
equal deleted inserted replaced
1:7706526f1d8b 2:d829ebcbeb7e
     1 #! /usr/bin/env python
     1 #! /usr/bin/env python
     2 
     2 
     3 import sys
     3 import sys
     4 import os
     4 
       
     5 from mercurial import ui, hg
     5 
     6 
     6 if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
     7 if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
     7     print """
     8     print """
     8 This utility just prints the length of the longest path
     9 This utility just prints the length of the longest path
     9 in the revision graph from revison 0 to the current one.
    10 in the revision graph from revison 0 to the current one.
    10 """
    11 """
    11     exit(0)
    12     exit(0)
    12 plist = os.popen("HGRCPATH='' 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 
    13 
    18 f = os.popen("HGRCPATH='' hg log -r 0:tip --template='{rev} {parents}\n'").\
    14 u = ui.ui()
    19     readlines()
    15 r = hg.repository(u, ".")
    20 REV = -1
    16 N = r.changectx(".").rev()
    21 lengths=[]
    17 lengths=[0]*(N+1)
    22 for l in f:
    18 for i in range(N+1):
    23     REV+=1
    19     p=r.changectx(i).parents()
    24     s = l.split()
    20     if p[0]:
    25     rev = int(s[0])
    21         p0=lengths[p[0].rev()]
    26     if REV != rev:
       
    27         print "Something is seriously wrong"
       
    28         exit(1)
       
    29     if len(s) == 1:
       
    30         par1 = par2 = rev - 1
       
    31     elif len(s) == 2:
       
    32         par1 = par2 = int(s[1].split(":")[0])
       
    33     else:
    22     else:
    34         par1 = int(s[1].split(":")[0])
    23         p0=-1
    35         par2 = int(s[2].split(":")[0])
    24     if len(p)>1 and p[1]:
    36     if rev == 0:
    25         p1=lengths[p[1].rev()]
    37         lengths.append(0)
       
    38     else:
    26     else:
    39         lengths.append(max(lengths[par1],lengths[par2])+1)
    27         p1=-1
    40 print lengths[PAR]
    28     lengths[i]=max(p0,p1)+1
       
    29 print lengths[N]