git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFC PATCH 0/2] First steps towards iterating over submodule refs
@ 2021-08-25 23:23 Jonathan Tan
  2021-08-25 23:23 ` [RFC PATCH 1/2] refs: make _advance() check struct repo, not flag Jonathan Tan
  2021-08-25 23:23 ` [RFC PATCH 2/2] refs: add repo paramater to _iterator_peel() Jonathan Tan
  0 siblings, 2 replies; 11+ messages in thread
From: Jonathan Tan @ 2021-08-25 23:23 UTC (permalink / raw)
  To: git; +Cc: Jonathan Tan, hanwen

Here are more results from my submodule partial clone work - teaching
ref iteration to work with submodules by introducing struct repo
parameters at different points. I'm sending this out early as RFC
(before implementing the part that actually adds support for other
repositories) because there might be a better way to do this that I
haven't thought of. (This patch set contains my best idea for how this
could be implemented, but admittedly it is a bit unelegant that the repo
parameter is injected differently into each iterator function.)

This will break any existing topic that introduces new ref store
backends (Han-Wen cc-ed for reftable), although I think that the changes
introduced here are not too significant.

Jonathan Tan (2):
  refs: make _advance() check struct repo, not flag
  refs: add repo paramater to _iterator_peel()

 refs.c                | 50 +++++++++++++++++++++++-------------------
 refs/debug.c          | 13 ++++++-----
 refs/files-backend.c  | 31 ++++++++++++++++++--------
 refs/iterator.c       | 38 ++++++++++++++++++++++++--------
 refs/packed-backend.c | 30 ++++++++++++++++---------
 refs/ref-cache.c      |  7 +++---
 refs/refs-internal.h  | 51 +++++++++++++++++++++++++++++--------------
 7 files changed, 144 insertions(+), 76 deletions(-)

-- 
2.33.0.rc2.250.ged5fa647cd-goog


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [RFC PATCH 1/2] refs: make _advance() check struct repo, not flag
  2021-08-25 23:23 [RFC PATCH 0/2] First steps towards iterating over submodule refs Jonathan Tan
