Skip to content

Commit ae84e92

Browse files
committed
Merge branch 'rs/tighten-callers-of-deref-tag'
Code clean-up. * rs/tighten-callers-of-deref-tag: line-log: handle deref_tag() returning NULL blame: handle deref_tag() returning NULL grep: handle deref_tag() returning NULL
2 parents 63e5273 + 5eb2ed6 commit ae84e92

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

blame.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,7 +2670,7 @@ static struct commit *find_single_final(struct rev_info *revs,
26702670
if (obj->flags & UNINTERESTING)
26712671
continue;
26722672
obj = deref_tag(revs->repo, obj, NULL, 0);
2673-
if (obj->type != OBJ_COMMIT)
2673+
if (!obj || obj->type != OBJ_COMMIT)
26742674
die("Non commit %s?", revs->pending.objects[i].name);
26752675
if (found)
26762676
die("More than one commit to dig from %s and %s?",
@@ -2701,7 +2701,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs,
27012701
/* Is that sole rev a committish? */
27022702
obj = revs->pending.objects[0].item;
27032703
obj = deref_tag(revs->repo, obj, NULL, 0);
2704-
if (obj->type != OBJ_COMMIT)
2704+
if (!obj || obj->type != OBJ_COMMIT)
27052705
return NULL;
27062706

27072707
/* Do we have HEAD? */
@@ -2737,7 +2737,7 @@ static struct commit *find_single_initial(struct rev_info *revs,
27372737
if (!(obj->flags & UNINTERESTING))
27382738
continue;
27392739
obj = deref_tag(revs->repo, obj, NULL, 0);
2740-
if (obj->type != OBJ_COMMIT)
2740+
if (!obj || obj->type != OBJ_COMMIT)
27412741
die("Non commit %s?", revs->pending.objects[i].name);
27422742
if (found)
27432743
die("More than one commit to dig up from, %s and %s?",

builtin/blame.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,8 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)
820820
if (kind != OBJ_TAG)
821821
return -1;
822822
obj = deref_tag(r, parse_object(r, &oid), NULL, 0);
823+
if (!obj)
824+
return -1;
823825
oidcpy(&oid, &obj->oid);
824826
}
825827
}

builtin/grep.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,17 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
670670
NULL, 0);
671671
obj_read_unlock();
672672

673+
if (!real_obj) {
674+
char hex[GIT_MAX_HEXSZ + 1];
675+
const char *name = list->objects[i].name;
676+
677+
if (!name) {
678+
oid_to_hex_r(hex, &list->objects[i].item->oid);
679+
name = hex;
680+
}
681+
die(_("invalid object '%s' given."), name);
682+
}
683+
673684
/* load the gitmodules file for this rev */
674685
if (recurse_submodules) {
675686
submodule_free(opt->repo);

line-log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ static struct commit *check_single_commit(struct rev_info *revs)
481481
if (obj->flags & UNINTERESTING)
482482
continue;
483483
obj = deref_tag(revs->repo, obj, NULL, 0);
484-
if (obj->type != OBJ_COMMIT)
484+
if (!obj || obj->type != OBJ_COMMIT)
485485
die("Non commit %s?", revs->pending.objects[i].name);
486486
if (commit)
487487
die("More than one commit to dig from: %s and %s?",

0 commit comments

Comments
 (0)