3

在 SVN 中有没有办法在树中的所有目录上设置 (bugtraq) 属性而不检查整个树?

如果不设置挂钩,我无法直接在存储库中设置属性。即使我可以,我也不确定这是否会有所帮助——你不能用 Tortoise 设置递归属性,而且我怀疑命令行客户端并不简单。

有稀疏检出 - 但如果我为每个目录设置深度为空,那么即使我手动检出每个子目录,递归设置属性也不起作用。

我可以检查整个存储库并使用 Tortoise 递归地设置目录上的 bugtraq 属性(默认情况下它们不会应用于文件)。但这将需要我为此检查整个存储库。

有没有更好的方法来做到这一点,我错过了?

编辑:

我尝试检查整个存储库并更改根目录的属性 - 但提交违反了我们的预提交挂钩:无法更改标签上的属性。在不移除钩子的情况下,看起来我需要手动更改属性(除了标签之外的所有内容)。

4

2 回答 2

4

获取所有目录的列表可能是很好的第一步。这是一种无需实际检查的方法:

  1. 使用存储库的内容创建一个文本文件:

    svn list --depth infinity https://myrepository.com/svn/path/to/root/directory > Everything.txt

  2. 将其修剪为仅目录。目录都以正斜杠结尾:

    grep "/$" Everything.txt > just_directories.txt

在您的情况下,您需要在文本编辑器中打开它并取出您的钩子阻塞的标签目录。

由于您已经检查了存储库,因此您可以将该文件直接用作 propset 操作的输入:

svn propset myprop myvalue --targets just_directories.txt

我想直接在文件的存储库版本上设置属性,而不先检查它们,但它没有用。我在每个目录名称前加上存储库路径(https://myrepository.com/svn/path/to/root/directory)并尝试svn propset myprop mypropvalue --targets just_directories.txt但它给出了一个错误: svn: Setting property在非本地目标“ https://myrepository.com/svn/path/to/root/directory/subdir1 ”上需要一个基本修订版。不确定是否有解决方法。

于 2009-07-17T20:22:19.243 回答
4

我最终使用 pysvn 绑定(非常易于使用)编写了一个脚本来执行此操作。它在下面,以防有人想要它。

import sys
import os
from optparse import OptionParser
import pysvn
import re

usage = """%prog [path] property-name property-value

Set property-name to property-value on all non-tag subdirectories in an svn working copy.

path is an optional argument and defaults to "."
"""

class Usage(Exception):
    def __init__(self, msg):
        self.msg = msg

def main():
    try:
        parser = OptionParser(usage)
        (options, args) = parser.parse_args()

        if len(args) < 2:
            raise Usage("Must specify property-name and property-value")
        elif len(args) == 2:
            directory = "."
            property_name = args[0]
            property_value = args[1]
        elif len(args) == 3:
            directory = args[0]
            property_name = args[1]
            property_value = args[2]
        elif len(args) > 3:
            raise Usage("Too many arguments specified")

        print "Setting property %s to %s for non-tag subdirectories of %s" % (property_name, property_value, directory)

        client = pysvn.Client()
        for path_info in client.info2(directory):
            path = path_info[0]
            if path_info[1]["kind"] != pysvn.node_kind.dir:
                #print "Ignoring file directory: %s" % path
                continue
            remote_path = path_info[1]["URL"]
            if not re.search('(?i)(\/tags$)|(\/tags\/)', remote_path):
                print "%s" % path
                client.propset(property_name, property_value, path, depth=pysvn.depth.empty)
            else:
                print "Ignoring tag directory: %s" % path
    except Usage, err:
        parser.error(err.msg)
        return 2


if __name__ == "__main__":
    sys.exit(main())
于 2009-07-23T15:18:12.297 回答