From: Eric S. Raymond Date: Sun, 9 Nov 2014 13:46:19 +0000 (-0500) Subject: Begin refactoring of tag code. X-Git-Tag: 0.3~13 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=70b8c711f1bb4ca546c3d8d1b326cf58fd706ebe;p=src.git Begin refactoring of tag code. --- diff --git a/src b/src index 8713c83..a56becf 100755 --- a/src +++ b/src @@ -137,6 +137,7 @@ class History: self.name = name self.revlist = [] self.symbols = {} + self.branch = "trunk" self.delimiter = None if not os.path.exists(backend.master(self.name)): croak("%s is not registered" % self.name) @@ -159,6 +160,11 @@ class History: if debug >= DEBUG_PARSE: sys.stderr.write("\t-> symbols\n") state = "symbols" + elif line.startswith("branch:"): + if not line.strip()[7:]: + self.branch = "trunk" + else: + croak("non-trunk branches are not yet supported.") elif line.startswith("----------------------------"): if debug >= DEBUG_PARSE: sys.stderr.write("\t-> logheader\n") @@ -648,9 +654,8 @@ def set_tags(args): if not quiet and len(args) > 1: announce("tag %s = %s in " % (tagname, revno, arg)) - -def tag_method(*args): - "Inspect, create, and delete tags." +def tag_helper(args, list_tags, delete_tags, set_tags): + "Dispatch to handlers for tag and branch manipulation." if not os.path.exists(repodir): croak("repository subdirectory %s does not exist" % repodir) args = list(args) @@ -660,21 +665,59 @@ def tag_method(*args): if args[0] == '--': args.pop(0) else: - deleteflag = args[0] in ("-d", "del", "delete") - if deleteflag: + if args[0] in ("-d", "del", "delete"): delete_tags(args[1:]) return + if args[0] in ("-l", "list"): + list_tags(*args[1:]) + return set_tags(args) +def tag_method(*args): + "Inspect, create, and delete tags." + tag_helper(args, list_tags, delete_tags, set_tags) + def branch_method(*args): "Inspect, create, and delete branch." if not os.path.exists(repodir): croak("repository subdirectory %s does not exist" % repodir) - args = list(args) + (revspec, args) = preamble("branch", args) + if len(args) == 1: + metadata = History(args[0]) + sys.stdout.write("%s\n" % metadata.branch) + for branchname in metadata.symbols: + if metadata.isbranch(key): + if key != metadata.branch: + sys.stdout.write("%s\n" % key) + return + deleteflag = False + if args[0] == '--': + args.pop(0) + elif args[0] in ("delete", "del", "-d"): + deleteflag = True + args.pop(0) if not args: - sys.stdout.write("trunk\n") - else: - croak("branches are not yet implemented.") + croak("branch requires at least a tagname argument") + branchname = args.pop(0) + if not deleteflag: + if args: + revspec = metadata.resolve(args[0]) + if revspec[0] == revspec[1]: + revspec = master.revno_to_rcs(revspec[0]) + else: + croak("branch cannot accept a range") + # We have a tag name, and either the delete flag is on or + # we have a native revision. Remaining args are files. + for arg in args: + metadata = History(arg) + if deleteflag: + if branchname in metadata.symbols: + backend.delete_tag(branchname, arg) + # FIXME: delete all the branch revisions + if len(args) and not quiet: + announce("branch %s removed from %s" % (branchname, arg)) + else: + croak("%s is not a branch in %s" % (branchname, arg)) def filecmd(legend, hook, args): (revspec, args) = preamble(legend, args)