git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff Hostetler <git@jeffhostetler.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>, git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
	"Derrick Stolee" <stolee@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH v2 04/10] dir.c: dump "UNTR" extension as json
Date: Mon, 24 Jun 2019 15:32:54 -0400	[thread overview]
Message-ID: <ec6bdf73-0c05-80cd-ecab-9a6ebf6aad6e@jeffhostetler.com> (raw)
In-Reply-To: <20190624130226.17293-5-pclouds@gmail.com>



On 6/24/2019 9:02 AM, Nguyễn Thái Ngọc Duy wrote:
> The big part of UNTR extension is dumped at the end instead of dumping
> as soon as we read it, because we actually "patch" some fields in
> untracked_cache_dir with EWAH bitmaps at the end.
> 
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>   dir.c                    | 57 +++++++++++++++++++++++++++++++++++++++-
>   dir.h                    |  4 ++-
>   json-writer.h            |  6 +++++
>   read-cache.c             |  2 +-
>   t/t3011-ls-files-json.sh |  3 ++-
>   t/t3011/basic            | 39 +++++++++++++++++++++++++++
>   6 files changed, 107 insertions(+), 4 deletions(-)
> 
> diff --git a/dir.c b/dir.c
> index ba4a51c296..8808577ea3 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -19,6 +19,7 @@
>   #include "varint.h"
>   #include "ewah/ewok.h"
>   #include "fsmonitor.h"
> +#include "json-writer.h"
>   #include "submodule-config.h"
>   
>   /*
> @@ -2826,7 +2827,42 @@ static void load_oid_stat(struct oid_stat *oid_stat, const unsigned char *data,
>   	oid_stat->valid = 1;
>   }
>   
> -struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz)
> +static void jw_object_oid_stat(struct json_writer *jw, const char *key,
> +			       const struct oid_stat *oid_stat)

I was hoping to reserve the jw_, jw_object_, and jw_array_ prefixes
to refer to public functions in the json-writer.[ch] files, rather
than private functions elsewhere in the code.  I think it is less
confusing that way.  IMHO.

It's fine to have such helper functions for local structure types,
but I think it'd be better for them to not be named like other
public functions.

> +{
> +	jw_object_inline_begin_object(jw, key);
> +	jw_object_bool(jw, "valid", oid_stat->valid);
> +	jw_object_string(jw, "oid", oid_to_hex(&oid_stat->oid));
> +	jw_object_stat_data(jw, "stat", &oid_stat->stat);
> +	jw_end(jw);
> +}
> +
> +static void jw_object_untracked_cache_dir(struct json_writer *jw,
> +					  const struct untracked_cache_dir *ucd)
> +{
> +	int i;
> +
> +	jw_object_bool(jw, "valid", ucd->valid);
> +	jw_object_bool(jw, "check-only", ucd->check_only);
> +	jw_object_stat_data(jw, "stat", &ucd->stat_data);
> +	jw_object_string(jw, "exclude-oid", oid_to_hex(&ucd->exclude_oid));
> +	jw_object_inline_begin_array(jw, "untracked");
> +	for (i = 0; i < ucd->untracked_nr; i++)
> +		jw_array_string(jw, ucd->untracked[i]);
> +	jw_end(jw);
> +
> +	jw_object_inline_begin_object(jw, "dirs");
> +	for (i = 0; i < ucd->dirs_nr; i++) {
> +		jw_object_inline_begin_object(jw, ucd->dirs[i]->name);
> +		jw_object_untracked_cache_dir(jw, ucd->dirs[i]);
> +		jw_end(jw);
> +	}
> +	jw_end(jw);
> +}
> +
> +struct untracked_cache *read_untracked_extension(const void *data,
> +						 unsigned long sz,
> +						 struct json_writer *jw)
>   {
>   	struct untracked_cache *uc;
>   	struct read_data rd;
> @@ -2864,6 +2900,19 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
>   	uc->dir_flags = get_be32(next + ouc_offset(dir_flags));
>   	exclude_per_dir = (const char *)next + exclude_per_dir_offset;
>   	uc->exclude_per_dir = xstrdup(exclude_per_dir);
> +
> +	if (jw) {
> +		jw_object_string(jw, "ident", ident);
> +		jw_object_oid_stat(jw, "info_exclude", &uc->ss_info_exclude);
> +		jw_object_oid_stat(jw, "excludes_file", &uc->ss_excludes_file);
> +		jw_object_intmax(jw, "flags", uc->dir_flags);
> +		if (uc->dir_flags & DIR_SHOW_OTHER_DIRECTORIES)
> +			jw_object_bool(jw, "show_other_directories", 1);
> +		if (uc->dir_flags & DIR_HIDE_EMPTY_DIRECTORIES)
> +			jw_object_bool(jw, "hide_empty_directories", 1);
> +		jw_object_string(jw, "excludes_per_dir", uc->exclude_per_dir);
> +	}
> +
>   	/* NUL after exclude_per_dir is covered by sizeof(*ouc) */
>   	next += exclude_per_dir_offset + strlen(exclude_per_dir) + 1;
>   	if (next >= end)
> @@ -2905,6 +2954,12 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
>   	ewah_each_bit(rd.sha1_valid, read_oid, &rd);
>   	next = rd.data;
>   
> +	if (jw) {
> +		jw_object_inline_begin_object(jw, "root");
> +		jw_object_untracked_cache_dir(jw, uc->root);
> +		jw_end(jw);
> +	}
> +
>   done:
>   	free(rd.ucd);
>   	ewah_free(rd.valid);
> diff --git a/dir.h b/dir.h
> index 680079bbe3..80efdd05c4 100644
> --- a/dir.h
> +++ b/dir.h
> @@ -6,6 +6,8 @@
>   #include "cache.h"
>   #include "strbuf.h"
>   
> +struct json_writer;
> +
>   struct dir_entry {
>   	unsigned int len;
>   	char name[FLEX_ARRAY]; /* more */
> @@ -362,7 +364,7 @@ void untracked_cache_remove_from_index(struct index_state *, const char *);
>   void untracked_cache_add_to_index(struct index_state *, const char *);
>   
>   void free_untracked_cache(struct untracked_cache *);
> -struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz);
> +struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz, struct json_writer *jw);
>   void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked);
>   void add_untracked_cache(struct index_state *istate);
>   void remove_untracked_cache(struct index_state *istate);
> diff --git a/json-writer.h b/json-writer.h
> index c48c4cbf33..c3d0fbd1ef 100644
> --- a/json-writer.h
> +++ b/json-writer.h
> @@ -121,6 +121,12 @@ static inline void jw_object_inline_begin_array_gently(struct json_writer *jw,
>   		jw_object_inline_begin_array(jw, name);
>   }
>   
> +static inline void jw_array_inline_begin_object_gently(struct json_writer *jw)
> +{
> +	if (jw)
> +		jw_array_inline_begin_object(jw);
> +}
> +
>   static inline void jw_end_gently(struct json_writer *jw)
>   {
>   	if (jw)

I'm not sure about the need for these _gently versions, but
maybe make them macros in json-writer.h

Jeff

  reply	other threads:[~2019-06-24 19:32 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-24 13:02 [PATCH v2 00/10] Add 'ls-files --debug-json' to dump the index in json Nguyễn Thái Ngọc Duy
2019-06-24 13:02 ` [PATCH v2 01/10] ls-files: add --json to dump the index Nguyễn Thái Ngọc Duy
2019-06-24 19:15   ` Jeff Hostetler
2019-06-24 20:04     ` Junio C Hamano
2019-06-25  9:21     ` Johannes Schindelin
2019-06-25  9:52     ` Duy Nguyen
2019-06-25 15:37       ` Jeff Hostetler
2019-06-25  9:05   ` Thomas Gummerer
2019-06-25  9:44   ` Johannes Schindelin
2019-06-25 11:31     ` Johannes Schindelin
2019-06-25 13:57       ` Johannes Schindelin
2019-06-25 22:28     ` Junio C Hamano
2019-06-26 19:51   ` Junio C Hamano
2019-06-24 13:02 ` [PATCH v2 02/10] read-cache.c: dump common extension info in json Nguyễn Thái Ngọc Duy
2019-06-24 13:02 ` [PATCH v2 03/10] cache-tree.c: dump "TREE" extension as json Nguyễn Thái Ngọc Duy
2019-06-24 13:02 ` [PATCH v2 04/10] dir.c: dump "UNTR" " Nguyễn Thái Ngọc Duy
2019-06-24 19:32   ` Jeff Hostetler [this message]
2019-06-24 13:02 ` [PATCH v2 05/10] split-index.c: dump "link" " Nguyễn Thái Ngọc Duy
2019-06-24 20:06   ` Jeff Hostetler
2019-06-25 10:29     ` Duy Nguyen
2019-06-25 12:40       ` Derrick Stolee
2019-06-27 10:48         ` Duy Nguyen
2019-06-27 13:24           ` Jeff Hostetler
2019-06-27 13:42             ` Derrick Stolee
2019-06-27 13:47               ` Duy Nguyen
2019-07-03  9:08   ` SZEDER Gábor
2019-07-04 20:01   ` SZEDER Gábor
2019-07-04 23:54     ` Duy Nguyen
2019-07-08 17:58       ` Junio C Hamano
2019-06-24 13:02 ` [PATCH v2 06/10] fsmonitor.c: dump "FSMN" " Nguyễn Thái Ngọc Duy
2019-06-24 13:02 ` [PATCH v2 07/10] resolve-undo.c: dump "REUC" " Nguyễn Thái Ngọc Duy
2019-06-24 13:02 ` [PATCH v2 08/10] read-cache.c: dump "EOIE" " Nguyễn Thái Ngọc Duy
2019-06-24 13:02 ` [PATCH v2 09/10] read-cache.c: dump "IEOT" " Nguyễn Thái Ngọc Duy
2019-06-24 13:02 ` [PATCH v2 10/10] t3008: use the new SINGLE_CPU prereq Nguyễn Thái Ngọc Duy
2019-06-24 18:00 ` [PATCH v2 00/10] Add 'ls-files --debug-json' to dump the index in json Johannes Schindelin
2019-06-24 18:39   ` Jeff Hostetler
2019-06-25  9:05   ` Duy Nguyen
2019-06-25  9:38     ` Thomas Gummerer
2019-06-25 11:27     ` Johannes Schindelin
2019-06-25 12:06       ` Duy Nguyen
2019-06-25 14:10         ` Johannes Schindelin
2019-06-25 17:08           ` Ramsay Jones
2019-06-26 15:05             ` Johannes Schindelin

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=ec6bdf73-0c05-80cd-ecab-9a6ebf6aad6e@jeffhostetler.com \
    --to=git@jeffhostetler.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=stolee@gmail.com \
    /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).