2017-08-04 168 views
1

我想列出從父SVN分支創建的所有分支,以在Subversion中建立分支的圖形表示。
有沒有可以用來實現這個目的的SVN命令?
還是有解決這個問題的方法嗎?有沒有辦法找到從SVN分支創建的所有分支?

實施例:

父分支:Branch1的
子分支:店2和店3(從分支1創建的兩個分支)。
GrandChildren分支:分支2.1,分支3.1等,
鑑於分支1,我試圖列出分別從父分支(Branch1)和子分支創建的子分支和大兒童分支。

結果:

分支1 ------------------- -------店2 Branch2.1,分行2.2 ..
| __________________店3 ------- Branch3.1,Branch3.2 ...


回答

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並根據需要打印出你需要的信息。

孩子們:爲了製作遞歸腳本,步驟1和步驟2必須在一個python腳本中轉換爲函數。第2步將調用第1步,找到的孩子名稱作爲參數。對象可能有助於跟蹤整個家族樹。