SVN:仅在目录上设置属性

发布于 2024-07-27 17:55:30 字数 466 浏览 6 评论 0原文

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

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

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

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

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

编辑:

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

In SVN is there any way to set (bugtraq) properties on all directories in a tree without checking out the whole tree?

I can't set properties in the repository directly without setting hooks. Even if I could I'm not sure this would help - you can't set recursive properties with Tortoise, and I suspect it wouldn't be straightforward with the command line client.

There are sparse checkouts - but if I set depth empty for each directory, then setting properties recursively won't work even if I manually check out each subdirectory.

I could check out the whole repository and use Tortoise to set the bugtraq properties on the directories recursively (they don't get applied to files by default). But that's going to require me checking out the entire repository just for this.

Is there a better way to do it that I'm missing?

Edit:

I tried checking out the whole repository and changing the properties at the root - but the commit violated our pre-commit hook: can't change properties on tags. Without removing the hook, it looks like I'm going to need to manually change the properties (on everything apart from tags).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无尽的现实 2024-08-03 17:55:30

获取所有目录的列表可能是一个好的第一步。 这是一种无需实际检查任何内容即可完成此操作的方法:

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

    svn list --深度无穷 https://myrepository.com/svn/path /到/root/目录> 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: 在非本地目标上设置属性 ' https://myrepository.com/svn/path/to/root/directory/ subdir1' 需要基础修订版。 不确定是否有办法解决这个问题。

Getting a list of all the directories might be a good first step. Here's one way to do that without actually checking anything out:

  1. Create a text file with the contents of the repository:

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

  2. Trim it down to just the directories. Directories will all end with a forward slash:

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

In your case you'll want to open it up in a text editor and take out the tag directories your hooks choke on.

Since you've got the repository checked out you can use that file directly as input to a propset operation:

svn propset myprop myvalue --targets just_directories.txt

I wanted to set the properties directly on the repository versions of the files without checking them out first, but it didn't work. I prepended each directory name with the repository path (https://myrepository.com/svn/path/to/root/directory) and tried svn propset myprop mypropvalue --targets just_directories.txt but it gave an error: svn: Setting property on non-local target 'https://myrepository.com/svn/path/to/root/directory/subdir1' needs a base revision. Not sure if there's a way around that.

心清如水 2024-08-03 17:55:30

我最终编写了一个脚本来使用 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())

I ended up writing a script to do this using the pysvn bindings (which are very easy to use). It's below in case anybody wants it.

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())
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文