git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 6/8] read-cache.c: dump "IEOT" extension as json
Date: Wed, 19 Jun 2019 16:58:56 +0700	[thread overview]
Message-ID: <20190619095858.30124-7-pclouds@gmail.com> (raw)
In-Reply-To: <20190619095858.30124-1-pclouds@gmail.com>

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 read-cache.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/read-cache.c b/read-cache.c
index 04863c3853..200834e77e 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1911,7 +1911,7 @@ struct index_entry_offset_table
 	struct index_entry_offset entries[FLEX_ARRAY];
 };
 
-static struct index_entry_offset_table *read_ieot_extension(const char *mmap, size_t mmap_size, size_t offset);
+static struct index_entry_offset_table *read_ieot_extension(const char *mmap, size_t mmap_size, size_t offset, struct json_writer *jw);
 static void write_ieot_extension(struct strbuf *sb, struct index_entry_offset_table *ieot);
 
 static size_t read_eoie_extension(const char *mmap, size_t mmap_size, struct json_writer *jw);
@@ -2232,6 +2232,8 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
 		nr_threads = 1;
 
 	if (istate->jw) {
+		size_t off;
+
 		jw_object_begin(istate->jw, jw_pretty);
 		jw_object_intmax(istate->jw, "version", istate->version);
 		jw_object_string(istate->jw, "oid", oid_to_hex(&istate->oid));
@@ -2243,8 +2245,11 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
 		 * debugging only, so performance is not a concern.
 		 */
 		nr_threads = 1;
-		/* and dump EOIE extension even with threading off */
-		read_eoie_extension(mmap, mmap_size, istate->jw);
+		/* and dump EOIE/IOET extensions even with threading off */
+		off = read_eoie_extension(mmap, mmap_size, istate->jw);
+		if (off)
+			free(read_ieot_extension(mmap, mmap_size,
+						 off, istate->jw));
 	}
 
 	if (nr_threads > 1) {
@@ -2266,7 +2271,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
 	 * to multi-thread the reading of the cache entries.
 	 */
 	if (extension_offset && nr_threads > 1)
-		ieot = read_ieot_extension(mmap, mmap_size, extension_offset);
+		ieot = read_ieot_extension(mmap, mmap_size, extension_offset, NULL);
 
 	if (ieot) {
 		src_offset += load_cache_entries_threaded(istate, mmap, mmap_size, nr_threads, ieot);
@@ -3630,7 +3635,9 @@ static void write_eoie_extension(struct strbuf *sb, git_hash_ctx *eoie_context,
 
 #define IEOT_VERSION	(1)
 
-static struct index_entry_offset_table *read_ieot_extension(const char *mmap, size_t mmap_size, size_t offset)
+static struct index_entry_offset_table *read_ieot_extension(
+	const char *mmap, size_t mmap_size,
+	size_t offset, struct json_writer *jw)
 {
 	const char *index = NULL;
 	uint32_t extsize, ext_version;
@@ -3666,6 +3673,12 @@ static struct index_entry_offset_table *read_ieot_extension(const char *mmap, si
 		error("invalid number of IEOT entries %d", nr);
 		return NULL;
 	}
+	if (jw) {
+		jw_object_inline_begin_object(jw, "index-entry-offsets");
+		jw_object_intmax(jw, "version", ext_version);
+		jw_object_intmax(jw, "ext-size", extsize);
+		jw_object_inline_begin_array(jw, "entries");
+	}
 	ieot = xmalloc(sizeof(struct index_entry_offset_table)
 		       + (nr * sizeof(struct index_entry_offset)));
 	ieot->nr = nr;
@@ -3674,6 +3687,17 @@ static struct index_entry_offset_table *read_ieot_extension(const char *mmap, si
 		index += sizeof(uint32_t);
 		ieot->entries[i].nr = get_be32(index);
 		index += sizeof(uint32_t);
+
+		if (jw) {
+			jw_array_inline_begin_object(jw);
+			jw_object_intmax(jw, "offset", ieot->entries[i].offset);
+			jw_object_intmax(jw, "count", ieot->entries[i].nr);
+			jw_end(jw);
+		}
+	}
+	if (jw) {
+		jw_end(jw);	/* entries */
+		jw_end(jw);	/* index-entry-offsets */
 	}
 
 	return ieot;
-- 
2.22.0.rc0.322.g2b0371e29a


  parent reply	other threads:[~2019-06-19  9:59 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-19  9:58 [PATCH 0/8] Add 'ls-files --json' to dump the index in json Nguyễn Thái Ngọc Duy
2019-06-19  9:58 ` [PATCH 1/8] ls-files: add --json to dump the index Nguyễn Thái Ngọc Duy
2019-06-19 10:30   ` Ævar Arnfjörð Bjarmason
2019-06-19 13:03   ` Derrick Stolee
2019-06-21 13:04     ` Johannes Schindelin
2019-06-24 12:50     ` Duy Nguyen
2019-06-19  9:58 ` [PATCH 2/8] split-index.c: dump "link" extension as json Nguyễn Thái Ngọc Duy
2019-06-19  9:58 ` [PATCH 3/8] fsmonitor.c: dump "FSMN" " Nguyễn Thái Ngọc Duy
2019-06-19  9:58 ` [PATCH 4/8] resolve-undo.c: dump "REUC" " Nguyễn Thái Ngọc Duy
2019-06-19 13:16   ` Derrick Stolee
2019-06-19  9:58 ` [PATCH 5/8] read-cache.c: dump "EOIE" " Nguyễn Thái Ngọc Duy
2019-06-19  9:58 ` Nguyễn Thái Ngọc Duy [this message]
2019-06-19 13:18   ` [PATCH 6/8] read-cache.c: dump "IEOT" " Derrick Stolee
2019-06-19 13:24     ` Duy Nguyen
2019-06-19 14:26       ` Derrick Stolee
2019-06-19  9:58 ` [PATCH 7/8] cache-tree.c: dump "TREE" " Nguyễn Thái Ngọc Duy
2019-06-19  9:58 ` [PATCH 8/8] dir.c: dump "UNTR" " Nguyễn Thái Ngọc Duy
2019-06-19 11:58 ` [PATCH 0/8] Add 'ls-files --json' to dump the index in json Derrick Stolee
2019-06-19 12:42   ` Duy Nguyen
2019-06-19 12:48     ` Derrick Stolee
2019-06-19 19:17 ` Jeff King
2019-06-21  8:37   ` Duy Nguyen
2019-06-21 20:48     ` Jeff King
2019-06-21 13:16   ` Johannes Schindelin
2019-06-21 13:49     ` Duy Nguyen
2019-06-21 15:10       ` Junio C Hamano
2019-06-21 20:52         ` Jeff King
2019-06-24  9:35           ` Johannes Schindelin
2019-06-24  9:33       ` Johannes Schindelin
2019-06-24  9:35         ` Duy Nguyen
2019-06-21 20:51     ` Jeff King
2019-06-24  9:52       ` Johannes Schindelin
2019-06-20  4:00 ` Junio C Hamano
2019-06-20 19:12 ` Jeff Hostetler
2019-06-21 23:30 ` brian m. carlson
2019-06-22  2:54   ` Duy Nguyen

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20190619095858.30124-7-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).