COIN-OR::LEMON - Graph Library

Changeset 376:4b2382fd80ef in lemon-main


Ignore:
Timestamp:
11/10/08 12:14:56 (16 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Phase:
public
Message:

chg-len.py uses the Mercurial API directly

This makes chg-len.py much faster.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • scripts/chg-len.py

    r284 r376  
    22
    33import sys
    4 import os
     4
     5from mercurial import ui, hg
    56
    67if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
     
    1011"""
    1112    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])
    1713
    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])
     14u = ui.ui()
     15r = hg.repository(u, ".")
     16N = r.changectx(".").rev()
     17lengths=[0]*(N+1)
     18for i in range(N+1):
     19    p=r.changectx(i).parents()
     20    if p[0]:
     21        p0=lengths[p[0].rev()]
    3322    else:
    34         par1 = int(s[1].split(":")[0])
    35         par2 = int(s[2].split(":")[0])
    36     if rev == 0:
    37         lengths.append(0)
     23        p0=-1
     24    if len(p)>1 and p[1]:
     25        p1=lengths[p[1].rev()]
    3826    else:
    39         lengths.append(max(lengths[par1],lengths[par2])+1)
    40 print lengths[PAR]
     27        p1=-1
     28    lengths[i]=max(p0,p1)+1
     29print lengths[N]
Note: See TracChangeset for help on using the changeset viewer.