scripts/chg-len.py
author Alpar Juttner <alpar@cs.elte.hu>
Sun, 07 Mar 2010 09:34:56 +0000
branch1.0
changeset 937 50b6b66daafd
parent 272 e63a95b68827
child 390 4b2382fd80ef
permissions -rwxr-xr-x
Update NEWS file
alpar@272
     1
#! /usr/bin/env python
alpar@272
     2
alpar@272
     3
import sys
alpar@272
     4
import os
alpar@272
     5
alpar@272
     6
if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
alpar@272
     7
    print """
alpar@272
     8
This utility just prints the length of the longest path
alpar@272
     9
in the revision graph from revison 0 to the current one.
alpar@272
    10
"""
alpar@272
    11
    exit(0)
alpar@284
    12
plist = os.popen("HGRCPATH='' hg parents --template='{rev}\n'").readlines()
alpar@272
    13
if len(plist)>1:
alpar@272
    14
    print "You are in the process of merging"
alpar@272
    15
    exit(1)
alpar@272
    16
PAR = int(plist[0])
alpar@272
    17
alpar@284
    18
f = os.popen("HGRCPATH='' hg log -r 0:tip --template='{rev} {parents}\n'").\
alpar@284
    19
    readlines()
alpar@272
    20
REV = -1
alpar@272
    21
lengths=[]
alpar@272
    22
for l in f:
alpar@272
    23
    REV+=1
alpar@272
    24
    s = l.split()
alpar@272
    25
    rev = int(s[0])
alpar@272
    26
    if REV != rev:
alpar@272
    27
        print "Something is seriously wrong"
alpar@272
    28
        exit(1)
alpar@272
    29
    if len(s) == 1:
alpar@272
    30
        par1 = par2 = rev - 1
alpar@272
    31
    elif len(s) == 2:
alpar@272
    32
        par1 = par2 = int(s[1].split(":")[0])
alpar@272
    33
    else:
alpar@272
    34
        par1 = int(s[1].split(":")[0])
alpar@272
    35
        par2 = int(s[2].split(":")[0])
alpar@272
    36
    if rev == 0:
alpar@272
    37
        lengths.append(0)
alpar@272
    38
    else:
alpar@272
    39
        lengths.append(max(lengths[par1],lengths[par2])+1)
alpar@272
    40
print lengths[PAR]