]> thyrsus.com Git - src.git/commitdiff
Begin refactoring of tag code.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 9 Nov 2014 13:46:19 +0000 (08:46 -0500)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 9 Nov 2014 13:46:19 +0000 (08:46 -0500)
src

diff --git a/src b/src
index 8713c83b5c302e0590cd433386fcb20c5dfc17fe..a56becfc1e0c82f372960dca0c147dd5a8e5843c 100755 (executable)
--- 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)