Re: [PATCH v2 2/3] builtin/log: prefetch necessary blobs for `git cherry`
- From
Elijah Newren <newren@gmail.com>
- Date
- Apr 21, 2026, 21:28 UTC
- Message-ID
- <CABPp-BF4woakYQ5RZ32J8SzDs_VpvT2Wv+Y2WaHTnFnM=96Kzg@mail.gmail.com>
- In-Reply-To
- <a010a4ad-403a-4b6f-9a92-a33323eca0f2@gmail.com>
Hi Phillip,
On Sun, Apr 19, 2026 at 7:04 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 15 quoted lines
> > Hi Elijah > > On 18/04/2026 01:32, Elijah Newren via GitGitGadget wrote: > > From: Elijah Newren <newren@gmail.com> > > > > In partial clones, `git cherry` fetches necessary blobs on-demand one > > at a time, which can be very slow. We would like to prefetch all > > necessary blobs upfront. To do so, we need to be able to first figure > > out which blobs are needed. > > "git rebase" without "--reapply-cherry-picks" suffers from this problem > as well as it does the equivalent of "git log --cherry-pick". Is there > any way to share prefetch_cherry_blobs() with the cherry-pick detection > in revision.c?
Yes, you're right; git rebase without --reapply-cherry-picks and git log --cherry-pick both go through cherry_pick_list() in revision.c, which has exactly the same shape as the patch-ids loop in cmd_cherry(): build a hashmap of one side via add_commit_patch_id(), then look up the other side via patch_id_iter_first(). The on-demand blob fetches come from the same patch_id_neq() callback.
After poking around, I think the approximate scope of the fix would be: Move collect_diff_blob_oids(), always_match(), and prefetch_cherry_blobs() from builtin/log.c to patch-ids.c and expose the last one in patch-ids.h. In cherry_pick_list(), between the add_commit_patch_id loop and the comparison loop, build a temporary list of just the lookup-side commits (filtering by SYMMETRIC_LEFT/BOUNDARY as the existing loop already does) and call prefetch_cherry_blobs() on it.
That said, I'd rather leave this out of the current series. The bigger picture is that I have reservations about expanding partial-clone support further into this area. git cherry, git log --cherry-pick, and the default cherry-pick detection in git rebase all exist to answer "has this patch already landed upstream?" -- a question that, in repositories large enough to need partial clones, I feel is rarely worth the cost of computing patch-ids across arbitrary amounts of history. The honest guidance I would probably give for users on a large repo is "pass --reapply-cherry-picks (with rebase) and skip this entirely" or to narrow the range under consideration. The omission of a --no-reapply-cherry-picks option in git-replay wasn't a lack of effort or oversight, but a deliberate choice where I'd rather hold off (possibly indefinitely) on implementing it. So I'm a bit reluctant to make the performance hazard less visible without also asking whether we should even be doing that piece of the operation.
I only implemented the git cherry fix because of a specific customer situation where the operation was already baked into tooling, and prefetching at least makes the worst case tolerable. I don't want to hold myself to doing the same for the cherry_pick_list() path, but I'm fairly confident the code here can be re-used for those other cases and I'd help review a patch from anyone who wants to carry it forward.
Anyway, you are making the right connection, it's just that my personal answer is to let some other interested individual do it.