【问题标题】:CVS branch name from tag name来自标签名称的 CVS 分支名称
【发布时间】:2010-02-13 15:01:06
【问题描述】:

我在 CVS 中有许多带有不同标签的模块。我将如何获取这些标记文件所在的分支的名称?我尝试使用cvs co -r TAG 从模块中检出一个文件,然后执行cvs log,但它似乎为我提供了该文件所在的所有分支的列表,而不仅仅是一个分支名称。

这也需要是一个自动化的过程,所以我不能使用像 viewvc 这样的基于网络的工具来收集这些信息。

【问题讨论】:

    标签: bash shell cvs ksh


    【解决方案1】:

    我有以下 Korn 函数,您可以调整它们以在 bash 中运行。它在做什么应该很明显。

    使用get_ver() 确定文件路径和给定标签的版本号。然后将文件路径和版本号传递给get_branch_name()get_branch_name() 函数依赖于其他一些帮助器来获取信息并分割版本号。

    get_ver()
    {
        typeset FILE_PATH=$1
        typeset TAG=$2
        TEMPINFO=/tmp/cvsinfo$$
    
        /usr/local/bin/cvs rlog -r$TAG $FILE_PATH 1>$TEMPINFO 2>/dev/null
    
        VER_LINE=`grep "^revision" $TEMPINFO | awk '{print $2}'`
        echo ${VER_LINE:-NONE}
        rm -Rf $TEMPINFO 2>/dev/null 1>&2
    }
    
    
    get_branch_name()
    {
        typeset FILE=$1
        typeset VER=$2
    
        BRANCH_TYPE=`is_branch $VER`
    
        if [[ $BRANCH_TYPE = "BRANCH" ]]
        then
            BRANCH_ID=`get_branch_id $VER`
            BRANCH_NAME=`get_tags $FILE $BRANCH_ID`
            echo $BRANCH_NAME
        else
            echo $BRANCH_TYPE
        fi
    }
    
    
    
    get_minor_ver()
    {
        typeset VER=$1
    
        END=`echo $VER | sed 's/.*\.\([0-9]*\)/\1/g'`
        echo $END
    }
    
    get_major_ver()
    {
        typeset VER=$1
    
        START=`echo $VER | sed 's/\(.*\.\)[0-9]*/\1/g'`
        echo $START
    }
    
    is_branch()
    {
        typeset VER=$1
        # We can work out if something is branched by looking at the version number.
        # If it has only two parts (i.e. 1.123) then it's on the trunk
        # If it has more parts (i.e. 1.2.2.4) then it's on the branch
        # We can error detect if it has an odd number of parts
    
        POINTS=`echo $VER | tr -dc "." | wc -c | awk '{print $1}'`
        PARTS=$(($POINTS + 1))
    
        if [[ $PARTS -eq 2 ]]
        then
            print "TRUNK"
        elif [[ $(($PARTS % 2)) -eq 0 ]]
        then
            print "BRANCH"
        else
            print "ERROR"
        fi
    }
    
    get_branch_id()
    {
        typeset VER=$1
    
        MAJOR_VER=`get_major_ver $VER`
        MAJOR_VER=${MAJOR_VER%.}
    
        BRANCH_NUMBER=`get_minor_ver $MAJOR_VER`
    
        BRANCH_POINT=`get_major_ver $MAJOR_VER`
    
        echo ${BRANCH_POINT}0.${BRANCH_NUMBER}
    }
    
    get_tags()
    {
        typeset FILE_PATH=$1
        typeset VER=$2
    
        TEMP_TAGS_INFO=/tmp/cvsinfo$$
    
        cvs rlog -r$VER $FILE_PATH 1>${TEMP_TAGS_INFO} 2>/dev/null
    
        TEMPTAGS=`sed -n '/symbolic names:/,/keyword substitution:/p' ${TEMP_TAGS_INFO} | grep ": ${VER}$" | cut -d: -f1 | awk '{print $1}'`
        TAGS=`echo $TEMPTAGS | tr ' ' '/'`
        echo ${TAGS:-NONE}
        rm -Rf $TEMP_TAGS_INFO 2>/dev/null 1>&2
    }
    

    【讨论】:

      猜你喜欢
      • 2015-05-14
      • 1970-01-01
      • 2013-09-10
      • 1970-01-01
      • 1970-01-01
      • 2011-12-09
      • 2010-11-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多