@ 2021-08-25 23:23 ` Jonathan Tan
  2021-08-26 16:39   ` Han-Wen Nienhuys
  2021-08-25 23:23 ` [RFC PATCH 2/2] refs: add repo paramater to _iterator_peel() Jonathan Tan
  1 sibling, 1 reply; 11+ messages in thread
From: Jonathan Tan @ 2021-08-25 23:23 UTC (permalink / raw)
  To: git; +Cc: Jonathan Tan, hanwen

Currently, ref iterators access the object store each time they advance
if and only if the boolean flag DO_FOR_EACH_INCLUDE_BROKEN is unset.
(The iterators access the object store because, if
DO_FOR_EACH_INCLUDE_BROKEN is unset, they need to attempt to resolve
each ref to determine that it is not broken.)

Also, the object store accessed is always that of the_repository, making
it impossible to iterate over a submodule's refs without
DO_FOR_EACH_INCLUDE_BROKEN (unless add_submodule_odb() is used).

As a first step in resolving both these problems, replace the
DO_FOR_EACH_INCLUDE_BROKEN flag with a struct repository pointer. This
commit is a mechanical conversion - whenever DO_FOR_EACH_INCLUDE_BROKEN
is set, a NULL repository (representing access to no object store) is
used instead, and whenever DO_FOR_EACH_INCLUDE_BROKEN is unset, a
non-NULL repository (representing access to that repository's object
store) is used instead. Right now, the locations in which
non-the_repository support needs to be added are marked with BUG()
statements - in a future patch, these will be replaced. (NEEDSWORK: in
this RFC patch set, this has not been done)

I have considered and rejected the following design alternatives:

- Making all ref stores not access the object store during their
  _advance() callbacks, and making ref_iterator_advance() be responsible
  for checking the object store - thus, simplifying the code in that the
  logic of checking for the flag (current) or the pointer (after the
  equivalent of this commit) is only in one place instead of in every
  ref store's callback. However, the ref stores already make use of this
  flag for another reason - for determining if refs are resolvable when
  writing (search for "REF_STORE_ODB"). Thus, I decided to retain each
  ref store's knowledge of this flag.

- Teaching the ref iterator mechanism to never skip any ref. This has
  the same problem as above, and furthermore, all callers now need to
  handle unresolvable refs.

- Change the _advance() callback to also have a repository object
  parameter, and either skip or not skip depending on whether that
  parameter is NULL. This burdens callers to have to carry this
  information along with the iterator, and such calling code may be
  unclear as to why that parameter can be NULL in some cases and cannot
  in others.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
 refs.c                | 48 +++++++++++++++++++++++--------------------
 refs/debug.c          |  4 ++--
 refs/files-backend.c  | 19 +++++++++++++----
 refs/packed-backend.c | 16 +++++++++++----
 refs/refs-internal.h  | 24 ++++++++++++----------
 5 files changed, 68 insertions(+), 43 deletions(-)

diff --git a/refs.c b/refs.c
index 8b9f7c3a80..35b85f3e79 100644
--- a/refs.c
+++ b/refs.c
@@ -1413,16 +1413,16 @@ int head_ref(each_ref_fn fn, void *cb_data)
 
 struct ref_iterator *refs_ref_iterator_begin(
 		struct ref_store *refs,
-		const char *prefix, int trim, int flags)
+		const char *prefix, int trim, struct repository *repo,
+		int flags)
 {
 	struct ref_iterator *iter;
 
 	if (ref_paranoia < 0)
 		ref_paranoia = git_env_bool("GIT_REF_PARANOIA", 0);
-	if (ref_paranoia)
-		flags |= DO_FOR_EACH_INCLUDE_BROKEN;
 
-	iter = refs->be->iterator_begin(refs, prefix, flags);
+	iter = refs->be->iterator_begin(refs, prefix,
+					ref_paranoia ? NULL : repo, flags);
 
 	/*
 	 * `iterator_begin()` already takes care of prefix, but we
@@ -1442,13 +1442,16 @@ struct ref_iterator *refs_ref_iterator_begin(
  * Call fn for each reference in the specified submodule for which the
  * refname begins with prefix. If trim is non-zero, then trim that
  * many characters off the beginning of each refname before passing
- * the refname to fn. flags can be DO_FOR_EACH_INCLUDE_BROKEN to
- * include broken references in the iteration. If fn ever returns a
+ * the refname to fn. If fn ever returns a
  * non-zero value, stop the iteration and return that value;
  * otherwise, return 0.
+ *
+ * See the documentation of refs_ref_iterator_begin() for more information on
+ * the repo parameter.
  */
 static int do_for_each_repo_ref(struct repository *r, const char *prefix,
-				each_repo_ref_fn fn, int trim, int flags,
+				each_repo_ref_fn fn, int trim,
+				struct repository *repo, int flags,
 				void *cb_data)
 {
 	struct ref_iterator *iter;
@@ -1457,7 +1460,7 @@ static int do_for_each_repo_ref(struct repository *r, const char *prefix,
 	if (!refs)
 		return 0;
 
-	iter = refs_ref_iterator_begin(refs, prefix, trim, flags);
+	iter = refs_ref_iterator_begin(refs, prefix, trim, repo, flags);
 
 	return do_for_each_repo_ref_iterator(r, iter, fn, cb_data);
 }
@@ -1479,7 +1482,8 @@ static int do_for_each_ref_helper(struct repository *r,
 }
 
 static int do_for_each_ref(struct ref_store *refs, const char *prefix,
-			   each_ref_fn fn, int trim, int flags, void *cb_data)
+			   each_ref_fn fn, int trim, struct repository *repo,
+			   int flags, void *cb_data)
 {
 	struct ref_iterator *iter;
 	struct do_for_each_ref_help hp = { fn, cb_data };
@@ -1487,7 +1491,7 @@ static int do_for_each_ref(struct ref_store *refs, const char *prefix,
 	if (!refs)
 		return 0;
 
-	iter = refs_ref_iterator_begin(refs, prefix, trim, flags);
+	iter = refs_ref_iterator_begin(refs, prefix, trim, repo, flags);
 
 	return do_for_each_repo_ref_iterator(the_repository, iter,
 					do_for_each_ref_helper, &hp);
@@ -1495,7 +1499,7 @@ static int do_for_each_ref(struct ref_store *refs, const char *prefix,
 
 int refs_for_each_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
 {
-	return do_for_each_ref(refs, "", fn, 0, 0, cb_data);
+	return do_for_each_ref(refs, "", fn, 0, the_repository, 0, cb_data);
 }
 
 int for_each_ref(each_ref_fn fn, void *cb_data)
@@ -1506,7 +1510,7 @@ int for_each_ref(each_ref_fn fn, void *cb_data)
 int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,
 			 each_ref_fn fn, void *cb_data)
 {
-	return do_for_each_ref(refs, prefix, fn, strlen(prefix), 0, cb_data);
+	return do_for_each_ref(refs, prefix, fn, strlen(prefix), the_repository, 0, cb_data);
 }
 
 int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
@@ -1518,10 +1522,10 @@ int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsig
 {
 	unsigned int flag = 0;
 
-	if (broken)
-		flag = DO_FOR_EACH_INCLUDE_BROKEN;
 	return do_for_each_ref(get_main_ref_store(the_repository),
-			       prefix, fn, 0, flag, cb_data);
+			       prefix, fn, 0,
+			       broken ? NULL : the_repository,
+			       flag, cb_data);
 }
 
 int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
@@ -1530,16 +1534,16 @@ int refs_for_each_fullref_in(struct ref_store *refs, const char *prefix,
 {
 	unsigned int flag = 0;
 
-	if (broken)
-		flag = DO_FOR_EACH_INCLUDE_BROKEN;
-	return do_for_each_ref(refs, prefix, fn, 0, flag, cb_data);
+	return do_for_each_ref(refs, prefix, fn, 0,
+			       broken ? NULL : the_repository,
+			       flag, cb_data);
 }
 
 int for_each_replace_ref(struct repository *r, each_repo_ref_fn fn, void *cb_data)
 {
 	return do_for_each_repo_ref(r, git_replace_ref_base, fn,
 				    strlen(git_replace_ref_base),
-				    DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
+				    NULL, 0, cb_data);
 }
 
 int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)
@@ -1548,7 +1552,7 @@ int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)
 	int ret;
 	strbuf_addf(&buf, "%srefs/", get_git_namespace());
 	ret = do_for_each_ref(get_main_ref_store(the_repository),
-			      buf.buf, fn, 0, 0, cb_data);
+			      buf.buf, fn, 0, the_repository, 0, cb_data);
 	strbuf_release(&buf);
 	return ret;
 }
@@ -1556,7 +1560,7 @@ int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)
 int refs_for_each_rawref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
 {
 	return do_for_each_ref(refs, "", fn, 0,
-			       DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
+			       NULL, 0, cb_data);
 }
 
 int for_each_rawref(each_ref_fn fn, void *cb_data)
@@ -2263,7 +2267,7 @@ int refs_verify_refname_available(struct ref_store *refs,
 	strbuf_addch(&dirname, '/');
 
 	iter = refs_ref_iterator_begin(refs, dirname.buf, 0,
-				       DO_FOR_EACH_INCLUDE_BROKEN);
+				       NULL, 0);
 	while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
 		if (skip &&
 		    string_list_has_string(skip, iter->refname))
diff --git a/refs/debug.c b/refs/debug.c
index 1a7a9e11cf..753d5da893 100644
--- a/refs/debug.c
+++ b/refs/debug.c
@@ -224,11 +224,11 @@ static struct ref_iterator_vtable debug_ref_iterator_vtable = {
 
 static struct ref_iterator *
 debug_ref_iterator_begin(struct ref_store *ref_store, const char *prefix,
-			 unsigned int flags)
+			 struct repository *repo, unsigned int flags)
 {
 	struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
 	struct ref_iterator *res =
-		drefs->refs->be->iterator_begin(drefs->refs, prefix, flags);
+		drefs->refs->be->iterator_begin(drefs->refs, prefix, repo, flags);
 	struct debug_ref_iterator *diter = xcalloc(1, sizeof(*diter));
 	base_ref_iterator_init(&diter->base, &debug_ref_iterator_vtable, 1);
 	diter->iter = res;
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 677b7e4cdd..4c42db1092 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -730,6 +730,7 @@ struct files_ref_iterator {
 	struct ref_iterator base;
 
 	struct ref_iterator *iter0;
+	struct repository *repo;
 	unsigned int flags;
 };
 
@@ -744,7 +745,13 @@ static int files_ref_iterator_advance(struct ref_iterator *ref_iterator)
 		    ref_type(iter->iter0->refname) != REF_TYPE_PER_WORKTREE)
 			continue;
 
-		if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
+		if (iter->repo && iter->repo != the_repository)
+			/*
+			 * NEEDSWORK: make ref_resolves_to_object() support
+			 * arbitrary repositories
+			 */
+			BUG("iter->repo must be NULL or the_repository");
+		if (iter->repo &&
 		    !ref_resolves_to_object(iter->iter0->refname,
 					    iter->iter0->oid,
 					    iter->iter0->flags))
@@ -793,7 +800,7 @@ static struct ref_iterator_vtable files_ref_iterator_vtable = {
 
 static struct ref_iterator *files_ref_iterator_begin(
 		struct ref_store *ref_store,
-		const char *prefix, unsigned int flags)
+		const char *prefix, struct repository *repo, unsigned int flags)
 {
 	struct files_ref_store *refs;
 	struct ref_iterator *loose_iter, *packed_iter, *overlay_iter;
@@ -801,7 +808,7 @@ static struct ref_iterator *files_ref_iterator_begin(
 	struct ref_iterator *ref_iterator;
 	unsigned int required_flags = REF_STORE_READ;
 
-	if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN))
+	if (repo)
 		required_flags |= REF_STORE_ODB;
 
 	refs = files_downcast(ref_store, required_flags, "ref_iterator_begin");
@@ -836,10 +843,13 @@ static struct ref_iterator *files_ref_iterator_begin(
 	 * references, and (if needed) do our own check for broken
 	 * ones in files_ref_iterator_advance(), after we have merged
 	 * the packed and loose references.
+	 *
+	 * Do this by not supplying any repo, regardless of whether a repo was
+	 * supplied to files_ref_iterator_begin().
 	 */
 	packed_iter = refs_ref_iterator_begin(
 			refs->packed_ref_store, prefix, 0,
-			DO_FOR_EACH_INCLUDE_BROKEN);
+			NULL, 0);
 
 	overlay_iter = overlay_ref_iterator_begin(loose_iter, packed_iter);
 
@@ -848,6 +858,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 = repo;
 	iter->flags = flags;
 
 	return ref_iterator;
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index f8aa97d799..bc2302a6e0 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -776,6 +776,7 @@ struct packed_ref_iterator {
 	struct object_id oid, peeled;
 	struct strbuf refname_buf;
 
+	struct repository *repo;
 	unsigned int flags;
 };
 
@@ -863,7 +864,13 @@ static int packed_ref_iterator_advance(struct ref_iterator *ref_iterator)
 		    ref_type(iter->base.refname) != REF_TYPE_PER_WORKTREE)
 			continue;
 
-		if (!(iter->flags & DO_FOR_EACH_INCLUDE_BROKEN) &&
+		if (iter->repo && iter->repo != the_repository)
+			/*
+			 * NEEDSWORK: make ref_resolves_to_object() support
+			 * arbitrary repositories
+			 */
+			BUG("iter->repo must be NULL or the_repository");
+		if (iter->repo &&
 		    !ref_resolves_to_object(iter->base.refname, &iter->oid,
 					    iter->flags))
 			continue;
@@ -913,7 +920,7 @@ static struct ref_iterator_vtable packed_ref_iterator_vtable = {
 
 static struct ref_iterator *packed_ref_iterator_begin(
 		struct ref_store *ref_store,
-		const char *prefix, unsigned int flags)
+		const char *prefix, struct repository *repo, unsigned int flags)
 {
 	struct packed_ref_store *refs;
 	struct snapshot *snapshot;
@@ -922,7 +929,7 @@ static struct ref_iterator *packed_ref_iterator_begin(
 	struct ref_iterator *ref_iterator;
 	unsigned int required_flags = REF_STORE_READ;
 
-	if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN))
+	if (repo)
 		required_flags |= REF_STORE_ODB;
 	refs = packed_downcast(ref_store, required_flags, "ref_iterator_begin");
 
@@ -954,6 +961,7 @@ static struct ref_iterator *packed_ref_iterator_begin(
 
 	iter->base.oid = &iter->oid;
 
+	iter->repo = repo;
 	iter->flags = flags;
 
 	if (prefix && *prefix)
@@ -1137,7 +1145,7 @@ static int write_with_updates(struct packed_ref_store *refs,
 	 * of updates is exhausted, leave i set to updates->nr.
 	 */
 	iter = packed_ref_iterator_begin(&refs->base, "",
-					 DO_FOR_EACH_INCLUDE_BROKEN);
+					 NULL, 0);
 	if ((ok = ref_iterator_advance(iter)) != ITER_OK)
 		iter = NULL;
 
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 3155708345..b20fa1f5cd 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -245,9 +245,6 @@ int refs_rename_ref_available(struct ref_store *refs,
 /* We allow "recursive" symbolic refs. Only within reason, though */
 #define SYMREF_MAXDEPTH 5
 
-/* Include broken references in a do_for_each_ref*() iteration: */
-#define DO_FOR_EACH_INCLUDE_BROKEN 0x01
-
 /*
  * Reference iterators
  *
@@ -349,16 +346,19 @@ int is_empty_ref_iterator(struct ref_iterator *ref_iterator);
  * Return an iterator that goes over each reference in `refs` for
  * which the refname begins with prefix. If trim is non-zero, then
  * trim that many characters off the beginning of each refname.
- * The output is ordered by refname. The following flags are supported:
+ * The output is ordered by refname.
+ *
+ * Pass NULL as repo to include broken references in the iteration, or non-NULL
+ * to skip references that do not resolve to an object in the given repo.
  *
- * DO_FOR_EACH_INCLUDE_BROKEN: include broken references in
- *         the iteration.
+ * The following flags are supported:
  *
  * DO_FOR_EACH_PER_WORKTREE_ONLY: only produce REF_TYPE_PER_WORKTREE refs.
  */
 struct ref_iterator *refs_ref_iterator_begin(
 		struct ref_store *refs,
-		const char *prefix, int trim, int flags);
+		const char *prefix, int trim, struct repository *repo,
+		int flags);
 
 /*
  * A callback function used to instruct merge_ref_iterator how to
@@ -446,8 +446,9 @@ void base_ref_iterator_free(struct ref_iterator *iter);
 /*
  * backend-specific implementation of ref_iterator_advance. For symrefs, the
  * function should set REF_ISSYMREF, and it should also dereference the symref
- * to provide the OID referent. If DO_FOR_EACH_INCLUDE_BROKEN is set, symrefs
- * with non-existent referents and refs pointing to non-existent object names
+ * to provide the OID referent. If a NULL repo was passed to the _begin()
+ * function that created this iterator, symrefs with non-existent referents and
+ * refs pointing to non-existent object names
  * should also be returned. If DO_FOR_EACH_PER_WORKTREE_ONLY, only
  * REF_TYPE_PER_WORKTREE refs should be returned.
  */
@@ -504,7 +505,7 @@ int do_for_each_repo_ref_iterator(struct repository *r,
  * where all reference backends will presumably store their
  * per-worktree refs.
  */
-#define DO_FOR_EACH_PER_WORKTREE_ONLY 0x02
+#define DO_FOR_EACH_PER_WORKTREE_ONLY 0x01
 
 struct ref_store;
 
@@ -569,7 +570,8 @@ typedef int copy_ref_fn(struct ref_store *ref_store,
  */
 typedef struct ref_iterator *ref_iterator_begin_fn(
 		struct ref_store *ref_store,
-		const char *prefix, unsigned int flags);
+		const char *prefix, struct repository *repo,
+		unsigned int flags);
 
 /* reflog functions */
 
-- 
2.33.0.rc2.250.ged5fa647cd-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [RFC PATCH 2/2] refs: add repo paramater to _iterator_peel()
  2021-08-25 23:23 [RFC PATCH 0/2] First steps towards iterating over submodule refs Jonathan Tan
  2021-08-25 23:23 ` [RFC PATCH 1/2] refs: make _advance() check struct repo, not flag Jonathan Tan
