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

[PATCHv7 0/2] Rewriting repack in C

From
Stefan Beller <stefanbeller@googlemail.com>
Date
Aug 29, 2013, 20:39 UTC
Message-ID
<1377808774-12505-1-git-send-email-stefanbeller@googlemail.com>

Hi, I am sorry to have been delaying this patch series for a few days, as I was busy. I'll continue to be busy for the next 2 weeks, so my replies (if needed), will take some time.

The first patch rewrites the repack shell script in C and tries to resemble the functionality as close to the original as possible. The second patch introduces some functional changes intentionally.

Stefan
Here is a diff since the last time sending this patch series:
---
 builtin/repack.c | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/builtin/repack.c b/builtin/repack.c
index 0ace2a3..0cc823d 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -41,10 +41,10 @@ static void remove_temporary_files(void)
 
 	strbuf_addstr(&buf, packdir);
 
-	/* dirlen holds the length of the path before the file name */
+	/* Point at the slash at the end of ".../objects/pack/" */
 	dirlen = buf.len + 1;
 	strbuf_addf(&buf, "%s", packtmp);
-	/* prefixlen holds the length of the prefix */
+	/* Point at the dash at the end of ".../.tmp-%d-pack-" */
 	prefixlen = buf.len - dirlen;
 
 	while ((e = readdir(dir))) {
@@ -109,9 +109,12 @@ static void remove_redundant_pack(const char *path_prefix, const char *hex)
 	}
 }
 
+#define ALL_INTO_ONE 1
+#define LOOSE_UNREACHABLE 2
+
 int cmd_repack(int argc, const char **argv, const char *prefix)
 {
-	const char *exts[2] = {".idx", ".pack"};
+	const char *exts[2] = {".pack", ".idx"};
 	struct child_process cmd;
 	struct string_list_item *item;
 	struct argv_array cmd_args = ARGV_ARRAY_INIT;
@@ -124,7 +127,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 
 	/* variables to be filled by option parsing */
 	int pack_everything = 0;
-	int pack_everything_but_loose = 0;
 	int delete_redundant = 0;
 	char *unpack_unreachable = NULL;
 	int window = 0, window_memory = 0;
@@ -136,10 +138,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 	int local = 0;
 
 	struct option builtin_repack_options[] = {
-		OPT_BOOL('a', NULL, &pack_everything,
-				N_("pack everything in a single pack")),
-		OPT_BOOL('A', NULL, &pack_everything_but_loose,
-				N_("same as -a, and turn unreachable objects loose")),
+		OPT_BIT('a', NULL, &pack_everything,
+				N_("pack everything in a single pack"), ALL_INTO_ONE),
+		OPT_BIT('A', NULL, &pack_everything,
+				N_("same as -a, and turn unreachable objects loose"), LOOSE_UNREACHABLE),
 		OPT_BOOL('d', NULL, &delete_redundant,
 				N_("remove redundant packs, and run git-prune-packed")),
 		OPT_BOOL('f', NULL, &no_reuse_delta,
@@ -193,7 +195,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 	if (no_reuse_object)
 		argv_array_pushf(&cmd_args, "--no-reuse-object");
 
-	if (!pack_everything && !pack_everything_but_loose) {
+	if (!pack_everything) {
 		argv_array_push(&cmd_args, "--unpacked");
 		argv_array_push(&cmd_args, "--incremental");
 	} else {
@@ -204,7 +206,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 				argv_array_pushf(&cmd_args,
 						"--unpack-unreachable=%s",
 						unpack_unreachable);
-			else if (pack_everything_but_loose)
+			else if (pack_everything & LOOSE_UNREACHABLE)
 				argv_array_push(&cmd_args,
 						"--unpack-unreachable");
 		}
@@ -246,6 +248,12 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 	if (!nr_packs && !quiet)
 		printf("Nothing new to pack.\n");
 
+	/*
+	 * Ok we have prepared all new packfiles.
+	 * First see if there are packs of the same name and if so
+	 * if we can move them out of the way (this can happen if we
+	 * repacked immediately after packing fully.
+	 */
 	failed = 0;
 	for_each_string_list_item(item, &names) {
 		for (ext = 0; ext < 2; ext++) {
@@ -366,5 +374,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 		run_command(&cmd);
 		argv_array_clear(&cmd_args);
 	}
+	remove_temporary_files();
 	return 0;
 }
-- 
1.8.4

Stefan Beller (2):
  repack: rewrite the shell script in C
  repack: retain the return value of pack-objects

 Makefile                                        |   2 +-
 builtin.h                                       |   1 +
 builtin/repack.c                                | 379 ++++++++++++++++++++++++
 git-repack.sh => contrib/examples/git-repack.sh |   0
 git.c                                           |   1 +
 5 files changed, 382 insertions(+), 1 deletion(-)
 create mode 100644 builtin/repack.c
 rename git-repack.sh => contrib/examples/git-repack.sh (100%)

-- 
1.8.4
Next: Stefan Beller
Message 1 of 9 in “[PATCHv7 0/2] Rewriting repack in C”
  1. Stefan BellerAug 29, 2013
  2. 1/2 repack: rewrite the shell script in CStefan Beller, Aug 29, 2013
  3. Felipe ContrerasAug 29, 2013
  4. René ScharfeSep 15, 2013
  5. Stefan BellerSep 15, 2013
  6. Stefan BellerSep 17, 2013
  7. 2/2 repack: retain the return value of pack-objectsStefan Beller, Aug 29, 2013
  8. Junio C HamanoAug 29, 2013
  9. Stefan BellerAug 30, 2013

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.