diff options
author | Jeff King <peff@peff.net> | 2013-03-17 12:23:31 +0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-03-17 23:52:14 +0400 |
commit | f7892d181752187513f10b13f2272fa46c9c8422 (patch) | |
tree | e2c442760956bc096f33a98cc4470a7aefb6ff2f | |
parent | 75a95490474ab6e991cbbbd10d980498a9109648 (diff) |
use parse_object_or_die instead of die("bad object")
Some call-sites do:
o = parse_object(sha1);
if (!o)
die("bad object %s", some_name);
We can now handle that as a one-liner, and get more
consistent output.
In the third case of this patch, it looks like we are losing
information, as the existing message also outputs the sha1
hex; however, parse_object will already have written a more
specific complaint about the sha1, so there is no point in
repeating it here.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | builtin/grep.c | 4 | ||||
-rw-r--r-- | builtin/prune.c | 4 | ||||
-rw-r--r-- | reachable.c | 4 |
3 files changed, 3 insertions, 9 deletions
diff --git a/builtin/grep.c b/builtin/grep.c index 0654e0b0f6..08ea5fdec8 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -898,9 +898,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix) unsigned char sha1[20]; /* Is it a rev? */ if (!get_sha1(arg, sha1)) { - struct object *object = parse_object(sha1); - if (!object) - die(_("bad object %s"), arg); + struct object *object = parse_object_or_die(sha1, arg); add_object_array(object, arg, &list); continue; } diff --git a/builtin/prune.c b/builtin/prune.c index 6cb99443c1..67ca3d5699 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -149,9 +149,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix) const char *name = *argv++; if (!get_sha1(name, sha1)) { - struct object *object = parse_object(sha1); - if (!object) - die("bad object: %s", name); + struct object *object = parse_object_or_die(sha1, name); add_pending_object(&revs, object, ""); } else diff --git a/reachable.c b/reachable.c index bf7970661f..e7e6a1e342 100644 --- a/reachable.c +++ b/reachable.c @@ -152,11 +152,9 @@ static int add_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1, static int add_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data) { - struct object *object = parse_object(sha1); + struct object *object = parse_object_or_die(sha1, path); struct rev_info *revs = (struct rev_info *)cb_data; - if (!object) - die("bad object ref: %s:%s", path, sha1_to_hex(sha1)); add_pending_object(revs, object, ""); return 0; |