@ 2021-08-25 23:23 ` Jonathan Tan
  1 sibling, 0 replies; 11+ messages in thread
From: Jonathan Tan @ 2021-08-25 23:23 UTC (permalink / raw)
  To: git; +Cc: Jonathan Tan, hanwen

Split the ref_iterator_peel() function into two functions: one that
returns information solely based on what the ref store contains
(success, failure, inconclusive), and one that takes a repo parameter
and accesses the object store if need be. Update the ref store's
callbacks to not access the object store, and to return
success/failure/inconclusive instead of a binary success/failure.

This makes it explicit whether a peel attempt may access the object
store of a repository.

The approach taken in this commit for peeling is different from the
approach taken in the parent commit for advancing:

- It is complicated to reuse the repo field (which determines if an
  object store is ever accessed during advancing, and if yes, which
  object store) added to ref stores in the parent commit; the files ref
  store wraps the packed ref store, and it does not want the packed ref
  store to access any object store during advancing (as described in
  files_ref_iterator_begin()) - thus repo is NULL - but it wants packed
  ref store peeling.

- Having the repo handy when peeling is not as cumbersome as it is when
  advancing. Firstly, the repo in this case is always non-NULL, and
  secondly, peeling is typically followed by reading the object, which
  requires the repo anyway.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
 refs.c                |  2 +-
 refs/debug.c          |  9 +++++----
 refs/files-backend.c  | 12 +++++++-----
 refs/iterator.c       | 38 +++++++++++++++++++++++++++++---------
 refs/packed-backend.c | 14 ++++++++------
 refs/ref-cache.c      |  7 ++++---
 refs/refs-internal.h  | 27 ++++++++++++++++++++++-----
 7 files changed, 76 insertions(+), 33 deletions(-)

diff --git a/refs.c b/refs.c
index 35b85f3e79..7bc23bcc3f 100644
--- a/refs.c
+++ b/refs.c
@@ -2012,7 +2012,7 @@ int peel_iterated_oid(const struct object_id *base, struct object_id *peeled)
 	if (current_ref_iter &&
 	    (current_ref_iter->oid == base ||
 	     oideq(current_ref_iter->oid, base)))
-		return ref_iterator_peel(current_ref_iter, peeled);
+		return ref_iterator_peel(current_ref_iter, the_repository, peeled);
 
 	return peel_object(base, peeled) ? -1 : 0;
 }
diff --git a/refs/debug.c b/refs/debug.c
index 753d5da893..7291a1a4fb 100644
--- a/refs/debug.c
+++ b/refs/debug.c
@@ -198,13 +198,14 @@ static int debug_ref_iterator_advance(struct ref_iterator *ref_iterator)
 	return res;
 }
 
-static int debug_ref_iterator_peel(struct ref_iterator *ref_iterator,
-				   struct object_id *peeled)
+static enum ref_iterator_peel_result debug_ref_iterator_peel(
+		struct ref_iterator *ref_iterator,
+		struct object_id *peeled)
 {
 	struct debug_ref_iterator *diter =
 		(struct debug_ref_iterator *)ref_iterator;
-	int res = diter->iter->vtable->peel(diter->iter, peeled);
-	trace_printf_key(&trace_refs, "iterator_peel: %s: %d\n", diter->iter->refname, res);
+	enum ref_iterator_peel_result res = diter->iter->vtable->peel(diter->iter, peeled);
+	trace_printf_key(&trace_refs, "iterator_peel: %s: %d\n", diter->iter->refname, (int) res);
 	return res;
 }
 
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 4c42db1092..e1930848b1 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -770,13 +770,14 @@ static int files_ref_iterator_advance(struct ref_iterator *ref_iterator)
 	return ok;
 }
 
-static int files_ref_iterator_peel(struct ref_iterator *ref_iterator,
-				   struct object_id *peeled)
+static enum ref_iterator_peel_result files_ref_iterator_peel(
+		struct ref_iterator *ref_iterator,
+		struct object_id *peeled)
 {
 	struct files_ref_iterator *iter =
 		(struct files_ref_iterator *)ref_iterator;
 
-	return ref_iterator_peel(iter->iter0, peeled);
+	return ref_iterator_peel_raw(iter->iter0, peeled);
 }
 
 static int files_ref_iterator_abort(struct ref_iterator *ref_iterator)
@@ -2122,8 +2123,9 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
 	return ok;
 }
 
-static int files_reflog_iterator_peel(struct ref_iterator *ref_iterator,
-				   struct object_id *peeled)
+static enum ref_iterator_peel_result files_reflog_iterator_peel(
+		struct ref_iterator *ref_iterator,
+		struct object_id *peeled)
 {
 	BUG("ref_iterator_peel() called for reflog_iterator");
 }
diff --git a/refs/iterator.c b/refs/iterator.c
index a89d132d4f..386e6310ed 100644
--- a/refs/iterator.c
+++ b/refs/iterator.c
@@ -13,10 +13,27 @@ int ref_iterator_advance(struct ref_iterator *ref_iterator)
 	return ref_iterator->vtable->advance(ref_iterator);
 }
 
+enum ref_iterator_peel_result ref_iterator_peel_raw(
+		struct ref_iterator *ref_iterator,
+		struct object_id *peeled)
+{
+	return ref_iterator->vtable->peel(ref_iterator, peeled);
+}
+
 int ref_iterator_peel(struct ref_iterator *ref_iterator,
+		      struct repository *repo,
 		      struct object_id *peeled)
 {
-	return ref_iterator->vtable->peel(ref_iterator, peeled);
+	enum ref_iterator_peel_result result =
+		ref_iterator_peel_raw(ref_iterator, peeled);
+
+	if (repo != the_repository)
+		/* NEEDSWORK: make peel_object() work with all repositories */
+		BUG("ref_iterator_peel() can only be used with the_repository");
+	if (result == REF_ITERATOR_PEEL_INCONCLUSIVE)
+		return peel_object(ref_iterator->oid, peeled) == PEEL_PEELED ?
+			0 : -1;
+	return result == REF_ITERATOR_PEEL_SUCCESS ? 0 : -1;
 }
 
 int ref_iterator_abort(struct ref_iterator *ref_iterator)
@@ -51,8 +68,9 @@ static int empty_ref_iterator_advance(struct ref_iterator *ref_iterator)
 	return ref_iterator_abort(ref_iterator);
 }
 
-static int empty_ref_iterator_peel(struct ref_iterator *ref_iterator,
-				   struct object_id *peeled)
+static enum ref_iterator_peel_result empty_ref_iterator_peel(
+		struct ref_iterator *ref_iterator,
+		struct object_id *peeled)
 {
 	BUG("peel called for empty iterator");
 }
@@ -170,8 +188,9 @@ static int merge_ref_iterator_advance(struct ref_iterator *ref_iterator)
 	return ITER_ERROR;
 }
 
-static int merge_ref_iterator_peel(struct ref_iterator *ref_iterator,
-				   struct object_id *peeled)
+static enum ref_iterator_peel_result merge_ref_iterator_peel(
+		struct ref_iterator *ref_iterator,
+		struct object_id *peeled)
 {
 	struct merge_ref_iterator *iter =
 		(struct merge_ref_iterator *)ref_iterator;
@@ -179,7 +198,7 @@ static int merge_ref_iterator_peel(struct ref_iterator *ref_iterator,
 	if (!iter->current) {
 		BUG("peel called before advance for merge iterator");
 	}
-	return ref_iterator_peel(*iter->current, peeled);
+	return ref_iterator_peel_raw(*iter->current, peeled);
 }
 
 static int merge_ref_iterator_abort(struct ref_iterator *ref_iterator)
@@ -355,13 +374,14 @@ static int prefix_ref_iterator_advance(struct ref_iterator *ref_iterator)
 	return ok;
 }
 
-static int prefix_ref_iterator_peel(struct ref_iterator *ref_iterator,
-				    struct object_id *peeled)
+static enum ref_iterator_peel_result prefix_ref_iterator_peel(
+		struct ref_iterator *ref_iterator,
+		struct object_id *peeled)
 {
 	struct prefix_ref_iterator *iter =
 		(struct prefix_ref_iterator *)ref_iterator;
 
-	return ref_iterator_peel(iter->iter0, peeled);
+	return ref_iterator_peel_raw(iter->iter0, peeled);
 }
 
 static int prefix_ref_iterator_abort(struct ref_iterator *ref_iterator)
diff --git a/refs/packed-backend.c b/refs/packed-backend.c
index bc2302a6e0..ef14390043 100644
--- a/refs/packed-backend.c
+++ b/refs/packed-backend.c
@@ -884,19 +884,21 @@ static int packed_ref_iterator_advance(struct ref_iterator *ref_iterator)
 	return ok;
 }
 
-static int packed_ref_iterator_peel(struct ref_iterator *ref_iterator,
-				   struct object_id *peeled)
+static enum ref_iterator_peel_result packed_ref_iterator_peel(
+		struct ref_iterator *ref_iterator,
+		struct object_id *peeled)
 {
 	struct packed_ref_iterator *iter =
 		(struct packed_ref_iterator *)ref_iterator;
 
 	if ((iter->base.flags & REF_KNOWS_PEELED)) {
 		oidcpy(peeled, &iter->peeled);
-		return is_null_oid(&iter->peeled) ? -1 : 0;
+		return is_null_oid(&iter->peeled) ?
+			REF_ITERATOR_PEEL_FAILURE : REF_ITERATOR_PEEL_SUCCESS;
 	} else if ((iter->base.flags & (REF_ISBROKEN | REF_ISSYMREF))) {
-		return -1;
+		return REF_ITERATOR_PEEL_FAILURE;
 	} else {
-		return peel_object(&iter->oid, peeled) ? -1 : 0;
+		return REF_ITERATOR_PEEL_INCONCLUSIVE;
 	}
 }
 
@@ -1226,7 +1228,7 @@ static int write_with_updates(struct packed_ref_store *refs,
 			/* Pass the old reference through. */
 
 			struct object_id peeled;
-			int peel_error = ref_iterator_peel(iter, &peeled);
+			int peel_error = ref_iterator_peel(iter, the_repository, &peeled);
 
 			if (write_packed_entry(out, iter->refname,
 					       iter->oid,
diff --git a/refs/ref-cache.c b/refs/ref-cache.c
index 49d732f6db..031b613bb2 100644
--- a/refs/ref-cache.c
+++ b/refs/ref-cache.c
@@ -488,10 +488,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)
+static enum ref_iterator_peel_result cache_ref_iterator_peel(
+		struct ref_iterator *ref_iterator,
+		struct object_id *peeled)
 {
-	return peel_object(ref_iterator->oid, peeled) ? -1 : 0;
+	return REF_ITERATOR_PEEL_INCONCLUSIVE;
 }
 
 static int cache_ref_iterator_abort(struct ref_iterator *ref_iterator)
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index b20fa1f5cd..aea8b0844f 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -317,11 +317,26 @@ struct ref_iterator {
  */
 int ref_iterator_advance(struct ref_iterator *ref_iterator);
 
+enum ref_iterator_peel_result {
+	REF_ITERATOR_PEEL_SUCCESS,
+	REF_ITERATOR_PEEL_FAILURE,
+	REF_ITERATOR_PEEL_INCONCLUSIVE
+};
+
+/*
+ * Peel the reference currently being viewed by the iterator without
+ * using any information from any object store.
+ */
+enum ref_iterator_peel_result ref_iterator_peel_raw(
+		struct ref_iterator *ref_iterator,
+		struct object_id *peeled);
+
 /*
- * If possible, peel the reference currently being viewed by the
- * iterator. Return 0 on success.
+ * Peel the reference currently being viewed by the iterator, using the object
+ * store if the ref store has insufficient information. Returns 0 upon success.
  */
 int ref_iterator_peel(struct ref_iterator *ref_iterator,
+		      struct repository *repo,
 		      struct object_id *peeled);
 
 /*
@@ -455,10 +470,12 @@ void base_ref_iterator_free(struct ref_iterator *iter);
 typedef int ref_iterator_advance_fn(struct ref_iterator *ref_iterator);
 
 /*
- * Peels the current ref, returning 0 for success or -1 for failure.
+ * Peels the current ref using only information from the ref store. If there is
+ * not enough information, returns REF_ITERATOR_PEEL_INCONCLUSIVE.
  */
-typedef int ref_iterator_peel_fn(struct ref_iterator *ref_iterator,
-				 struct object_id *peeled);
+typedef enum ref_iterator_peel_result ref_iterator_peel_fn(
+		struct ref_iterator *ref_iterator,
+		struct object_id *peeled);
 
 /*
  * Implementations of this function should free any resources specific
-- 
2.33.0.rc2.250.ged5fa647cd-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 1/2] refs: make _advance() check struct repo, not flag
  2021-08-25 23:23 ` [RFC PATCH 1/2] refs: make _advance() check struct repo, not flag Jonathan Tan
