From patchwork Wed Dec 22 18:11:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12697120 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B51FEC433EF for ; Wed, 22 Dec 2021 18:12:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344529AbhLVSMA (ORCPT ); Wed, 22 Dec 2021 13:12:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231340AbhLVSL6 (ORCPT ); Wed, 22 Dec 2021 13:11:58 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B925DC061574 for ; Wed, 22 Dec 2021 10:11:57 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id c66so2141370wma.5 for ; Wed, 22 Dec 2021 10:11:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=NLNhtxkS7saYPa+ywEVQBzDkS2rCVcTTPKK1xJSF998=; b=OmLS3/+JdVr+bQb+Kh+QJY2MyisfnDthOOw3+EIU7Odn+jejEtrNZAf6PMRH9Jxdxx ZichAZ/w8D+H7gs27KBptoCF1iL/gkyjPjtdcG/eIBW17MWatf2x9Lx/kOdF6ycglmlU 0BYI6Cs++IHN5VShRXmT6wh8BbZgDHf7NvNJPDIqTCb6e++eyQdEkZ3hoVhnkE0EE5uQ 22feDv5Uoa/4zV2Nw1NqFmtezkQyvm/G7Mph6cbODZtsyro+xYYEKbp1PPp7zOUhfGj+ ARVsYpZEQpoFLhVhbwLw7IXHrFrCDYhr5kCTZzEqy4JCoxbdLP/SxHPz2H9WWibSqm5y m7ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=NLNhtxkS7saYPa+ywEVQBzDkS2rCVcTTPKK1xJSF998=; b=TTFf/O3MlhZSZgUZdXh4ZfQdtXgQ5Bzw8a1Fp69Pmxp9hPJAbl7vGEhR2qfgwSn+1F 9YyPHWfgEkainDipMGrxtJ4fbwj3N7uzWtLwsxO4OJnrwEITppx7Vi6Rth0kxpEu9VFy i0+ftwOydx4G4W0YMJdHHCKUP4c1/ijRJPCLL9E6Ns4ZFm+aw3FRsTb4yu1MexqoIifv xowLhuNoZzkOIYn0tbDJBMDrPSztXrq2u4Wjptg63eOFnJnPTxbFrxbmqxXDQz5zwwiZ ahqLrcwRSJo/2l4M+Z0evhtVRvncZk2PFYxLIvKKfdqY8ejPnTE3ETy088qL5ZnW+UEr 22Jw== X-Gm-Message-State: AOAM531EV1Kfrz+UltxTL1HdfXJ5oFzgrnKcXlH2BgWtjP9d09OAazjX 1vLbLfwrW09QZ2QiGzrhykwQ00Ks+Bc= X-Google-Smtp-Source: ABdhPJwjTqf5/sHEn6TCgxFgjx1olRbMvuOw05Sv9IVnqE9crU3yVA7w0npPug7dTL6V4lT9a7aClg== X-Received: by 2002:a1c:1f93:: with SMTP id f141mr1749326wmf.56.1640196716192; Wed, 22 Dec 2021 10:11:56 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m1sm2316105wme.39.2021.12.22.10.11.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Dec 2021 10:11:55 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 22 Dec 2021 18:11:52 +0000 Subject: [PATCH v2 1/3] refs: pass gitdir to packed_ref_store_create Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys This is consistent with the calling convention for ref backend creation, and avoids storing ".git/packed-refs" (the name of a regular file) in a variable called ref_store::gitdir. Signed-off-by: Han-Wen Nienhuys --- refs/files-backend.c | 5 ++--- refs/packed-backend.c | 9 +++++---- refs/packed-backend.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 90b671025a7..f1b66130dfb 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -93,9 +93,8 @@ static struct ref_store *files_ref_store_create(struct repository *repo, 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(repo, sb.buf, flags); - strbuf_release(&sb); + refs->packed_ref_store = + packed_ref_store_create(repo, refs->gitcommondir, flags); chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir); chdir_notify_reparent("files-backend $GIT_COMMONDIR", diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 67152c664e2..caa1957252a 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -194,20 +194,21 @@ static int release_snapshot(struct snapshot *snapshot) } struct ref_store *packed_ref_store_create(struct repository *repo, - const char *path, + const char *gitdir, unsigned int store_flags) { struct packed_ref_store *refs = xcalloc(1, sizeof(*refs)); struct ref_store *ref_store = (struct ref_store *)refs; + struct strbuf sb = STRBUF_INIT; base_ref_store_init(ref_store, &refs_be_packed); ref_store->repo = repo; - ref_store->gitdir = xstrdup(path); + ref_store->gitdir = xstrdup(gitdir); refs->store_flags = store_flags; + strbuf_addf(&sb, "%s/packed-refs", gitdir); + refs->path = strbuf_detach(&sb, NULL); - refs->path = xstrdup(path); chdir_notify_reparent("packed-refs", &refs->path); - return ref_store; } diff --git a/refs/packed-backend.h b/refs/packed-backend.h index f61a73ec25b..9dd8a344c34 100644 --- a/refs/packed-backend.h +++ b/refs/packed-backend.h @@ -14,7 +14,7 @@ struct ref_transaction; */ struct ref_store *packed_ref_store_create(struct repository *repo, - const char *path, + const char *gitdir, unsigned int store_flags); /* From patchwork Wed Dec 22 18:11:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12697121 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 293B4C433FE for ; Wed, 22 Dec 2021 18:12:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344536AbhLVSMD (ORCPT ); Wed, 22 Dec 2021 13:12:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344523AbhLVSL6 (ORCPT ); Wed, 22 Dec 2021 13:11:58 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B503C061574 for ; Wed, 22 Dec 2021 10:11:58 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id g132so2156722wmg.2 for ; Wed, 22 Dec 2021 10:11:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=77ZwXy3rQHnaJX6J6R2oYsiyoRUtAOTsz+aMmsE4hCE=; b=MoywKVuaC6+U1QrHFG1fpUCUNSjAF2EU00eQkjSKHmlQT+XvTySUvMBvqXGPJkogBS Wo+ngCL7hQoA8OxPGKD0MnTBOv+tf35VRIctxL7NzSMT2gOTf/KY9mgS5bfYmEoatX9Z by3Hh2+Q+nqhFP+gl+hTC7eByrjBf7YowDCcag6+gzISCSyAChpT+WA9fbd05xycZD2F 1jwm3S9eujqcceXAlHtc24q8GonZ7E4d1mJRXLgsg9rRJdmcTxwSbvaSr1kzmF3sjVse zWWxhBX/0vksnsn2Ahj5XOvv002144sP0QsmF7EwexPQHRDxPjiQY/B+nug2yj9pd9Bg E4+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=77ZwXy3rQHnaJX6J6R2oYsiyoRUtAOTsz+aMmsE4hCE=; b=Iu6nwop4NVX2tsAajyU4DwJUQELBgReZtVtOSGxxvMUXwDH7DeBFcpQmQ0SBUlkdpQ 9sjezlDTbFTpkenS7liKltoktfjNjrdIc4lqDQ4U6pP6P/ldX+X3klweo1i/jVRNr1+D 4fj0XjRLYVfaNagX+ym/8me4g8HCJEbVevFadVt+s6Ka5lbtDc4ts/0b9huu1CvDm+Tb EAl//tHQ8KoPfEB/79x9TyXaYr6qp4m0GjAyur8n1gQLJeUMwkgICUhrLju7Fkx1PqQR WeVCKS1G7WFm4gVLpW7RGlc8fb7JHqTv7e0UzaYDLdKrpzJ53/dGIa5x/SGXbGKjadkb 0F4g== X-Gm-Message-State: AOAM533rEfPPqUsaRDUYeWzduiku8wkso94seyAi2QIk9vZRqB0Tpzv6 026e3oGdMn00LINPHiCZRcIZjcPsGIY= X-Google-Smtp-Source: ABdhPJymwTJIUfZ1E48q2+LTBhGWZyJ2SptO2KuCreok2C1Cv6fLLPS8cKGHxyl+1gVawmQHmbXWOA== X-Received: by 2002:a1c:f217:: with SMTP id s23mr1722360wmc.70.1640196716808; Wed, 22 Dec 2021 10:11:56 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p5sm2573144wrd.13.2021.12.22.10.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Dec 2021 10:11:56 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 22 Dec 2021 18:11:53 +0000 Subject: [PATCH v2 2/3] refs: print error message in debug output Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys Signed-off-by: Han-Wen Nienhuys --- refs/debug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/refs/debug.c b/refs/debug.c index 791423c6a7d..8a6bb157ee6 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -47,7 +47,8 @@ static int debug_transaction_prepare(struct ref_store *refs, transaction->ref_store = drefs->refs; res = drefs->refs->be->transaction_prepare(drefs->refs, transaction, err); - trace_printf_key(&trace_refs, "transaction_prepare: %d\n", res); + trace_printf_key(&trace_refs, "transaction_prepare: %d \"%s\"\n", res, + err->buf); return res; } From patchwork Wed Dec 22 18:11:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han-Wen Nienhuys X-Patchwork-Id: 12697122 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BC8DC433EF for ; Wed, 22 Dec 2021 18:12:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344537AbhLVSME (ORCPT ); Wed, 22 Dec 2021 13:12:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344524AbhLVSL7 (ORCPT ); Wed, 22 Dec 2021 13:11:59 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14D25C06173F for ; Wed, 22 Dec 2021 10:11:59 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id g191-20020a1c9dc8000000b0032fbf912885so1956716wme.4 for ; Wed, 22 Dec 2021 10:11:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=qgI6TbDXAZM6wFatIsEGgk9qsgud0pAZlI0mLqvy4xQ=; b=eD+EJt151JixLqT9wxWxBA2wjAL1MwQ84bAmgx8TVKKQR5vbrmNuAAxfThvamfP1b9 PHFcrXJ7dZ64OmocNPNVfXlib96NezlK2GRr/31/u5FMLfYTMJwMlc8ke8g6Mqze5aRW Cdscq0QkNRmPlymXEN7ZDVMwTvZd8REM/dBHrWoebdxBairoQc0BBN4VwllVdQa4PpdG L4yIy8Su8gM5J33g3YG6DP2US+8Wjdsst+oraCtkkyxJ9yKgyWCbLx+UNiMKJ/pt3GuK LBfZMjQXMMBwO/DYL3T7/DS3cVPy/9yuABBdw2YZSMaUhiv9YYy/iJgHriAzGmxB6iB3 yc9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=qgI6TbDXAZM6wFatIsEGgk9qsgud0pAZlI0mLqvy4xQ=; b=jw654ItTVJy1E8LeOaftmuABvNJ7cc8W3wg3cS8vdZ5+ZrO4eZbG1ysicNnyQM9GEf 5xymkImOW3zUunwvakGICZz67FWDcdQvWU8/6Gg+k5m9OJQxbVpjTdiXa94hSqStIdL2 szDRtGKGMrFZWTdSIk+5io9Zw8Y4srz88Gwe7pM0OL9AW2Kd37RvZBlEXYbrX8PKjqLB VQGdBkXS/SubXfJBemLzC3HiIqG8LBnihCIPPj3G1CZAYNF7vXq/epfehJb/jGs3VGRv zWpMgklBLTZteB4SdLWjcD4dQvTFm6oIIm5eDTCt8azL8RS5baDK0drOYr2VMDpucUTE LdVQ== X-Gm-Message-State: AOAM532tIFL5xkdc+1SRrtgyvPzWH4SQCgbTFEDjMkU//ST4Y2zJsgka c8mW7v6ytuLXkEuI2qQ+hphLrckbsVI= X-Google-Smtp-Source: ABdhPJy9osaQ9V1JFHo2+phcfWxrWxiu4txeq2kFQ+JkVM8VdCRmCMDOkW7p0Tl1AuVnoYMDqxfTZA== X-Received: by 2002:a05:600c:24c:: with SMTP id 12mr1763938wmj.191.1640196717539; Wed, 22 Dec 2021 10:11:57 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k19sm5663422wmo.29.2021.12.22.10.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Dec 2021 10:11:57 -0800 (PST) Message-Id: In-Reply-To: References: Date: Wed, 22 Dec 2021 18:11:54 +0000 Subject: [PATCH v2 3/3] refs: centralize initialization of the base ref_store. Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys From: Han-Wen Nienhuys Signed-off-by: Han-Wen Nienhuys --- refs.c | 6 ++++-- refs/debug.c | 3 ++- refs/files-backend.c | 5 +---- refs/packed-backend.c | 6 ++---- refs/refs-internal.h | 4 ++-- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/refs.c b/refs.c index 4c317955813..f91edb73075 100644 --- a/refs.c +++ b/refs.c @@ -2007,10 +2007,12 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt) return refs; } -void base_ref_store_init(struct ref_store *refs, - const struct ref_storage_be *be) +void base_ref_store_init(struct ref_store *refs, struct repository *repo, + const char *path, const struct ref_storage_be *be) { refs->be = be; + refs->repo = repo; + refs->gitdir = xstrdup(path); } /* backend functions */ diff --git a/refs/debug.c b/refs/debug.c index 8a6bb157ee6..2b0771ca53b 100644 --- a/refs/debug.c +++ b/refs/debug.c @@ -26,7 +26,8 @@ struct ref_store *maybe_debug_wrap_ref_store(const char *gitdir, struct ref_stor be_copy->name = store->be->name; trace_printf_key(&trace_refs, "ref_store for %s\n", gitdir); res->refs = store; - base_ref_store_init((struct ref_store *)res, be_copy); + base_ref_store_init((struct ref_store *)res, store->repo, gitdir, + be_copy); return (struct ref_store *)res; } diff --git a/refs/files-backend.c b/refs/files-backend.c index f1b66130dfb..5c6d49a267e 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -86,11 +86,8 @@ static struct ref_store *files_ref_store_create(struct repository *repo, 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); + base_ref_store_init(ref_store, repo, gitdir, &refs_be_files); refs->store_flags = flags; - get_common_dir_noenv(&sb, gitdir); refs->gitcommondir = strbuf_detach(&sb, NULL); refs->packed_ref_store = diff --git a/refs/packed-backend.c b/refs/packed-backend.c index caa1957252a..d91a2018f60 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -201,13 +201,11 @@ struct ref_store *packed_ref_store_create(struct repository *repo, struct ref_store *ref_store = (struct ref_store *)refs; struct strbuf sb = STRBUF_INIT; - base_ref_store_init(ref_store, &refs_be_packed); - ref_store->repo = repo; - ref_store->gitdir = xstrdup(gitdir); + base_ref_store_init(ref_store, repo, gitdir, &refs_be_packed); refs->store_flags = store_flags; + strbuf_addf(&sb, "%s/packed-refs", gitdir); refs->path = strbuf_detach(&sb, NULL); - chdir_notify_reparent("packed-refs", &refs->path); return ref_store; } diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 46a839539e3..7ff6fba4f0d 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -710,8 +710,8 @@ int parse_loose_ref_contents(const char *buf, struct object_id *oid, * Fill in the generic part of refs and add it to our collection of * reference stores. */ -void base_ref_store_init(struct ref_store *refs, - const struct ref_storage_be *be); +void base_ref_store_init(struct ref_store *refs, struct repository *repo, + const char *path, const struct ref_storage_be *be); /* * Support GIT_TRACE_REFS by optionally wrapping the given ref_store instance.