1.1 --- a/scripts/chg-len.py Fri Nov 13 12:33:33 2009 +0100
1.2 +++ b/scripts/chg-len.py Thu Dec 10 17:05:35 2009 +0100
1.3 @@ -1,7 +1,11 @@
1.4 #! /usr/bin/env python
1.5
1.6 import sys
1.7 -import os
1.8 +
1.9 +from mercurial import ui, hg
1.10 +from mercurial import util
1.11 +
1.12 +util.rcpath = lambda : []
1.13
1.14 if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
1.15 print """
1.16 @@ -9,32 +13,20 @@
1.17 in the revision graph from revison 0 to the current one.
1.18 """
1.19 exit(0)
1.20 -plist = os.popen("HGRCPATH='' hg parents --template='{rev}\n'").readlines()
1.21 -if len(plist)>1:
1.22 - print "You are in the process of merging"
1.23 - exit(1)
1.24 -PAR = int(plist[0])
1.25
1.26 -f = os.popen("HGRCPATH='' hg log -r 0:tip --template='{rev} {parents}\n'").\
1.27 - readlines()
1.28 -REV = -1
1.29 -lengths=[]
1.30 -for l in f:
1.31 - REV+=1
1.32 - s = l.split()
1.33 - rev = int(s[0])
1.34 - if REV != rev:
1.35 - print "Something is seriously wrong"
1.36 - exit(1)
1.37 - if len(s) == 1:
1.38 - par1 = par2 = rev - 1
1.39 - elif len(s) == 2:
1.40 - par1 = par2 = int(s[1].split(":")[0])
1.41 +u = ui.ui()
1.42 +r = hg.repository(u, ".")
1.43 +N = r.changectx(".").rev()
1.44 +lengths=[0]*(N+1)
1.45 +for i in range(N+1):
1.46 + p=r.changectx(i).parents()
1.47 + if p[0]:
1.48 + p0=lengths[p[0].rev()]
1.49 else:
1.50 - par1 = int(s[1].split(":")[0])
1.51 - par2 = int(s[2].split(":")[0])
1.52 - if rev == 0:
1.53 - lengths.append(0)
1.54 + p0=-1
1.55 + if len(p)>1 and p[1]:
1.56 + p1=lengths[p[1].rev()]
1.57 else:
1.58 - lengths.append(max(lengths[par1],lengths[par2])+1)
1.59 -print lengths[PAR]
1.60 + p1=-1
1.61 + lengths[i]=max(p0,p1)+1
1.62 +print lengths[N]