@ 2021-08-26 16:39   ` Han-Wen Nienhuys
  2021-08-26 22:24     ` Jonathan Tan
  0 siblings, 1 reply; 11+ messages in thread
From: Han-Wen Nienhuys @ 2021-08-26 16:39 UTC (permalink / raw)
  To: Jonathan Tan; +Cc: git

On Thu, Aug 26, 2021 at 1:23 AM Jonathan Tan <jonathantanmy@google.com> wrote:
>
> Currently, ref iterators access the object store each time they advance
> if and only if the boolean flag DO_FOR_EACH_INCLUDE_BROKEN is unset.
> (The iterators access the object store because, if
> DO_FOR_EACH_INCLUDE_BROKEN is unset, they need to attempt to resolve
> each ref to determine that it is not broken.)
>
> Also, the object store accessed is always that of the_repository, making
> it impossible to iterate over a submodule's refs without
> DO_FOR_EACH_INCLUDE_BROKEN (unless add_submodule_odb() is used).
>
> As a first step in resolving both these problems, replace the
> DO_FOR_EACH_INCLUDE_BROKEN flag with a struct repository pointer. This
> commit is a mechanical conversion - whenever DO_FOR_EACH_INCLUDE_BROKEN
> is set, a NULL repository (representing access to no object store) is
> used instead, and whenever DO_FOR_EACH_INCLUDE_BROKEN is unset, a
> non-NULL repository (representing access to that repository's object
> store) is used instead. Right now, the locations in which
> non-the_repository support needs to be added are marked with BUG()
> statements - in a future patch, these will be replaced. (NEEDSWORK: in
> this RFC patch set, this has not been done)

