scripts/chg-len.py
changeset 2 4c8956a7bdf4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripts/chg-len.py	Sun Dec 05 17:35:23 2010 +0100
     1.3 @@ -0,0 +1,46 @@
     1.4 +#! /usr/bin/env python
     1.5 +#
     1.6 +# This file is a part of LEMON, a generic C++ optimization library.
     1.7 +#
     1.8 +# Copyright (C) 2003-2009
     1.9 +# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 +# (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 +#
    1.12 +# Permission to use, modify and distribute this software is granted
    1.13 +# provided that this copyright notice appears in all copies. For
    1.14 +# precise terms see the accompanying LICENSE file.
    1.15 +#
    1.16 +# This software is provided "AS IS" with no warranty of any kind,
    1.17 +# express or implied, and with no claim as to its suitability for any
    1.18 +# purpose.
    1.19 +
    1.20 +import sys
    1.21 +
    1.22 +from mercurial import ui, hg
    1.23 +from mercurial import util
    1.24 +
    1.25 +util.rcpath = lambda : []
    1.26 +
    1.27 +if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
    1.28 +    print """
    1.29 +This utility just prints the length of the longest path
    1.30 +in the revision graph from revison 0 to the current one.
    1.31 +"""
    1.32 +    exit(0)
    1.33 +
    1.34 +u = ui.ui()
    1.35 +r = hg.repository(u, ".")
    1.36 +N = r.changectx(".").rev()
    1.37 +lengths=[0]*(N+1)
    1.38 +for i in range(N+1):
    1.39 +    p=r.changectx(i).parents()
    1.40 +    if p[0]:
    1.41 +        p0=lengths[p[0].rev()]
    1.42 +    else:
    1.43 +        p0=-1
    1.44 +    if len(p)>1 and p[1]:
    1.45 +        p1=lengths[p[1].rev()]
    1.46 +    else:
    1.47 +        p1=-1
    1.48 +    lengths[i]=max(p0,p1)+1
    1.49 +print lengths[N]