From patchwork Fri Oct 8 21:08:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12546455 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 AADACC433F5 for ; Fri, 8 Oct 2021 21:08:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8399F60F9E for ; Fri, 8 Oct 2021 21:08:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243374AbhJHVKY (ORCPT ); Fri, 8 Oct 2021 17:10:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243252AbhJHVKX (ORCPT ); Fri, 8 Oct 2021 17:10:23 -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 766D3C061570 for ; Fri, 8 Oct 2021 14:08:27 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id z2-20020a254c02000000b005b68ef4fe24so14221572yba.11 for ; Fri, 08 Oct 2021 14:08:27 -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=wSQ99jjxVl/mNmoRMOWX1gPFUEKmek58/+NZa0+tBoA=; b=GSd3tgmP918RjataDsLREjnTSUl3RrxgJsswfhLaXl3S5iRN8xtCAN3/US5zdz44YR n1wsdO3oEOipsgs0xdc+3O8T+R3dDeQOcpbRUzOufadWPNWHT5TTLXIHLxXgtWY+U0TW 125yduG/Ou7L4b6Wgg5eiQmI00aoXwGhnqzjYLUgr15DvHON246xmwdwwn99hBrg4hRD ZMOwzpL6WCRbFe2foFXXbdBa+cMlH/HF+LKqRoJ2+fk7vtwlVD82gSclOwoFPYFLDZjN W1s2j/5xx0P28Ltf0Hdgxasjv9sJZcNUdTHXCzp1mkyTa+WKOfETUBhUTW4lUTUR5XQE MmFw== 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=wSQ99jjxVl/mNmoRMOWX1gPFUEKmek58/+NZa0+tBoA=; b=E1znGHmvGQk4GZrhadhZZ7BBasHipuTizU8L3aERk/j9oyLmL8Wsu34FKBu0fG+S4P ZKawhJ+OwVMAIb9KdByO4j3aN/bu41BhnxAmINMGHk+0kS6P3Pt88Whury4u9GiBMfOf b8bJJObfQJKx0/PMuDQMo/gLSJ5Z9fu/a/g/wIJQcRbaJdQlGjgzv7QRWd0vcBmJIFpV feK3IaRixFSwJvNlI6rYaIaLtOHdklQ1nybK0o0A3/9Ep/bNyEmlLgBzQcmGHc2ZptcL jN/sbrXwt5UngggxFiQkH8ggKhwNCWySdhmSNRv2O3rvrRGZP4qskCo6MDHHGQEIyxbz C6qg== X-Gm-Message-State: AOAM533GCSpuAYHkoQ+mX5wUa+QJStwv3rJTGbf7vYfldMrFf1dERJOe Y+maYkYv6MkYgFyEhoMhiW+a10Ta50CV9BEsdHapU3IqCNBxuEVj5632i3dMgryEFd+bq/ltMT1 lNynvGUfTYJLeq+dh2SsiifkxYxGI5yw/GvKSXvvFk/EhLu2bS/gDL5Kw8pI3eBsTeDj9ZKuqus vj X-Google-Smtp-Source: ABdhPJxdi/F5oMRzl5R7vcetyDoiWwXc8zTy7W85nvdbTlOHRpAbcV+GxHcSBactrXptDHoaXThz1gRbR7wkY0iMwkZQ X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:a25:47d6:: with SMTP id u205mr5762578yba.193.1633727306589; Fri, 08 Oct 2021 14:08:26 -0700 (PDT) Date: Fri, 8 Oct 2021 14:08:14 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH v4 1/7] refs: plumb repo into ref stores From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , carenas@gmail.com, chooglen@google.com, steadmon@google.com, Junio C Hamano 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 to ref iterators, plumb a repository into all ref stores. There are no changes to program logic. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- refs.c | 29 ++++++++++++++++++++++------- refs/files-backend.c | 6 ++++-- refs/packed-backend.c | 4 +++- refs/packed-backend.h | 4 +++- refs/refs-internal.h | 10 ++++++++-- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/refs.c b/refs.c index 2be0d0f057..9c4e388153 100644 --- a/refs.c +++ b/refs.c @@ -1873,7 +1873,8 @@ static struct ref_store *lookup_ref_store_map(struct hashmap *map, * Create, record, and return a ref_store instance for the specified * gitdir. */ -static struct ref_store *ref_store_init(const char *gitdir, +static struct ref_store *ref_store_init(struct repository *repo, + const char *gitdir, unsigned int flags) { const char *be_name = "files"; @@ -1883,7 +1884,7 @@ static struct ref_store *ref_store_init(const char *gitdir, if (!be) BUG("reference backend %s is unknown", be_name); - refs = be->init(gitdir, flags); + refs = be->init(repo, gitdir, flags); return refs; } @@ -1895,7 +1896,7 @@ struct ref_store *get_main_ref_store(struct repository *r) 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, r->gitdir, REF_STORE_ALL_CAPS); r->refs_private = maybe_debug_wrap_ref_store(r->gitdir, r->refs_private); return r->refs_private; } @@ -1925,6 +1926,7 @@ struct ref_store *get_submodule_ref_store(const char *submodule) struct ref_store *refs; char *to_free = NULL; size_t len; + struct repository *subrepo; if (!submodule) return NULL; @@ -1950,8 +1952,19 @@ struct ref_store *get_submodule_ref_store(const char *submodule) if (submodule_to_gitdir(&submodule_sb, submodule)) goto done; - /* assume that add_submodule_odb() has been called */ - refs = ref_store_init(submodule_sb.buf, + subrepo = xmalloc(sizeof(*subrepo)); + /* + * NEEDSWORK: Make get_submodule_ref_store() work with arbitrary + * superprojects other than the_repository. This probably should be + * done by making it take a struct repository * parameter instead of a + * submodule path. + */ + if (repo_submodule_init(subrepo, the_repository, submodule, + null_oid())) { + free(subrepo); + goto done; + } + refs = ref_store_init(subrepo, submodule_sb.buf, REF_STORE_READ | REF_STORE_ODB); register_ref_store_map(&submodule_ref_stores, "submodule", refs, submodule); @@ -1977,10 +1990,12 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt) return refs; if (wt->id) - refs = ref_store_init(git_common_path("worktrees/%s", wt->id), + refs = ref_store_init(the_repository, + git_common_path("worktrees/%s", wt->id), REF_STORE_ALL_CAPS); else - refs = ref_store_init(get_git_common_dir(), + refs = ref_store_init(the_repository, + get_git_common_dir(), REF_STORE_ALL_CAPS); if (refs) diff --git a/refs/files-backend.c b/refs/files-backend.c index 1148c0cf09..6a481e968f 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -79,13 +79,15 @@ static void clear_loose_ref_cache(struct files_ref_store *refs) * Create a new submodule ref cache and add it to the internal * set of caches. */ -static struct ref_store *files_ref_store_create(const char *gitdir, +static struct ref_store *files_ref_store_create(struct repository *repo, + const char *gitdir, unsigned int flags) { struct files_ref_store *refs = xcalloc(1, sizeof(*refs)); struct ref_store *ref_store = (struct ref_store *)refs; struct strbuf sb = STRBUF_INIT; + ref_store->repo = repo; ref_store->gitdir = xstrdup(gitdir); base_ref_store_init(ref_store, &refs_be_files); refs->store_flags = flags; @@ -93,7 +95,7 @@ static struct ref_store *files_ref_store_create(const char *gitdir, get_common_dir_noenv(&sb, gitdir); refs->gitcommondir = strbuf_detach(&sb, NULL); strbuf_addf(&sb, "%s/packed-refs", refs->gitcommondir); - refs->packed_ref_store = packed_ref_store_create(sb.buf, flags); + refs->packed_ref_store = packed_ref_store_create(repo, sb.buf, flags); strbuf_release(&sb); chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir); diff --git a/refs/packed-backend.c b/refs/packed-backend.c index f8aa97d799..ea3493b24e 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -193,13 +193,15 @@ static int release_snapshot(struct snapshot *snapshot) } } -struct ref_store *packed_ref_store_create(const char *path, +struct ref_store *packed_ref_store_create(struct repository *repo, + const char *path, unsigned int store_flags) { struct packed_ref_store *refs = xcalloc(1, sizeof(*refs)); struct ref_store *ref_store = (struct ref_store *)refs; base_ref_store_init(ref_store, &refs_be_packed); + ref_store->repo = repo; ref_store->gitdir = xstrdup(path); refs->store_flags = store_flags; diff --git a/refs/packed-backend.h b/refs/packed-backend.h index a01a0aff9c..f61a73ec25 100644 --- a/refs/packed-backend.h +++ b/refs/packed-backend.h @@ -1,6 +1,7 @@ #ifndef REFS_PACKED_BACKEND_H #define REFS_PACKED_BACKEND_H +struct repository; struct ref_transaction; /* @@ -12,7 +13,8 @@ struct ref_transaction; * even among packed refs. */ -struct ref_store *packed_ref_store_create(const char *path, +struct ref_store *packed_ref_store_create(struct repository *repo, + const char *path, unsigned int store_flags); /* diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 96911fb26e..d28440c9cc 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -539,7 +539,8 @@ struct ref_store; * should call base_ref_store_init() to initialize the shared part of * the ref_store and to record the ref_store for later lookup. */ -typedef struct ref_store *ref_store_init_fn(const char *gitdir, +typedef struct ref_store *ref_store_init_fn(struct repository *repo, + const char *gitdir, unsigned int flags); typedef int ref_init_db_fn(struct ref_store *refs, struct strbuf *err); @@ -697,7 +698,12 @@ struct ref_store { /* The backend describing this ref_store's storage scheme: */ const struct ref_storage_be *be; - /* The gitdir that this ref_store applies to: */ + struct repository *repo; + + /* + * The gitdir that this ref_store applies to. Note that this is not + * necessarily repo->gitdir if the repo has multiple worktrees. + */ char *gitdir; }; From patchwork Fri Oct 8 21:08:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12546457 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 C8725C433F5 for ; Fri, 8 Oct 2021 21:08:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A856160F9E for ; Fri, 8 Oct 2021 21:08:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243391AbhJHVK1 (ORCPT ); Fri, 8 Oct 2021 17:10:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243252AbhJHVKY (ORCPT ); Fri, 8 Oct 2021 17:10:24 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF3FCC061570 for ; Fri, 8 Oct 2021 14:08:28 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 15-20020a630d4f000000b00287c5b3f77bso2257750pgn.11 for ; Fri, 08 Oct 2021 14:08:28 -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=fu8w6CAhroCUMXcDEpc3UT4XMkPw+h1Y0PFI8YGUXWU=; b=FyhYRYek9pVerLdbVok/Mc7e/Yk4XMl2xkUqx2soT9cgp221+y3tAPwQi0YaCIKNwx c4l+DkH7akxcClV+hkI2VmPRsKGnF8WNpfzyC6foh8aez6E9mBMLndY8wOmrVgP+nHUz egOMP+tlqVx0b53Knv61AI1sRbtCvAYPPpcdT6AjRuz7GR8kieHVNLtF8Z9LJjtpyndy X8efLWmXo8b/IeFmDxgdHsQhRWJEvGqhu7g2vT9gvZpYYa0PAWXMeJCCKeSE8z4Juf4t k88a4ufFd5r+vFWHn1LPM5v8ccEiEEHSANAaCFSujTtOH8AjhJ+I+CxS1g+s8DsZLYUJ b5eA== 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=fu8w6CAhroCUMXcDEpc3UT4XMkPw+h1Y0PFI8YGUXWU=; b=L7XEsFWPmkAJxB4cr994++kcsGzGcAmR/AZgad2QMpwbK7eCxq7w4cUnbTjELPotbU 7qYgGP0nrqazckjgH/zJF820m0LPlb57zbNLzK6EyNrvfDfiihNUqrm4tGoU5RCwok6R T2sh09sxj0In476LiGFW8xLwXrOi+h3duyAII2DCvFM8vkT8N0Jvlqoidm1KelOJSprL qL27SMga9QUaYJ47e+t3KN+2t8bJCpixf3M6DJ8waS8ImdlQBcBjJd47Bh6yqYjvy2ue JmcKCjvh3QRaQOGT9TmdIMHFC/rocudlClcM4LIVVBRCR9JVnLkOnFTM5Q0uv0z7WVIF VH6g== X-Gm-Message-State: AOAM533pLrre03hezmpVXufR16ukJ7LwN493aHJcuFC6uKrJOzi4GVMZ MV41fhFhZ+9jcNCtHmxaWTCowOl9fBJ4LUu+sAWnCS5JqV1ZHLnq3Kz6K9UiituwbJSPVMph8AA zCDU0//6xkygxetBsZm21LWoYkQIsTEDdWefw3M6k246e8q6DdF2DBem2LvAXzBh7gjnbnbissk vz X-Google-Smtp-Source: ABdhPJyLbR1KrhHyGGCkDi9Os3QTvL7UDS09I//LwKB3dGikT8F3VVeIwyCo476wFQ2vE57/5ephqnlequn+IRhf1nXX X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:a17:902:654d:b0:13e:a097:208e with SMTP id d13-20020a170902654d00b0013ea097208emr11575763pln.31.1633727308195; Fri, 08 Oct 2021 14:08:28 -0700 (PDT) Date: Fri, 8 Oct 2021 14:08:15 -0700 In-Reply-To: Message-Id: <64182569199f89642051fd7b5a2e756d0e082ff7.1633727270.git.jonathantanmy@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH v4 2/7] refs: teach arbitrary repo support to iterators From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , carenas@gmail.com, chooglen@google.com, steadmon@google.com, Junio C Hamano 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 Signed-off-by: Junio C Hamano --- 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 9c4e388153..c07aeff6f4 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 6a481e968f..3f213d24b0 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -732,6 +732,7 @@ struct files_ref_iterator { struct ref_iterator base; struct ref_iterator *iter0; + struct repository *repo; unsigned int flags; }; @@ -753,6 +754,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; @@ -855,6 +857,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 = ref_store->repo; iter->flags = flags; return ref_iterator; @@ -1139,7 +1142,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 ea3493b24e..63f78bbaea 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -778,6 +778,7 @@ struct packed_ref_iterator { struct object_id oid, peeled; struct strbuf refname_buf; + struct repository *repo; unsigned int flags; }; @@ -866,8 +867,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; @@ -956,6 +957,7 @@ static struct ref_iterator *packed_ref_iterator_begin( iter->base.oid = &iter->oid; + iter->repo = ref_store->repo; iter->flags = flags; if (prefix && *prefix) diff --git a/refs/refs-internal.h b/refs/refs-internal.h index d28440c9cc..500d77864d 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 Fri Oct 8 21:08:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12546459 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 A10B6C433EF for ; Fri, 8 Oct 2021 21:08:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8600060F9E for ; Fri, 8 Oct 2021 21:08:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243394AbhJHVK2 (ORCPT ); Fri, 8 Oct 2021 17:10:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243387AbhJHVKZ (ORCPT ); Fri, 8 Oct 2021 17:10:25 -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 49052C061570 for ; Fri, 8 Oct 2021 14:08:30 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id c2-20020a63d5020000b029023ae853b72cso2243766pgg.18 for ; Fri, 08 Oct 2021 14:08:30 -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=Ok1Nf2VKN1RPSMBn6FVTM8yVEK3rvC5LKnZeXent7sE=; b=EdVfjl+4e2jq+gMWH+62dPvl+lK30Wv4o1vzHIkhPadU1yh8UP21bemeLeFQZuSXKD ihfD4Ozt58LFmfXgybysNrQLKe9t0BoKZiKXPc1+wnUiLwaecQpHjBcDEX2Mh6l+MhZy P2FX/zhjNYHQPyd+y+nWLIpaqi6kwQgukQTTZtXztk0+o/I2Cr3Gkc919zP7DauPwCsx Oe3FmGEairM72bUWq/8b/4B2xfMPwV46RN9g00/PbHCF+Ee4NY6tRiPPCibJ36G8WCzj Lr0ZSoDsfSTPpuh8iMRoRoNZioL+QwK6jtbckk+HSLOuFbxFeeyAw/5LS5vF7AC/j16x j8Lw== 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=Ok1Nf2VKN1RPSMBn6FVTM8yVEK3rvC5LKnZeXent7sE=; b=gCpGgJYo0ik6LF6sl5K6UaTLciqy34uoFWX8DxGwrueDA14TNhue1dPU6mAU6f3Vd5 XvOhf9IKFJGrsQsVtt7rDZelFvyPjeV5kE7YjZN+tXASelxBTHKz6Pr3vk0Iyh2tBIYA YkBcwrRtKTWX3xsJp003lhuspp1L8DGGWYd6P1mu9ZF4DG9NoXzr3nDbiLwDVA8gKbmn 3hZNBIwnEbrG4TUfn+f2S2gtsxGNIK8lQl2z+qrMTtx8ymS6rNQ31TrYM8jJXY87Ihzp vbQtxbHr9b0z6cOpC6CX0P18XW6mtmXgBK6l7MjG4S6ETy9DlMBl+hsiKvLRSHDwWJkv jxEg== X-Gm-Message-State: AOAM531F7Y1I4Z0Z+Y1ahW/GeOsNv2Tbs/goc/Ak8YHLmeKuc9mwB0Ni dfdMjRZfCWbWrNDtd7UFkgYWeSZDN2S32IDCvwFBDS0pMmQc9F73fPFfKV1oKh45LAKJNaTyYBw qrX933XgsbLQuiK6Ll5gjrS3pa2hL47d/GSLCC3iIgJeqnjPUxDisniWbc+nM8D1KKbn0H6JaXR rw X-Google-Smtp-Source: ABdhPJwG0dUNkeXSnGHK7VcNdggtc/c79QGOmXNhgDQ82exBbvI/UdPRlOxxMRFl4/+E01R7x3VjsyyghiATPZj2hMe2 X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:a17:902:708b:b0:13e:1a20:f1b0 with SMTP id z11-20020a170902708b00b0013e1a20f1b0mr11497221plk.51.1633727309707; Fri, 08 Oct 2021 14:08:29 -0700 (PDT) Date: Fri, 8 Oct 2021 14:08:16 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH v4 3/7] refs: peeling non-the_repository iterators is BUG From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , carenas@gmail.com, chooglen@google.com, steadmon@google.com, Junio C Hamano 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 Signed-off-by: Junio C Hamano --- 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 3f213d24b0..8ee6ac2103 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -833,7 +833,7 @@ static struct ref_iterator *files_ref_iterator_begin( */ loose_iter = cache_ref_iterator_begin(get_loose_ref_cache(refs), - prefix, 1); + prefix, ref_store->repo, 1); /* * The packed-refs file might contain broken references, for @@ -1165,7 +1165,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 63f78bbaea..2161218719 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -886,6 +886,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 Fri Oct 8 21:08:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12546461 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 78CEEC4332F for ; Fri, 8 Oct 2021 21:08:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B99E60F9E for ; Fri, 8 Oct 2021 21:08:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243400AbhJHVK3 (ORCPT ); Fri, 8 Oct 2021 17:10:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243392AbhJHVK1 (ORCPT ); Fri, 8 Oct 2021 17:10:27 -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 2873EC061762 for ; Fri, 8 Oct 2021 14:08:32 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 15-20020a630d4f000000b00287c5b3f77bso2257795pgn.11 for ; Fri, 08 Oct 2021 14:08:32 -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=bNnNZe8DvIbePyYjKDiiPKA4oTAH7gMmrR6jn+/5hWc=; b=K7SAxQZ/ZlSUJrZfcX8a0wRBKHHQL+DFKSMXmpo0ECZI+qMRHgUBCBrQzpfME16Ssv eU5N+TDgdcPs+JgNB6pgvpQJqODIbjMtjF9cjRvZk9jGcc9qNMWFqNyYGRbtO17+JbEq IcIByheAC+RkLu98cL/fR5V/JVVNzPlxYUhY4jF+1UDNORlccn3s/HqkyGKnS519tEO4 gxsybXbxrYOpZwcaQADxDZnIcKS/ZNgiU5iFxUvtGfaLiUxu8v8X8Xda8ao2TDvnwoCI l8bWj56zZq+kAKZnAklmOuIfo86iRBl9yWhPqmOneQ/GyONXNWpr9uxTzjA4nA2xDnSR iWoA== 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=bNnNZe8DvIbePyYjKDiiPKA4oTAH7gMmrR6jn+/5hWc=; b=Q6bihFa8AgkwfYpoK7Z6BuyFodlT9VKcbt2kWwEZ+1WL4xoBUDmfxhVxE872OlbskW 1t5FrtHjh96cAcHMb7PW1naApWTzfLfxYx0yVVMudFmeWUL06FUBDmUVhKbjponTeKoh fLw+dQ+lzT5JZIn9RbBQPSYLt34jkkBeLfJicA4wqH9IMEswFQg7EW4MMo0lEZfMxtmz 37b87JR9rzPk2/GcoJUnwnMcOpd5fUm1eeNWyHulf0t9DFMYbM6+On4Gb/NHDATEK+qm x+oVQ3MfEHzv8Pec2YSJlA++4QMz7jHA2qcPbBnd+Y5rBPs58XdkDQ10pewIZconOdS1 tBrA== X-Gm-Message-State: AOAM531ARfiYlH6G8JkP0C2I1HgELFln4aW0D4TSAO+vJ+KGYdB0L0b8 jMt7k/2nCGuk4T+iaIlZA/N5bvjrQ7pzL4RN9li+8nmKtP2dxXWP/84JCs231Ar9amF8uD9G7Oo aRKlrgjHOfQtxlZcZfTAP7cqyivROesCXI4L51Idzl+cJgkUJIpUVbACIRigx7EZe8NKVGhwWeO zi X-Google-Smtp-Source: ABdhPJzARcsVxG0DtMjApI4aStO+UjyA0XzTaZEAzAn8wylpeC9f/YzB3fgizvAmClEDX0vvXP7KwAZ80FaYpgJ87jB3 X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:a17:90a:8b8d:: with SMTP id z13mr591497pjn.0.1633727311187; Fri, 08 Oct 2021 14:08:31 -0700 (PDT) Date: Fri, 8 Oct 2021 14:08:17 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH v4 4/7] merge-{ort,recursive}: remove add_submodule_odb() From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , carenas@gmail.com, chooglen@google.com, steadmon@google.com, Junio C Hamano 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 Signed-off-by: Junio C Hamano --- 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 Fri Oct 8 21:08:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12546463 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 C66DDC433EF for ; Fri, 8 Oct 2021 21:08:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AABA860F5E for ; Fri, 8 Oct 2021 21:08:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243409AbhJHVKa (ORCPT ); Fri, 8 Oct 2021 17:10:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243398AbhJHVK3 (ORCPT ); Fri, 8 Oct 2021 17:10:29 -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 7A705C061570 for ; Fri, 8 Oct 2021 14:08:33 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id 2-20020aa79102000000b0044c216dd8ecso4975943pfh.18 for ; Fri, 08 Oct 2021 14:08:33 -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=2Bg6Smsefxe/mCrHnotq+16z95fJQIxNbww+rLENA70=; b=CjfVElZadedZDmGcB7HqNIInwVLLG67NWjR7oc6pSub1arAxWs1/hplk77GP1tKxnV XFFKRwvhqWB0/dHTos+Frm7c/xO55j2bmPFmhTwTWSmAH3/ODn4nek1tMn/trRsifop7 MMeympt0BIer7RjHTB9b4vd1B+E72ubs52c2WfOKtTaqxEOyIQjGPXG3MtBR4bI1FISk RBJOZtlDqw+1C57xHal4595+kkRXqsFLH1gclbakDvA6CQ02+enaizFeLa5ptBsVsSCY uBi0Npbn9mSPdrcMLEHO6/xeiIny7+nD0/Efw3bQFeYbtvsryw8XIM5+sEj7ARnoTJ3l HSOw== 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=2Bg6Smsefxe/mCrHnotq+16z95fJQIxNbww+rLENA70=; b=3dtjU9FCG7NcYTqG3Cs6Muk09DHvMJHlomplJdAesliED70tYc6Bi6ZGo+Z+D53Kzg DqykWDEq9uHy/d67jJCyHHeSKFFaEyLAmsSqk9f9oMhqvScroIyglAYbgQPrTXggICTy fmfkANaDTC7xEOm6sGtuREKW96cAZDIdvHAORlC04jCh1eUBAlW4KTyOAjniWH+JQ2T6 pmktptjH4p9dHHGhj6yktnHyqGH3U5W8rgJlSAvDicp5RH/CoxtzdDZi6fB9Ekd8lUAT pFOYHow236dx4Y3h/Bj8g/PQftJUaXVzGlf3kZ9mkrTQm76n+9dyMwU18Mvftconhbmr vPFg== X-Gm-Message-State: AOAM532wu4nUHiXA+K0EAoBYFvqOOe+0kS8kHod6mTFBi/eEARbrv07u Ljhr8d/l83nbLhdtrmdo0g+73TSWjf3h7jcN97jFJiatJZRfG0KZpTLLCy/bZ/SKvdO/VSYkV1A Bj0z/eZXLArOhom9acPlR30GIQMLRT4S+DgbIcxa5sdBY0e7/OwJciMcXM/IF+nRxNOcecATscE vL X-Google-Smtp-Source: ABdhPJxgnSEHF4QfWQWANLvLG0+He0Z6pzB7Poy324Wp40hlrZq41pYcLM6aeKiI7T7m7g68zch8fJPYMIuwAZ4BEy76 X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:a17:902:8ec5:b0:13a:2789:cbb0 with SMTP id x5-20020a1709028ec500b0013a2789cbb0mr11473586plo.60.1633727312880; Fri, 08 Oct 2021 14:08:32 -0700 (PDT) Date: Fri, 8 Oct 2021 14:08:18 -0700 In-Reply-To: Message-Id: <78473b0f892da8f69b334e88208321b277c33c3c.1633727270.git.jonathantanmy@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH v4 5/7] object-file: only register submodule ODB if needed From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , carenas@gmail.com, chooglen@google.com, steadmon@google.com, Junio C Hamano 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 Signed-off-by: Junio C Hamano --- object-file.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/object-file.c b/object-file.c index be4f94ecf3..0a1835fe30 100644 --- a/object-file.c +++ b/object-file.c @@ -1614,7 +1614,14 @@ static int do_oid_object_info_extended(struct repository *r, break; } - if (register_all_submodule_odb_as_alternates()) + /* + * If r is the_repository, this might be an attempt at + * accessing a submodule object as if it were in the_repository + * (having called add_submodule_odb() on that submodule's ODB). + * If any such ODBs exist, register them and try again. + */ + if (r == the_repository && + register_all_submodule_odb_as_alternates()) /* We added some alternates; retry */ continue; From patchwork Fri Oct 8 21:08:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12546465 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 91C4BC433EF for ; Fri, 8 Oct 2021 21:08:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 769C960F5E for ; Fri, 8 Oct 2021 21:08:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243417AbhJHVKc (ORCPT ); Fri, 8 Oct 2021 17:10:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243392AbhJHVKb (ORCPT ); Fri, 8 Oct 2021 17:10:31 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36A9AC061570 for ; Fri, 8 Oct 2021 14:08:35 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id q7-20020a170902edc700b0013f15c17dd0so1726361plk.23 for ; Fri, 08 Oct 2021 14:08:35 -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=5OOpp9SlmF7Gf3zVAe4BgqXPK4NbP23bfkkhNrj9N1A=; b=C8OHummbJM67YL0Xrr+9jLvL/IlIPjcPSJUCePbj4suDunjV0nXlz2iyWs9Q9XEEk6 L+9piimCm/ck5pS0LNzkUATxQuyScKQxMwgwTi+WXOCFmovxOO91mh7X9QKz9pGryAmT LVAUheLik5YdcVLw5XiQK6S4NZ4DDvj37JkCWisgdr3ILtVftMIFsrcCn+o15icAplKF oHn0cut7toYJVhzu+E3JF/BjLVTfDK2jV34bvxDA34HlsoVRDV0UwBmpe2B9dPJSc7fC tC+QhNHXdGoMXPVglhFLei/vbYKUCM9KhSLIe7kiYQSjXN8L7VV52LXmnpI2sL+g1v8z 3QiA== 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=5OOpp9SlmF7Gf3zVAe4BgqXPK4NbP23bfkkhNrj9N1A=; b=pAhbjbNLHXT4EpMdSp2RHGjwyVO+wD2HS8dE0sTNqW9PoPOyGzG6cwibWE0tQoiEKm L6bnDXiOtW6ZGimaoq4xf8HgGsXxrnAdcYYIGFfU7OJYfd5pQw7ewoXh+tRH1iQvsdA+ gRd3t8+iCqtPI4kMjVwf4xpT0nrtYRdVP5AGr0vmFA1INnEWnYPap+SgDo51AI/98LL0 IU8LMU/HcQGCYwADqGodwDERDS+obnBwCxtWPiyIyCVyZ444Lpup2oBAKaCTdso0nrFC 42XHHOgJmWSd65v57NObuYhQgzhjO1MfpMAoyS0jC8JNBciLsLZ/sX1aW/q9Ez5ffU1v l8Rw== X-Gm-Message-State: AOAM5303UDQisQOwMbPMRfEjwr4g00QWdaOXZDvX5KTWabcIAkMnuJCi JLaSuOztay00oapjWu35Uh0FfWI1rIjdn0vvYvzOHsOnKgxmJPFLeJKIqDp3L796qAzRMRk/Lsl 1kKmALEWacCnwaZ7jsGsP9gWK1GXqZiK1uMD1AZtveymwRJzYK+eIDr/kNkKG5FZryoYPsVgUoM s4 X-Google-Smtp-Source: ABdhPJxbcuwiF34zqACHVes91gNND0tR0iu0rG7/Lgy/At2fgGb1/qjs23Pcve5JIh9KPcOrIYcax+Q+KnaQGtleq6WL X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:aa7:8891:0:b0:44c:255d:391f with SMTP id z17-20020aa78891000000b0044c255d391fmr12700229pfe.26.1633727314596; Fri, 08 Oct 2021 14:08:34 -0700 (PDT) Date: Fri, 8 Oct 2021 14:08:19 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH v4 6/7] submodule: pass repo to check_has_commit() From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , carenas@gmail.com, chooglen@google.com, steadmon@google.com, Junio C Hamano 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, the last remaining tests no longer rely on add_submodule_odb(), so mark these tests accordingly. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- submodule.c | 16 +++++++++++++--- t/t5526-fetch-submodules.sh | 3 +++ t/t5531-deep-submodule-push.sh | 3 +++ t/t5545-push-options.sh | 3 +++ t/t5572-pull-submodule.sh | 3 +++ t/t7418-submodule-sparse-gitmodules.sh | 3 +++ 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/submodule.c b/submodule.c index 62beb8fd5f..4bf552b0e5 100644 --- a/submodule.c +++ b/submodule.c @@ -928,23 +928,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/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 () { 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 Fri Oct 8 21:08:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Tan X-Patchwork-Id: 12546467 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 08377C433F5 for ; Fri, 8 Oct 2021 21:08:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DBD4F60F9D for ; Fri, 8 Oct 2021 21:08:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243392AbhJHVKe (ORCPT ); Fri, 8 Oct 2021 17:10:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243398AbhJHVKc (ORCPT ); Fri, 8 Oct 2021 17:10:32 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A83D8C061570 for ; Fri, 8 Oct 2021 14:08:36 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id n7-20020a17090aab8700b0019fb1ee78e3so6331320pjq.6 for ; Fri, 08 Oct 2021 14:08:36 -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=mKIEFC+0c8za1wT1qlFOq/rs+zQroefTv/ez3t5+n5g=; b=j9kkpFaMXgD8apyO6BwkCI2t5RkLufIXUzElh7PBUXGhSn3QAgRYLV/magbzo7374d FxqwW0+WUsFZSqW7b2lVVZiwS4mhc8u3nlNL5mshZm8/gpnsvfHdcHKVby+sgrzxa3SQ gKPFiLomK2xvwl5HpNDVE5Q6Gl7CPYkvKA/GMsRu3PpyWNClMD6LjIEpec47iJjGHfeZ p4cCVNAk0b0G+JBdI9V+ZT8MxRfCKj/ivIVJv+tAnEV4tpHR/qwryXBb8Zi8GcQDqd4M ySlEQ9y2DdlNSCI1lTYPmELkq9bmoTG3PxeWcTxvOyy+s0z7ySr8hrwX+NNFbITPMbfa qYHA== 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=mKIEFC+0c8za1wT1qlFOq/rs+zQroefTv/ez3t5+n5g=; b=rzVNUCtK4Aoh41no7pU1y8DKShqgTYbSQZXReBpKuosk9WMOSYJJFg69bHzSVjWQDX NxaU/SVXYJqf69GzpRD2RzYVRbF1eW9h7J5xKynD3GlGSsfh3POx8QBqTgEUnBTbCYdi gfvT/koNqZ6TL21p8/9lTkeK6wR4aq9KK5o7M+xeEGEwIEKdj1ghjZmI3FZiHs9QX7Ci rkQNY64OLBhK6tJV5k4X7hIb894C5aPhlwM9bmsTU07toKNpVAjIQmf8qSRTZZnGTqT8 JJTykS3O4VUa2n84YZOi9nW2OQC9LmWER/acd6urZq8g+5Brb8N1+HSF70RTY6Vi5JNY 04OQ== X-Gm-Message-State: AOAM532Yqv/pc2h8QRIjO5x5R2Csj68XBIH1pqYX4i8OHoLWyMh40b8c Bg8xCwtWozpTUlMmI2Up9CwUtgdy9hF3YgV5mFv4yOaDqFpu4ilawB/iXOhwp7rcdsFYmJNnZmz LLbn4SNPs3yyJFEoB7hM9t29v7dtrr+UzPKj8PCDl6372yDoWFBqfyMzHocYyRz/qRmfIFlxJr/ DA X-Google-Smtp-Source: ABdhPJxDXlVuqTCedQFmpMdPU7D5FPS+1Wsjv7oo9glRQFRQPwl+FQ1CuTEIWbg0Zilo1Udrt5f35VgdPhNfQgQO+ZTy X-Received: from twelve4.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:437a]) (user=jonathantanmy job=sendgmr) by 2002:a05:6a00:1585:b0:44c:ea04:26d4 with SMTP id u5-20020a056a00158500b0044cea0426d4mr2494189pfk.31.1633727315906; Fri, 08 Oct 2021 14:08:35 -0700 (PDT) Date: Fri, 8 Oct 2021 14:08:20 -0700 In-Reply-To: Message-Id: <8922bf48a2fcecfba0030c66f5ea7204b2600181.1633727270.git.jonathantanmy@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH v4 7/7] submodule: trace adding submodule ODB as alternate From: Jonathan Tan To: git@vger.kernel.org Cc: Jonathan Tan , carenas@gmail.com, chooglen@google.com, steadmon@google.com, Junio C Hamano 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 Signed-off-by: Junio C Hamano --- submodule.c | 2 ++ t/README | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/submodule.c b/submodule.c index 4bf552b0e5..61575e5a56 100644 --- a/submodule.c +++ b/submodule.c @@ -201,6 +201,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"); } diff --git a/t/README b/t/README index 51065d0800..b677caaf68 100644 --- a/t/README +++ b/t/README @@ -456,11 +456,8 @@ GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=, when true, makes registering submodule ODBs as alternates a fatal action. Support for this environment variable can be removed once the migration to explicitly providing repositories when accessing submodule objects is -complete (in which case we might want to replace this with a trace2 -call so that users can make it visible if accessing submodule objects -without an explicit repository still happens) or needs to be abandoned -for whatever reason (in which case the migrated codepaths still retain -their performance benefits). +complete or needs to be abandoned for whatever reason (in which case the +migrated codepaths still retain their performance benefits). Naming Tests ------------