From 7a95f5ef4abc5b78cbc1d40ccac06f4f49c67fc1 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 16 Nov 2014 14:00:00 -0500 Subject: [PATCH] Reluctantly, we give up on {tag,branch} without a modifier. The problem is that it's just to easy to forget -l when you want to list tags and wind up creating unwanted tags named for the first file on your list. Regression test passes. --- src | 50 ++++++++++++++++++++++++++++---------------------- src.asc | 8 ++++---- srctest | 8 ++++---- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src b/src index 4f95e96..afe5c27 100755 --- a/src +++ b/src @@ -372,13 +372,13 @@ src status [-a] ['file'...] tracked, I = ignored, L = locked (recover with src checkout). Find more details under 'help status'. 'st' is a synonym fot status. -src tag [list|-l|delete|del|-d] ['name'] ['revision'] ['file'...] +src tag [list|-l|create|-c|delete|del|-d] ['name'] ['revision'] ['file'...] List tags, create tags, or delete tags. Takes a singleton revision, defaulting to the current branch tip. -src branch [list|-l|delete|del|-d] ['name'] ['file'...] - List, create, or delete branches. the active branch is first in - the list. The default branch is 'trunk'. +src branch [list|create|-c-l|delete|del|-d] ['name'] ['file'...] + List, create, or delete branches. When listing, the active branch + is first in the list. The default branch is 'trunk'. src rename ['tag'|'branch'] ['oldname'] ['newname'] ['file'...] Rename a tag or branch. Refuses to step on an existing symbol or @@ -551,9 +551,9 @@ you give none is the tip revision of the current branch. This command is mainly intended for use in scripts. """, "tag" : """ -src tag [list|-l|delete|del|-d] ['name'] ['revision'] ['file'...] +src tag [list|-l|create|-c|delete|del|-d] ['name'] ['revision'] ['file'...] -List tags (with -l), create tags, or delete tags (with -d). +List tags (with -l), create tags (with -c), or delete tags (with -d). Takes at most a singleton revision; the default is the current branch tip. @@ -562,9 +562,10 @@ creation will not step on an existing tag name, and a noneitent branch cannot be deleted. """, "branch" : """ -src branch [list|-l|delete|del|-d] ['name'] ['file'...] +src branch [list|-l|create|-c|delete|del|-d] ['name'] ['file'...] -List branches (with -l), create branches, or delete branches (with -d). +List branches (with -l), create branches (with -c), or delete branches +(with -d). In the list produced by '-', the active branch is first in the list. @@ -1158,7 +1159,7 @@ def tag_helper(args, legend, validation_hook, delete_method, set_method): if not quiet and len(args) > 1: announce("in %s, %s %s removed" % (arg, legend, name)) return - elif args[0] in ("-l", "list"): + if args[0] in ("-l", "list"): args.pop(0) ctx = CommandContext(legend + " listing", args, require_empty=True) width = screenwidth() @@ -1187,19 +1188,24 @@ def tag_helper(args, legend, validation_hook, delete_method, set_method): if backend.isbranch(value) == (legend == "branch"): sys.stdout.write("%4s\t%s\n" % (display,key)) return - if not args: - croak("%s setting requires a name argument" % legend) - name = args.pop(0) - ctx = CommandContext(legend, args) - if ctx.is_range(): - croak("can't accept a range when setting a %s" % legend) - for arg in ctx.args: - metadata = History(arg) - revision = validation_hook(ctx, metadata, name) - with backend.lifter(arg): - set_method(name, revision, metadata) - if not quiet and len(args) > 1: - announce("in %s, %s %s = %s" % (arg, legend, name, ctx.start)) + if args[0] in ("-c", "create"): + args.pop(0) + if not args: + croak("%s setting requires a name argument" % legend) + name = args.pop(0) + ctx = CommandContext(legend, args) + if ctx.is_range(): + croak("can't accept a range when setting a %s" % legend) + for arg in ctx.args: + metadata = History(arg) + revision = validation_hook(ctx, metadata, name) + with backend.lifter(arg): + set_method(name, revision, metadata) + if not quiet and len(args) > 1: + announce("in %s, %s %s = %s" % (arg, legend, name, ctx.start)) + return + else: + croak("%s requires a list, create, or delete modifier" % legend) def tag_method(*args): "Inspect, create, and delete tags." diff --git a/src.asc b/src.asc index 20cb1ec..e8d254a 100644 --- a/src.asc +++ b/src.asc @@ -79,13 +79,13 @@ src status [-a] ['file'...]:: give the -a switch or specify which files to look at. "st" is a synonym for status. -src tag [list|-l|delete|del|-d] ['name'] ['revision'] ['file'...]:: +src tag [list|-l|create|-c|delete|del|-d] ['name'] ['revision'] ['file'...]:: List tags, create tags, or delete tags. Takes a singleton revision, defaulting to the current branch tip. -src branch [list|-l|delete|del|-d] ['name'] ['file'...]:: - List, create, or delete branches. the active branch is first in - the list. The default branch is 'trunk'. +src branch [list|-l|create|-c|delete|del|-d] ['name'] ['file'...]:: + List, create, or delete branches. When listing, the active branch + is first in the list. The default branch is 'trunk'. src rename ['tag'|'branch'] ['oldname'] ['newname'] ['file'...]:: Rename a tag or branch. Refuses to step on an existing symbol or diff --git a/srctest b/srctest index 15bf44b..e1413d6 100755 --- a/srctest +++ b/srctest @@ -135,18 +135,18 @@ do check "revision $rev content test" done -src $TESTOPTS tag sampletag +src $TESTOPTS tag create sampletag check "tag set to default tip revision" cat >testfile8 <testfile9 +src $TESTOPTS tag list >testfile9 diff -u testfile8 testfile9 check "tag list check" -src $TESTOPTS tag basetag 1 +src $TESTOPTS tag create basetag 1 check "tag set to revision 1" cat >testfile10 <testfile10 <testfile11 +src $TESTOPTS tag -l >testfile11 diff -u testfile10 testfile11 check "second tag list check" -- 2.43.0