Svn 在subversion中自动创建标记

Svn 在subversion中自动创建标记,svn,Svn,我在我的公司维护构建系统,该公司目前正在使用CVS。此构建系统用于多个项目和多个CVS存储库 每当我们有一个发布里程碑,我们就创建一个标签。在CVS中,这很容易: $ cvs tag TAG_NAME 无论CVS模块或存储库如何,只要该命令在CVS工作目录中执行,它都可以工作 不过,为了在subversion中执行相同的操作,我似乎首先必须解析svn info的输出以获得存储库根。然后,我可以使用以下内容创建标记: svn cp . $REPO_ROOT/tags/TAG_NAME -m"Cr

我在我的公司维护构建系统,该公司目前正在使用CVS。此构建系统用于多个项目和多个CVS存储库

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

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

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

svn cp . $REPO_ROOT/tags/TAG_NAME -m"Created tag TAG_NAME"
当然,这假定svn存储库具有推荐的“trunk、tags、branchs”目录结构。为了安全起见,我可能需要先验证一下


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

与CVS不同,标签在subversions中不仅仅是一个符号名称,这就是重点。我们创建一个标记,实际上是创建一个分支。如果您还没有读过这篇文章,我建议您阅读:

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

.../PROJECTNAME/trunk
                tags
                branches
假设您位于PROJECTNAME/Branchs/foo的工作副本中:

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

代码并不漂亮,但它为我节省了许多击键次数,并且以我意想不到的方式发挥了作用。如果您感兴趣,我愿意与您分享。

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

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


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

以下是我如何实现的,以防有人好奇:

<!-- 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>

找不到“标记”子目录。
${svn.ls.error}
subversion存储库应具有“主干”、“分支”和“标记”
子目录。需要手动创建标记“${tag}”。

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

如果将--parents添加到svn cp,则会在不存在时创建标记目录。嗯,1.4客户端在这里似乎不起作用。您使用的是什么版本的svn?谢谢,我当然有兴趣看一看。我无法直接使用它,因为我必须支持windows客户端,但我很想看看它是如何工作的。您可以在这里找到脚本:[[at github]]。我了解所有这些,但这并不相关。我的客户想要一个符号标记名,而不是修订名。这不会改变(我已经试过了)。svn对待标签的方式很愚蠢。为什么在一个索引文件中有一个元组rev number标记名列表,并将其用作字典很困难?同意damian的观点。修订号本身不可用作标记,因为它只是一个数字。此外,如果您有多个分支,了解修订号也没有帮助,因为整个树共享修订号。