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