No code which reads cmdline in struct rev_info can handle NULL objects
in cmdline.rev[i].item, so stop adding them to the cmdline.rev array.
Objects in cmdline are NULL when the given object is promisor and
--exclude-promisor-objects is enabled.

This new behavior avoids a segmentation fault in the added test case in
t0410.

We could simply die if add_rev_cmdline is called with a NULL item,
(rather than warn if --exclude-promisor-objects is set) but because the
amended test case already expects the command to finish successfully,
difference and show a warning. Note that this command:

        git rev-list --objects --missing=print $missing_hash

Already fails with a "fatal: bad object HASH" message and this patch
does not change that.

Signed-off-by: Matthew DeVore <matv...@google.com>
---
 revision.c               | 12 ++++++++++++
 t/t0410-partial-clone.sh | 11 ++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/revision.c b/revision.c
index a1ddb9e11c..8724dca2e2 100644
--- a/revision.c
+++ b/revision.c
@@ -1148,6 +1148,18 @@ static void add_rev_cmdline(struct rev_info *revs,
                            int whence,
                            unsigned flags)
 {
+       if (!item) {
+               /*
+                * item is likely a promisor object returned from get_reference.
+                */
+               if (revs->exclude_promisor_objects) {
+                       warning(_("ignoring missing object %s"), name);
+                       return;
+               } else {
+                       die(_("missing object %s"), name);
+               }
+       }
+
        struct rev_cmdline_info *info = &revs->cmdline;
        unsigned int nr = info->nr;
 
diff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh
index ba3887f178..e02cd3f818 100755
--- a/t/t0410-partial-clone.sh
+++ b/t/t0410-partial-clone.sh
@@ -366,7 +366,16 @@ test_expect_success 'rev-list accepts missing and promised 
objects on command li
 
        git -C repo config core.repositoryformatversion 1 &&
        git -C repo config extensions.partialclone "arbitrary string" &&
-       git -C repo rev-list --exclude-promisor-objects --objects "$COMMIT" 
"$TREE" "$BLOB"
+
+       printf "warning: ignoring missing object %s\n" \
+              "$COMMIT" "$TREE" "$BLOB" >expect &&
+       git -C repo rev-list --objects \
+               --exclude-promisor-objects "$COMMIT" "$TREE" "$BLOB" 2>actual &&
+       test_cmp expect actual &&
+
+       git -C repo rev-list --objects-edge-aggressive \
+               --exclude-promisor-objects "$COMMIT" "$TREE" "$BLOB" 2>actual &&
+       test_cmp expect actual
 '
 
 test_expect_success 'gc repacks promisor objects separately from non-promisor 
objects' '
-- 
2.19.1.568.g152ad8e336-goog

Reply via email to