* [PATCH/RFC] upload-pack: fix slow fetches from a shallow repository
@ 2026-10-17 22:11 Harald Nordgren via GitGitGadget
0 siblings, 0 replies; only message in thread
From: Harald Nordgren via GitGitGadget @ 2026-10-17 22:11 UTC (permalink / raw)
To: git; +Cc: Harald Nordgren, Harald Nordgren
From: Harald Nordgren <haraldnordgren@gmail.com>
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 <haraldnordgren@gmail.com>
---
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-17 22:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-17 22:11 [PATCH/RFC] upload-pack: fix slow fetches from a shallow repository Harald Nordgren via GitGitGadget
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox