scripts/chg-len.py
author Alpar Juttner <alpar@cs.elte.hu>
Sun, 05 Dec 2010 17:35:23 +0100
changeset 2 4c8956a7bdf4
permissions -rwxr-xr-x
Set up CMAKE build environment
alpar@2
     1
#! /usr/bin/env python
alpar@2
     2
#
alpar@2
     3
# This file is a part of LEMON, a generic C++ optimization library.
alpar@2
     4
#
alpar@2
     5
# Copyright (C) 2003-2009
alpar@2
     6
# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@2
     7
# (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@2
     8
#
alpar@2
     9
# Permission to use, modify and distribute this software is granted
alpar@2
    10
# provided that this copyright notice appears in all copies. For
alpar@2
    11
# precise terms see the accompanying LICENSE file.
alpar@2
    12
#
alpar@2
    13
# This software is provided "AS IS" with no warranty of any kind,
alpar@2
    14
# express or implied, and with no claim as to its suitability for any
alpar@2
    15
# purpose.
alpar@2
    16
alpar@2
    17
import sys
alpar@2
    18
alpar@2
    19
from mercurial import ui, hg
alpar@2
    20
from mercurial import util
alpar@2
    21
alpar@2
    22
util.rcpath = lambda : []
alpar@2
    23
alpar@2
    24
if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
alpar@2
    25
    print """
alpar@2
    26
This utility just prints the length of the longest path
alpar@2
    27
in the revision graph from revison 0 to the current one.
alpar@2
    28
"""
alpar@2
    29
    exit(0)
alpar@2
    30
alpar@2
    31
u = ui.ui()
alpar@2
    32
r = hg.repository(u, ".")
alpar@2
    33
N = r.changectx(".").rev()
alpar@2
    34
lengths=[0]*(N+1)
alpar@2
    35
for i in range(N+1):
alpar@2
    36
    p=r.changectx(i).parents()
alpar@2
    37
    if p[0]:
alpar@2
    38
        p0=lengths[p[0].rev()]
alpar@2
    39
    else:
alpar@2
    40
        p0=-1
alpar@2
    41
    if len(p)>1 and p[1]:
alpar@2
    42
        p1=lengths[p[1].rev()]
alpar@2
    43
    else:
alpar@2
    44
        p1=-1
alpar@2
    45
    lengths[i]=max(p0,p1)+1
alpar@2
    46
print lengths[N]