From 3b7bf12da822bc817e45c74680fb564bd4468760 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 30 Aug 2012 11:35:26 -0400 Subject: [PATCH] allow optional source argument to "branch" --- README | 25 ++++++++++++++----------- jsvn | 44 ++++++++++++++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/README b/README index 7c039d3..f6194d5 100644 --- a/README +++ b/README @@ -27,11 +27,14 @@ Implemented subcommands: - bad mark the current revision as bad - containing the change sought - good mark the current revision as good - older than the change sought - reset terminate the bisect operation and return to the original revision - branch[es] [-d] [-s] [] - - with no arguments, list branches with '*' by the current one - - with -d, delete - - otherwise, create a new branch from the current one - - also switch to the new branch if -s is given + branch[es] + - branch: list branches with '*' by the current one + - branch -d name: delete branch + - branch [-s] name [source[@rev]]: create branch + - if is given it is resolved as a reference name (can be 'trunk', + or a tag or branch name) + - if is not given the HEAD of the current working-copy URL is used. + - also switch to the new branch if -s is given diff - allow specifying ref1..ref2 syntax to show the diff between two references - references can be tag names, branch names, or 'trunk' @@ -78,12 +81,12 @@ Implemented subcommands: - falls back to Subversion "switch" if doesn't exist tag[s] - tag: list tags - - tag -d : delete tag - - tag -m : rename tag to - - tag [source_ref[@rev]]: create tag ; if source_ref is given - it is resolved as a reference name (can be 'trunk', or another tag or a - branch name); if source is not given the HEAD of the current working- - copy URL is used + - tag -d name: delete tag + - tag -m old new: rename tag to + - tag name [source[@rev]]: create tag + - if is given it is resolved as a reference name (can be 'trunk', + or another tag or a branch name) + - if is not given the HEAD of the current working-copy URL is used. url - output repository URL of current working directory users diff --git a/jsvn b/jsvn index e5209c4..d063ca1 100755 --- a/jsvn +++ b/jsvn @@ -679,6 +679,9 @@ Operations: update_h(['update', '-r%d' % rev], svn, out, config) return RET_OK +# branch # list branches +# branch -d name # delete branch +# branch [-s] name [source[@rev]] # create branch [from [at revision ]] def branch_h(argv, svn, out, config): argv = argv[1:] # strip 'branch' command options, args = getopt.getopt(argv, 'ds') @@ -687,7 +690,19 @@ def branch_h(argv, svn, out, config): if origin == '' or root == '': sys.stderr.write("Could not determine origin/root URL\n") return RET_ERR - if len(options) == 0 and len(args) == 0: + do_switch = False + for opt, val in options: + if opt == '-d': + # delete branch + if len(args) < 1: + sys.stderr.write('Must supply branch name\n') + return RET_ERR + Popen([svn, 'rm', root + '/branches/' + args[0], '-m', + "Removed branch '%s'" % args[0]], stdout=out).wait() + return RET_OK + elif opt == '-s': + do_switch = True + if len(args) == 0: bl = ['trunk'] + get_svn_branch_list(svn) current = origin.split('/')[-1] bl.sort() @@ -702,26 +717,27 @@ def branch_h(argv, svn, out, config): ansi_reset(out) out.write('\n') return RET_OK - if len(args) == 0: - sys.stderr.write('Error: must supply branch name\n') - return RET_ERR branch_name = args[0] - do_switch = False - for opt, val in options: - if opt == '-d': - # delete branch - Popen([svn, 'rm', root + '/branches/' + branch_name, '-m', - "Removed branch '%s'" % branch_name], stdout=out).wait() - return RET_OK - elif opt == '-s': - do_switch = True bl = get_svn_branch_list(svn) if branch_name in bl: sys.stderr.write('Error: branch %s already exists\n' % branch_name) return RET_ERR comment = "Created '%s' branch" % branch_name branch_path = root + '/branches/' + branch_name - Popen([svn, 'copy', origin, branch_path, '-m', comment], stdout=out).wait() + branch_source = origin + if len(args) >= 2: + source = args[1] + m = re.match(r'(.*?)(@\d+)?$', source) + if m is not None: + ref_name, rev_str = m.group(1, 2) + url, path = resolve_reference(svn, ref_name) + if url != '': + branch_source = url + if rev_str is not None: + branch_source += rev_str + else: + branch_source = source + Popen([svn, 'copy', branch_source, branch_path, '-m', comment], stdout=out).wait() if do_switch: return switch_h(['switch', branch_name], svn, out, config) return RET_OK