【问题标题】:Is there a way to find all branches created from a SVN branch?有没有办法找到从 SVN 分支创建的所有分支?
【发布时间】:2017-08-04 06:44:09
【问题描述】:

我正在尝试列出从父 SVN 分支创建的所有分支,以在 Subversion 中建立一个分支的图形表示。
是否有任何可用于实现此目的的 SVN 命令?
或者有没有办法解决这个问题?

示例:

父分支:Branch1
子分支:Branch2 和 Branch3(两个分支都是从 Branch1 创建的)。
孙子分行:Branch2.1、Branch3.1等,
鉴于 Branch1,我正在尝试分别列出从父分支 (Branch1) 和子分支创建的子分支和大子分支。

结果:

Branch1-------------------Branch2-------Branch2.1,Branch 2.2 ..
|__________________Branch3--------Branch3.1,Branch3.2...


【问题讨论】:

    标签: svn tortoisesvn subversion-edge


    【解决方案1】:

    我有一个类似的问题要解决。但是,我将搜索范围限制在孩子们身上。制作递归脚本会让你找到孙子。

    因为我要检查的存储库有很多分支和提交,svn log 命令可能会很慢。所以,我把工作分成了两个步骤:

    1. 检索创建子分支的提交日志。我将它们保存在一个文件中,一行:

      parent='/branches/2014/new-components'
      svn log  https://svn.abc.org/branches/ -r1903:HEAD -v | ack -C2 "A.+\(from ${parent}:[0-9]+" >> kids.log
      

      -r1903 是为了限制搜索以尝试加快速度。我知道父分支是在 r1903 创建的,所以不需要往前看。

      我使用了ack,但grep 也可以使用。

    2. 我写了一个python 2.7脚本来解析kids.log文件:

      from __future__ import print_function
      
      import re
      import subprocess
      
      parser = argparse.ArgumentParser()
      parser.add_argument("file", help="svn log file to parse")
      args = parser.parse_args()
      
      parent='/branches/2014/new-components'
      
      # Regexp to match the svn log command output
      #    1st match = revision number
      #    2nd match = author
      #    3rd match = date of creation
      #    4th match = branch path
      #    5th match = 1st line of commit message
      
      my_regexp = re.compile(r'r([0-9]+) \| (.+) \| ....-..-.. ..:..:.. \+.... \((.+)\) \| [0-9]+ lines?\n'
                             'Changed paths:\n'
                             ' *A (.+) \(from '+parent+':[0-9]+\)\n'
                             '\n'
                             '(.+)\n')
      
      with open(args.file, 'r') as f:
          matches = my_regexp.finditer(f.read())
      
      # print kids name
      bnames =  [m.group(4) for m in matches]
      print('\n'.join(bnames))
      

      提示:我将最后两行替换为以下内容以收集所有匹配项:

      allinfo = [[m.group(i) for i in range(1,6)] for m in matches]
      

      然后你就可以遍历allinfo 并根据需要打印出你需要的信息。

    Grand kids:要制作递归脚本,必须将第 1 步和第 2 步转换为一个 Python 脚本中的函数。第 2 步将调用第 1 步,并将找到的孩子姓名作为参数。对象可能有助于跟踪整个家谱。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-16
      • 1970-01-01
      • 2020-12-07
      • 2020-12-09
      • 2012-06-01
      • 2017-12-15
      • 2016-09-11
      相关资源
      最近更新 更多