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

[PATCH 19/21] index-pack, pack-objects: allow creating .idx v2 with .pack v4

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Sep 11, 2013, 06:06 UTC
Message-ID
<1378879582-15372-20-git-send-email-pclouds@gmail.com>
In-Reply-To
<1378879582-15372-1-git-send-email-pclouds@gmail.com>

While .idx v3 is recommended because it's smaller, there is no reason why .idx v2 can't use with .pack v4. Enable it, at least for the test suite as some tests need to this kind of information from show-index and show-index does not support .idx v3.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/index-pack.c   | 14 ++++++++++----
 builtin/pack-objects.c | 14 ++++++++++----
 2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 1895adf..4607dc6 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -89,7 +89,7 @@ static int verbose;
 static int show_stat;
 static int check_self_contained_and_connected;
 static int packv4;
-
+static int idx_version_set;
 static struct progress *progress;
 
 /* We always read in 4kB chunks. */
@@ -1892,8 +1892,9 @@ static int git_index_pack_config(const char *k, const char *v, void *cb)
 
 	if (!strcmp(k, "pack.indexversion")) {
 		opts->version = git_config_int(k, v);
-		if (opts->version > 2)
+		if (opts->version > 3)
 			die(_("bad pack.indexversion=%"PRIu32), opts->version);
+		idx_version_set = 1;
 		return 0;
 	}
 	if (!strcmp(k, "pack.threads")) {
@@ -2107,12 +2108,13 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 			} else if (!prefixcmp(arg, "--index-version=")) {
 				char *c;
 				opts.version = strtoul(arg + 16, &c, 10);
-				if (opts.version > 2)
+				if (opts.version > 3)
 					die(_("bad %s"), arg);
 				if (*c == ',')
 					opts.off32_limit = strtoul(c+1, &c, 0);
 				if (*c || opts.off32_limit & 0x80000000)
 					die(_("bad %s"), arg);
+				idx_version_set = 1;
 			} else
 				usage(index_pack_usage);
 			continue;
@@ -2151,6 +2153,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 		if (!index_name)
 			die(_("--verify with no packfile name given"));
 		read_idx_option(&opts, index_name);
+		idx_version_set = 1;
 		opts.flags |= WRITE_IDX_VERIFY | WRITE_IDX_STRICT;
 	}
 	if (strict)
@@ -2167,6 +2170,9 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 
 	curr_pack = open_pack_file(pack_name);
 	parse_pack_header();
+	if (!packv4 && opts.version >= 3)
+		die(_("pack idx version %d does not work with pack version %d"),
+		    opts.version, 4);
 	objects = xcalloc(nr_objects + 1, sizeof(struct object_entry));
 	deltas = xcalloc(nr_objects, sizeof(struct delta_entry));
 	parse_dictionaries();
@@ -2180,7 +2186,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 	if (show_stat)
 		show_pack_info(stat_only);
 
-	if (packv4)
+	if (packv4 && !idx_version_set)
 		opts.version = 3;
 
 	idx_objects = xmalloc((nr_objects) * sizeof(struct pack_idx_entry *));
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index ac25973..f604fa5 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -66,7 +66,7 @@ static uint32_t nr_objects, nr_alloc, nr_result, nr_written;
 
 static struct packv4_tables v4;
 
-static int non_empty;
+static int non_empty, idx_version_set;
 static int reuse_delta = 1, reuse_object = 1;
 static int keep_unreachable, unpack_unreachable, include_tag;
 static unsigned long unpack_unreachable_expiration;
@@ -2205,7 +2205,8 @@ static void prepare_pack(int window, int depth)
 		sort_dict_entries_by_hits(v4.commit_ident_table);
 		sort_dict_entries_by_hits(v4.tree_path_table);
 		v4.all_objs = xmalloc(nr_objects * sizeof(*v4.all_objs));
-		pack_idx_opts.version = 3;
+		if (!idx_version_set)
+			pack_idx_opts.version = 3;
 		allow_ofs_delta = 0;
 	}
 
@@ -2319,9 +2320,10 @@ static int git_pack_config(const char *k, const char *v, void *cb)
 	}
 	if (!strcmp(k, "pack.indexversion")) {
 		pack_idx_opts.version = git_config_int(k, v);
-		if (pack_idx_opts.version > 2)
+		if (pack_idx_opts.version > 3)
 			die("bad pack.indexversion=%"PRIu32,
 			    pack_idx_opts.version);
+		idx_version_set = 1;
 		return 0;
 	}
 	return git_default_config(k, v, cb);