from a design perspective, it would be nice if the ref backend
wouldn't need to know about the object store. Can't this be hidden in
the layer in refs.c that calls into the backends?

If they have to know about the object store, have you considered
passing the repository pointer
in xxx_ref_store_create() ? Then there is no possibliity to mismatch
the repository pointers and with the ref store.

> - Making all ref stores not access the object store during their
>   _advance() callbacks, and making ref_iterator_advance() be responsible
>   for checking the object store - thus, simplifying the code in that the
>   logic of checking for the flag (current) or the pointer (after the
>   equivalent of this commit) is only in one place instead of in every
>   ref store's callback. However, the ref stores already make use of this
>   flag for another reason - for determining if refs are resolvable when
>   writing (search for "REF_STORE_ODB"). Thus, I decided to retain each

I looked, but I couldn't figure out how this flag is used.
-- 
Han-Wen Nienhuys - Google Munich
I work 80%. Don't expect answers from me on Fridays.
--
Han-Wen Nienhuys
Google Munich
hanwen@google.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 1/2] refs: make _advance() check struct repo, not flag
  2021-08-26 16:39   ` Han-Wen Nienhuys
@ 2021-08-26 22:24     ` Jonathan Tan
  2021-09-14 22:41       ` Glen Choo
  0 siblings, 1 reply; 11+ messages in thread
From: Jonathan Tan @ 2021-08-26 22:24 UTC (permalink / raw)
  To: hanwen; +Cc: jonathantanmy, git

> from a design perspective, it would be nice if the ref backend
> wouldn't need to know about the object store. Can't this be hidden in
> the layer in refs.c that calls into the backends?

Thanks for taking a look.

The answer requires additional context, so I'll answer this at the end
of this email.

> If they have to know about the object store, have you considered
> passing the repository pointer
> in xxx_ref_store_create() ? Then there is no possibliity to mismatch
> the repository pointers and with the ref store.

I thought about that, but didn't want to make things worse - the effort
in this patch set is, after all, to attempt to increase the dissociation
between the ref stores and a certain object store (that is,
the_repository's object store), and I thought that reintroducing an
association (albeit to arbitrary object stores instead of a hardcoded
object store) would be a step back.

But this may be the way to go - the ref stores already have a gitdir
field that we could replace with a struct repository field.

> > - Making all ref stores not access the object store during their
> >   _advance() callbacks, and making ref_iterator_advance() be responsible
> >   for checking the object store - thus, simplifying the code in that the
> >   logic of checking for the flag (current) or the pointer (after the
> >   equivalent of this commit) is only in one place instead of in every
> >   ref store's callback. However, the ref stores already make use of this
> >   flag for another reason - for determining if refs are resolvable when
> >   writing (search for "REF_STORE_ODB"). Thus, I decided to retain each
> 
> I looked, but I couldn't figure out how this flag is used.

I was thinking of files_ref_iterator_begin() setting a local variable
required_flags. Somehow I thought that files_pack_refs() relied on
files_ref_iterator_begin() setting that variable, but now I see that
that's not true - both functions are independently checking that the
underlying ref store supports ODB access, so I can remove ODB from
files_ref_iterator_begin() if I want to.

To go back to the question at the top, now I agree that hiding the ODB
access in _advance() in the layer in refs.c is possible. The last part
still accessing the ODB is files_pack_refs(), I think. Refactoring that
is possible, but I'll leave that to another patch set.

If you or anyone else has more questions or comments, please reply - and
in the meantime, I'll update this patch set to move the ODB access in
_advance() to the layer in refs.c.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 1/2] refs: make _advance() check struct repo, not flag
  2021-08-26 22:24     ` Jonathan Tan
