Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- json-writer.c | 14 ++++++++++++++ json-writer.h | 2 ++ split-index.c | 13 ++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/json-writer.c b/json-writer.c index 281bc50b39..70403580ca 100644 --- a/json-writer.c +++ b/json-writer.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "ewah/ewok.h" #include "json-writer.h" void jw_init(struct json_writer *jw) @@ -218,6 +219,19 @@ void jw_object_stat_data(struct json_writer *jw, const char *name, jw_end(jw); } +static void dump_ewah_one(size_t pos, void *jw) +{ + jw_array_intmax(jw, pos); +} + +void jw_object_ewah(struct json_writer *jw, const char *key, + struct ewah_bitmap *ewah) +{ + jw_object_inline_begin_array(jw, key); + ewah_each_bit(ewah, dump_ewah_one, jw); + jw_end(jw); +} + static void increase_indent(struct strbuf *sb, const struct json_writer *jw, int indent) diff --git a/json-writer.h b/json-writer.h index 38f9c9bf68..3c173647d3 100644 --- a/json-writer.h +++ b/json-writer.h @@ -85,6 +85,8 @@ void jw_object_bool(struct json_writer *jw, const char *key, int value); void jw_object_null(struct json_writer *jw, const char *key); void jw_object_stat_data(struct json_writer *jw, const char *key, const struct stat_data *sd); +void jw_object_ewah(struct json_writer *jw, const char *key, + struct ewah_bitmap *ewah); void jw_object_sub_jw(struct json_writer *jw, const char *key, const struct json_writer *value); diff --git a/split-index.c b/split-index.c index e6154e4ea9..d7b4420c92 100644 --- a/split-index.c +++ b/split-index.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "json-writer.h" #include "split-index.h" #include "ewah/ewok.h" @@ -16,6 +17,7 @@ int read_link_extension(struct index_state *istate, { const unsigned char *data = data_; struct split_index *si; + unsigned long original_sz = sz; int ret; if (sz < the_hash_algo->rawsz) @@ -25,7 +27,7 @@ int read_link_extension(struct index_state *istate, data += the_hash_algo->rawsz; sz -= the_hash_algo->rawsz; if (!sz) - return 0; + goto done; si->delete_bitmap = ewah_new(); ret = ewah_read_mmap(si->delete_bitmap, data, sz); if (ret < 0) @@ -38,6 +40,15 @@ int read_link_extension(struct index_state *istate, return error("corrupt replace bitmap in link extension"); if (ret != sz) return error("garbage at the end of link extension"); +done: + if (istate->jw) { + jw_object_inline_begin_object(istate->jw, "split-index"); + jw_object_string(istate->jw, "oid", oid_to_hex(&si->base_oid)); + jw_object_ewah(istate->jw, "delete-bitmap", si->delete_bitmap); + jw_object_ewah(istate->jw, "replace-bitmap", si->replace_bitmap); + jw_object_intmax(istate->jw, "ext-size", original_sz); + jw_end(istate->jw); + } return 0; } -- 2.22.0.rc0.322.g2b0371e29a