From: Harald Nordgren via GitGitGadget Date: Sat, 17 Oct 2026 22:11:46 GMT Subject: [PATCH/RFC] upload-pack: fix slow fetches from a shallow repository Message-ID: From: Harald Nordgren Fetching from a shallow repository with a long history can hang. In a homebrew-core clone with 900k commits, fetching one new commit into another clone took 7 minutes. The same fetch over protocol v0 takes about a second. Over protocol v2, the server goes through all of its history to work out which of its shallow commits to tell the client about, and a history with many merges makes it go over the same commits again and again. Protocol v0 lists all shallow commits and lets the client sort them out. Do the same in v2 when the client does not ask for a depth. This also makes `git clone --reject-shallow` refuse a shallow repository over v2 in every case, as it already does over v0. For `git fetch --unshallow`, which still needs to go through the history, visit each commit only once. Signed-off-by: Harald Nordgren --- upload-pack: fix slow fetches from a shallow repository Fix git fetch hanging for minutes when the remote is a shallow repository with a long history. Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2455%2FHaraldNordgren%2Fupload-pack-shallow-walk-v1 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2455/HaraldNordgren/upload-pack-shallow-walk-v1 Pull-Request: https://github.com/git/git/pull/2455 shallow.c | 3 ++- upload-pack.c | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/shallow.c b/shallow.c index 8e244a5669..921db5e17a 100644 --- a/shallow.c +++ b/shallow.c @@ -209,7 +209,8 @@ static struct commit_list *get_shallows_or_depth(struct object_array *heads, *depth_slot = xmalloc(sizeof(int)); **depth_slot = cur_depth; } else { - if (cur_depth >= **depth_slot) + if (depth == INFINITE_DEPTH || + cur_depth >= **depth_slot) continue; **depth_slot = cur_depth; } diff --git a/upload-pack.c b/upload-pack.c index 197bcfa279..844bf80575 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -1718,9 +1718,8 @@ static void send_shallow_info(struct upload_pack_data *data) packet_writer_write(&data->writer, "shallow-info\n"); - if (!send_shallow_list(data) && - is_repository_shallow(the_repository)) - deepen(data, INFINITE_DEPTH); + if (!send_shallow_list(data)) + advertise_shallow_grafts(1); packet_delim(1); } base-commit: c51408889c3b372814bc20b9431c3b74d0d268eb -- gitgitgadget