COIN-OR::LEMON - Graph Library

source: lemon-1.2/scripts/chg-len.py @ 410:eac19fb31a09

Last change on this file since 410:eac19fb31a09 was 376:4b2382fd80ef, checked in by Alpar Juttner <alpar@…>, 16 years ago

chg-len.py uses the Mercurial API directly

This makes chg-len.py much faster.

  • Property exe set to *
File size: 594 bytes
Line 
1#! /usr/bin/env python
2
3import sys
4
5from mercurial import ui, hg
6
7if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
8    print """
9This utility just prints the length of the longest path
10in the revision graph from revison 0 to the current one.
11"""
12    exit(0)
13
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()]
22    else:
23        p0=-1
24    if len(p)>1 and p[1]:
25        p1=lengths[p[1].rev()]
26    else:
27        p1=-1
28    lengths[i]=max(p0,p1)+1
29print lengths[N]
Note: See TracBrowser for help on using the repository browser.