summaryrefslogtreecommitdiff
path: root/builtin-grep.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-07-04 09:44:48 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-07-04 10:15:46 (GMT)
commit088b084bbbb7c076a85db941ad60edce582017b4 (patch)
treee61e7ecdd0d55fdf5ddc66f83d14e6bc22a4960f /builtin-grep.c
parentfcfe34b5ace3e75d37c462712c7103e39cdb1fbc (diff)
downloadgit-088b084bbbb7c076a85db941ad60edce582017b4.zip
git-088b084bbbb7c076a85db941ad60edce582017b4.tar.gz
git-088b084bbbb7c076a85db941ad60edce582017b4.tar.bz2
git-grep: use a bit more specific error messages.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'builtin-grep.c')
-rw-r--r--builtin-grep.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/builtin-grep.c b/builtin-grep.c
index bc53546..6973c66 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -657,6 +657,13 @@ static int grep_object(struct grep_opt *opt, const char **paths,
static const char builtin_grep_usage[] =
"git-grep <option>* <rev>* [-e] <pattern> [<path>...]";
+static const char emsg_invalid_context_len[] =
+"%s: invalid context length argument";
+static const char emsg_missing_context_len[] =
+"missing context length argument";
+static const char emsg_missing_argument[] =
+"option requires an argument -%s";
+
int cmd_grep(int argc, const char **argv, char **envp)
{
int hit = 0;
@@ -764,7 +771,7 @@ int cmd_grep(int argc, const char **argv, char **envp)
case 'A': case 'B': case 'C':
if (!arg[2]) {
if (argc <= 1)
- usage(builtin_grep_usage);
+ die(emsg_missing_context_len);
scan = *++argv;
argc--;
}
@@ -776,7 +783,7 @@ int cmd_grep(int argc, const char **argv, char **envp)
break;
}
if (sscanf(scan, "%u", &num) != 1)
- usage(builtin_grep_usage);
+ die(emsg_invalid_context_len, scan);
switch (arg[1]) {
case 'A':
opt.post_context = num;
@@ -795,7 +802,7 @@ int cmd_grep(int argc, const char **argv, char **envp)
int lno = 0;
char buf[1024];
if (argc <= 1)
- usage(builtin_grep_usage);
+ die(emsg_missing_argument, arg);
patterns = fopen(argv[1], "r");
if (!patterns)
die("'%s': %s", argv[1], strerror(errno));
@@ -820,7 +827,7 @@ int cmd_grep(int argc, const char **argv, char **envp)
argc--;
continue;
}
- usage(builtin_grep_usage);
+ die(emsg_missing_argument, arg);
}
if (!strcmp("--", arg)) {
/* later processing wants to have this at argv[1] */