Is there a way to find all branches created from a SVN branch?

900 Views Asked by At

I'm trying to list all branches created from a Parent SVN branch to establish a graphical representation of a branch in Subversion.
Are there any SVN command which can be used to achieve this?
Or is there an approach to solve this?

Example:

Parent Branch: Branch1
Child Branch: Branch2 and Branch3 (both branches created from Branch1).
GrandChildren Branch: Branch2.1, Branch3.1 etc.,
Given Branch1, I'm trying to list the child branches and Grand Children branches that were created from Parent Branch (Branch1) and Child Branches respectively.

Result:

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


1

There are 1 best solutions below

0
On

I had a similar problem to solve. However I have limited my search to the children. Making a recursive script will let you find the grand children.

Because the repository I have to examine has a lot of branches and commits, svn log commands can be very slow. So, I separated the work in two steps:

  1. Retrieve the commits logs that create the Children branches. I save them in a file, with a one line:

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

    The -r1903 is to limit the search to try speed up things a bit. I knew the parent branch was created at r1903, so no need to look before.

    I used ack, but grep would work the same.

  2. I wrote a python 2.7 script to parse the kids.log file:

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

    Tip: I replace the last two lines with the following to gather all the matches:

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

    then you can loop over allinfo and print out the information you need as you want.

Grand kids: To make a recursive script, steps 1 and 2 have to be converted into functions in one python script. And step 2 would call step 1 with the found kids name as argument. Objects may help keeping track of the entire family tree.