diff -r c6acc34f98dc -r 1a7fe3bef514 scripts/chg-len.py --- a/scripts/chg-len.py Fri Oct 16 10:21:37 2009 +0200 +++ b/scripts/chg-len.py Thu Nov 05 15:50:01 2009 +0100 @@ -1,7 +1,25 @@ #! /usr/bin/env python +# +# This file is a part of LEMON, a generic C++ optimization library. +# +# Copyright (C) 2003-2009 +# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport +# (Egervary Research Group on Combinatorial Optimization, EGRES). +# +# Permission to use, modify and distribute this software is granted +# provided that this copyright notice appears in all copies. For +# precise terms see the accompanying LICENSE file. +# +# This software is provided "AS IS" with no warranty of any kind, +# express or implied, and with no claim as to its suitability for any +# purpose. import sys -import os + +from mercurial import ui, hg +from mercurial import util + +util.rcpath = lambda : [] if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]: print """ @@ -9,32 +27,20 @@ in the revision graph from revison 0 to the current one. """ exit(0) -plist = os.popen("HGRCPATH='' hg parents --template='{rev}\n'").readlines() -if len(plist)>1: - print "You are in the process of merging" - exit(1) -PAR = int(plist[0]) -f = os.popen("HGRCPATH='' hg log -r 0:tip --template='{rev} {parents}\n'").\ - readlines() -REV = -1 -lengths=[] -for l in f: - REV+=1 - s = l.split() - rev = int(s[0]) - if REV != rev: - print "Something is seriously wrong" - exit(1) - if len(s) == 1: - par1 = par2 = rev - 1 - elif len(s) == 2: - par1 = par2 = int(s[1].split(":")[0]) +u = ui.ui() +r = hg.repository(u, ".") +N = r.changectx(".").rev() +lengths=[0]*(N+1) +for i in range(N+1): + p=r.changectx(i).parents() + if p[0]: + p0=lengths[p[0].rev()] else: - par1 = int(s[1].split(":")[0]) - par2 = int(s[2].split(":")[0]) - if rev == 0: - lengths.append(0) + p0=-1 + if len(p)>1 and p[1]: + p1=lengths[p[1].rev()] else: - lengths.append(max(lengths[par1],lengths[par2])+1) -print lengths[PAR] + p1=-1 + lengths[i]=max(p0,p1)+1 +print lengths[N]