git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC] upload-pack: fix slow fetches from a shallow repository

From
Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 17, 2026, 22:11 UTC
Message-ID
<pull.2455.git.git.1792275106640.gitgitgadget@gmail.com>
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
Next: Junio C Hamano
Message 1 of 5 in “upload-pack: fix slow fetches from a shallow repository”
  1. upload-pack: fix slow fetches from a shallow repositoryHarald Nordgren via GitGitGadget, Oct 17, 2026
  2. Junio C HamanoOct 19, 2026
  3. Harald NordgrenOct 19, 2026
  4. upload-pack: fix slow fetches from a shallow repositoryHarald Nordgren via GitGitGadget, Oct 20, 2026
  5. Harald NordgrenNov 11, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.