COIN-OR::LEMON - Graph Library

Ticket #144: e63a95b68827.patch

File e63a95b68827.patch, 1.4 KB (added by Alpar Juttner, 12 years ago)
  • new file scripts/chg-len.py

    # HG changeset patch
    # User Alpar Juttner <alpar@cs.elte.hu>
    # Date 1221551462 -3600
    # Node ID e63a95b6882734037c4e102bf6d5008f150edac3
    # Parent  c691064dfd4f2e3d4e230a1fd9845a1d96de2a5d
    Python script for computing the longest path in the revision tree
    
    diff --git a/scripts/chg-len.py b/scripts/chg-len.py
    new file mode 100755
    - +  
     1#! /usr/bin/env python
     2
     3import sys
     4import os
     5
     6if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
     7    print """
     8This utility just prints the length of the longest path
     9in the revision graph from revison 0 to the current one.
     10"""
     11    exit(0)
     12plist = os.popen("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])
     17
     18f = os.popen("hg log -r 0:tip --template='{rev} {parents}\n'").readlines()
     19REV = -1
     20lengths=[]
     21for l in f:
     22    REV+=1
     23    s = l.split()
     24    rev = int(s[0])
     25    if REV != rev:
     26        print "Something is seriously wrong"
     27        exit(1)
     28    if len(s) == 1:
     29        par1 = par2 = rev - 1
     30    elif len(s) == 2:
     31        par1 = par2 = int(s[1].split(":")[0])
     32    else:
     33        par1 = int(s[1].split(":")[0])
     34        par2 = int(s[2].split(":")[0])
     35    if rev == 0:
     36        lengths.append(0)
     37    else:
     38        lengths.append(max(lengths[par1],lengths[par2])+1)
     39print lengths[PAR]