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

[PATCH v3 4/4] upload-pack: use --objects-edge-aggressive for shallow fetches

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Dec 23, 2014, 12:01 UTC
Message-ID
<1419336082-283091-5-git-send-email-sandals@crustytoothpaste.net>
In-Reply-To
<1419336082-283091-1-git-send-email-sandals@crustytoothpaste.net>

When fetching into a shallow repository, we want to aggressively mark edges as uninteresting, since this decreases the pack size. However, is_shallow_repository() returns false on the server side, since the server is not shallow.

As the server, we get an indication of whether the client is shallow based on stdin; however, by the time we get to parsing stdin, we already will have called setup_revisions and won't be able to change our decision anymore. Teach pack-objects a --shallow option to indicate that the remote side is shallow and use it in upload-pack.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 Documentation/git-pack-objects.txt | 7 ++++++-
 builtin/pack-objects.c             | 5 ++++-
 upload-pack.c                      | 4 +++-
 3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-pack-objects.txt b/Documentation/git-pack-objects.txt
index d2d8f47..c2f76fb 100644
--- a/Documentation/git-pack-objects.txt
+++ b/Documentation/git-pack-objects.txt
@@ -13,7 +13,7 @@ SYNOPSIS
 	[--no-reuse-delta] [--delta-base-offset] [--non-empty]
 	[--local] [--incremental] [--window=<n>] [--depth=<n>]
 	[--revs [--unpacked | --all]] [--stdout | base-name]
-	[--keep-true-parents] < object-list
+	[--shallow] [--keep-true-parents] < object-list
 
 
 DESCRIPTION
@@ -190,6 +190,11 @@ required objects and is thus unusable by Git without making it
 self-contained. Use `git index-pack --fix-thin`
 (see linkgit:git-index-pack[1]) to restore the self-contained property.
 
+--shallow::
+	Optimize a pack that will be provided to a client with a shallow
+	repository.  This option, combined with \--thin, can result in a
+	smaller pack at the cost of speed.
+
 --delta-base-offset::
 	A packed archive can express the base object of a delta as
 	either a 20-byte object name or as an offset in the
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index f3ba861..6bfbd3d 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2613,6 +2613,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 {
 	int use_internal_rev_list = 0;
 	int thin = 0;
+	int shallow = 0;
 	int all_progress_implied = 0;
 	struct argv_array rp = ARGV_ARRAY_INIT;
 	int rev_list_unpacked = 0, rev_list_all = 0, rev_list_reflog = 0;
@@ -2677,6 +2678,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 		  PARSE_OPT_OPTARG, option_parse_unpack_unreachable },
 		OPT_BOOL(0, "thin", &thin,
 			 N_("create thin packs")),
+		OPT_BOOL(0, "shallow", &shallow,
+			 N_("create packs suitable for shallow fetches")),
 		OPT_BOOL(0, "honor-pack-keep", &ignore_packed_keep,
 			 N_("ignore packs that have companion .keep file")),
 		OPT_INTEGER(0, "compression", &pack_compression_level,
@@ -2711,7 +2714,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 	argv_array_push(&rp, "pack-objects");
 	if (thin) {
 		use_internal_rev_list = 1;
-		argv_array_push(&rp, is_repository_shallow()
+		argv_array_push(&rp, is_repository_shallow() || shallow
 				? "--objects-edge-aggressive"
 				: "--objects-edge");
 	} else
diff --git a/upload-pack.c b/upload-pack.c
index ac9ac15..b531a32 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -86,7 +86,7 @@ static void create_pack_file(void)
 		"corruption on the remote side.";
 	int buffered = -1;
 	ssize_t sz;
-	const char *argv[12];
+	const char *argv[13];
 	int i, arg = 0;
 	FILE *pipe_fd;
 
@@ -100,6 +100,8 @@ static void create_pack_file(void)
 		argv[arg++] = "--thin";
 
 	argv[arg++] = "--stdout";
+	if (shallow_nr)
+		argv[arg++] = "--shallow";
 	if (!no_progress)
 		argv[arg++] = "--progress";
 	if (use_ofs_delta)
-- 
2.2.1.209.g41e5f3a
Previous: brian m. carlsonNext: Junio C Hamano
Message 9 of 11 in “Improve push performance with lots of refs”
  1. 0/4 Improve push performance with lots of refsbrian m. carlson, Dec 23, 2014
  2. 1/4 Documentation: add missing article in rev-list-options.txtbrian m. carlson, Dec 23, 2014
  3. 2/4 rev-list: add an option to mark fewer edges as uninterestingbrian m. carlson, Dec 23, 2014
  4. Michael BlumeDec 23, 2014
  5. Jeff KingDec 23, 2014
  6. Junio C HamanoDec 23, 2014
  7. brian m. carlsonDec 24, 2014
  8. 3/4 pack-objects: use --objects-edge-aggressive only for shallow reposbrian m. carlson, Dec 23, 2014
  9. 4/4 upload-pack: use --objects-edge-aggressive for shallow fetchesbrian m. carlson, Dec 23, 2014
  10. Junio C HamanoDec 23, 2014
  11. brian m. carlsonDec 24, 2014

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.