From patchwork Wed Aug 19 14:27:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11724295 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 28EFE739 for ; Wed, 19 Aug 2020 14:28:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F33C2076E for ; Wed, 19 Aug 2020 14:28:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lHMCkEF7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728499AbgHSO2U (ORCPT ); Wed, 19 Aug 2020 10:28:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728431AbgHSO2H (ORCPT ); Wed, 19 Aug 2020 10:28:07 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D533C061343 for ; Wed, 19 Aug 2020 07:28:06 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id r4so21707959wrx.9 for ; Wed, 19 Aug 2020 07:28:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=PkGI2LMW/ZUwdqVFcB7zHQ7z8COU+eDI3R4VNjzHwOg=; b=lHMCkEF7tWNPvJb4guSKuJOYswlLvkuXHsNCNWbfpcdWIH+1mr2y7e7CSpMde12SXC bdj1Dhhe4D31h/4ErcQgOSQpHoD8F1MDrqvFBxDU6PxT6MwGzvHWTKKGAM9ndxhfUqeS PRmRNYhNOW2m0azQ1yElCrO5fQO4Fgb4Mt63TG0NBdM2HPprZhM/nVgAB0gTU9Le8wES hl783F2GmfrpHNhmJnzjIADQSEtHaLH+cHH5aeihQMIZ7kT2X5VYCnYGE8XIYbfpGQzj g6l+iGCqGOtL/km64Fv+ko3ZnYAfmy42fTJLHCYB77E+R7ryIpNioN5vTHzhKQYteZr4 oN7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=PkGI2LMW/ZUwdqVFcB7zHQ7z8COU+eDI3R4VNjzHwOg=; b=II5Re31zfu2by/YSb6xiJzCGepyfAffa9nsJqITNTfZxVvKn7YqfPq5AUwOac6nKMr 0LG7xg0ZtazYOBwFMJJeKoMd7kCYNDCop+HHpZKn2FNDh7ybqexAqVptNMrDelWHEHO7 XQZkbyFW/0katazV8yrfVx585jbe5rxoqAWTnRVFpjvSaZr8smyZzm2ZrOXRqCzSj/NT t7x66ayThBu9FTg2EJbf/JciS1SbkV80tBXMsmXFgxjmue63oqnjUxtMbqOx0PaXckhq iAofIXXDNAfN+YBbxGEb/yFVanAFL092Dm9m8XFC3SUxlboEM+pHl3y6ut7Z7Kkzo4LB FJxg== X-Gm-Message-State: AOAM530g5w1JrF5Qv0qRb4YO3iYe8eoFxdH/scIfByoFyxvBHuX9vdeb fndewoOkH2lMtIKgXNd6sgdFpVOKEvU= X-Google-Smtp-Source: ABdhPJycxZEBsfuJyMV1Z5j6fqAJ8E4dJ6JcSFTMrd1ZQ1ywrGsMjnmjY6lzjl9AjyPRvr8dzRDziw== X-Received: by 2002:adf:ec45:: with SMTP id w5mr25515573wrn.415.1597847281311; Wed, 19 Aug 2020 07:28:01 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x11sm5599012wmc.33.2020.08.19.07.28.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 07:28:00 -0700 (PDT) Message-Id: <557727064d5e060e164984887652aa956b9d111c.1597847278.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Han-Wen Nienhuys via GitGitGadget" Date: Wed, 19 Aug 2020 14:27:55 +0000 Subject: [PATCH v2 1/4] refs: split off reading loose ref data in separate function Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys This prepares for handling FETCH_HEAD (which is not a regular ref) separately from the ref backend. Signed-off-by: Han-Wen Nienhuys --- refs/files-backend.c | 34 +++++++++++++++++++--------------- refs/refs-internal.h | 6 ++++++ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 985631f33e..3a3573986f 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -360,7 +360,6 @@ static int files_read_raw_ref(struct ref_store *ref_store, struct strbuf sb_path = STRBUF_INIT; const char *path; const char *buf; - const char *p; struct stat st; int fd; int ret = -1; @@ -465,6 +464,21 @@ static int files_read_raw_ref(struct ref_store *ref_store, close(fd); strbuf_rtrim(&sb_contents); buf = sb_contents.buf; + + ret = parse_loose_ref_contents(buf, oid, referent, type); + +out: + save_errno = errno; + strbuf_release(&sb_path); + strbuf_release(&sb_contents); + errno = save_errno; + return ret; +} + +int parse_loose_ref_contents(const char *buf, struct object_id *oid, + struct strbuf *referent, unsigned int *type) +{ + const char *p; if (skip_prefix(buf, "ref:", &buf)) { while (isspace(*buf)) buf++; @@ -472,29 +486,19 @@ static int files_read_raw_ref(struct ref_store *ref_store, strbuf_reset(referent); strbuf_addstr(referent, buf); *type |= REF_ISSYMREF; - ret = 0; - goto out; + return 0; } /* - * Please note that FETCH_HEAD has additional - * data after the sha. + * FETCH_HEAD has additional data after the sha. */ if (parse_oid_hex(buf, oid, &p) || (*p != '\0' && !isspace(*p))) { *type |= REF_ISBROKEN; errno = EINVAL; - goto out; + return -1; } - - ret = 0; - -out: - save_errno = errno; - strbuf_release(&sb_path); - strbuf_release(&sb_contents); - errno = save_errno; - return ret; + return 0; } static void unlock_ref(struct ref_lock *lock) diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 357359a0be..24d79fb5c1 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -674,6 +674,12 @@ struct ref_store { const struct ref_storage_be *be; }; +/* + * Parse contents of a loose ref file. + */ +int parse_loose_ref_contents(const char *buf, struct object_id *oid, + struct strbuf *referent, unsigned int *type); + /* * Fill in the generic part of refs and add it to our collection of * reference stores. From patchwork Wed Aug 19 14:27:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11724289 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3858739 for ; Wed, 19 Aug 2020 14:28:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C21E2080C for ; Wed, 19 Aug 2020 14:28:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ExI3/jp4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728476AbgHSO2M (ORCPT ); Wed, 19 Aug 2020 10:28:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727049AbgHSO2E (ORCPT ); Wed, 19 Aug 2020 10:28:04 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2F70C061383 for ; Wed, 19 Aug 2020 07:28:03 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id g75so2411823wme.4 for ; Wed, 19 Aug 2020 07:28:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=1rorAVKM+u4KBXRYDRlgewUD+8J1/AJMNCNaL1BonPs=; b=ExI3/jp42cDMNteNxgdiwjebE7lx8gPOT6AnFuIIqsyPKU77kDrhwUNqIrzZJkcQeG DavXUvOQ6Z5IrgDNnmotge68GEa345liJ9w+ZxIAhmSPxQE+gNUlet6j4iB2h1HEa46w 9W2RPH5za2WbDpSVewGjXhZ3iOHHx8iMHReZAdpLD4hwHrQbC4WBpwVXB88vXky3i6nI k3IGO1onJMEVtU76z5BWDZipU3CMH2o4f6KV6urWUMuN19yCiUNMS1cuBkH1VhfaCGi3 mncU+CxWEJK1pd5PODv5SbyTsG9Iu0/Zod1GupF6DhQYCZRfxuQ7k0Ww1Uv+H7+YUQ5U bzSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=1rorAVKM+u4KBXRYDRlgewUD+8J1/AJMNCNaL1BonPs=; b=kMDq/LkB9ISaff1eC8Fanor3YiKekeN2dCu9f4o2+Jr5TrJUklMkbwBf91PCaPn7h6 JOqlPXetuSBYtKTgYlF/CH1XKdIZpy2j2FTJP8oos39Yox+t8hMTaeChrii2Pe375a38 0V6rM0J18nq5wkKmWkiTPzRaxA/nYxjEOeTzRQYrL4Lf6/suzDJFCO9DjZ++JHD/vxV2 ynhBHzG0XbFIwBuSDRVGgd8rbZ9Pe5DnWS//70ufMKniddccUw3Xw0mDr1KzrkxJqqRv fjJKJAWzvW4iaj/OeteyEh8fzgNZhQDRlvz/5lmDr98n59+3deEX52ept0qOSjmUzozK 8PdQ== X-Gm-Message-State: AOAM53142eRvn4pzy3tNyH2D3nIExBr41mONA2hvRE7zUcqYQPbvCO3j Mo37MZhDZiyScvfr17g4PUTQa1DmRCM= X-Google-Smtp-Source: ABdhPJzGtdCDaTJIuilXDBN7vmXFto40uOoXYIqKyU1REjVDOanRmOM1QJpUmBknLD7sMomfGh83/g== X-Received: by 2002:a7b:c845:: with SMTP id c5mr5323052wml.180.1597847282173; Wed, 19 Aug 2020 07:28:02 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h7sm5840974wmf.43.2020.08.19.07.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 07:28:01 -0700 (PDT) Message-Id: <6da0e62e73a34e70535e3ef41b2259e18ff91c34.1597847278.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Han-Wen Nienhuys via GitGitGadget" Date: Wed, 19 Aug 2020 14:27:56 +0000 Subject: [PATCH v2 2/4] refs: fix comment about submodule ref_stores Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys Signed-off-by: Han-Wen Nienhuys --- refs/refs-internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 24d79fb5c1..9188ddbec2 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -667,7 +667,7 @@ extern struct ref_storage_be refs_be_packed; /* * A representation of the reference store for the main repository or * a submodule. The ref_store instances for submodules are kept in a - * linked list. + * hash map; see get_submodule_ref_store() for more info. */ struct ref_store { /* The backend describing this ref_store's storage scheme: */ From patchwork Wed Aug 19 14:27:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11724291 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DF3ED739 for ; Wed, 19 Aug 2020 14:28:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE0B520882 for ; Wed, 19 Aug 2020 14:28:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BeX+TAdy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728479AbgHSO2Q (ORCPT ); Wed, 19 Aug 2020 10:28:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728175AbgHSO2F (ORCPT ); Wed, 19 Aug 2020 10:28:05 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85CF8C061757 for ; Wed, 19 Aug 2020 07:28:04 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id a14so21754579wra.5 for ; Wed, 19 Aug 2020 07:28:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=2i3qUwPJDAmy4lYfuNBK8v1B1C+CYmST/yp8s9bmrTI=; b=BeX+TAdyOffiveir8zSavUvFy6yg/RXJ3NORZFlNMZaD1xN19mOrUTuS92jk8IGuAy +2q8zT9LJk6gVtTf3GYs1FFWTOkKNT31VniM1PYBvPi1LNkQLFuMnoi3J0b+qBXACtxe Ft59hKErRAvZcIUiJwqVNZTyx3Bd6EJSs4kSMLK6MSHzARMQ2TkGhB5PrhNmh6hPbFxu KwNvmkypdNELOeSuScqnn3oTlHfC6FlADMvtxjo9lvMsva4lu0THpP+Dm8l1yBdO2m6Y GDaKSkxzXsLogw0cP5tZU41JGOJ7tIoblI1bN2nLmrvNRPEoiulXzlo+DXqUy7p8aoub 2ANw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=2i3qUwPJDAmy4lYfuNBK8v1B1C+CYmST/yp8s9bmrTI=; b=scvIXZQjSGXz5Cv63GRidWUTqOBKa9aqjH9dfIiRhhPCIkLzQNmr8Jb2f4hGWARAbW 6c0ZRu4VvXUFBz7ltzXs+cRKmYk8PrZMdn/lgsb1StZ/Kx/oeP8dEtK640m3W1z0eodX vzsm9rf790IFv7cF2/CSvtlYATFjNBd495xHnR4A/SIYd1rI6bfUMIjeJYgak8wM3WgZ U9tk0e8njX1WxMjngDM7pOAZeXflxTlR9nRLhqrFNUzO1hHk8mTxG45ilYl7FCnEbm39 UtwXl+3koUMLyRkfYLIk6zjBsMELh2omCdPvz7oVeC2oJM7mtrb8aQ0tJyB1VGSB9W4H kL/A== X-Gm-Message-State: AOAM530gSetIIuXLnd32wiWOmGlI9Od7Uf8HLAtjKyUkGCYumdxjrBT0 53/hy7i4uf+k4YFusVRwiqLGlXb8qB0= X-Google-Smtp-Source: ABdhPJySxrk9Y/OSA7ICExqTWVWA5Kb6ETrpNBP/B8min3Dn0CuSDaX46OvflyjxCCN1JTx6i3xOiQ== X-Received: by 2002:a5d:548f:: with SMTP id h15mr25345433wrv.331.1597847282968; Wed, 19 Aug 2020 07:28:02 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 188sm11609593wmz.2.2020.08.19.07.28.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 07:28:02 -0700 (PDT) Message-Id: <6263b4b3f2dd2f0e77235f5f09daed7c0bd69099.1597847278.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Han-Wen Nienhuys via GitGitGadget" Date: Wed, 19 Aug 2020 14:27:57 +0000 Subject: [PATCH v2 3/4] refs: move gitdir into base ref_store Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys Signed-off-by: Han-Wen Nienhuys --- refs/files-backend.c | 15 ++++++--------- refs/packed-backend.c | 1 + refs/refs-internal.h | 3 +++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/refs/files-backend.c b/refs/files-backend.c index 3a3573986f..dd712e47f4 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -67,7 +67,6 @@ struct files_ref_store { struct ref_store base; unsigned int store_flags; - char *gitdir; char *gitcommondir; struct ref_cache *loose; @@ -94,18 +93,17 @@ static struct ref_store *files_ref_store_create(const char *gitdir, struct ref_store *ref_store = (struct ref_store *)refs; struct strbuf sb = STRBUF_INIT; + ref_store->gitdir = xstrdup(gitdir); base_ref_store_init(ref_store, &refs_be_files); refs->store_flags = flags; - refs->gitdir = xstrdup(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); strbuf_release(&sb); - chdir_notify_reparent("files-backend $GIT_DIR", - &refs->gitdir); + chdir_notify_reparent("files-backend $GIT_DIR", &refs->base.gitdir); chdir_notify_reparent("files-backend $GIT_COMMONDIR", &refs->gitcommondir); @@ -176,7 +174,7 @@ static void files_reflog_path(struct files_ref_store *refs, switch (ref_type(refname)) { case REF_TYPE_PER_WORKTREE: case REF_TYPE_PSEUDOREF: - strbuf_addf(sb, "%s/logs/%s", refs->gitdir, refname); + strbuf_addf(sb, "%s/logs/%s", refs->base.gitdir, refname); break; case REF_TYPE_OTHER_PSEUDOREF: case REF_TYPE_MAIN_PSEUDOREF: @@ -198,7 +196,7 @@ static void files_ref_path(struct files_ref_store *refs, switch (ref_type(refname)) { case REF_TYPE_PER_WORKTREE: case REF_TYPE_PSEUDOREF: - strbuf_addf(sb, "%s/%s", refs->gitdir, refname); + strbuf_addf(sb, "%s/%s", refs->base.gitdir, refname); break; case REF_TYPE_MAIN_PSEUDOREF: if (!skip_prefix(refname, "main-worktree/", &refname)) @@ -2203,12 +2201,11 @@ static struct ref_iterator *files_reflog_iterator_begin(struct ref_store *ref_st files_downcast(ref_store, REF_STORE_READ, "reflog_iterator_begin"); - if (!strcmp(refs->gitdir, refs->gitcommondir)) { + if (!strcmp(refs->base.gitdir, refs->gitcommondir)) { return reflog_iterator_begin(ref_store, refs->gitcommondir); } else { return merge_ref_iterator_begin( - 0, - reflog_iterator_begin(ref_store, refs->gitdir), + 0, reflog_iterator_begin(ref_store, refs->base.gitdir), reflog_iterator_begin(ref_store, refs->gitcommondir), reflog_iterator_select, refs); } diff --git a/refs/packed-backend.c b/refs/packed-backend.c index 4458a0f69c..b912f2505f 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -200,6 +200,7 @@ struct ref_store *packed_ref_store_create(const char *path, struct ref_store *ref_store = (struct ref_store *)refs; base_ref_store_init(ref_store, &refs_be_packed); + ref_store->gitdir = xstrdup(path); refs->store_flags = store_flags; refs->path = xstrdup(path); diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 9188ddbec2..527b0a6e2e 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -672,6 +672,9 @@ extern struct ref_storage_be refs_be_packed; 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: */ + char *gitdir; }; /* From patchwork Wed Aug 19 14:27:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 11724293 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E04BC739 for ; Wed, 19 Aug 2020 14:28:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C53AC20882 for ; Wed, 19 Aug 2020 14:28:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DC+ACPnK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728493AbgHSO2S (ORCPT ); Wed, 19 Aug 2020 10:28:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728393AbgHSO2G (ORCPT ); Wed, 19 Aug 2020 10:28:06 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 751FEC061342 for ; Wed, 19 Aug 2020 07:28:05 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id a14so21754635wra.5 for ; Wed, 19 Aug 2020 07:28:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=2Nm9NToXXZPc36xOHORm95YmqHPjhog2RFKnTRhYc5Q=; b=DC+ACPnKyI/q91t+NgrKTvMuMYhASSLad5Fb5hQ5iaMurjIbklfrm52fk5WQIRfnBS bnrB3txpMVSmyuoQrJ7IB4IWOLbxFbrAvLbzdKKO0DuGWDxqQVuqUahdSp6MgLrfyUBr JifTGYUIYZUAWfH3vvlquTigWlLY3efcG62gOpZ+nP5fuEKQv8qMLPSwAXmwW0er74j1 10pe4erOJDtUbvEklZ2+Ca9vMHuLJjszFFlgOdXjgywz5iib3mLcMFx6qzSOdch4RqQS nLBa1x2a8Juo9auYhfD6KkPf/5ClMy8FxEL1G4i861dVFsv9psQhL14O0dP1MsHYB3kl h7eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=2Nm9NToXXZPc36xOHORm95YmqHPjhog2RFKnTRhYc5Q=; b=noi9L3Hi4qwdVHgu44Q/TVngYAg5+yEXR6sgzC3CQgFIwzrwnXQMBjMaycy49jLcX1 Br483RPq1nmDTydT5iVfq5saNGL044IRk9b1uKYyhpQ3emNRD42MBl3Ko/9DdmCPoTbX 2aNcDnEBfak71roHjF4+7hQ0nGuFAp6Nk/wo9sv7IyuJJaNDeCaHctzeaPRpQySHEeR5 3TZDP6iBhXnBiq5fabmShENM1TdG8dLQfWYtnMgMZK3v3rJk/tnqWgaNYgXfMbv+kqM4 gDlKkXBJQMyhaGyAAwCbYAisiNyEgFzeZrX25qxIvPTCCLqfKJCFjbr1WCR3PXPj4Ppv 1l1w== X-Gm-Message-State: AOAM5306Gt6KJxW5iCSY3FbjKDAQdt1mW+Q51tFzY2qNYNaRyizbam0p hZL2UygvG+UKsmvF2IIZwriXNUlL3ek= X-Google-Smtp-Source: ABdhPJxGmFw84il3Gw62gr/ebYzca1eVPafHkYET8Vla+mGl4+CEUTDG6n93UMm3GYGu9n5fSPsS2Q== X-Received: by 2002:adf:e902:: with SMTP id f2mr24755867wrm.174.1597847283834; Wed, 19 Aug 2020 07:28:03 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f15sm43211625wrt.80.2020.08.19.07.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2020 07:28:03 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Han-Wen Nienhuys via GitGitGadget" Date: Wed, 19 Aug 2020 14:27:58 +0000 Subject: [PATCH v2 4/4] refs: read FETCH_HEAD and MERGE_HEAD generically Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han-Wen Nienhuys , Han-Wen Nienhuys Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Han-Wen Nienhuys The FETCH_HEAD and MERGE_HEAD refs must be stored in a file, regardless of the type of ref backend. This is because they can hold more than just a single ref. To accomodate them for alternate ref backends, read them from a file generically in refs_read_raw_ref() Signed-off-by: Han-Wen Nienhuys --- refs.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/refs.c b/refs.c index cf91711968..3ee3afaf41 100644 --- a/refs.c +++ b/refs.c @@ -1527,11 +1527,37 @@ int for_each_rawref(each_ref_fn fn, void *cb_data) return refs_for_each_rawref(get_main_ref_store(the_repository), fn, cb_data); } +static int refs_read_special_head(struct ref_store *ref_store, + const char *refname, struct object_id *oid, + struct strbuf *referent, unsigned int *type) +{ + struct strbuf full_path = STRBUF_INIT; + struct strbuf content = STRBUF_INIT; + int result = -1; + strbuf_addf(&full_path, "%s/%s", ref_store->gitdir, refname); + + if (strbuf_read_file(&content, full_path.buf, 0) < 0) + goto done; + + result = parse_loose_ref_contents(content.buf, oid, referent, type); + +done: + strbuf_release(&full_path); + strbuf_release(&content); + return result; +} + int refs_read_raw_ref(struct ref_store *ref_store, const char *refname, struct object_id *oid, struct strbuf *referent, unsigned int *type) { - return ref_store->be->read_raw_ref(ref_store, refname, oid, referent, type); + if (!strcmp(refname, "FETCH_HEAD") || !strcmp(refname, "MERGE_HEAD")) { + return refs_read_special_head(ref_store, refname, oid, referent, + type); + } + + return ref_store->be->read_raw_ref(ref_store, refname, oid, referent, + type); } /* This function needs to return a meaningful errno on failure */