2009-07-17 68 views
3

在SVN中,没有任何方法可以在树中的所有目录上设置(bugtraq)属性,而无需检查整个树?SVN:仅在目录中设置属性

我无法直接设置存储库中的属性而无需设置挂钩。即使我可以,我不知道这会有所帮助 - 你不能用Tortoise设置递归属性,我怀疑它不会直接与命令行客户端。

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

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

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

编辑:

我尝试检查出的整个仓库,并在根更改属性 - 但提交违反我们的pre-commit钩子:在标签上不能更改的属性。不删除挂钩,它看起来像我将需要手动更改属性(除标签之外的所有内容)。

+0

http:// stackoverflow。com/questions/537234/svn-checkout-export-only-the-directory-structure 刚发现这个,也许使用ls可以提供帮助。 – 2009-07-17 14:33:18

回答

4

获取所有目录的列表可能是一个不错的第一步。下面就做,没有实际检查什么出路之一:

  1. 创建与存储库中的内容的文本文件:

    SVN列表--depth无穷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:对非本地目标“https://myrepository.com/svn/path/to/root/directory/subdir1”设置属性需要一个基础版本 。不知道是否有解决办法。

+0

“需要基本修订”消息是因为您无法在存储库上设置版本化属性,只能在工作副本上设置。 – 2009-07-20 15:05:38

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())