COIN-OR::LEMON - Graph Library

Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • scripts/chg-len.py

    r422 r284  
    22
    33import sys
    4 
    5 from mercurial import ui, hg
    6 from mercurial import util
    7 
    8 util.rcpath = lambda : []
     4import os
    95
    106if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
     
    1410"""
    1511    exit(0)
     12plist = os.popen("HGRCPATH='' hg parents --template='{rev}\n'").readlines()
     13if len(plist)>1:
     14    print "You are in the process of merging"
     15    exit(1)
     16PAR = int(plist[0])
    1617
    17 u = ui.ui()
    18 r = hg.repository(u, ".")
    19 N = r.changectx(".").rev()
    20 lengths=[0]*(N+1)
    21 for i in range(N+1):
    22     p=r.changectx(i).parents()
    23     if p[0]:
    24         p0=lengths[p[0].rev()]
     18f = os.popen("HGRCPATH='' hg log -r 0:tip --template='{rev} {parents}\n'").\
     19    readlines()
     20REV = -1
     21lengths=[]
     22for 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])
    2533    else:
    26         p0=-1
    27     if len(p)>1 and p[1]:
    28         p1=lengths[p[1].rev()]
     34        par1 = int(s[1].split(":")[0])
     35        par2 = int(s[2].split(":")[0])
     36    if rev == 0:
     37        lengths.append(0)
    2938    else:
    30         p1=-1
    31     lengths[i]=max(p0,p1)+1
    32 print lengths[N]
     39        lengths.append(max(lengths[par1],lengths[par2])+1)
     40print lengths[PAR]
Note: See TracChangeset for help on using the changeset viewer.