]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'rs/tighten-callers-of-deref-tag'
authorJunio C Hamano <gitster@pobox.com>
Tue, 27 Oct 2020 22:09:46 +0000 (15:09 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Oct 2020 22:09:46 +0000 (15:09 -0700)
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

blame.c
builtin/blame.c
builtin/grep.c
line-log.c

diff --git a/blame.c b/blame.c
index 686845b2b43dffe35d9f9811b61c80a0e0536332..de7b5d411fe3386661bea93388589977c67b3929 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -2670,7 +2670,7 @@ static struct commit *find_single_final(struct rev_info *revs,
                if (obj->flags & UNINTERESTING)
                        continue;
                obj = deref_tag(revs->repo, obj, NULL, 0);
-               if (obj->type != OBJ_COMMIT)
+               if (!obj || obj->type != OBJ_COMMIT)
                        die("Non commit %s?", revs->pending.objects[i].name);
                if (found)
                        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,
        /* Is that sole rev a committish? */
        obj = revs->pending.objects[0].item;
        obj = deref_tag(revs->repo, obj, NULL, 0);
-       if (obj->type != OBJ_COMMIT)
+       if (!obj || obj->type != OBJ_COMMIT)
                return NULL;
 
        /* Do we have HEAD? */
@@ -2737,7 +2737,7 @@ static struct commit *find_single_initial(struct rev_info *revs,
                if (!(obj->flags & UNINTERESTING))
                        continue;
                obj = deref_tag(revs->repo, obj, NULL, 0);
-               if (obj->type != OBJ_COMMIT)
+               if (!obj || obj->type != OBJ_COMMIT)
                        die("Non commit %s?", revs->pending.objects[i].name);
                if (found)
                        die("More than one commit to dig up from, %s and %s?",
index bb0f29300e5ca4caf3a6b9fa8e4ae96ce38c34d1..b5036ab3277ef10ab94d4b50df32f1251f788fe0 100644 (file)
@@ -820,6 +820,8 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata)
                if (kind != OBJ_TAG)
                        return -1;
                obj = deref_tag(r, parse_object(r, &oid), NULL, 0);
+               if (!obj)
+                       return -1;
                oidcpy(&oid, &obj->oid);
        }
 }
index c8037388c6e7fd4c62d1a019b1c7b17f020370df..e58e57504c3b5108eb09c9d8198efaa4128ff363 100644 (file)
@@ -670,6 +670,17 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
                                     NULL, 0);
                obj_read_unlock();
 
+               if (!real_obj) {
+                       char hex[GIT_MAX_HEXSZ + 1];
+                       const char *name = list->objects[i].name;
+
+                       if (!name) {
+                               oid_to_hex_r(hex, &list->objects[i].item->oid);
+                               name = hex;
+                       }
+                       die(_("invalid object '%s' given."), name);
+               }
+
                /* load the gitmodules file for this rev */
                if (recurse_submodules) {
                        submodule_free(opt->repo);
index 68eeb425f8adff845409d2f0f7f64118d97593a2..75c8b1acfff86508614321a83989e2940fc21d4b 100644 (file)
@@ -481,7 +481,7 @@ static struct commit *check_single_commit(struct rev_info *revs)
                if (obj->flags & UNINTERESTING)
                        continue;
                obj = deref_tag(revs->repo, obj, NULL, 0);
-               if (obj->type != OBJ_COMMIT)
+               if (!obj || obj->type != OBJ_COMMIT)
                        die("Non commit %s?", revs->pending.objects[i].name);
                if (commit)
                        die("More than one commit to dig from: %s and %s?",