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>
Jeff King committed
Mar 17, 2013 at 04:23 UTC
f7892d181752187513f10b13f2272fa46c9c8422
3 files changed
+3
-9
builtin/grep.c
+1
-3
@@ -898,9 +898,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
898
unsigned char sha1[20];
899
/* Is it a rev? */
900
if (!get_sha1(arg, sha1)) {
901
- struct object *object = parse_object(sha1);
902
- if (!object)
903
- die(_("bad object %s"), arg);
901
+ struct object *object = parse_object_or_die(sha1, arg);
902
add_object_array(object, arg, &list);
903
continue;
904
}
builtin/prune.c
+1
-3
@@ -149,9 +149,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
149
const char *name = *argv++;
150
151
if (!get_sha1(name, sha1)) {
152
- struct object *object = parse_object(sha1);
153
- if (!object)
154
- die("bad object: %s", name);
152
+ struct object *object = parse_object_or_die(sha1, name);
153
add_pending_object(&revs, object, "");
154
}
155
else
reachable.c
+1
-3
@@ -152,11 +152,9 @@ static int add_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
152
153
static int add_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
154
{
155
- struct object *object = parse_object(sha1);
155
+ struct object *object = parse_object_or_die(sha1, path);
156
struct rev_info *revs = (struct rev_info *)cb_data;
157
158
- if (!object)
159
- die("bad object ref: %s:%s", path, sha1_to_hex(sha1));
158
add_pending_object(revs, object, "");
159
160
return 0;