Message ID | pull.705.v2.git.1597847278.gitgitgadget@gmail.com (mailing list archive) |
---|---|
Headers | show |
Series | Handle FETCH_HEAD and MERGE_HEAD generically | expand |
"Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com> writes: > This moves the FETCH_HEAD handling into refs.c as discussed in > https://public-inbox.org/git/xmqq5z9pav01.fsf@gitster.c.googlers.com/ Thanks. The way the support for MERGE_HEAD is added to the series looks very sensible, too. Will replace. > -+static int refs_read_fetch_head(struct ref_store *ref_store, > -+ struct object_id *oid, struct strbuf *referent, > -+ unsigned int *type) > ++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, "FETCH_HEAD"); > ++ strbuf_addf(&full_path, "%s/%s", ref_store->gitdir, refname); > + > + if (strbuf_read_file(&content, full_path.buf, 0) < 0) > + goto done; > @@ refs.c: int for_each_rawref(each_ref_fn fn, void *cb_data) > struct strbuf *referent, unsigned int *type) > { > - return ref_store->be->read_raw_ref(ref_store, refname, oid, referent, type); > -+ if (!strcmp(refname, "FETCH_HEAD")) { > -+ return refs_read_fetch_head(ref_store, 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,
This moves the FETCH_HEAD handling into refs.c as discussed in https://public-inbox.org/git/xmqq5z9pav01.fsf@gitster.c.googlers.com/ Han-Wen Nienhuys (4): refs: split off reading loose ref data in separate function refs: fix comment about submodule ref_stores refs: move gitdir into base ref_store refs: read FETCH_HEAD and MERGE_HEAD generically refs.c | 28 ++++++++++++++++++++++++- refs/files-backend.c | 49 ++++++++++++++++++++++--------------------- refs/packed-backend.c | 1 + refs/refs-internal.h | 11 +++++++++- 4 files changed, 63 insertions(+), 26 deletions(-) base-commit: 2befe97201e1f3175cce557866c5822793624b5a Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-705%2Fhanwen%2Ffetch-head-generically-v2 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-705/hanwen/fetch-head-generically-v2 Pull-Request: https://github.com/gitgitgadget/git/pull/705 Range-diff vs v1: 1: 10b333695e ! 1: 557727064d Split off reading loose ref data in separate function @@ Metadata Author: Han-Wen Nienhuys <hanwen@google.com> ## Commit message ## - Split off reading loose ref data in separate function + refs: split off reading loose ref data in separate function This prepares for handling FETCH_HEAD (which is not a regular ref) separately from the ref backend. 2: 52b397ec9e = 2: 6da0e62e73 refs: fix comment about submodule ref_stores 3: c624e17dc6 = 3: 6263b4b3f2 refs: move gitdir into base ref_store 4: d4e9c5f499 ! 4: a3e903e4c0 refs: read FETCH_HEAD generically @@ Metadata Author: Han-Wen Nienhuys <hanwen@google.com> ## Commit message ## - refs: read FETCH_HEAD generically + refs: read FETCH_HEAD and MERGE_HEAD generically - The FETCH_HEAD ref must be stored in a file, regardless of the type of - ref backend. This is because it can hold more than just a single ref. + 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 FETCH_HEAD for alternate ref backends, read FETCH_HEAD - from a file generically in refs_read_raw_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 <hanwen@google.com> @@ refs.c: 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_fetch_head(struct ref_store *ref_store, -+ struct object_id *oid, struct strbuf *referent, -+ unsigned int *type) ++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, "FETCH_HEAD"); ++ strbuf_addf(&full_path, "%s/%s", ref_store->gitdir, refname); + + if (strbuf_read_file(&content, full_path.buf, 0) < 0) + goto done; @@ refs.c: int for_each_rawref(each_ref_fn fn, void *cb_data) struct strbuf *referent, unsigned int *type) { - return ref_store->be->read_raw_ref(ref_store, refname, oid, referent, type); -+ if (!strcmp(refname, "FETCH_HEAD")) { -+ return refs_read_fetch_head(ref_store, 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,