Use hg templating instead of scripts/chg-len.py (#434)
authorAlpar Juttner <alpar@cs.elte.hu>
Mon, 30 Jan 2012 17:49:50 +0100 (2012-01-30)
changeset 9820b9a94956916
parent 981 cdd2c7dad989
child 983 fc1aa7c01c55
Use hg templating instead of scripts/chg-len.py (#434)
CMakeLists.txt
scripts/chg-len.py
     1.1 --- a/CMakeLists.txt	Mon Jan 30 10:54:49 2012 +0100
     1.2 +++ b/CMakeLists.txt	Mon Jan 30 17:49:50 2012 +0100
     1.3 @@ -12,29 +12,47 @@
     1.4    SET(LEMON_VERSION $ENV{LEMON_VERSION} CACHE STRING "LEMON version string.")
     1.5  ELSE()
     1.6    EXECUTE_PROCESS(
     1.7 -    COMMAND ${PYTHON_EXECUTABLE} ./scripts/chg-len.py
     1.8 +    COMMAND
     1.9 +    hg log -r. --template "{latesttag}"
    1.10      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
    1.11 -    OUTPUT_VARIABLE HG_REVISION_PATH
    1.12 +    OUTPUT_VARIABLE HG_REVISION_TAG
    1.13      ERROR_QUIET
    1.14      OUTPUT_STRIP_TRAILING_WHITESPACE
    1.15    )
    1.16    EXECUTE_PROCESS(
    1.17 -    COMMAND hg id -i
    1.18 +    COMMAND
    1.19 +    hg log -r. --template "{latesttagdistance}"
    1.20      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
    1.21 -    OUTPUT_VARIABLE HG_REVISION
    1.22 +    OUTPUT_VARIABLE HG_REVISION_DIST
    1.23      ERROR_QUIET
    1.24      OUTPUT_STRIP_TRAILING_WHITESPACE
    1.25    )
    1.26 -  IF(HG_REVISION STREQUAL "")
    1.27 +  EXECUTE_PROCESS(
    1.28 +    COMMAND
    1.29 +    hg log -r. --template "{node|short}"
    1.30 +    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
    1.31 +    OUTPUT_VARIABLE HG_REVISION_ID
    1.32 +    ERROR_QUIET
    1.33 +    OUTPUT_STRIP_TRAILING_WHITESPACE
    1.34 +  )
    1.35 +
    1.36 +  IF(HG_REVISION_TAG STREQUAL "")
    1.37      SET(HG_REVISION_ID "hg-tip")
    1.38    ELSE()
    1.39 -    IF(HG_REVISION_PATH STREQUAL "")
    1.40 -      SET(HG_REVISION_ID ${HG_REVISION})
    1.41 +    IF(HG_REVISION_TAG STREQUAL "null")
    1.42 +      SET(HG_REVISION_TAG "trunk")
    1.43 +    ELSEIF(HG_REVISION_TAG MATCHES "^r")
    1.44 +      STRING(SUBSTRING ${HG_REVISION_TAG} 1 -1 HG_REVISION_TAG)
    1.45 +    ENDIF()
    1.46 +    IF(HG_REVISION_DIST STREQUAL "0")
    1.47 +      SET(HG_REVISION ${HG_REVISION_TAG})
    1.48      ELSE()
    1.49 -      SET(HG_REVISION_ID ${HG_REVISION_PATH}.${HG_REVISION})
    1.50 +      SET(HG_REVISION
    1.51 +	"${HG_REVISION_TAG}+${HG_REVISION_DIST}-${HG_REVISION_ID}")
    1.52      ENDIF()
    1.53    ENDIF()
    1.54 -  SET(LEMON_VERSION ${HG_REVISION_ID} CACHE STRING "LEMON version string.")
    1.55 +
    1.56 +  SET(LEMON_VERSION ${HG_REVISION} CACHE STRING "LEMON version string.")
    1.57  ENDIF()
    1.58  
    1.59  SET(PROJECT_VERSION ${LEMON_VERSION})
     2.1 --- a/scripts/chg-len.py	Mon Jan 30 10:54:49 2012 +0100
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,46 +0,0 @@
     2.4 -#! /usr/bin/env python
     2.5 -#
     2.6 -# This file is a part of LEMON, a generic C++ optimization library.
     2.7 -#
     2.8 -# Copyright (C) 2003-2009
     2.9 -# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    2.10 -# (Egervary Research Group on Combinatorial Optimization, EGRES).
    2.11 -#
    2.12 -# Permission to use, modify and distribute this software is granted
    2.13 -# provided that this copyright notice appears in all copies. For
    2.14 -# precise terms see the accompanying LICENSE file.
    2.15 -#
    2.16 -# This software is provided "AS IS" with no warranty of any kind,
    2.17 -# express or implied, and with no claim as to its suitability for any
    2.18 -# purpose.
    2.19 -
    2.20 -import sys
    2.21 -
    2.22 -from mercurial import ui, hg
    2.23 -from mercurial import util
    2.24 -
    2.25 -util.rcpath = lambda : []
    2.26 -
    2.27 -if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
    2.28 -    print """
    2.29 -This utility just prints the length of the longest path
    2.30 -in the revision graph from revison 0 to the current one.
    2.31 -"""
    2.32 -    exit(0)
    2.33 -
    2.34 -u = ui.ui()
    2.35 -r = hg.repository(u, ".")
    2.36 -N = r.changectx(".").rev()
    2.37 -lengths=[0]*(N+1)
    2.38 -for i in range(N+1):
    2.39 -    p=r.changectx(i).parents()
    2.40 -    if p[0]:
    2.41 -        p0=lengths[p[0].rev()]
    2.42 -    else:
    2.43 -        p0=-1
    2.44 -    if len(p)>1 and p[1]:
    2.45 -        p1=lengths[p[1].rev()]
    2.46 -    else:
    2.47 -        p1=-1
    2.48 -    lengths[i]=max(p0,p1)+1
    2.49 -print lengths[N]