@ 2021-09-14 22:41       ` Glen Choo
  2021-09-15  7:35         ` Han-Wen Nienhuys
  2021-09-16 17:24         ` Jonathan Tan
  0 siblings, 2 replies; 11+ messages in thread
From: Glen Choo @ 2021-09-14 22:41 UTC (permalink / raw)
  To: Jonathan Tan; +Cc: hanwen, git

On Thu, Aug 26, 2021 at 03:24:39PM -0700, Jonathan Tan wrote:
> > If they have to know about the object store, have you considered
> > passing the repository pointer
> > in xxx_ref_store_create() ? Then there is no possibliity to mismatch
> > the repository pointers and with the ref store.
> 
> I thought about that, but didn't want to make things worse - the effort
> in this patch set is, after all, to attempt to increase the dissociation
> between the ref stores and a certain object store (that is,
> the_repository's object store), and I thought that reintroducing an
> association (albeit to arbitrary object stores instead of a hardcoded
> object store) would be a step back.
> 
> But this may be the way to go - the ref stores already have a gitdir
> field that we could replace with a struct repository field.

I'm curious about how we'd want to resolve the general problem of ref
stores referencing odbs. 

A discussion I had with Jonathan Nieder suggests that ref stores are
doing two slightly related, but not equivalent things:

- a logical ref database that preserves its own consistency
- a layer of ref storage in such a ref database

In the current state of affairs, the files ref store and the packed ref
store seem to behave as a single logical ref database. An example of
this (that I care about in particular) is in refs/files-backend.c where
the files backend validates oids using the_repository's odb.
refs/packed-backend.c doesn't do any such validation, and presumably
just relies on the correctness of refs/files-backend.c. I assume that
this also explains why some functions in refs_be_packed are stubs.

The answer to whether or not a ref store should refer to a certain
object store seems unresolved because a ref store is trying to do two
separate things. Perhaps it is reasonable to associate a ref database
with an object store (so that it can validate its refs), but we would
prefer to dissociate the physical ref storage layer from the object
store. (I'm paraphrasing Johnathan Nieder here, this isn't an original
thought).

Perhaps this is a question we want to resolve when considering reftable
and other ref databases.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 1/2] refs: make _advance() check struct repo, not flag
  2021-09-14 22:41       ` Glen Choo
