git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Nicolas Pitre" <nico@fluxnic.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 19/21] index-pack, pack-objects: allow creating .idx v2 with .pack v4
Date: Wed, 11 Sep 2013 13:06:20 +0700	[thread overview]
Message-ID: <1378879582-15372-20-git-send-email-pclouds@gmail.com> (raw)
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

  parent reply	other threads:[~2013-09-11  6:09 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-09 19:52 [PULL REQUEST] initial pack v4 support Nicolas Pitre
2013-09-09 22:28 ` Junio C Hamano
2013-09-10 21:21 ` Junio C Hamano
2013-09-10 21:32   ` Nicolas Pitre
2013-09-10 21:52     ` Junio C Hamano
2013-09-10 22:31   ` Nicolas Pitre
2013-09-11  6:06   ` [PATCH 00/21] np/pack-v4 updates Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 01/21] fixup! pack-objects: prepare SHA-1 table in v4 Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 02/21] fixup! pack-objects: support writing pack v4 Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 03/21] fixup! pack v4: support "end-of-pack" indicator in index-pack and pack-objects Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 04/21] fixup! index-pack: parse v4 header and dictionaries Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 05/21] fixup! index-pack: record all delta bases in v4 (tree and ref-delta) Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 06/21] pack v4: lift dict size check in load_dict() Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 07/21] pack v4: move pv4 objhdr parsing code to packv4-parse.c Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 08/21] pack-objects: respect compression level in v4 Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 09/21] pack-objects: recognize v4 as pack source Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 10/21] pack v4: add a note that streaming does not support OBJ_PV4_* Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 11/21] unpack-objects: report missing object name Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 12/21] unpack-objects: recognize end-of-pack in v4 thin pack Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 13/21] unpack-objects: read v4 dictionaries Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 14/21] unpack-objects: decode v4 object header Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 15/21] unpack-objects: decode v4 ref-delta Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 16/21] unpack-objects: decode v4 commits Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 17/21] unpack-objects: allow to save processed bytes to a buffer Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` [PATCH 18/21] unpack-objects: decode v4 trees Nguyễn Thái Ngọc Duy
2013-09-11  6:06     ` Nguyễn Thái Ngọc Duy [this message]
2013-09-11 15:48       ` [PATCH 19/21] index-pack, pack-objects: allow creating .idx v2 with .pack v4 Nicolas Pitre
2013-09-11  6:06     ` [PATCH 20/21] show-index: acknowledge that it does not read .idx v3 Nguyễn Thái Ngọc Duy
2013-09-11 16:19       ` Nicolas Pitre
2013-09-11  6:06     ` [PATCH 21/21] t1050, t5500: replace the use of "show-index|wc -l" with verify-pack Nguyễn Thái Ngọc Duy
2013-09-11 14:21     ` [PATCH 00/21] np/pack-v4 updates Duy Nguyen
2013-09-11 16:25       ` Nicolas Pitre
2013-09-12  3:38         ` Duy Nguyen
2013-09-12 16:20           ` Nicolas Pitre
2013-09-13  1:11             ` Duy Nguyen
2013-09-11 16:24     ` Nicolas Pitre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1378879582-15372-20-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=nico@fluxnic.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).