代码之家  ›  专栏  ›  技术社区  ›  Jason Day

在subversion中自动创建标记

svn
  •  6
  • Jason Day  · 技术社区  · 17 年前

    每当我们有一个发布里程碑,我们就创建一个标签。在CVS中,这很容易:

    $ cvs tag TAG_NAME
    

    无论CVS模块或存储库如何,只要该命令在CVS工作目录中执行,它都可以工作。

    不过,为了在subversion中执行相同的操作,看起来我必须首先解析 svn info 获取存储库根目录。然后,我可以使用以下内容创建标记:

    svn cp . $REPO_ROOT/tags/TAG_NAME -m"Created tag TAG_NAME"
    

    仅仅将修订号映射到符号名似乎需要做很多工作。有更好的办法吗?

    4 回复  |  直到 17 年前
        1
  •  5
  •   bendin    17 年前

    我几乎完全从命令行使用svn,很快我就厌倦了输入monster URL。我终于写了一个剧本 svnurl ,我从外壳中使用。其运作假设“项目”具有以下形式:

    .../PROJECTNAME/trunk
                    tags
                    branches
    

    svnurl -tl  # gives a list of tags for the current project 
    svnurl -tlu # the same as full urls
    svnurl -t 1.1 # the url for the tag 1.1 of the current project
    # analagous functions for branches
    svnurl -ru  # the url of the "root" of the current working copy
                # eg  svn://.../PROJECTNAME/branches/foo
    svnurl -T   # the url of the trunk of the current project
    svnurl -pn  # the name of the current project, `PROJECTNAME`
    # ...
    

    用法如下所示:

    $ svn cp $(svnurl -T) $(svnurl -t 1.1.1)  # tag trunk as 1.1.1
    

        2
  •  5
  •   rjray    17 年前

    您缺少Subversion的一个核心原则:修订号 标签。当你用svn cp“标记”它时,你只是用一个更长的名字复制了一个特定的版本。与CVS标记不同,您(或其他开发人员)可以继续在该“标记”上进行持续开发。它不像CVS标记那样是一个静态实体(公平地说,您可以在单个CVS文件上移动标记,从而有效地“更改”它)。

    大多数svn用户对待标签的方式与CVS呈现的方式相同。并且(至少在Apache下)可以将DAV服务器配置为不允许在任何标记目录下写入/签入。我还没有尝试过,这可能会阻止您使用http URL创建标记(您必须使用主机上shell的文件路径)。但出于所有实际目的,您的发布过程应该更关注特定的修订号,而不是一些任意的文本字符串。后者可以在发布后进行更改;前者应[*]始终允许您在每次签出时访问完全相同的文件集。

    [*]事后,总有办法在幕后摆弄文件。。。当我需要修改注释等时,我曾经用vi手工编辑RCS和CVS文件。但是如果没有一些严重的svn技巧,给定的修订号应该是非常恒定的。

        3
  •  5
  •   Jason Day    17 年前

    <!-- First, we need to get the svn repository root URL by parsing
    the output of 'svn info'. -->
    <exec executable="svn" failonerror="yes">
        <arg line="info"/>
    
        <redirector outputproperty="svninfo.out" errorproperty="svninfo.err">
            <outputfilterchain>
                <linecontains>
                    <contains value="Repository Root: "/>
                </linecontains>
    
                <tokenfilter>
                    <replacestring from="Repository Root: " to=""/>
                </tokenfilter>
            </outputfilterchain>
        </redirector>
    </exec>
    
    <echo level="verbose" message="Root from svn info: ${svninfo.out}"/>
    
    <!-- Set the svn.root property from the svn info output, and append
    the module prefix if it exists. The module prefix allows multiple
    projects to use the same repository root. -->
    <condition property="svn.root" value="${svninfo.out}/${svn.module.prefix}">
        <isset property="svn.module.prefix"/>
    </condition>
    <!-- Note that the next line will have no effect if the property was
    set in the condition above, since ant properties are immutable. The
    effect is an "else", if the condition above is NOT true. -->
    <property name="svn.root" value="${svninfo.out}"/>
    <echo level="verbose" message="Root: ${svn.root}"/>
    
    <!-- Verify the tags directory exists. -->
    <exec executable="svn"
          failonerror="no"
          outputproperty="null"
          errorproperty="svn.ls.error">
        <arg line="ls ${svn.root}/tags"/>
    </exec>
    <fail>
    Cannot find 'tags' subdirectory.
    
    ${svn.ls.error}
    
    The subversion repository is expected to have 'trunk', 'branches', and 'tags'
    subdirectories. The tag '${tag}' will need to be manually created.
        <condition>
            <not>
                <equals arg1="${svn.ls.error}" arg2="" trim="yes"/>
            </not>
        </condition>
    </fail>
    
    <!-- Finally, do the actual tag (copy in subversion). -->
    <exec executable="svn" failonerror="yes">
        <arg line="cp . ${svn.root}/tags/${tag} -m 'Created tag ${tag}'"/>
    </exec>
    

    我还想指出,我知道CVS和subversion在标记方面的差异,并且subversion修订版在所有实际用途上都等同于标记。不幸的是,这并不真正相关;我的用户需要由模块名和(不同的)版本号组成的符号名。

        4
  •  2
  •   Davide    17 年前

    与CVS不同,标签在subversions中不仅仅是一个符号名称,这就是重点。我们创建一个标记,实际上是创建一个分支。如果您还没有: http://svnbook.red-bean.com/