@ 2021-09-15  7:35         ` Han-Wen Nienhuys
  2021-09-16 17:26           ` Jonathan Tan
  2021-09-16 17:24         ` Jonathan Tan
  1 sibling, 1 reply; 11+ messages in thread
From: Han-Wen Nienhuys @ 2021-09-15  7:35 UTC (permalink / raw)
  To: Glen Choo; +Cc: Jonathan Tan, git

On Wed, Sep 15, 2021 at 12:41 AM Glen Choo <chooglen@google.com> wrote:
> In the current state of affairs, the files ref store and the packed ref
> store seem to behave as a single logical ref database. An example of
> this (that I care about in particular) is in refs/files-backend.c where
> the files backend validates oids using the_repository's odb.
> refs/packed-backend.c doesn't do any such validation, and presumably
> just relies on the correctness of refs/files-backend.c. I assume that
> this also explains why some functions in refs_be_packed are stubs.

The loose/packed storage is implemented in terms of files backend (the
public entry point) that defers to a packed backend in some cases. The
latter is implemented as a ref backend, but for no good reason.

> The answer to whether or not a ref store should refer to a certain
> object store seems unresolved because a ref store is trying to do two
> separate things. Perhaps it is reasonable to associate a ref database
> with an object store (so that it can validate its refs), but we would
> prefer to dissociate the physical ref storage layer from the object
> store. (I'm paraphrasing Johnathan Nieder here, this isn't an original
> thought).
>
> Perhaps this is a question we want to resolve when considering reftable
> and other ref databases.

Work on reftable shows that there are more egregious breaks of
abstraction boundaries. For example, there are still parts of the code
that equate

  (file under .git/ == ref)

you can find a good part of them if you run GIT_TEST_REFTABLE=1 with
the reftable support switched on. Another place where API contracts
are unclear is resolving symrefs: on first sight, you'd think that a
ref backend should just provide storage for a refname => {symref,
commit SHA-1, tag + commit SHA-1} mapping. However, in some places it
is currently necessary for the ref backend to resolve symrefs. You can
find these places by grepping for refs_resolve_ref_unsafe() in the
files backend.

I think Jonathan is right, but I also think that teasing apart the ref
backend and the ODB is premature until the ref backend itself is a
strongly enforced abstraction boundary.

-- 
Han-Wen Nienhuys - Google Munich
I work 80%. Don't expect answers from me on Fridays.
--

Google Germany GmbH, Erika-Mann-Strasse 33, 80636 Munich

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg

Geschäftsführer: Paul Manicle, Halimah DeLaine Prado

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 1/2] refs: make _advance() check struct repo, not flag
  2021-09-14 22:41       ` Glen Choo
  2021-09-15  7:35         ` Han-Wen Nienhuys
@ 2021-09-16 17:24         ` Jonathan Tan
  1 sibling, 0 replies; 11+ messages in thread
