show-branch --reflog: tighten input validation.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 19, 2007 at 22:51 UTC
b15af07928cf8aaf405407ec94fca4a9202edbc2
1 file changed
+11
-4
builtin-show-branch.c
+11
-4
@@ -4,7 +4,9 @@
4
#include "builtin.h"
5
6
static const char show_branch_usage[] =
7
-"git-show-branch [--sparse] [--current] [--all] [--remotes] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...] | --reflog[=n] <branch>";
7
+"git-show-branch [--sparse] [--current] [--all] [--remotes] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...] | --reflog[=n[,b]] <branch>";
8
+static const char show_branch_usage_reflog[] =
9
+"--reflog is incompatible with --all, --remotes, --independent or --merge-base";
10
11
static int default_num;
12
static int default_alloc;
@@ -664,12 +666,14 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
666
*/
667
if (independent || merge_base)
668
usage(show_branch_usage);
667
- if (!!reflog && (0 < extra))
669
+ if (!!reflog && ((0 < extra) || all_heads || all_remotes))
670
/*
671
* Asking for --more in reflog mode does not
670
- * make sense.
672
+ * make sense. --list is Ok.
673
+ *
674
+ * Also --all and --remotes do not make sense either.
675
*/
672
- usage(show_branch_usage);
676
+ usage(show_branch_usage_reflog);
677
}
678
679
/* If nothing is specified, show all branches by default */
@@ -685,6 +689,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
689
int base = 0;
690
if (ac != 1)
691
die("--reflog option needs one branch name");
692
+ if (MAX_REVS < reflog)
693
+ die("Only %d entries can be shown at one time.",
694
+ MAX_REVS);
695
if (!dwim_ref(*av, strlen(*av), sha1, &ref))
696
die("No such ref %s", *av);
697