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

[PATCH 2/4] pack-objects: support --keep

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 16, 2014, 13:35 UTC
Message-ID
<1394976904-15395-4-git-send-email-pclouds@gmail.com>
In-Reply-To
<1394976904-15395-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-pack-objects.txt |  4 ++++
 builtin/pack-objects.c             | 26 ++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
diff --git a/Documentation/git-pack-objects.txt b/Documentation/git-pack-objects.txt
index cdab9ed..8aae3b5 100644
--- a/Documentation/git-pack-objects.txt
+++ b/Documentation/git-pack-objects.txt
@@ -117,6 +117,10 @@ base-name::
 	has a .keep file to be ignored, even if it would have
 	otherwise been packed.
 
+--keep::
+	Before moving the index into its final destination
+	create an empty .keep file for the associated pack file.
+
 --incremental::
 	This flag causes an object already in a pack to be ignored
 	even if it would have otherwise been packed.
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 1fb972f..46c7a57 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -57,6 +57,7 @@ static int num_preferred_base;
 static struct progress *progress_state;
 static int pack_compression_level = Z_DEFAULT_COMPRESSION;
 static int pack_compression_seen;
+static int keep_pack;
 
 static struct packed_git *reuse_packfile;
 static uint32_t reuse_packfile_objects;
@@ -745,6 +746,23 @@ static off_t write_reused_pack(struct sha1file *f)
 	return reuse_packfile_offset - sizeof(struct pack_header);
 }
 
+static void write_keep_file(const unsigned char *sha1)
+{
+	const char *msg = "pack-objects --keep\n";
+	char name[PATH_MAX];
+	int keep_fd = odb_pack_keep(name, sizeof(name), sha1);
+	if (keep_fd < 0) {
+		if (errno != EEXIST)
+			die_errno(_("cannot write keep file '%s'"),
+				  name);
+		return;
+	}
+	write_or_die(keep_fd, msg, strlen(msg));
+	if (close(keep_fd) != 0)
+		die_errno(_("cannot close written keep file '%s'"),
+			  name);
+}
+
 static void write_pack_file(void)
 {
 	uint32_t i = 0, j;
@@ -805,6 +823,9 @@ static void write_pack_file(void)
 			struct stat st;
 			char tmpname[PATH_MAX];
 
+			if (keep_pack)
+				write_keep_file(sha1);
+
 			/*
 			 * Packs are runtime accessed in their mtime
 			 * order since newer packs are more likely to contain
@@ -2609,6 +2630,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 			 N_("use a bitmap index if available to speed up counting objects")),
 		OPT_BOOL(0, "write-bitmap-index", &write_bitmap_index,
 			 N_("write a bitmap index together with the pack index")),
+		OPT_BOOL(0, "keep", &keep_pack,
+			 N_("create .keep for the new pack")),
 		OPT_END(),
 	};
 
@@ -2672,6 +2695,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 	if (!pack_to_stdout && thin)
 		die("--thin cannot be used to build an indexable pack.");
 
+	if (pack_to_stdout && keep_pack)
+		die("--keep cannot be used with --stdout");
+
 	if (keep_unreachable && unpack_unreachable)
 		die("--keep-unreachable and --unpack-unreachable are incompatible.");
 
-- 
1.9.0.40.gaa8c3ea
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 4 of 21 in “Better "gc --aggressive"”
  1. 0/4 Better "gc --aggressive"Nguyễn Thái Ngọc Duy, Mar 16, 2014
  2. 1/4 environment.c: fix constness for odb_pack_keep()Nguyễn Thái Ngọc Duy, Mar 16, 2014
  3. index-pack: do not segfault when keep_name is NULLNguyễn Thái Ngọc Duy, Mar 16, 2014
  4. 2/4 pack-objects: support --keepNguyễn Thái Ngọc Duy, Mar 16, 2014
  5. 3/4 gc --aggressive: make --depth configurableNguyễn Thái Ngọc Duy, Mar 16, 2014
  6. 4/4 gc --aggressive: three phase repackingNguyễn Thái Ngọc Duy, Mar 16, 2014
  7. Junio C HamanoMar 17, 2014
  8. Duy NguyenMar 17, 2014
  9. Junio C HamanoMar 17, 2014
  10. Jeff KingMar 18, 2014
  11. Duy NguyenMar 18, 2014
  12. Jeff KingMar 18, 2014
  13. David KastrupMar 18, 2014
  14. Duy NguyenMar 19, 2014
  15. Jeff KingMar 18, 2014
  16. Duy NguyenMar 18, 2014
  17. Duy NguyenMar 18, 2014
  18. David KastrupMar 18, 2014
  19. David KastrupMar 18, 2014
  20. Duy NguyenMar 16, 2014
  21. Duy NguyenMar 20, 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.