scripts/chg-len.py
author Peter Kovacs <kpeter@inf.elte.hu>
Sat, 18 Oct 2008 11:46:25 +0200
changeset 323 94b832d461f7
parent 272 e63a95b68827
child 376 4b2382fd80ef
permissions -rwxr-xr-x
Improve the 0.x->1.x converter script (ticket #157)

- Support updating more files at once.
- Much better regexp solution for "whole words only" replacements.
     1 #! /usr/bin/env python
     2 
     3 import sys
     4 import os
     5 
     6 if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
     7     print """
     8 This utility just prints the length of the longest path
     9 in the revision graph from revison 0 to the current one.
    10 """
    11     exit(0)
    12 plist = os.popen("HGRCPATH='' hg parents --template='{rev}\n'").readlines()
    13 if len(plist)>1:
    14     print "You are in the process of merging"
    15     exit(1)
    16 PAR = int(plist[0])
    17 
    18 f = os.popen("HGRCPATH='' hg log -r 0:tip --template='{rev} {parents}\n'").\
    19     readlines()
    20 REV = -1
    21 lengths=[]
    22 for l in f:
    23     REV+=1
    24     s = l.split()
    25     rev = int(s[0])
    26     if REV != rev:
    27         print "Something is seriously wrong"
    28         exit(1)
    29     if len(s) == 1:
    30         par1 = par2 = rev - 1
    31     elif len(s) == 2:
    32         par1 = par2 = int(s[1].split(":")[0])
    33     else:
    34         par1 = int(s[1].split(":")[0])
    35         par2 = int(s[2].split(":")[0])
    36     if rev == 0:
    37         lengths.append(0)
    38     else:
    39         lengths.append(max(lengths[par1],lengths[par2])+1)
    40 print lengths[PAR]