Re: [PATCH 1/9] refs: make _advance() check struct repo, not flag
flat view
From: Jeff King <hidden>
Date: 2021-09-24 18:13:44
On Tue, Sep 21, 2021 at 09:51:03AM -0700, Jonathan Tan 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)
I think your goal here of passing around a repository object is good. But rolling the meaning of DO_FOR_EACH_INCLUDE_BROKEN into an implicit "do we have a non-NULL repository" makes things awkward, I think. As you noticed, we can't get rid of the flags parameter entirely. We still have DO_FOR_EACH_PER_WORKTREE_ONLY. But I also have a series which adds another flag which pairs with INCLUDE_BROKEN. Having half of the logic implicit in the repository pointer and half in a flag would be weird. I'll post that series in a moment, but what I'm wondering here is: would it be that big a deal to just pass the repository object around, and it is simply not used if INCLUDE_BROKEN is passed? -Peff