From: Jonathan Tan @ 2021-09-16 17:24 UTC (permalink / raw)
  To: chooglen; +Cc: jonathantanmy, hanwen, git

> The answer to whether or not a ref store should refer to a certain
> object store seems unresolved because a ref store is trying to do two
> separate things. Perhaps it is reasonable to associate a ref database
> with an object store (so that it can validate its refs), but we would
> prefer to dissociate the physical ref storage layer from the object
> store. (I'm paraphrasing Johnathan Nieder here, this isn't an original
> thought).
> 
> Perhaps this is a question we want to resolve when considering reftable
> and other ref databases.

Either adding an explicit dependency on an object store to a ref store
or dissociating it would be an improvement over what we have now, which
is an implicit dependency on the_repository's object store. Of the two,
I also prefer dissociating it. In practice, if I remember correctly, the
part that checks object existence during ref writing is the last
dependency, so if we can eliminate that without a convoluted design, I
think it's worth dissociating.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 1/2] refs: make _advance() check struct repo, not flag
  2021-09-15  7:35         ` Han-Wen Nienhuys
@ 2021-09-16 17:26           ` Jonathan Tan
  2021-09-16 21:56             ` Junio C Hamano
  0 siblings, 1 reply; 11+ messages in thread
From: Jonathan Tan @ 2021-09-16 17:26 UTC (permalink / raw)
  To: hanwen; +Cc: chooglen, jonathantanmy, git

> On Wed, Sep 15, 2021 at 12:41 AM Glen Choo <chooglen@google.com> wrote:
> > In the current state of affairs, the files ref store and the packed ref
> > store seem to behave as a single logical ref database. An example of
> > this (that I care about in particular) is in refs/files-backend.c where
> > the files backend validates oids using the_repository's odb.
> > refs/packed-backend.c doesn't do any such validation, and presumably
> > just relies on the correctness of refs/files-backend.c. I assume that
> > this also explains why some functions in refs_be_packed are stubs.
> 
> The loose/packed storage is implemented in terms of files backend (the
> public entry point) that defers to a packed backend in some cases. The
> latter is implemented as a ref backend, but for no good reason.

Yes, the packed backend doesn't need to be a ref backend.

> I think Jonathan is right, but I also think that teasing apart the ref
> backend and the ODB is premature until the ref backend itself is a
> strongly enforced abstraction boundary.

I think both efforts can proceed independently.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 1/2] refs: make _advance() check struct repo, not flag
  2021-09-16 17:26           ` Jonathan Tan
@ 2021-09-16 21:56             ` Junio C Hamano
  2021-09-16 22:05               ` Jonathan Tan
  0 siblings, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2021-09-16 21:56 UTC (permalink / raw)
  To: Jonathan Tan; +Cc: hanwen, chooglen, git

Jonathan Tan <jonathantanmy@google.com> writes:

>> On Wed, Sep 15, 2021 at 12:41 AM Glen Choo <chooglen@google.com> wrote:
>> > In the current state of affairs, the files ref store and the packed ref
>> > store seem to behave as a single logical ref database. An example of
>> > this (that I care about in particular) is in refs/files-backend.c where
>> > the files backend validates oids using the_repository's odb.
>> > refs/packed-backend.c doesn't do any such validation, and presumably
>> > just relies on the correctness of refs/files-backend.c. I assume that
>> > this also explains why some functions in refs_be_packed are stubs.
>> 
>> The loose/packed storage is implemented in terms of files backend (the
>> public entry point) that defers to a packed backend in some cases. The
>> latter is implemented as a ref backend, but for no good reason.
>
> Yes, the packed backend doesn't need to be a ref backend.

Sorry, I do not follow.  Do you mean we cannot have a version of Git
that offers say a read-only access to the repository without any
loose refs, with the default ref backend being the packed one?

Or do you mean that we can ignore such a hypothetical use case and
could reimplement the files backend that can also understand the
$GIT_DIR/packed-refs file directly without "deferring to another ref
backend which is 'packed'"?


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC PATCH 1/2] refs: make _advance() check struct repo, not flag
  2021-09-16 21:56             ` Junio C Hamano
@ 2021-09-16 22:05               ` Jonathan Tan
  0 siblings, 0 replies; 11+ messages in thread
From: Jonathan Tan @ 2021-09-16 22:05 UTC (permalink / raw)
  To: gitster; +Cc: jonathantanmy, hanwen, chooglen, git

> > Yes, the packed backend doesn't need to be a ref backend.
> 
> Sorry, I do not follow.  Do you mean we cannot have a version of Git
> that offers say a read-only access to the repository without any
> loose refs, with the default ref backend being the packed one?
> 
> Or do you mean that we can ignore such a hypothetical use case and
> could reimplement the files backend that can also understand the
> $GIT_DIR/packed-refs file directly without "deferring to another ref
> backend which is 'packed'"?

I meant the latter - more specifically, the files backend could defer to
functions that are not necessarily inside a struct ref_storage_be.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-09-16 22:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-25 23:23 [RFC PATCH 0/2] First steps towards iterating over submodule refs Jonathan Tan
2021-08-25 23:23 ` [RFC PATCH 1/2] refs: make _advance() check struct repo, not flag Jonathan Tan
2021-08-26 16:39   ` Han-Wen Nienhuys
2021-08-26 22:24     ` Jonathan Tan
2021-09-14 22:41       ` Glen Choo
2021-09-15  7:35         ` Han-Wen Nienhuys
2021-09-16 17:26           ` Jonathan Tan
2021-09-16 21:56             ` Junio C Hamano
2021-09-16 22:05               ` Jonathan Tan
2021-09-16 17:24         ` Jonathan Tan
2021-08-25 23:23 ` [RFC PATCH 2/2] refs: add repo paramater to _iterator_peel() Jonathan Tan

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).