From patchwork Tue Sep 28 20:10:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12523769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEB38C433EF for ; Tue, 28 Sep 2021 20:11:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 978CE611BD for ; Tue, 28 Sep 2021 20:11:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242616AbhI1UMq (ORCPT ); Tue, 28 Sep 2021 16:12:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242568AbhI1UMp (ORCPT ); Tue, 28 Sep 2021 16:12:45 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ACB5C06161C for ; Tue, 28 Sep 2021 13:11:06 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id 61-20020aed2143000000b002a6a0f52ce7so295314qtc.0 for ; Tue, 28 Sep 2021 13:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=+RUX9pV133In8vfTVdole7ux6JBRSaJseZcig1ALGJ8=; b=pQA7ePOPRuLr3+Zeg3u+KOBApu+cIiKtWhbEITkVOxYmleRgelWgTId2FSMkyp7o6J RDgkCNtKqeHo2ItlAz34v/DdlyDomsTnsqCgCLoqjgpuyGvfbQpzuNDiXKzCV/kP9MeA O0F6797Pbky497OKq0aM1SzX+i7RPczIoMeza2fvwsCzdyXpVp+zXhkUZuGBL7c97gtX fJKeyyogw6kzaNobOjUhyPxBivJOQWhGLzQ277K/fbpkKQrhXXxeeJEZV+dZlyW/svtr qhIta7C20aA/an4/l5hGzMx2+TvmKytjpaz6dmcFF25HmcLjsQejMOswjONwgcXVBxSu Zk6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+RUX9pV133In8vfTVdole7ux6JBRSaJseZcig1ALGJ8=; b=LtyRoj6lYLOx1Bev9KpLclyeIW8FTYzAetO3ey1l5ZtOrwBruv/2YEuGuZRlm+9+Sf 6RmmLxnlHZdKw6Xa9B1dn3ETJ2Km02wiasjSDzA8acTmNzbr/wLTgDMQgMEBbnBnSyZi PYA3yeQ+p2cEMLws57JMBgltI0v9VQ/lzqg2wRJYng6pTjGsgqCrNBlUKwDxPqoxkUYe dhuAbJMTwnsHDNl95EuDr5ONBTYb6OZsVC5L7VpM3SGsDs8jEemTtRgn2HqrOyQvD8a0 nXzLsmuZex8njue6Rc7Bkag2AnmfJyv4SUcocxsVvHXCdF2Bx51dyVANGxJuC9voBplm P2aQ== X-Gm-Message-State: AOAM530SH8+zIWAcClXIIDI8HBafoKUb6TBpFUGISEQuMtPbHZEgzItJ F1dqyelA8uet7VjdO74wbsYzNW8UAuop/gteb6PV5oBTtqM9WllSfz/UGAGOCLHIFpq2Dntsf7J RCFie0pUjF2uyHg40FFtn2k88Nk5wDrTv/qfpvbqxiQ/6Dzyx21DkBaxJ7FZLjEp+2jQjoSjOhb yu X-Google-Smtp-Source: ABdhPJx4FNY+F0oE7Ts1/9vu/zlpu1ylTu6fiVhHUuQMv4JJ66TDGpnnb8kxGBnhvuW514sTJ3hS8lVjQWxAAJsLT/QK X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:a05:6214:6aa:: with SMTP id s10mr7481235qvz.56.1632859864865; Tue, 28 Sep 2021 13:11:04 -0700 (PDT) Date: Tue, 28 Sep 2021 13:10:47 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog Subject: [PATCH v2 1/9] refs: plumb repo param in begin-iterator functions From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , peff@peff.net, newren@gmail.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In preparation for the next 2 patches that adds (partial) support for arbitrary repositories, plumb a repository parameter in all functions that create iterators. There are no changes to program logic. Signed-off-by: Jonathan Tan --- refs.c | 9 +++++---- refs/debug.c | 4 ++-- refs/files-backend.c | 3 ++- refs/packed-backend.c | 8 +++++++- refs/refs-internal.h | 3 ++- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/refs.c b/refs.c index 2be0d0f057..6f7b3447a7 100644 --- a/refs.c +++ b/refs.c @@ -1414,6 +1414,7 @@ int head_ref(each_ref_fn fn, void *cb_data) struct ref_iterator *refs_ref_iterator_begin( struct ref_store *refs, const char *prefix, int trim, + struct repository *repo, enum do_for_each_ref_flags flags) { struct ref_iterator *iter; @@ -1429,7 +1430,7 @@ struct ref_iterator *refs_ref_iterator_begin( } } - iter = refs->be->iterator_begin(refs, prefix, flags); + iter = refs->be->iterator_begin(refs, prefix, repo, flags); /* * `iterator_begin()` already takes care of prefix, but we @@ -1464,7 +1465,7 @@ static int do_for_each_repo_ref(struct repository *r, const char *prefix, if (!refs) return 0; - iter = refs_ref_iterator_begin(refs, prefix, trim, flags); + iter = refs_ref_iterator_begin(refs, prefix, trim, r, flags); return do_for_each_repo_ref_iterator(r, iter, fn, cb_data); } @@ -1495,7 +1496,7 @@ static int do_for_each_ref(struct ref_store *refs, const char *prefix, if (!refs) return 0; - iter = refs_ref_iterator_begin(refs, prefix, trim, flags); + iter = refs_ref_iterator_begin(refs, prefix, trim, the_repository, flags); return do_for_each_repo_ref_iterator(the_repository, iter, do_for_each_ref_helper, &hp); @@ -2260,7 +2261,7 @@ int refs_verify_refname_available(struct ref_store *refs, strbuf_addstr(&dirname, refname + dirname.len); strbuf_addch(&dirname, '/'); - iter = refs_ref_iterator_begin(refs, dirname.buf, 0, + iter = refs_ref_iterator_begin(refs, dirname.buf, 0, the_repository, DO_FOR_EACH_INCLUDE_BROKEN); while ((ok = ref_iterator_advance(iter)) == ITER_OK) { if (skip && diff --git a/refs/debug.c b/refs/debug.c index 1a7a9e11cf..753d5da893 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -224,11 +224,11 @@ static struct ref_iterator_vtable debug_ref_iterator_vtable = { static struct ref_iterator * debug_ref_iterator_begin(struct ref_store *ref_store, const char *prefix, - unsigned int flags) + struct repository *repo, unsigned int flags) { struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store; struct ref_iterator *res = - drefs->refs->be->iterator_begin(drefs->refs, prefix, flags); + drefs->refs->be->iterator_begin(drefs->refs, prefix, repo, flags); struct debug_ref_iterator *diter = xcalloc(1, sizeof(*diter)); base_ref_iterator_init(&diter->base, &debug_ref_iterator_vtable, 1); diter->iter = res; diff --git a/refs/files-backend.c b/refs/files-backend.c index 1148c0cf09..f0cbea41c9 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -798,7 +798,7 @@ static struct ref_iterator_vtable files_ref_iterator_vtable = { static struct ref_iterator *files_ref_iterator_begin( struct ref_store *ref_store, - const char *prefix, unsigned int flags) + const char *prefix, struct repository *repo, unsigned int flags) { struct files_ref_store *refs; struct ref_iterator *loose_iter, *packed_iter, *overlay_iter; @@ -844,6 +844,7 @@ static struct ref_iterator *files_ref_iterator_begin( */ packed_iter = refs_ref_iterator_begin( refs->packed_ref_store, prefix, 0, + repo, DO_FOR_EACH_INCLUDE_BROKEN); overlay_iter = overlay_ref_iterator_begin(loose_iter, packed_iter); diff --git a/refs/packed-backend.c b/refs/packed-backend.c index f8aa97d799..94fb1042a2 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -913,7 +913,7 @@ static struct ref_iterator_vtable packed_ref_iterator_vtable = { static struct ref_iterator *packed_ref_iterator_begin( struct ref_store *ref_store, - const char *prefix, unsigned int flags) + const char *prefix, struct repository *repo, unsigned int flags) { struct packed_ref_store *refs; struct snapshot *snapshot; @@ -1135,8 +1135,14 @@ static int write_with_updates(struct packed_ref_store *refs, * of the lists each time through the loop. When the current * list of refs is exhausted, set iter to NULL. When the list * of updates is exhausted, leave i set to updates->nr. + * + * Note that the repository does not matter since + * DO_FOR_EACH_INCLUDE_BROKEN means that we do not access any objects, + * but the_repository here makes the most sense because we only support + * writing refs to the main repository. */ iter = packed_ref_iterator_begin(&refs->base, "", + the_repository, DO_FOR_EACH_INCLUDE_BROKEN); if ((ok = ref_iterator_advance(iter)) != ITER_OK) iter = NULL; diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 96911fb26e..9440be51da 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -382,6 +382,7 @@ int is_empty_ref_iterator(struct ref_iterator *ref_iterator); struct ref_iterator *refs_ref_iterator_begin( struct ref_store *refs, const char *prefix, int trim, + struct repository *repo, enum do_for_each_ref_flags flags); /* @@ -583,7 +584,7 @@ typedef int copy_ref_fn(struct ref_store *ref_store, */ typedef struct ref_iterator *ref_iterator_begin_fn( struct ref_store *ref_store, - const char *prefix, unsigned int flags); + const char *prefix, struct repository *repo, unsigned int flags); /* reflog functions */ From patchwork Tue Sep 28 20:10:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12523771 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7099C433EF for ; Tue, 28 Sep 2021 20:11:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B6557611C3 for ; Tue, 28 Sep 2021 20:11:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242623AbhI1UMs (ORCPT ); Tue, 28 Sep 2021 16:12:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242618AbhI1UMq (ORCPT ); Tue, 28 Sep 2021 16:12:46 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2295EC06161C for ; Tue, 28 Sep 2021 13:11:07 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id j12-20020aa783cc000000b0044b702424b7so8380277pfn.6 for ; Tue, 28 Sep 2021 13:11:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=aGoXUhGWjtwWe92po6Rtl/aLT+nNtXai3nLWXr/8a+c=; b=VDijicMIFJsRzjEAWDGxMs+sHKoFhOK0Pa+ZEtVnsKtZJ4KEdtMbM1kQaoaY7blWeI QS7Q5i5kwRpdAgROCdLfj7/29vsxVRv0Et6DaxhK+Weilp7P7g5SjeBNR4Wb/48ERv0p wn2YLcWfawf3l5Ay83D7jHPuhoj6Ji8CI+t0SlMPn1HqUp6EpsFZvaRbGZZL838am0Ty +YZM2J2yAkgsofn5OBu+HfxsbUWFNILKXCa9H3X3R3lVMWI208XpMHoSOO7kok87bAdZ Far1v6eO4zb6VtMUhBWr+WkYFdIZW/QoyH4/Rx8FsXtmOV9gyfd1dDTuHdYQSobe0cEa xSUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=aGoXUhGWjtwWe92po6Rtl/aLT+nNtXai3nLWXr/8a+c=; b=CX1P4dZ0UY0CbNemSp33jYAq+qUr9kj5S7goao/jOSzY08/04+fLmBRO28UtWIigoy SlHV0UNnpvbD0fxEUdqiIG4hSEQ5+OcjyjQaVp/UIUYWgewES4hy/yElRys2XFOJ3Sg2 w7KCUQNx+aDntnNacAAYe+aMAQdbjbWQES9QLjRSQhI8QOX96DHu8OUgVq/abjJ0bXe+ AcRDAkFHm6r/wwpSFKLcAz0tD+ni/JKRUieRfoTtldpt//vvUc6FpZ6dX6/x2Q9vPUhr DSFBi2iiG7igG1+JEpQds0BaIe3QbPOdiIZuN0QNTyVcBegisDHPlJ4VNeCOkGABwn68 TZxQ== X-Gm-Message-State: AOAM530qx3LQtoQtLd2hsz6RpHTHKhThKqR0FP30oWvtV/m4K1TL+Y+o I3j4OpmRxQtlbobZlguNvW0ZoVXGRWl4kFLDz0ZsebHQ3f2o/SbQpPBu8AnDpgS+U7G2Ej8p0MK JqI4GlURZLd1OPOtiRYb9gLrkA2sUMYAg7C/SMlda5LkU4a1R3TE+JfXa56xtTTj+cNHl5Qpc1E Gn X-Google-Smtp-Source: ABdhPJxyY1IuEBwjLMXproM3kD6D8tpG5aJ3SUD56WJGvMcORHvyRinM0MhAKygemqyjA26wAgw2F2hw86I3JSglPdWn X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:a17:90a:2a4b:: with SMTP id d11mr1936981pjg.172.1632859866436; Tue, 28 Sep 2021 13:11:06 -0700 (PDT) Date: Tue, 28 Sep 2021 13:10:48 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog Subject: [PATCH v2 2/9] refs: teach arbitrary repo support to iterators From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , peff@peff.net, newren@gmail.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Note that should_pack_ref() is called when writing refs, which is only supported for the_repository, hence the_repository is hardcoded there. Signed-off-by: Jonathan Tan --- refs.c | 3 ++- refs/files-backend.c | 5 ++++- refs/packed-backend.c | 6 ++++-- refs/refs-internal.h | 1 + 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/refs.c b/refs.c index 6f7b3447a7..5163e064ae 100644 --- a/refs.c +++ b/refs.c @@ -255,12 +255,13 @@ int refname_is_safe(const char *refname) * does not exist, emit a warning and return false. */ int ref_resolves_to_object(const char *refname, + struct repository *repo, const struct object_id *oid, unsigned int flags) { if (flags & REF_ISBROKEN) return 0; - if (!has_object_file(oid)) { + if (!repo_has_object_file(repo, oid)) { error(_("%s does not point to a valid object!"), refname); return 0; } diff --git a/refs/files-backend.c b/refs/files-backend.c index f0cbea41c9..4d883d9a89 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -730,6 +730,7 @@ struct files_ref_iterator { struct ref_iterator base; struct ref_iterator *iter0; + struct repository *repo; unsigned int flags; }; @@ -751,6 +752,7 @@ static int files_ref_iterator_advance(struct ref_iterator *ref_iterator) if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) && !ref_resolves_to_object(iter->iter0->refname, + iter->repo, iter->iter0->oid, iter->iter0->flags)) continue; @@ -854,6 +856,7 @@ static struct ref_iterator *files_ref_iterator_begin( base_ref_iterator_init(ref_iterator, &files_ref_iterator_vtable, overlay_iter->ordered); iter->iter0 = overlay_iter; + iter->repo = repo; iter->flags = flags; return ref_iterator; @@ -1138,7 +1141,7 @@ static int should_pack_ref(const char *refname, return 0; /* Do not pack broken refs: */ - if (!ref_resolves_to_object(refname, oid, ref_flags)) + if (!ref_resolves_to_object(refname, the_repository, oid, ref_flags)) return 0; return 1; diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 94fb1042a2..55c8bd3081 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -776,6 +776,7 @@ struct packed_ref_iterator { struct object_id oid, peeled; struct strbuf refname_buf; + struct repository *repo; unsigned int flags; }; @@ -864,8 +865,8 @@ static int packed_ref_iterator_advance(struct ref_iterator *ref_iterator) continue; if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) && - !ref_resolves_to_object(iter->base.refname, &iter->oid, - iter->flags)) + !ref_resolves_to_object(iter->base.refname, iter->repo, + &iter->oid, iter->flags)) continue; return ITER_OK; @@ -954,6 +955,7 @@ static struct ref_iterator *packed_ref_iterator_begin( iter->base.oid = &iter->oid; + iter->repo = repo; iter->flags = flags; if (prefix && *prefix) diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 9440be51da..e7b0a0a658 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -66,6 +66,7 @@ int refname_is_safe(const char *refname); * referred-to object does not exist, emit a warning and return false. */ int ref_resolves_to_object(const char *refname, + struct repository *repo, const struct object_id *oid, unsigned int flags); From patchwork Tue Sep 28 20:10:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12523773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2786C433F5 for ; Tue, 28 Sep 2021 20:11:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3CFC611C3 for ; Tue, 28 Sep 2021 20:11:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242618AbhI1UMw (ORCPT ); Tue, 28 Sep 2021 16:12:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242625AbhI1UMs (ORCPT ); Tue, 28 Sep 2021 16:12:48 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D823C061745 for ; Tue, 28 Sep 2021 13:11:09 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id z24-20020aa79f98000000b004463f2f0277so15260963pfr.23 for ; Tue, 28 Sep 2021 13:11:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=4ooikbujL/FbFPkGOXKemlcmwuOOciQiq1oPUQ7+nZs=; b=sXeFk8474+M7NQEgK+p3+SjP+b9w5F4oqnoMygPxFjVQvqnCiEtO/iniUar7dyqfp0 Jc7YdQl0VwKvLfaKlYAKjWxBFa4xLfJBb2BYGAjbTKBdYLyR9hCCMLQYI+SQMybK/V9q UbvlZGs1CjxmL8xREBR+Sei9/qPWEs3cXf+NSD1hc6oh7G/xOlKh7LxwaeBIGwWx060M lnXCO+DjfD/19x/mYU/wIh/ieiEzdksCvdz5RpnDvGGbx/jnUJKwClEanJydrr1U7GWp 0iL/ccB+vqPwhvSICY8Sac3Of4zurA9hFdQ1H6Kzhk4Zcs2GZ10rTHBfkUzf5wWjlCC9 5MWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=4ooikbujL/FbFPkGOXKemlcmwuOOciQiq1oPUQ7+nZs=; b=VNC+ocCnTv1MF6dbeKdiXmnBT9CF13TP3MyMQ+7a2ngE6lG93xdnN8tV1khWcRHybz VROGwjTMmQmLMlT+LVoeA8PDHKsKbG9YDPuF5uuPQQYh/TC7NjPoJvwmw7ivC1VWPoEV 9HAWVOEa+GEt51uBfKmX324DXlTy5O5nXeaD+KV/VAq8vnvH+5hfk1xdfsZnlzh/PKkJ ouYKgoqWx8mXN2M5SHPl6dnEbiJhyPosd0kJzfJzdmoExCiNb/P2guO9KRi5DGNwh1Jz wN4myic+9MEHojl3IAvaRAAEGdd3zldjz2SFnGlUQqkfcyUD3T3lmc49pFFwI5XmVgnh 8Bww== X-Gm-Message-State: AOAM53071UMcNkeZuikWd/HdmkuYRnn/3Gh2jIkHyHxFBDjFHaQnYj1M 4OtcgsIo4SfAGUcIFN4xLqRYjSHLOwIu1wiPoUfslelSj8Sew1mVWgFQwYWWbgQXzcOgVAzXRuw 5Cj6iPzbedLEdNjr3C9vPHflB/iqUAdyHHFhPIwHawgYyk9HhncjtKXqQcuiRufUjNg+fW+0VvN VM X-Google-Smtp-Source: ABdhPJwSbL2jzljH9HUauqcze+VFviI2e7goaRqXRHKFueeOb600KMMDS4l7Zh2yGqw1gxqVlSpsPJKvmEoiGzlSSbaS X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:aa7:9816:0:b0:447:bdf9:eac2 with SMTP id e22-20020aa79816000000b00447bdf9eac2mr7420409pfl.31.1632859868258; Tue, 28 Sep 2021 13:11:08 -0700 (PDT) Date: Tue, 28 Sep 2021 13:10:49 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog Subject: [PATCH v2 3/9] refs: peeling non-the_repository iterators is BUG From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , peff@peff.net, newren@gmail.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org There is currently no support for peeling the current ref of an iterator iterating over a non-the_repository ref store, and none is needed. Thus, for now, BUG() if that happens. Signed-off-by: Jonathan Tan --- refs/files-backend.c | 5 +++-- refs/packed-backend.c | 3 +++ refs/ref-cache.c | 10 ++++++++++ refs/ref-cache.h | 1 + 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 4d883d9a89..3289beb03e 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -831,7 +831,7 @@ static struct ref_iterator *files_ref_iterator_begin( */ loose_iter = cache_ref_iterator_begin(get_loose_ref_cache(refs), - prefix, 1); + prefix, repo, 1); /* * The packed-refs file might contain broken references, for @@ -1164,7 +1164,8 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags) packed_refs_lock(refs->packed_ref_store, LOCK_DIE_ON_ERROR, &err); - iter = cache_ref_iterator_begin(get_loose_ref_cache(refs), NULL, 0); + iter = cache_ref_iterator_begin(get_loose_ref_cache(refs), NULL, + the_repository, 0); while ((ok = ref_iterator_advance(iter)) == ITER_OK) { /* * If the loose reference can be packed, add an entry diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 55c8bd3081..e2f57a013e 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -884,6 +884,9 @@ static int packed_ref_iterator_peel(struct ref_iterator *ref_iterator, struct packed_ref_iterator *iter = (struct packed_ref_iterator *)ref_iterator; + if (iter->repo != the_repository) + BUG("peeling for non-the_repository is not supported"); + if ((iter->base.flags & REF_KNOWS_PEELED)) { oidcpy(peeled, &iter->peeled); return is_null_oid(&iter->peeled) ? -1 : 0; diff --git a/refs/ref-cache.c b/refs/ref-cache.c index 49d732f6db..97a6ac349e 100644 --- a/refs/ref-cache.c +++ b/refs/ref-cache.c @@ -435,6 +435,8 @@ struct cache_ref_iterator { * on from there.) */ struct cache_ref_iterator_level *levels; + + struct repository *repo; }; static int cache_ref_iterator_advance(struct ref_iterator *ref_iterator) @@ -491,6 +493,11 @@ static int cache_ref_iterator_advance(struct ref_iterator *ref_iterator) static int cache_ref_iterator_peel(struct ref_iterator *ref_iterator, struct object_id *peeled) { + struct cache_ref_iterator *iter = + (struct cache_ref_iterator *)ref_iterator; + + if (iter->repo != the_repository) + BUG("peeling for non-the_repository is not supported"); return peel_object(ref_iterator->oid, peeled) ? -1 : 0; } @@ -513,6 +520,7 @@ static struct ref_iterator_vtable cache_ref_iterator_vtable = { struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache, const char *prefix, + struct repository *repo, int prime_dir) { struct ref_dir *dir; @@ -547,5 +555,7 @@ struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache, level->prefix_state = PREFIX_CONTAINS_DIR; } + iter->repo = repo; + return ref_iterator; } diff --git a/refs/ref-cache.h b/refs/ref-cache.h index 3bfb89d2b3..7877bf86ed 100644 --- a/refs/ref-cache.h +++ b/refs/ref-cache.h @@ -238,6 +238,7 @@ struct ref_entry *find_ref_entry(struct ref_dir *dir, const char *refname); */ struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache, const char *prefix, + struct repository *repo, int prime_dir); #endif /* REFS_REF_CACHE_H */ From patchwork Tue Sep 28 20:10:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12523775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A667EC433EF for ; Tue, 28 Sep 2021 20:11:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A39961157 for ; Tue, 28 Sep 2021 20:11:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242676AbhI1UMx (ORCPT ); Tue, 28 Sep 2021 16:12:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242636AbhI1UMu (ORCPT ); Tue, 28 Sep 2021 16:12:50 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2E4CC06161C for ; Tue, 28 Sep 2021 13:11:10 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id y134-20020a25dc8c000000b0059f0301df0fso125835ybe.21 for ; Tue, 28 Sep 2021 13:11:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=xAdwh07H3YlOWaAh1TOVRQyYoBNTR4+AQbg29FSVGHI=; b=Lk1PlfFkvefHdacV8wRE/821AwluWMXJlHxBXwNiLUBJIfod/qCMsaQl6eGa+8MQxT s4eU+h10w6FUdzHKzpnEYwnFWMCUqJ5fE9ao5pPVd4zs5pn1DUmZrm5RSZO1Srqq+5pN d5OkzDx/IB5J0oAWuQ9Iwk8hiyTEu2PBSby5Q4FuCtklBZKFhpB5LK4+rfq+pjS9s0CU ankDwe5Zz3m0WE151NIMb8awImt+qw/QkXnwVzQ9yIoFxZwkKKAELDgqNN/RwBEx2bUD jkh2E/PDZ77mwbhc5VO84xE/+epfQKd4a00pxBw29QllShsABX4156n795urtvet1u1K ggpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=xAdwh07H3YlOWaAh1TOVRQyYoBNTR4+AQbg29FSVGHI=; b=GG6OxEBnI+fE915+JuYQLEK97pg1f99fWwbDkTrfeHbGBYrKRsM8kUJiGbX2xXZlfU 0tMUzj46DodwEiTC6gXRLVQqM/8ugSeV36I4/p++iwtDsnmEQFEdUSmvKfW03Gf4wJB7 MzJCrEiv7CewacxolDrgREMRrDGZ+w/kE6EZwS8z5YbT7D+VnlbATbSQWk7wzwoeTW/6 H5uK27SIV5WCHdZbhlzi45OSNBfLuAA5PPLmJ0txfccOLVUAV6fKPiKuRDgygFVSi++l HY+06JKEeNJ0TTNHH0LN1ygsDGc1YsIs7lrUywdJVgZhbjxEByodrKUoDmlzBCkpg8Ye bIwQ== X-Gm-Message-State: AOAM532e8FhYnrhjDeO8e/gjbx+KHr4KPlvyztkqn0wEDYzdZm9DKtsS k0mGngqzbCRKoVfLFhKRmGkcGGxke1/a1AwM0ooAIgynU0HMQQJ+b7kMCtIMxkjI+58G5pYYGYc 2kR99dU2QRUOz0FBAWIwzRkCC7pQbaTdZ7gkRhMa1Q+XDy65EuU05tzlgTRyh6SZcUMMltC1ZyR Vt X-Google-Smtp-Source: ABdhPJyicaJ7yyAlexgAtFxcMFc0PIUo72wzyao9ATkKle3hZVrr1PQ3RzMY100cczQBrVeagfbc8TFz9vy+8ihRFjjf X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:a25:9941:: with SMTP id n1mr8409685ybo.247.1632859869850; Tue, 28 Sep 2021 13:11:09 -0700 (PDT) Date: Tue, 28 Sep 2021 13:10:50 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog Subject: [PATCH v2 4/9] refs: teach refs_for_each_ref() arbitrary repos From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , peff@peff.net, newren@gmail.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org A subsequent patch needs to perform a revision walk with --all. As seen from handle_revision_pseudo_opt() in revision.c, refs_for_each_ref() needs to be updated to take a repository struct and pass it to the underlying ref iterator mechanism. This is so that refs can be checked if they resolve to an existing object and in doing so, non-resolving refs can be skipped over. (refs_head_ref() doesn't seem to read any objects and doesn't need this treatment.) Update refs_for_each_ref() accordingly. Now that get_main_ref_store() can take repositories other than the_repository, ensure that it sets the correct flags according to the repository passed as an argument. The signatures of some other functions need to be changed too for consistency (because of handle_refs() in revision.c), so do that in this patch too. Signed-off-by: Jonathan Tan --- builtin/submodule--helper.c | 16 +++++++----- object-name.c | 4 +-- refs.c | 49 ++++++++++++++++++++----------------- refs.h | 10 ++++---- revision.c | 12 ++++----- submodule.c | 10 ++++++-- 6 files changed, 57 insertions(+), 44 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 88ce6be69c..d951b7acc5 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -801,15 +801,16 @@ static void status_submodule(const char *path, const struct object_id *ce_oid, displaypath); } else if (!(flags & OPT_CACHED)) { struct object_id oid; - struct ref_store *refs = get_submodule_ref_store(path); + struct repository subrepo; - if (!refs) { + if (repo_submodule_init(&subrepo, the_repository, path, null_oid())) { print_status(flags, '-', path, ce_oid, displaypath); goto cleanup; } - if (refs_head_ref(refs, handle_submodule_head_ref, &oid)) + if (refs_head_ref(&subrepo, handle_submodule_head_ref, &oid)) die(_("could not resolve HEAD ref inside the " "submodule '%s'"), path); + repo_clear(&subrepo); print_status(flags, '+', path, &oid, displaypath); } else { @@ -1018,9 +1019,12 @@ static void generate_submodule_summary(struct summary_cb *info, if (!info->cached && oideq(&p->oid_dst, null_oid())) { if (S_ISGITLINK(p->mod_dst)) { - struct ref_store *refs = get_submodule_ref_store(p->sm_path); - if (refs) - refs_head_ref(refs, handle_submodule_head_ref, &p->oid_dst); + struct repository subrepo; + + if (!repo_submodule_init(&subrepo, the_repository, p->sm_path, null_oid())) { + refs_head_ref(&subrepo, handle_submodule_head_ref, &p->oid_dst); + repo_clear(&subrepo); + } } else if (S_ISLNK(p->mod_dst) || S_ISREG(p->mod_dst)) { struct stat st; int fd = open(p->sm_path, O_RDONLY); diff --git a/object-name.c b/object-name.c index fdff4601b2..f3012b5ec3 100644 --- a/object-name.c +++ b/object-name.c @@ -1822,8 +1822,8 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, cb.repo = repo; cb.list = &list; - refs_for_each_ref(get_main_ref_store(repo), handle_one_ref, &cb); - refs_head_ref(get_main_ref_store(repo), handle_one_ref, &cb); + refs_for_each_ref(repo, handle_one_ref, &cb); + refs_head_ref(repo, handle_one_ref, &cb); commit_list_sort_by_date(&list); return get_oid_oneline(repo, name + 2, oid, list); } diff --git a/refs.c b/refs.c index 5163e064ae..15a3aa47cf 100644 --- a/refs.c +++ b/refs.c @@ -408,34 +408,34 @@ void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_li for_each_rawref(warn_if_dangling_symref, &data); } -int refs_for_each_tag_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) +int refs_for_each_tag_ref(struct repository *repo, each_ref_fn fn, void *cb_data) { - return refs_for_each_ref_in(refs, "refs/tags/", fn, cb_data); + return refs_for_each_ref_in(get_main_ref_store(repo), "refs/tags/", fn, cb_data); } int for_each_tag_ref(each_ref_fn fn, void *cb_data) { - return refs_for_each_tag_ref(get_main_ref_store(the_repository), fn, cb_data); + return refs_for_each_tag_ref(the_repository, fn, cb_data); } -int refs_for_each_branch_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) +int refs_for_each_branch_ref(struct repository *repo, each_ref_fn fn, void *cb_data) { - return refs_for_each_ref_in(refs, "refs/heads/", fn, cb_data); + return refs_for_each_ref_in(get_main_ref_store(repo), "refs/heads/", fn, cb_data); } int for_each_branch_ref(each_ref_fn fn, void *cb_data) { - return refs_for_each_branch_ref(get_main_ref_store(the_repository), fn, cb_data); + return refs_for_each_branch_ref(the_repository, fn, cb_data); } -int refs_for_each_remote_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) +int refs_for_each_remote_ref(struct repository *repo, each_ref_fn fn, void *cb_data) { - return refs_for_each_ref_in(refs, "refs/remotes/", fn, cb_data); + return refs_for_each_ref_in(get_main_ref_store(repo), "refs/remotes/", fn, cb_data); } int for_each_remote_ref(each_ref_fn fn, void *cb_data) { - return refs_for_each_remote_ref(get_main_ref_store(the_repository), fn, cb_data); + return refs_for_each_remote_ref(the_repository, fn, cb_data); } int head_ref_namespaced(each_ref_fn fn, void *cb_data) @@ -1395,12 +1395,12 @@ int refs_rename_ref_available(struct ref_store *refs, return ok; } -int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) +int refs_head_ref(struct repository *repo, each_ref_fn fn, void *cb_data) { struct object_id oid; int flag; - if (!refs_read_ref_full(refs, "HEAD", RESOLVE_REF_READING, + if (!refs_read_ref_full(get_main_ref_store(repo), "HEAD", RESOLVE_REF_READING, &oid, &flag)) return fn("HEAD", &oid, flag, cb_data); @@ -1409,7 +1409,7 @@ int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) int head_ref(each_ref_fn fn, void *cb_data) { - return refs_head_ref(get_main_ref_store(the_repository), fn, cb_data); + return refs_head_ref(the_repository, fn, cb_data); } struct ref_iterator *refs_ref_iterator_begin( @@ -1489,6 +1489,7 @@ static int do_for_each_ref_helper(struct repository *r, static int do_for_each_ref(struct ref_store *refs, const char *prefix, each_ref_fn fn, int trim, + struct repository *repo, enum do_for_each_ref_flags flags, void *cb_data) { struct ref_iterator *iter; @@ -1497,26 +1498,26 @@ static int do_for_each_ref(struct ref_store *refs, const char *prefix, if (!refs) return 0; - iter = refs_ref_iterator_begin(refs, prefix, trim, the_repository, flags); + iter = refs_ref_iterator_begin(refs, prefix, trim, repo, flags); - return do_for_each_repo_ref_iterator(the_repository, iter, + return do_for_each_repo_ref_iterator(repo, iter, do_for_each_ref_helper, &hp); } -int refs_for_each_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) +int refs_for_each_ref(struct repository *repo, each_ref_fn fn, void *cb_data) { - return do_for_each_ref(refs, "", fn, 0, 0, cb_data); + return do_for_each_ref(get_main_ref_store(repo), "", fn, 0, repo, 0, cb_data); } int for_each_ref(each_ref_fn fn, void *cb_data) { - return refs_for_each_ref(get_main_ref_store(the_repository), fn, cb_data); + return refs_for_each_ref(the_repository, fn, cb_data); } int refs_for_each_ref_in(struct ref_store *refs, const char *prefix, each_ref_fn fn, void *cb_data) { - return do_for_each_ref(refs, prefix, fn, strlen(prefix), 0, cb_data); + return do_for_each_ref(refs, prefix, fn, strlen(prefix), the_repository, 0, cb_data); } int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data) @@ -1527,13 +1528,13 @@ int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data) int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data) { return do_for_each_ref(get_main_ref_store(the_repository), - prefix, fn, 0, 0, cb_data); + prefix, fn, 0, the_repository, 0, cb_data); } int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix, each_ref_fn fn, void *cb_data) { - return do_for_each_ref(refs, prefix, fn, 0, 0, cb_data); + return do_for_each_ref(refs, prefix, fn, 0, the_repository, 0, cb_data); } int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_data) @@ -1549,14 +1550,14 @@ int for_each_namespaced_ref(each_ref_fn fn, void *cb_data) int ret; strbuf_addf(&buf, "%srefs/", get_git_namespace()); ret = do_for_each_ref(get_main_ref_store(the_repository), - buf.buf, fn, 0, 0, cb_data); + buf.buf, fn, 0, the_repository, 0, cb_data); strbuf_release(&buf); return ret; } int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data) { - return do_for_each_ref(refs, "", fn, 0, + return do_for_each_ref(refs, "", fn, 0, the_repository, DO_FOR_EACH_INCLUDE_BROKEN, cb_data); } @@ -1891,13 +1892,15 @@ static struct ref_store *ref_store_init(const char *gitdir, struct ref_store *get_main_ref_store(struct repository *r) { + unsigned flags = r == the_repository ? + REF_STORE_ALL_CAPS : REF_STORE_READ | REF_STORE_ODB; if (r->refs_private) return r->refs_private; if (!r->gitdir) BUG("attempting to get main_ref_store outside of repository"); - r->refs_private = ref_store_init(r->gitdir, REF_STORE_ALL_CAPS); + r->refs_private = ref_store_init(r->gitdir, flags); r->refs_private = maybe_debug_wrap_ref_store(r->gitdir, r->refs_private); return r->refs_private; } diff --git a/refs.h b/refs.h index 10e7696a64..e9ecb5e54e 100644 --- a/refs.h +++ b/refs.h @@ -316,17 +316,17 @@ typedef int each_repo_ref_fn(struct repository *r, * modifies the reference also returns a nonzero value to immediately * stop the iteration. Returned references are sorted. */ -int refs_head_ref(struct ref_store *refs, +int refs_head_ref(struct repository *repo, each_ref_fn fn, void *cb_data); -int refs_for_each_ref(struct ref_store *refs, +int refs_for_each_ref(struct repository *repo, each_ref_fn fn, void *cb_data); int refs_for_each_ref_in(struct ref_store *refs, const char *prefix, each_ref_fn fn, void *cb_data); -int refs_for_each_tag_ref(struct ref_store *refs, +int refs_for_each_tag_ref(struct repository *repo, each_ref_fn fn, void *cb_data); -int refs_for_each_branch_ref(struct ref_store *refs, +int refs_for_each_branch_ref(struct repository *repo, each_ref_fn fn, void *cb_data); -int refs_for_each_remote_ref(struct ref_store *refs, +int refs_for_each_remote_ref(struct repository *repo, each_ref_fn fn, void *cb_data); /* just iterates the head ref. */ diff --git a/revision.c b/revision.c index 3ad217f2ff..cd34e12b2e 100644 --- a/revision.c +++ b/revision.c @@ -1565,7 +1565,7 @@ void add_ref_exclusion(struct string_list **ref_excludes_p, const char *exclude) static void handle_refs(struct ref_store *refs, struct rev_info *revs, unsigned flags, - int (*for_each)(struct ref_store *, each_ref_fn, void *)) + int (*for_each)(struct repository *, each_ref_fn, void *)) { struct all_refs_cb cb; @@ -1575,7 +1575,7 @@ static void handle_refs(struct ref_store *refs, } init_all_refs_cb(&cb, revs, flags); - for_each(refs, handle_one_ref, &cb); + for_each(revs->repo, handle_one_ref, &cb); } static void handle_one_reflog_commit(struct object_id *oid, void *cb_data) @@ -2553,14 +2553,14 @@ static int for_each_bisect_ref(struct ref_store *refs, each_ref_fn fn, return status; } -static int for_each_bad_bisect_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) +static int for_each_bad_bisect_ref(struct repository *repo, each_ref_fn fn, void *cb_data) { - return for_each_bisect_ref(refs, fn, cb_data, term_bad); + return for_each_bisect_ref(get_main_ref_store(repo), fn, cb_data, term_bad); } -static int for_each_good_bisect_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) +static int for_each_good_bisect_ref(struct repository *repo, each_ref_fn fn, void *cb_data) { - return for_each_bisect_ref(refs, fn, cb_data, term_good); + return for_each_bisect_ref(get_main_ref_store(repo), fn, cb_data, term_good); } static int handle_revision_pseudo_opt(struct rev_info *revs, diff --git a/submodule.c b/submodule.c index 62beb8fd5f..bc3ec4a242 100644 --- a/submodule.c +++ b/submodule.c @@ -92,8 +92,14 @@ int is_staging_gitmodules_ok(struct index_state *istate) static int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) { - return refs_for_each_remote_ref(get_submodule_ref_store(submodule), - fn, cb_data); + struct repository subrepo; + int ret; + + if (repo_submodule_init(&subrepo, the_repository, submodule, null_oid())) + return 0; + ret = refs_for_each_remote_ref(&subrepo, fn, cb_data); + repo_clear(&subrepo); + return ret; } /* From patchwork Tue Sep 28 20:10:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12523777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7DBBC433F5 for ; Tue, 28 Sep 2021 20:11:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C8A29611C3 for ; Tue, 28 Sep 2021 20:11:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242681AbhI1UMy (ORCPT ); Tue, 28 Sep 2021 16:12:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242671AbhI1UMv (ORCPT ); Tue, 28 Sep 2021 16:12:51 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FA55C061749 for ; Tue, 28 Sep 2021 13:11:12 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id l22-20020ac87b36000000b002a6c575f419so87899qtu.23 for ; Tue, 28 Sep 2021 13:11:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Upy0c5uTxmwwaMQ3imcsowolViZMkgLpftPPpt7wA8M=; b=tFxh9pQHPFgVTT+vvLyBvYL++B82vkLApNQlJVoli5XgOESIfXx/dLn2pxXNWE7o1E lMVs0awMD2tpxGPQ4wIJ/GfPwqfHw7JtWnZqwf0/JoNfEkLSDpKyLmqXPfuIk5yabf6j H8PHD10Sam2c9JfcPSfuODPOJeXMk4c9dnxM1PGhXOB+5n0ycDmkLCX6hvnIEWRclLlc fU9NY635Q4TMGGP9dHqraiu/OzkK6Yz7MdFc8qDhDnULukXDsHfvvh2o6BDNegMBlaTO 5lvHZRXlIcLSfW/BUoN8MBgkK29C2eeJMaojkMApylUYf+yh7buPmIRZx+CRXMj4KaAh kHyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Upy0c5uTxmwwaMQ3imcsowolViZMkgLpftPPpt7wA8M=; b=R02bF10qjrV2FFmdXSLo0uigR9bcz/sVb6lc2LN7Dh0ZwZAN5uX8VOS9TEFs585eF4 b4APEuKb/lY0LqVAhF6/DzIBtLeRA6M3+o3dAHivymxrobDM5skIy7DlXelcqwEjUM6h mQKCSk4XLjbr1WesM1x+tzgDUIqe3eQxRf2QeAwHUdSvkzJa0bjD0dLCOn3PEdXEmjbV dXlF5+mx0X34MTamq5AN7zkT/W+4/EsTMDCgmkER6UAr/zQCYRftor3VhGpV7EWxUmIc 1aBb2/M6e/i+m61pSxLnF2V6dZox+VNWrn1rRgwSwaBG3V9Q7WfIe3x3f7JvJgxZKjHc Fn/g== X-Gm-Message-State: AOAM533P8w/YqFfO7Jd5kkMGZMfDQn+iN3OepKDmRYbuqKGTjXGlCkUR ZApjbNb2dlW/p3GZAr3n3iWwoSfvR1dC8f6Ug0/orB+eEpwfED7D082xu9Z14ZXzeQ62tcAJWMx LYaZ5y7tgOw43w8bOoNQnXgMBQXXibNlxPasfbcLpkkJyuX4Oo73FzzNcsI9YjR8BSr+SyVGDVi Sz X-Google-Smtp-Source: ABdhPJxw+LJozPympYTN1GOuiNPe+9CDZ5jdPMSuK2SMSER1uYoQLQiAc+aUjo6A9HlxHdi3r8RgWPywpEnDuPxUbTNO X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:a05:6214:172:: with SMTP id y18mr1878502qvs.1.1632859871178; Tue, 28 Sep 2021 13:11:11 -0700 (PDT) Date: Tue, 28 Sep 2021 13:10:51 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog Subject: [PATCH v2 5/9] merge-{ort,recursive}: remove add_submodule_odb() From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , peff@peff.net, newren@gmail.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org After the parent commit and some of its ancestors, the only place commits are being accessed through alternates is in the user-facing message formatting code. Fix those, and remove the add_submodule_odb() calls. Signed-off-by: Jonathan Tan --- merge-ort.c | 18 ++++------------- merge-recursive.c | 41 +++++++++++++++++++------------------- strbuf.c | 12 ++++++++--- strbuf.h | 6 ++++-- t/t6437-submodule-merge.sh | 3 +++ 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index b88475475d..fbc5c204c1 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -609,6 +609,7 @@ static int err(struct merge_options *opt, const char *err, ...) static void format_commit(struct strbuf *sb, int indent, + struct repository *repo, struct commit *commit) { struct merge_remote_desc *desc; @@ -622,7 +623,7 @@ static void format_commit(struct strbuf *sb, return; } - format_commit_message(commit, "%h %s", sb, &ctx); + repo_format_commit_message(repo, commit, "%h %s", sb, &ctx); strbuf_addch(sb, '\n'); } @@ -1578,17 +1579,6 @@ static int merge_submodule(struct merge_options *opt, if (is_null_oid(b)) return 0; - /* - * NEEDSWORK: Remove this when all submodule object accesses are - * through explicitly specified repositores. - */ - if (add_submodule_odb(path)) { - path_msg(opt, path, 0, - _("Failed to merge submodule %s (not checked out)"), - path); - return 0; - } - if (repo_submodule_init(&subrepo, opt->repo, path, null_oid())) { path_msg(opt, path, 0, _("Failed to merge submodule %s (not checked out)"), @@ -1653,7 +1643,7 @@ static int merge_submodule(struct merge_options *opt, break; case 1: - format_commit(&sb, 4, + format_commit(&sb, 4, &subrepo, (struct commit *)merges.objects[0].item); path_msg(opt, path, 0, _("Failed to merge submodule %s, but a possible merge " @@ -1670,7 +1660,7 @@ static int merge_submodule(struct merge_options *opt, break; default: for (i = 0; i < merges.nr; i++) - format_commit(&sb, 4, + format_commit(&sb, 4, &subrepo, (struct commit *)merges.objects[i].item); path_msg(opt, path, 0, _("Failed to merge submodule %s, but multiple " diff --git a/merge-recursive.c b/merge-recursive.c index 5a2d8a60c0..80594153f1 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -334,7 +334,9 @@ static void output(struct merge_options *opt, int v, const char *fmt, ...) flush_output(opt); } -static void output_commit_title(struct merge_options *opt, struct commit *commit) +static void repo_output_commit_title(struct merge_options *opt, + struct repository *repo, + struct commit *commit) { struct merge_remote_desc *desc; @@ -343,23 +345,29 @@ static void output_commit_title(struct merge_options *opt, struct commit *commit if (desc) strbuf_addf(&opt->obuf, "virtual %s\n", desc->name); else { - strbuf_add_unique_abbrev(&opt->obuf, &commit->object.oid, - DEFAULT_ABBREV); + strbuf_repo_add_unique_abbrev(&opt->obuf, repo, + &commit->object.oid, + DEFAULT_ABBREV); strbuf_addch(&opt->obuf, ' '); - if (parse_commit(commit) != 0) + if (repo_parse_commit(repo, commit) != 0) strbuf_addstr(&opt->obuf, _("(bad commit)\n")); else { const char *title; - const char *msg = get_commit_buffer(commit, NULL); + const char *msg = repo_get_commit_buffer(repo, commit, NULL); int len = find_commit_subject(msg, &title); if (len) strbuf_addf(&opt->obuf, "%.*s\n", len, title); - unuse_commit_buffer(commit, msg); + repo_unuse_commit_buffer(repo, commit, msg); } } flush_output(opt); } +static void output_commit_title(struct merge_options *opt, struct commit *commit) +{ + repo_output_commit_title(opt, the_repository, commit); +} + static int add_cacheinfo(struct merge_options *opt, const struct diff_filespec *blob, const char *path, int stage, int refresh, int options) @@ -1149,14 +1157,14 @@ static int find_first_merges(struct repository *repo, return result->nr; } -static void print_commit(struct commit *commit) +static void print_commit(struct repository *repo, struct commit *commit) { struct strbuf sb = STRBUF_INIT; struct pretty_print_context ctx = {0}; ctx.date_mode.type = DATE_NORMAL; /* FIXME: Merge this with output_commit_title() */ assert(!merge_remote_util(commit)); - format_commit_message(commit, " %h: %m %s", &sb, &ctx); + repo_format_commit_message(repo, commit, " %h: %m %s", &sb, &ctx); fprintf(stderr, "%s\n", sb.buf); strbuf_release(&sb); } @@ -1196,15 +1204,6 @@ static int merge_submodule(struct merge_options *opt, if (is_null_oid(b)) return 0; - /* - * NEEDSWORK: Remove this when all submodule object accesses are - * through explicitly specified repositores. - */ - if (add_submodule_odb(path)) { - output(opt, 1, _("Failed to merge submodule %s (not checked out)"), path); - return 0; - } - if (repo_submodule_init(&subrepo, opt->repo, path, null_oid())) { output(opt, 1, _("Failed to merge submodule %s (not checked out)"), path); return 0; @@ -1229,7 +1228,7 @@ static int merge_submodule(struct merge_options *opt, oidcpy(result, b); if (show(opt, 3)) { output(opt, 3, _("Fast-forwarding submodule %s to the following commit:"), path); - output_commit_title(opt, commit_b); + repo_output_commit_title(opt, &subrepo, commit_b); } else if (show(opt, 2)) output(opt, 2, _("Fast-forwarding submodule %s"), path); else @@ -1242,7 +1241,7 @@ static int merge_submodule(struct merge_options *opt, oidcpy(result, a); if (show(opt, 3)) { output(opt, 3, _("Fast-forwarding submodule %s to the following commit:"), path); - output_commit_title(opt, commit_a); + repo_output_commit_title(opt, &subrepo, commit_a); } else if (show(opt, 2)) output(opt, 2, _("Fast-forwarding submodule %s"), path); else @@ -1274,7 +1273,7 @@ static int merge_submodule(struct merge_options *opt, case 1: output(opt, 1, _("Failed to merge submodule %s (not fast-forward)"), path); output(opt, 2, _("Found a possible merge resolution for the submodule:\n")); - print_commit((struct commit *) merges.objects[0].item); + print_commit(&subrepo, (struct commit *) merges.objects[0].item); output(opt, 2, _( "If this is correct simply add it to the index " "for example\n" @@ -1287,7 +1286,7 @@ static int merge_submodule(struct merge_options *opt, default: output(opt, 1, _("Failed to merge submodule %s (multiple merges found)"), path); for (i = 0; i < merges.nr; i++) - print_commit((struct commit *) merges.objects[i].item); + print_commit(&subrepo, (struct commit *) merges.objects[i].item); } object_array_clear(&merges); diff --git a/strbuf.c b/strbuf.c index c8a5789694..b22e981655 100644 --- a/strbuf.c +++ b/strbuf.c @@ -1059,15 +1059,21 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm, strbuf_setlen(sb, sb->len + len); } -void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid, - int abbrev_len) +void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo, + const struct object_id *oid, int abbrev_len) { int r; strbuf_grow(sb, GIT_MAX_HEXSZ + 1); - r = find_unique_abbrev_r(sb->buf + sb->len, oid, abbrev_len); + r = repo_find_unique_abbrev_r(repo, sb->buf + sb->len, oid, abbrev_len); strbuf_setlen(sb, sb->len + r); } +void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid, + int abbrev_len) +{ + strbuf_repo_add_unique_abbrev(sb, the_repository, oid, abbrev_len); +} + /* * Returns the length of a line, without trailing spaces. * diff --git a/strbuf.h b/strbuf.h index 5b1113abf8..2d9e01c16f 100644 --- a/strbuf.h +++ b/strbuf.h @@ -634,8 +634,10 @@ void strbuf_list_free(struct strbuf **list); * Add the abbreviation, as generated by find_unique_abbrev, of `sha1` to * the strbuf `sb`. */ -void strbuf_add_unique_abbrev(struct strbuf *sb, - const struct object_id *oid, +struct repository; +void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo, + const struct object_id *oid, int abbrev_len); +void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid, int abbrev_len); /** diff --git a/t/t6437-submodule-merge.sh b/t/t6437-submodule-merge.sh index e5e89c2045..178413c22f 100755 --- a/t/t6437-submodule-merge.sh +++ b/t/t6437-submodule-merge.sh @@ -5,6 +5,9 @@ test_description='merging with submodules' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 +export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB + . ./test-lib.sh . "$TEST_DIRECTORY"/lib-merge.sh From patchwork Tue Sep 28 20:10:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12523779 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A002C433EF for ; Tue, 28 Sep 2021 20:11:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BFBD611C3 for ; Tue, 28 Sep 2021 20:11:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242703AbhI1UM4 (ORCPT ); Tue, 28 Sep 2021 16:12:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242625AbhI1UMx (ORCPT ); Tue, 28 Sep 2021 16:12:53 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 501BCC06161C for ; Tue, 28 Sep 2021 13:11:13 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id w5-20020a654105000000b002692534afceso179479pgp.8 for ; Tue, 28 Sep 2021 13:11:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=nEK0YW4RyngRwSrhB2/a1MiORL8rUO3dHHdC1i3zZNE=; b=J2Bhxl3wybzauM0BFE0AkvHpralOYFMa9Zk70A+mZQ/ydMPFoJk6W8DuuJa3U3KYWd LHOCJJeuL5dynFUkH5tOk0iw2sX9Hpp0ttLSviIz4rFJNUlO4MxzLlIGLNX5OsJ9H7Ct Viak/iIGZuB6naPj5uI5GN7xyOltiS7BF4yvJ9jcROs7ECoyIuGcMy9u/Rang1cOcNuB XiYFhImPq59SFdcYuakLuJ+qVFakHuzQzwzHkvACsPicWHGQ63UvAl6RmCcwp8h+KxL9 dlFg17TFwErLIVoFIDVzL+ACqnXnPOxUMgds1cSUAKDA/AhDFietqk5JUTip9bRzn2gJ VV7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=nEK0YW4RyngRwSrhB2/a1MiORL8rUO3dHHdC1i3zZNE=; b=7bRi0N/a+JCghjCn9p6r0vYtM+p8nCBB5qpsMX7pDYPKThpxeGSyK5mnz0mqtnUsGC KmVUncx04jHGm4epnaFB40dIENHx2N1l8uSkQnRxIIhrGFMVMccqitelIzVwiTF1/ZBB RS+P0pB3SlDT5nep0UIxn3SZIjZuOmxmIHQaMQBFsQzR46kpHuovgfSlSx/K/7a/Zsm1 /CI4ETnEQrrngW51HsQVe5yJbkMTcMtWtEdOmztGSlr0yur/ktHVW0O1im91arRKd/S3 1gxiPYVq6EZS+jlSzAzfQvTgusakbjjB2CvVLTosewkA8eFh7UdBZyZh9Qw9gG+rdwOY W4Bg== X-Gm-Message-State: AOAM532RzC1jFN0FPti7W8TFxmifx5GKtTP7bbpPy7uSCozlY1BTAi0n 3QaTK9EOLDrX6IIuF24eaSUDls8M1Gj6DMAPKiWpe810TfzajTQ2LXTAunYztgrtfd9J40JJg0u d28kF4NeL2zxfrYC1194jEZoXcPnm/NOBvnzNn5HqBPOziK4/BeOumSjL2fJdmNJ0lb08Mr8+zV vo X-Google-Smtp-Source: ABdhPJwpDoiJLebQGutOM5Nr19iXDYfsTAM1xFxCEEuCtOBLheve/1AF61YF6nyPGv3mchaR90rFwPicKBdIZa/bkbIR X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:a17:902:64d6:b0:13e:59fe:8124 with SMTP id y22-20020a17090264d600b0013e59fe8124mr1085596pli.89.1632859872642; Tue, 28 Sep 2021 13:11:12 -0700 (PDT) Date: Tue, 28 Sep 2021 13:10:52 -0700 In-Reply-To: Message-Id: <9c5ce004b283788763df0e574edcf7f77b166370.1632859148.git.jonathantanmy@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog Subject: [PATCH v2 6/9] object-file: only register submodule ODB if needed From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , peff@peff.net, newren@gmail.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a35e03dee0 ("submodule: lazily add submodule ODBs as alternates", 2021-09-08), Git was taught to add all known submodule ODBs as alternates when attempting to read an object that doesn't exist, as a fallback for when a submodule object is read as if it were in the_repository. However, this behavior wasn't restricted to happen only when reading from the_repository. Fix this. Signed-off-by: Jonathan Tan --- object-file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/object-file.c b/object-file.c index be4f94ecf3..2b988b7c36 100644 --- a/object-file.c +++ b/object-file.c @@ -1614,7 +1614,8 @@ static int do_oid_object_info_extended(struct repository *r, break; } - if (register_all_submodule_odb_as_alternates()) + if (r == the_repository && + register_all_submodule_odb_as_alternates()) /* We added some alternates; retry */ continue; From patchwork Tue Sep 28 20:10:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12523781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0019CC433FE for ; Tue, 28 Sep 2021 20:11:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD95C611C3 for ; Tue, 28 Sep 2021 20:11:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242708AbhI1UM5 (ORCPT ); Tue, 28 Sep 2021 16:12:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242694AbhI1UMz (ORCPT ); Tue, 28 Sep 2021 16:12:55 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47E8FC061746 for ; Tue, 28 Sep 2021 13:11:15 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id q10-20020a05620a0d8a00b0045de482ae16so55588947qkl.12 for ; Tue, 28 Sep 2021 13:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=FMo5m71X/pOjr4FDnJntl6CMsU98+1MECDqIZbL7WCs=; b=YMzmeavS6cF19MYJB3dvvk0cMJtZmS3rNu88nquvpR9wncXtxbFbWwJv4Dv1kMHafR xFKHJ5WTDsCB9Cpa4DSZfXNLet/LxGOfeIcA5UCBV7YBOF40MkIjb2fVPSugjpMSWs24 +dC+2pVqky8wa53f++O2hqbHunvekJobVi4GyqZvUXxTSvzGmAegxD/39QA54B79HoCX O1yTScytK4c4UJnuJTk8X2RvH1LeTNqLSEEQYeQMIqtXX1Y2mLfF0TrQFOT08KZu5inq pjjXczLGTvYQk3qi86y2tpIvZ+7DKCiDq2iYzp87pbVIGJI/Bg/im5sGbyy51jt1yl/j FAIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=FMo5m71X/pOjr4FDnJntl6CMsU98+1MECDqIZbL7WCs=; b=Bhi9/xNeTwdnMK+Mtym89Pf+L73CabnYohMN8UQJZixsRojDUyeSL2NA9rdPPP5KNp x1Lf/cNskBKyPhF77dAMWW6U0SElZy2KIjLHowRq9GtL2xUbvdHkrQ/Kp+emgYzKHvvi GHiNCUa/sUeRnBsoiQqFyKdDD3Uvbq9Ux7HJYD/UZA5waceMxC/b6RnOQpDsrvC3TrpG P2/upHFcP06KVD9sDGo8Ea+qnE2l5uP18YA6CWQIWa3yyBsPo4IJHfwR8BEgdCtybL6O cWlECcgNNhyuGfe0a5WqwdHg4o4YBHnRq9FEN3C0yoDHXE1Ghs8OCDK7PCAoPaifn9DS FLrw== X-Gm-Message-State: AOAM531MQtLA1/uS+u2D5mD9DIAREfHUsKn3DHXkdQXZQ1p0IzJKzh3L nOeXsYVOS0BG+v8YGcTGt7HpyONitHZ8+BzJhymRSdGlStky9sPwUn2UmW1G6J3YlJULcUZKhAV y02OHqJ+gR+AOQHuZcYss3ykFExrNpPTB8hf/jOiswb6+suO9kvZs8SjgLH3oK51E9ZNoZOgbvq 9W X-Google-Smtp-Source: ABdhPJxgNVRxMDrDpeMS8pCoafpiyesKLZU7hm0dpup3O1sxq/qvZ0x5Ey5XmLMn28Yti4gLlMAom5G10+0FE/GAVfmG X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:a0c:e1cf:: with SMTP id v15mr1678836qvl.32.1632859874369; Tue, 28 Sep 2021 13:11:14 -0700 (PDT) Date: Tue, 28 Sep 2021 13:10:53 -0700 In-Reply-To: Message-Id: <1fca3b1a2582e86fdc16b5f9db0f3c446b94a56f.1632859148.git.jonathantanmy@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog Subject: [PATCH v2 7/9] submodule: pass repo to check_has_commit() From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , peff@peff.net, newren@gmail.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Pass the repo explicitly when calling check_has_commit() to avoid relying on add_submodule_odb(). With this commit and the parent commit, several tests no longer rely on add_submodule_odb(), so mark these tests accordingly. Signed-off-by: Jonathan Tan --- submodule.c | 16 +++++++++++++--- t/t5526-fetch-submodules.sh | 3 +++ t/t5572-pull-submodule.sh | 3 +++ t/t7418-submodule-sparse-gitmodules.sh | 3 +++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/submodule.c b/submodule.c index bc3ec4a242..992890321a 100644 --- a/submodule.c +++ b/submodule.c @@ -934,23 +934,33 @@ struct has_commit_data { static int check_has_commit(const struct object_id *oid, void *data) { struct has_commit_data *cb = data; + struct repository subrepo; + enum object_type type; - enum object_type type = oid_object_info(cb->repo, oid, NULL); + if (repo_submodule_init(&subrepo, cb->repo, cb->path, null_oid())) { + cb->result = 0; + goto cleanup; + } + + type = oid_object_info(&subrepo, oid, NULL); switch (type) { case OBJ_COMMIT: - return 0; + goto cleanup; case OBJ_BAD: /* * Object is missing or invalid. If invalid, an error message * has already been printed. */ cb->result = 0; - return 0; + goto cleanup; default: die(_("submodule entry '%s' (%s) is a %s, not a commit"), cb->path, oid_to_hex(oid), type_name(type)); } +cleanup: + repo_clear(&subrepo); + return 0; } static int submodule_has_commits(struct repository *r, diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh index ed11569d8d..2dc75b80db 100755 --- a/t/t5526-fetch-submodules.sh +++ b/t/t5526-fetch-submodules.sh @@ -6,6 +6,9 @@ test_description='Recursive "git fetch" for submodules' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 +export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB + . ./test-lib.sh pwd=$(pwd) diff --git a/t/t5572-pull-submodule.sh b/t/t5572-pull-submodule.sh index 4f92a116e1..fa6b4cca65 100755 --- a/t/t5572-pull-submodule.sh +++ b/t/t5572-pull-submodule.sh @@ -2,6 +2,9 @@ test_description='pull can handle submodules' +GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 +export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB + . ./test-lib.sh . "$TEST_DIRECTORY"/lib-submodule-update.sh diff --git a/t/t7418-submodule-sparse-gitmodules.sh b/t/t7418-submodule-sparse-gitmodules.sh index 3f7f271883..f87e524d6d 100755 --- a/t/t7418-submodule-sparse-gitmodules.sh +++ b/t/t7418-submodule-sparse-gitmodules.sh @@ -12,6 +12,9 @@ The test setup uses a sparse checkout, however the same scenario can be set up also by committing .gitmodules and then just removing it from the filesystem. ' +GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 +export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB + . ./test-lib.sh test_expect_success 'sparse checkout setup which hides .gitmodules' ' From patchwork Tue Sep 28 20:10:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12523783 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 098C9C433EF for ; Tue, 28 Sep 2021 20:11:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E784061157 for ; Tue, 28 Sep 2021 20:11:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242701AbhI1UM7 (ORCPT ); Tue, 28 Sep 2021 16:12:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242704AbhI1UM4 (ORCPT ); Tue, 28 Sep 2021 16:12:56 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAEDDC061745 for ; Tue, 28 Sep 2021 13:11:16 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id f8-20020a2585480000b02905937897e3daso273480ybn.2 for ; Tue, 28 Sep 2021 13:11:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=9xyF0CgCOMC2vT/7bwiznBEaq3BRY7cRpKzeixQeiUI=; b=bA/kArt+yvHNVxZJ23NUyN/p9JGpG+Neu59iaOb992v5rJb88b0L1nbADUptBL7XtJ bFKLiJWbs18pTH6Xvf3ha+8aA4mau/1Jmkt1FmAhNQ42l3erkO8SP960vtOQgfQEzEAu btPOXXvAzTDD16bonRjJqBVPTCOTD1DhfJ2+8Z6zkPuuFWk2XviV6e5MbrVCMi4VqzGx zYufgqatlc4d5OYYxcomGnbFjeFYnOMC0hJgFUKSoVgr+VqHhibMf3twRZeC1a+SSSZl fTMIquoIgtckn7g1hUkyMhjLiPc/+67oh0lOJFTskgw7tZz1QxLnumqTIg0Tof5yb3Jd SK8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=9xyF0CgCOMC2vT/7bwiznBEaq3BRY7cRpKzeixQeiUI=; b=FpDeomf2nJ81HeokVDaYs8uwIFr1vbmdTGLrZNtdfhxNaNzQEDbyKf580bLTKjSmKx nA8kVwgfOzC/7tmWwg2sLA3Vdoo+2L9CVIS/qknOjzHPwUPws1FZrNib0Fq8qnByWJY9 nvsk5Mp4yu/3JDgzzOaWaLH0xsFgpWbM551wrmM/iUUcngFgv5/j30zFHinITR94acFv 7piqm6hRUj0CvRFziyHcP6C/utLsDO2KBa5xYzqbcMj73yzLpntNtT8jAINwGExngxAO pJkR1Mc63ZdvxJmDr4qPhlpK/MFIWU5i1YgM9iyWwB8GG906+PWfD0UCPq18+AsRBAqi /S4Q== X-Gm-Message-State: AOAM530XA5BTGqtoPPTZCDIAYoxUOkbUE4mofH/xDiR12D93+97qOQua 6rOH0TSVawIm5lfTvbs68tqOKcue4Sq7pTvzk61xXGOlWL24cWRhqX50MQVD/Z+Mi01n/o/922i 7cPe9gTTmNqHog7mtmw/RBKQu7KOEF3iujIaQEt/dfzNVIBADPynV/vNQHEuGKvzSfgVfptIg0V B6 X-Google-Smtp-Source: ABdhPJzUnAxEcodyJKBY4UDeWxfvQIqWkd7l5RKnBImkjcOejmqUy5xJEbEF+2DadgnLsCHaHKM5HrNPCBNZ6q/JezsN X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:a25:1989:: with SMTP id 131mr9209444ybz.429.1632859875951; Tue, 28 Sep 2021 13:11:15 -0700 (PDT) Date: Tue, 28 Sep 2021 13:10:54 -0700 In-Reply-To: Message-Id: <7b5087a14d8e2c5b3cbd837bc95bcea96dded8b9.1632859148.git.jonathantanmy@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog Subject: [PATCH v2 8/9] refs: change refs_for_each_ref_in() to take repo From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , peff@peff.net, newren@gmail.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Pass a repository to refs_for_each_ref_in() so that object accesses during iteration (done to skip over invalid refs) are made with the correct repository instead of relying on add_submodule_odb(). With this, the last remaining tests no longer rely on add_submodule_odb(), so mark them accordingly. The test-ref-store test helper needed to be changed to reflect the new API. For now, just pass the repository through a global variable. Signed-off-by: Jonathan Tan --- refs.c | 12 ++++++------ refs.h | 2 +- t/helper/test-ref-store.c | 20 +++++++++----------- t/t5531-deep-submodule-push.sh | 3 +++ t/t5545-push-options.sh | 3 +++ 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/refs.c b/refs.c index 15a3aa47cf..5b0937ac20 100644 --- a/refs.c +++ b/refs.c @@ -410,7 +410,7 @@ void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_li int refs_for_each_tag_ref(struct repository *repo, each_ref_fn fn, void *cb_data) { - return refs_for_each_ref_in(get_main_ref_store(repo), "refs/tags/", fn, cb_data); + return refs_for_each_ref_in(repo, "refs/tags/", fn, cb_data); } int for_each_tag_ref(each_ref_fn fn, void *cb_data) @@ -420,7 +420,7 @@ int for_each_tag_ref(each_ref_fn fn, void *cb_data) int refs_for_each_branch_ref(struct repository *repo, each_ref_fn fn, void *cb_data) { - return refs_for_each_ref_in(get_main_ref_store(repo), "refs/heads/", fn, cb_data); + return refs_for_each_ref_in(repo, "refs/heads/", fn, cb_data); } int for_each_branch_ref(each_ref_fn fn, void *cb_data) @@ -430,7 +430,7 @@ int for_each_branch_ref(each_ref_fn fn, void *cb_data) int refs_for_each_remote_ref(struct repository *repo, each_ref_fn fn, void *cb_data) { - return refs_for_each_ref_in(get_main_ref_store(repo), "refs/remotes/", fn, cb_data); + return refs_for_each_ref_in(repo, "refs/remotes/", fn, cb_data); } int for_each_remote_ref(each_ref_fn fn, void *cb_data) @@ -1514,15 +1514,15 @@ int for_each_ref(each_ref_fn fn, void *cb_data) return refs_for_each_ref(the_repository, fn, cb_data); } -int refs_for_each_ref_in(struct ref_store *refs, const char *prefix, +int refs_for_each_ref_in(struct repository *repo, const char *prefix, each_ref_fn fn, void *cb_data) { - return do_for_each_ref(refs, prefix, fn, strlen(prefix), the_repository, 0, cb_data); + return do_for_each_ref(get_main_ref_store(repo), prefix, fn, strlen(prefix), repo, 0, cb_data); } int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data) { - return refs_for_each_ref_in(get_main_ref_store(the_repository), prefix, fn, cb_data); + return refs_for_each_ref_in(the_repository, prefix, fn, cb_data); } int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data) diff --git a/refs.h b/refs.h index e9ecb5e54e..458d8eddde 100644 --- a/refs.h +++ b/refs.h @@ -320,7 +320,7 @@ int refs_head_ref(struct repository *repo, each_ref_fn fn, void *cb_data); int refs_for_each_ref(struct repository *repo, each_ref_fn fn, void *cb_data); -int refs_for_each_ref_in(struct ref_store *refs, const char *prefix, +int refs_for_each_ref_in(struct repository *repo, const char *prefix, each_ref_fn fn, void *cb_data); int refs_for_each_tag_ref(struct repository *repo, each_ref_fn fn, void *cb_data); diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index b314b81a45..1964cb349e 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -5,6 +5,8 @@ #include "object-store.h" #include "repository.h" +static struct repository *repo; + static const char *notnull(const char *arg, const char *name) { if (!arg) @@ -24,18 +26,13 @@ static const char **get_store(const char **argv, struct ref_store **refs) if (!argv[0]) { die("ref store required"); } else if (!strcmp(argv[0], "main")) { + repo = the_repository; *refs = get_main_ref_store(the_repository); } else if (skip_prefix(argv[0], "submodule:", &gitdir)) { - struct strbuf sb = STRBUF_INIT; - int ret; - - ret = strbuf_git_path_submodule(&sb, gitdir, "objects/"); - if (ret) - die("strbuf_git_path_submodule failed: %d", ret); - add_to_alternates_memory(sb.buf); - strbuf_release(&sb); - - *refs = get_submodule_ref_store(gitdir); + repo = xmalloc(sizeof(*repo)); + if (repo_submodule_init(repo, the_repository, gitdir, null_oid())) + die("repo_submodule_init failed"); + *refs = get_main_ref_store(repo); } else if (skip_prefix(argv[0], "worktree:", &gitdir)) { struct worktree **p, **worktrees = get_worktrees(); @@ -52,6 +49,7 @@ static const char **get_store(const char **argv, struct ref_store **refs) if (!*p) die("no such worktree: %s", gitdir); + repo = the_repository; *refs = get_worktree_ref_store(*p); } else die("unknown backend %s", argv[0]); @@ -113,7 +111,7 @@ static int cmd_for_each_ref(struct ref_store *refs, const char **argv) { const char *prefix = notnull(*argv++, "prefix"); - return refs_for_each_ref_in(refs, prefix, each_ref, NULL); + return refs_for_each_ref_in(repo, prefix, each_ref, NULL); } static int cmd_resolve_ref(struct ref_store *refs, const char **argv) diff --git a/t/t5531-deep-submodule-push.sh b/t/t5531-deep-submodule-push.sh index d573ca496a..3f58b515ce 100755 --- a/t/t5531-deep-submodule-push.sh +++ b/t/t5531-deep-submodule-push.sh @@ -5,6 +5,9 @@ test_description='test push with submodules' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 +export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB + . ./test-lib.sh test_expect_success setup ' diff --git a/t/t5545-push-options.sh b/t/t5545-push-options.sh index 58c7add7ee..214228349a 100755 --- a/t/t5545-push-options.sh +++ b/t/t5545-push-options.sh @@ -5,6 +5,9 @@ test_description='pushing to a repository using push options' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 +export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB + . ./test-lib.sh mk_repo_pair () { From patchwork Tue Sep 28 20:10:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12523785 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98BFEC433EF for ; Tue, 28 Sep 2021 20:11:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 75EF361157 for ; Tue, 28 Sep 2021 20:11:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242603AbhI1UNG (ORCPT ); Tue, 28 Sep 2021 16:13:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242692AbhI1UM6 (ORCPT ); Tue, 28 Sep 2021 16:12:58 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 627CAC061749 for ; Tue, 28 Sep 2021 13:11:18 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id d81-20020a251d54000000b005b55772ca97so140092ybd.19 for ; Tue, 28 Sep 2021 13:11:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=g9NiPhmvd3iIq+aqdMHRHTZSIhgVyvtcXxiZvrp8lD0=; b=EqhPBzQOoCasTBRi5vx1yTt8qP4d3K41vdboHvDyQF50buwPvliWaMnOH6iep/g1Sk gWJLDK3w2LhGOTYeUagi121cYcJVUG6YBBeP3GQiKnQm+luwz4iO2WnouJSddnUDWvQe OVtuAD5iCdvvz9KNwh4X4GYrDYHBlEwA8DNKJuemxW3ogHPma/OJAntGXnGQ8jIdAQtR i7F8FaYn5twoZbgqxOt0NFO9Kam3QImERqmrMtAK327v8XESuQkMBf0iTZq82buDCqPB Hg42f/EGbGBclyCFVTCLARxSXBLT2vv02/9hdKqWbeqoT/jGc47rCMU9SI1wqTj02FbQ gOjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=g9NiPhmvd3iIq+aqdMHRHTZSIhgVyvtcXxiZvrp8lD0=; b=5/ni9lvKMxKiYTfMXWUCK/i30aGfkl/qbYmHLMsd+GS6vqnKtn6YFp91fS85/gwcvl eyaxP2NXn9c8/ev0LKMjURd9zeq/pIWNCTIBETsFqL5L6/3eD+CUD/DRQNTUGZuyi0VG Zut/Em3aTlA8xC+aqBvWwVXMY3kP/hzeiiPuJJ3sCmReTbceY824j/RVHVKLd4mek9R3 zP0RQcrz6/ZWNrJ+vmgIFTWmy3T5K4xoHGAqc5FnugzVARgz/0QdylBY5JHJnqN+9Mxg Qjxukhy3SdT5sg559/QSMinZsW4VJ/PHEKMG+9OP0TzecGxxLePlITIlHYGQg5ZD++zy guJw== X-Gm-Message-State: AOAM532hgBUY7ZZfhlsIfffbGMLWvvHtITbX4GKvymk4gpxm0MITehfy XnJ8ExIZfS2EK/ME8oq1RgrmE5uhsLShXOBlCYls++/o11A2CPgK7aZA6zsP5VzqlZW00w+lziV aPE6IeLv5u4gM1bQjV9lsqYDY7zuPMtAARLpmjOPeX2jryGI6k0NG/2eaxldVzztUkMKkf17BTi NI X-Google-Smtp-Source: ABdhPJxwOm2G+Pp92vkC3rCta3bZWSBe+ObF/iXLxxnazhWhB/hwHAQvpSeUYpm6DgYc/Wa9WYiXQ7FabawVdYkLvfYm X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:a05:6902:72d:: with SMTP id l13mr9661454ybt.168.1632859877588; Tue, 28 Sep 2021 13:11:17 -0700 (PDT) Date: Tue, 28 Sep 2021 13:10:55 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.685.g46640cef36-goog Subject: [PATCH v2 9/9] submodule: trace adding submodule ODB as alternate From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , peff@peff.net, newren@gmail.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Submodule ODBs are never added as alternates during the execution of the test suite, but there may be a rare interaction that the test suite does not have coverage of. Add a trace message when this happens, so that users who trace their commands can notice such occurrences. Signed-off-by: Jonathan Tan --- submodule.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/submodule.c b/submodule.c index 992890321a..188552531b 100644 --- a/submodule.c +++ b/submodule.c @@ -207,6 +207,8 @@ int register_all_submodule_odb_as_alternates(void) add_to_alternates_memory(added_submodule_odb_paths.items[i].string); if (ret) { string_list_clear(&added_submodule_odb_paths, 0); + trace2_data_intmax("submodule", the_repository, + "register_all_submodule_odb_as_alternates/registered", ret); if (git_env_bool("GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB", 0)) BUG("register_all_submodule_odb_as_alternates() called"); }