From: "Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Han-Wen Nienhuys <hanwenn@gmail.com>,
Han-Wen Nienhuys <hanwen@google.com>
Subject: [PATCH v2 1/4] refs: split off reading loose ref data in separate function
Date: Wed, 19 Aug 2020 14:27:55 +0000 [thread overview]
Message-ID: <557727064d5e060e164984887652aa956b9d111c.1597847278.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.705.v2.git.1597847278.gitgitgadget@gmail.com>
From: Han-Wen Nienhuys <hanwen@google.com>
This prepares for handling FETCH_HEAD (which is not a regular ref)
separately from the ref backend.
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
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.
--
gitgitgadget
next prev parent reply other threads:[~2020-08-19 14:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-17 15:39 [PATCH 0/4] Handle FETCH_HEAD generically Han-Wen Nienhuys via GitGitGadget
2020-08-17 15:39 ` [PATCH 1/4] Split off reading loose ref data in separate function Han-Wen Nienhuys via GitGitGadget
2020-08-17 15:39 ` [PATCH 2/4] refs: fix comment about submodule ref_stores Han-Wen Nienhuys via GitGitGadget
2020-08-17 15:39 ` [PATCH 3/4] refs: move gitdir into base ref_store Han-Wen Nienhuys via GitGitGadget
2020-08-17 15:39 ` [PATCH 4/4] refs: read FETCH_HEAD generically Han-Wen Nienhuys via GitGitGadget
2020-08-17 19:40 ` [PATCH 0/4] Handle " Junio C Hamano
2020-08-19 14:27 ` [PATCH v2 0/4] Handle FETCH_HEAD and MERGE_HEAD generically Han-Wen Nienhuys via GitGitGadget
2020-08-19 14:27 ` Han-Wen Nienhuys via GitGitGadget [this message]
2020-08-19 14:27 ` [PATCH v2 2/4] refs: fix comment about submodule ref_stores Han-Wen Nienhuys via GitGitGadget
2020-08-19 14:27 ` [PATCH v2 3/4] refs: move gitdir into base ref_store Han-Wen Nienhuys via GitGitGadget
2020-08-19 14:27 ` [PATCH v2 4/4] refs: read FETCH_HEAD and MERGE_HEAD generically Han-Wen Nienhuys via GitGitGadget
2020-08-19 21:09 ` [PATCH v2 0/4] Handle " Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=557727064d5e060e164984887652aa956b9d111c.1597847278.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=hanwen@google.com \
--cc=hanwenn@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).