Skip to content

Commit

Permalink
use parse_object_or_die instead of die("bad object")
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
peff authored and gitster committed Mar 17, 2013
1 parent 75a9549 commit f7892d1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
4 changes: 1 addition & 3 deletions builtin/grep.c
Expand Up @@ -898,9 +898,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
unsigned char sha1[20]; unsigned char sha1[20];
/* Is it a rev? */ /* Is it a rev? */
if (!get_sha1(arg, sha1)) { if (!get_sha1(arg, sha1)) {
struct object *object = parse_object(sha1); struct object *object = parse_object_or_die(sha1, arg);
if (!object)
die(_("bad object %s"), arg);
add_object_array(object, arg, &list); add_object_array(object, arg, &list);
continue; continue;
} }
Expand Down
4 changes: 1 addition & 3 deletions builtin/prune.c
Expand Up @@ -149,9 +149,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
const char *name = *argv++; const char *name = *argv++;


if (!get_sha1(name, sha1)) { if (!get_sha1(name, sha1)) {
struct object *object = parse_object(sha1); struct object *object = parse_object_or_die(sha1, name);
if (!object)
die("bad object: %s", name);
add_pending_object(&revs, object, ""); add_pending_object(&revs, object, "");
} }
else else
Expand Down
4 changes: 1 addition & 3 deletions reachable.c
Expand Up @@ -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) 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; 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, ""); add_pending_object(revs, object, "");


return 0; return 0;
Expand Down

0 comments on commit f7892d1

Please sign in to comment.