Skip to content

Commit f7892d1

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 75a9549 commit f7892d1

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

builtin/grep.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,9 +898,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
898898
unsigned char sha1[20];
899899
/* Is it a rev? */
900900
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);
904902
add_object_array(object, arg, &list);
905903
continue;
906904
}

builtin/prune.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
149149
const char *name = *argv++;
150150

151151
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);
155153
add_pending_object(&revs, object, "");
156154
}
157155
else

reachable.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,9 @@ static int add_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1,
152152

153153
static int add_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
154154
{
155-
struct object *object = parse_object(sha1);
155+
struct object *object = parse_object_or_die(sha1, path);
156156
struct rev_info *revs = (struct rev_info *)cb_data;
157157

158-
if (!object)
159-
die("bad object ref: %s:%s", path, sha1_to_hex(sha1));
160158
add_pending_object(revs, object, "");
161159

162160
return 0;

0 commit comments

Comments
 (0)