@@ -2604,12 +2606,13 @@ static int option_parse_index_version(const struct option *opt,
 	char *c;
 	const char *val = arg;
 	pack_idx_opts.version = strtoul(val, &c, 10);
-	if (pack_idx_opts.version > 2)
+	if (pack_idx_opts.version > 3)
 		die(_("unsupported index version %s"), val);
 	if (*c == ',' && c[1])
 		pack_idx_opts.off32_limit = strtoul(c+1, &c, 0);
 	if (*c || pack_idx_opts.off32_limit & 0x80000000)
 		die(_("bad index version '%s'"), val);
+	idx_version_set = 1;
 	return 0;
 }
 
@@ -2739,6 +2742,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 		usage_with_options(pack_usage, pack_objects_options);
 	if (pack_version != 2 && pack_version != 4)
 		die(_("pack version %d is not supported"), pack_version);
+	if (pack_version < 4 && pack_idx_opts.version >= 3)
+		die(_("pack idx version %d cannot be used with pack version %d"),
+		    pack_idx_opts.version, pack_version);
 
 	rp_av[rp_ac++] = "pack-objects";
 	if (thin) {
-- 
1.8.2.82.gc24b958
Previous: Nguyễn Thái Ngọc DuyNext: Nicolas Pitre
Message 26 of 36 in “[PULL REQUEST] initial pack v4 support”
  1. Nicolas PitreSep 9, 2013
  2. Junio C HamanoSep 9, 2013
  3. Junio C HamanoSep 10, 2013
  4. Nicolas PitreSep 10, 2013
  5. Junio C HamanoSep 10, 2013
  6. Nicolas PitreSep 10, 2013
  7. 00/21 np/pack-v4 updatesNguyễn Thái Ngọc Duy, Sep 11, 2013
  8. 01/21 fixup! pack-objects: prepare SHA-1 table in v4Nguyễn Thái Ngọc Duy, Sep 11, 2013
  9. 02/21 fixup! pack-objects: support writing pack v4Nguyễn Thái Ngọc Duy, Sep 11, 2013
  10. 03/21 fixup! pack v4: support "end-of-pack" indicator in index-pack and pack-objectsNguyễn Thái Ngọc Duy, Sep 11, 2013
  11. 04/21 fixup! index-pack: parse v4 header and dictionariesNguyễn Thái Ngọc Duy, Sep 11, 2013
  12. 05/21 fixup! index-pack: record all delta bases in v4 (tree and ref-delta)Nguyễn Thái Ngọc Duy, Sep 11, 2013
  13. 06/21 pack v4: lift dict size check in load_dict()Nguyễn Thái Ngọc Duy, Sep 11, 2013
  14. 07/21 pack v4: move pv4 objhdr parsing code to packv4-parse.cNguyễn Thái Ngọc Duy, Sep 11, 2013
  15. 08/21 pack-objects: respect compression level in v4Nguyễn Thái Ngọc Duy, Sep 11, 2013
  16. 09/21 pack-objects: recognize v4 as pack sourceNguyễn Thái Ngọc Duy, Sep 11, 2013
  17. 10/21 pack v4: add a note that streaming does not support OBJ_PV4_*Nguyễn Thái Ngọc Duy, Sep 11, 2013
  18. 11/21 unpack-objects: report missing object nameNguyễn Thái Ngọc Duy, Sep 11, 2013
  19. 12/21 unpack-objects: recognize end-of-pack in v4 thin packNguyễn Thái Ngọc Duy, Sep 11, 2013
  20. 13/21 unpack-objects: read v4 dictionariesNguyễn Thái Ngọc Duy, Sep 11, 2013
  21. 14/21 unpack-objects: decode v4 object headerNguyễn Thái Ngọc Duy, Sep 11, 2013
  22. 15/21 unpack-objects: decode v4 ref-deltaNguyễn Thái Ngọc Duy, Sep 11, 2013
  23. 16/21 unpack-objects: decode v4 commitsNguyễn Thái Ngọc Duy, Sep 11, 2013
  24. 17/21 unpack-objects: allow to save processed bytes to a bufferNguyễn Thái Ngọc Duy, Sep 11, 2013
  25. 18/21 unpack-objects: decode v4 treesNguyễn Thái Ngọc Duy, Sep 11, 2013
  26. 19/21 index-pack, pack-objects: allow creating .idx v2 with .pack v4Nguyễn Thái Ngọc Duy, Sep 11, 2013
  27. Nicolas PitreSep 11, 2013
  28. 20/21 show-index: acknowledge that it does not read .idx v3Nguyễn Thái Ngọc Duy, Sep 11, 2013
  29. Nicolas PitreSep 11, 2013
  30. 21/21 t1050, t5500: replace the use of "show-index|wc -l" with verify-packNguyễn Thái Ngọc Duy, Sep 11, 2013
  31. Duy NguyenSep 11, 2013
  32. Nicolas PitreSep 11, 2013
  33. Duy NguyenSep 12, 2013
  34. Nicolas PitreSep 12, 2013
  35. Duy NguyenSep 13, 2013
  36. Nicolas PitreSep 11, 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.