git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
	Hariom Verma <hariom18599@gmail.com>,
	Christian Couder <christian.couder@gmail.com>,
	ZheNing Hu <adlternative@gmail.com>
Subject: [PATCH v2 0/2] [GSOC][RFC] ref-filter: introduce enum atom_type
Date: Mon, 10 May 2021 15:03:17 +0000	[thread overview]
Message-ID: <pull.951.v2.git.1620659000.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.951.git.1620487353.gitgitgadget@gmail.com>

Change from last version:

 * Remove the atom_type member from valid_atom at the suggestion of
   Christian and Junio, and use ATOM_* as the coordinates of valid_atom.
 * Add ATOM_INVALID and ATOM_UNKNOWN under Christian's suggestion, we can
   traverse valid_atom through them.
 * Add a note about enum atom_type to remind readers of its role.

ZheNing Hu (2):
  [GSOC] ref-filter: add objectsize to used_atom
  [GSOC] ref-filter: introduce enum atom_type

 ref-filter.c | 231 ++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 155 insertions(+), 76 deletions(-)


base-commit: 7e391989789db82983665667013a46eabc6fc570
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-951%2Fadlternative%2Fref-filter-atom-type-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-951/adlternative/ref-filter-atom-type-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/951

Range-diff vs v1:

 1:  91ca57c9d04a = 1:  91ca57c9d04a [GSOC] ref-filter: add objectsize to used_atom
 2:  3770df182983 ! 2:  a1f70b39b7ef [GSOC][RFC] ref-filter: introduce enum atom_type
     @@ Metadata
      Author: ZheNing Hu <adlternative@gmail.com>
      
       ## Commit message ##
     -    [GSOC][RFC] ref-filter: introduce enum atom_type
     +    [GSOC] ref-filter: introduce enum atom_type
      
          In the original ref-filter design, it will copy the parsed
          atom's name and attributes to `used_atom[i].name` in the
     @@ Commit message
          in the later specific ref attributes filling step. It use
          a lot of string matching to determine which atom we need.
      
     -    Introduce the enum member `valid_atom.atom_type` which
     -    record type of each valid_atom, in the first step of the
     -    atom parsing, `used_atom.atom_type` will record corresponding
     -    enum value from `valid_atom.atom_type`, and then in specific
     -    reference attribute filling step, only need to compare the
     -    value of the `used_atom.atom_type` to judge the atom type.
     +    Introduce the enum "atom_type", each enum value is named
     +    as `ATOM_*`, which is the index of each corresponding
     +    valid_atom entry. In the first step of the atom parsing,
     +    `used_atom.atom_type` will record corresponding enum value
     +    from valid_atom entry index, and then in specific reference
     +    attribute filling step, only need to compare the value of
     +    the `used_atom.atom_type` to judge the atom type.
      
     -    At the same time, The value of an atom_type is the coordinate
     -    of its corresponding valid_atom entry, we can quickly index
     -    to the corresponding valid_atom entry by the atom_type value.
     +    the enum value of `ATOM_UNKNOWN` is equals to zero, which
     +    could ensure that we can easily distinguish such a struct
     +    where the atom_type is known from such a struct where it
     +    is unknown yet.
     +
     +    the enum value of `ATOM_INVALID` is equals to the size of
     +    valid_atom array, which could help us iterate over
     +    valid_atom array using something like:
     +
     +    for (i = ATOM_UNKNOWN + 1; i < ATOM_INVALID; i++)
     +            /* do something with valid_atom[i] */;
      
          Signed-off-by: ZheNing Hu <adlternative@gmail.com>
      
     @@ ref-filter.c: static struct ref_to_worktree_map {
       	struct worktree **worktrees;
       } ref_to_worktree_map;
       
     ++/*
     ++ * The enum atom_type is used as the coordinates of valid_atom entry.
     ++ * In the atom parsing stage, it will be passed to used_atom.atom_type
     ++ * as the identifier of the atom type. We can judge the type of used_atom
     ++ * entry by `if (used_atom[i].atom_type == ATOM_*)`.
     ++ *
     ++ * ATOM_UNKNOWN equals to 0, used as an enumeration value of uninitialized
     ++ * atom_type.
     ++ * ATOM_INVALID equals to the size of valid_atom array, which could help us
     ++ * iterate over valid_atom array like this:
     ++ *
     ++ * 	for (i = ATOM_UNKNOWN + 1; i < ATOM_INVALID; i++) {
     ++ *		int len = strlen(valid_atom[i].name);
     ++ *		if (len == atom_len && !memcmp(valid_atom[i].name, sp, len))
     ++ *			break;
     ++ *	}
     ++ */
      +enum atom_type {
     ++ATOM_UNKNOWN,
      +ATOM_REFNAME,
      +ATOM_OBJECTTYPE,
      +ATOM_OBJECTSIZE,
     @@ ref-filter.c: static struct ref_to_worktree_map {
      +ATOM_IF,
      +ATOM_THEN,
      +ATOM_ELSE,
     ++ATOM_INVALID,
      +};
      +
       /*
        * An atom is a valid field atom listed below, possibly prefixed with
        * a "*" to denote deref_tag().
     -@@ ref-filter.c: static struct used_atom {
     - 	const char *name;
     - 	cmp_type type;
     - 	info_source source;
     -+	enum atom_type atom_type;
     - 	union {
     - 		char color[COLOR_MAXLEN];
     - 		struct align align;
     -@@ ref-filter.c: static int head_atom_parser(const struct ref_format *format, struct used_atom *a
     - }
     - 
     - static struct {
     +@@ ref-filter.c: static struct ref_to_worktree_map {
     +  * array.
     +  */
     + static struct used_atom {
      +	enum atom_type atom_type;
       	const char *name;
     + 	cmp_type type;
       	info_source source;
     - 	cmp_type cmp_type;
     +@@ ref-filter.c: static struct {
       	int (*parser)(const struct ref_format *format, struct used_atom *atom,
       		      const char *arg, struct strbuf *err);
       } valid_atom[] = {
     @@ ref-filter.c: static int head_atom_parser(const struct ref_format *format, struc
      -	{ "if", SOURCE_NONE, FIELD_STR, if_atom_parser },
      -	{ "then", SOURCE_NONE },
      -	{ "else", SOURCE_NONE },
     -+	{ ATOM_REFNAME, "refname", SOURCE_NONE, FIELD_STR, refname_atom_parser },
     -+	{ ATOM_OBJECTTYPE, "objecttype", SOURCE_OTHER, FIELD_STR, objecttype_atom_parser },
     -+	{ ATOM_OBJECTSIZE, "objectsize", SOURCE_OTHER, FIELD_ULONG, objectsize_atom_parser },
     -+	{ ATOM_OBJECTNAME, "objectname", SOURCE_OTHER, FIELD_STR, oid_atom_parser },
     -+	{ ATOM_DELTABASE, "deltabase", SOURCE_OTHER, FIELD_STR, deltabase_atom_parser },
     -+	{ ATOM_TREE, "tree", SOURCE_OBJ, FIELD_STR, oid_atom_parser },
     -+	{ ATOM_PARENT, "parent", SOURCE_OBJ, FIELD_STR, oid_atom_parser },
     -+	{ ATOM_NUMPARENT, "numparent", SOURCE_OBJ, FIELD_ULONG },
     -+	{ ATOM_OBJECT, "object", SOURCE_OBJ },
     -+	{ ATOM_TYPE, "type", SOURCE_OBJ },
     -+	{ ATOM_TAG, "tag", SOURCE_OBJ },
     -+	{ ATOM_AUTHOR, "author", SOURCE_OBJ },
     -+	{ ATOM_AUTHORNAME, "authorname", SOURCE_OBJ },
     -+	{ ATOM_AUTHOREMAIL, "authoremail", SOURCE_OBJ, FIELD_STR, person_email_atom_parser },
     -+	{ ATOM_AUTHORDATE, "authordate", SOURCE_OBJ, FIELD_TIME },
     -+	{ ATOM_COMMITTER, "committer", SOURCE_OBJ },
     -+	{ ATOM_COMMITTERNAME, "committername", SOURCE_OBJ },
     -+	{ ATOM_COMMITTEREMAIL, "committeremail", SOURCE_OBJ, FIELD_STR, person_email_atom_parser },
     -+	{ ATOM_COMMITTERDATE, "committerdate", SOURCE_OBJ, FIELD_TIME },
     -+	{ ATOM_TAGGER, "tagger", SOURCE_OBJ },
     -+	{ ATOM_TAGGERNAME, "taggername", SOURCE_OBJ },
     -+	{ ATOM_TAGGEREMAIL, "taggeremail", SOURCE_OBJ, FIELD_STR, person_email_atom_parser },
     -+	{ ATOM_TAGGERDATE, "taggerdate", SOURCE_OBJ, FIELD_TIME },
     -+	{ ATOM_CREATOR, "creator", SOURCE_OBJ },
     -+	{ ATOM_CREATORDATE, "creatordate", SOURCE_OBJ, FIELD_TIME },
     -+	{ ATOM_SUBJECT, "subject", SOURCE_OBJ, FIELD_STR, subject_atom_parser },
     -+	{ ATOM_BODY, "body", SOURCE_OBJ, FIELD_STR, body_atom_parser },
     -+	{ ATOM_TRAILERS, "trailers", SOURCE_OBJ, FIELD_STR, trailers_atom_parser },
     -+	{ ATOM_CONTENTS, "contents", SOURCE_OBJ, FIELD_STR, contents_atom_parser },
     -+	{ ATOM_UPSTREAM, "upstream", SOURCE_NONE, FIELD_STR, remote_ref_atom_parser },
     -+	{ ATOM_PUSH, "push", SOURCE_NONE, FIELD_STR, remote_ref_atom_parser },
     -+	{ ATOM_SYMREF, "symref", SOURCE_NONE, FIELD_STR, refname_atom_parser },
     -+	{ ATOM_FLAG, "flag", SOURCE_NONE },
     -+	{ ATOM_HEAD, "HEAD", SOURCE_NONE, FIELD_STR, head_atom_parser },
     -+	{ ATOM_COLOR, "color", SOURCE_NONE, FIELD_STR, color_atom_parser },
     -+	{ ATOM_WORKTREEPATH, "worktreepath", SOURCE_NONE },
     -+	{ ATOM_ALIGN, "align", SOURCE_NONE, FIELD_STR, align_atom_parser },
     -+	{ ATOM_END, "end", SOURCE_NONE },
     -+	{ ATOM_IF, "if", SOURCE_NONE, FIELD_STR, if_atom_parser },
     -+	{ ATOM_THEN, "then", SOURCE_NONE },
     -+	{ ATOM_ELSE, "else", SOURCE_NONE },
     ++	[ATOM_REFNAME] = { "refname", SOURCE_NONE, FIELD_STR, refname_atom_parser },
     ++	[ATOM_OBJECTTYPE] = { "objecttype", SOURCE_OTHER, FIELD_STR, objecttype_atom_parser },
     ++	[ATOM_OBJECTSIZE] = { "objectsize", SOURCE_OTHER, FIELD_ULONG, objectsize_atom_parser },
     ++	[ATOM_OBJECTNAME] = { "objectname", SOURCE_OTHER, FIELD_STR, oid_atom_parser },
     ++	[ATOM_DELTABASE] = { "deltabase", SOURCE_OTHER, FIELD_STR, deltabase_atom_parser },
     ++	[ATOM_TREE] = { "tree", SOURCE_OBJ, FIELD_STR, oid_atom_parser },
     ++	[ATOM_PARENT] = { "parent", SOURCE_OBJ, FIELD_STR, oid_atom_parser },
     ++	[ATOM_NUMPARENT] = { "numparent", SOURCE_OBJ, FIELD_ULONG },
     ++	[ATOM_OBJECT] = { "object", SOURCE_OBJ },
     ++	[ATOM_TYPE] = { "type", SOURCE_OBJ },
     ++	[ATOM_TAG] = { "tag", SOURCE_OBJ },
     ++	[ATOM_AUTHOR] = { "author", SOURCE_OBJ },
     ++	[ATOM_AUTHORNAME] = { "authorname", SOURCE_OBJ },
     ++	[ATOM_AUTHOREMAIL] = { "authoremail", SOURCE_OBJ, FIELD_STR, person_email_atom_parser },
     ++	[ATOM_AUTHORDATE] = { "authordate", SOURCE_OBJ, FIELD_TIME },
     ++	[ATOM_COMMITTER] = { "committer", SOURCE_OBJ },
     ++	[ATOM_COMMITTERNAME] = { "committername", SOURCE_OBJ },
     ++	[ATOM_COMMITTEREMAIL] = { "committeremail", SOURCE_OBJ, FIELD_STR, person_email_atom_parser },
     ++	[ATOM_COMMITTERDATE] = { "committerdate", SOURCE_OBJ, FIELD_TIME },
     ++	[ATOM_TAGGER] = { "tagger", SOURCE_OBJ },
     ++	[ATOM_TAGGERNAME] = { "taggername", SOURCE_OBJ },
     ++	[ATOM_TAGGEREMAIL] = { "taggeremail", SOURCE_OBJ, FIELD_STR, person_email_atom_parser },
     ++	[ATOM_TAGGERDATE] = { "taggerdate", SOURCE_OBJ, FIELD_TIME },
     ++	[ATOM_CREATOR] = { "creator", SOURCE_OBJ },
     ++	[ATOM_CREATORDATE] = { "creatordate", SOURCE_OBJ, FIELD_TIME },
     ++	[ATOM_SUBJECT] = { "subject", SOURCE_OBJ, FIELD_STR, subject_atom_parser },
     ++	[ATOM_BODY] = { "body", SOURCE_OBJ, FIELD_STR, body_atom_parser },
     ++	[ATOM_TRAILERS] = { "trailers", SOURCE_OBJ, FIELD_STR, trailers_atom_parser },
     ++	[ATOM_CONTENTS] = { "contents", SOURCE_OBJ, FIELD_STR, contents_atom_parser },
     ++	[ATOM_UPSTREAM] = { "upstream", SOURCE_NONE, FIELD_STR, remote_ref_atom_parser },
     ++	[ATOM_PUSH] = { "push", SOURCE_NONE, FIELD_STR, remote_ref_atom_parser },
     ++	[ATOM_SYMREF] = { "symref", SOURCE_NONE, FIELD_STR, refname_atom_parser },
     ++	[ATOM_FLAG] = { "flag", SOURCE_NONE },
     ++	[ATOM_HEAD] = { "HEAD", SOURCE_NONE, FIELD_STR, head_atom_parser },
     ++	[ATOM_COLOR] = { "color", SOURCE_NONE, FIELD_STR, color_atom_parser },
     ++	[ATOM_WORKTREEPATH] = { "worktreepath", SOURCE_NONE },
     ++	[ATOM_ALIGN] = { "align", SOURCE_NONE, FIELD_STR, align_atom_parser },
     ++	[ATOM_END] = { "end", SOURCE_NONE },
     ++	[ATOM_IF] = { "if", SOURCE_NONE, FIELD_STR, if_atom_parser },
     ++	[ATOM_THEN] = { "then", SOURCE_NONE },
     ++	[ATOM_ELSE] = { "else", SOURCE_NONE },
       	/*
       	 * Please update $__git_ref_fieldlist in git-completion.bash
       	 * when you add new atoms
     +@@ ref-filter.c: static int parse_ref_filter_atom(const struct ref_format *format,
     + 	atom_len = (arg ? arg : ep) - sp;
     + 
     + 	/* Is the atom a valid one? */
     +-	for (i = 0; i < ARRAY_SIZE(valid_atom); i++) {
     ++	for (i = ATOM_UNKNOWN + 1; i < ATOM_INVALID; i++) {
     + 		int len = strlen(valid_atom[i].name);
     + 		if (len == atom_len && !memcmp(valid_atom[i].name, sp, len))
     + 			break;
     + 	}
     + 
     +-	if (ARRAY_SIZE(valid_atom) <= i)
     ++	if (i == ATOM_INVALID)
     + 		return strbuf_addf_ret(err, -1, _("unknown field name: %.*s"),
     + 				       (int)(ep-atom), atom);
     + 	if (valid_atom[i].source != SOURCE_NONE && !have_git_dir())
      @@ ref-filter.c: static int parse_ref_filter_atom(const struct ref_format *format,
       	at = used_atom_cnt;
       	used_atom_cnt++;
       	REALLOC_ARRAY(used_atom, used_atom_cnt);
     -+	used_atom[at].atom_type = valid_atom[i].atom_type;
     ++	used_atom[at].atom_type = i;
       	used_atom[at].name = xmemdupz(atom, ep - atom);
       	used_atom[at].type = valid_atom[i].cmp_type;
       	used_atom[at].source = valid_atom[i].source;
     @@ ref-filter.c: static int parse_ref_filter_atom(const struct ref_format *format,
       	if (*atom == '*')
       		need_tagged = 1;
      -	if (!strcmp(valid_atom[i].name, "symref"))
     -+	if (valid_atom[i].atom_type == ATOM_SYMREF)
     ++	if (i == ATOM_SYMREF)
       		need_symref = 1;
       	return at;
       }

-- 
gitgitgadget

  parent reply	other threads:[~2021-05-10 15:24 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-08 15:22 [PATCH " ZheNing Hu via GitGitGadget
2021-05-08 15:22 ` [PATCH 1/2] [GSOC] ref-filter: add objectsize to used_atom ZheNing Hu via GitGitGadget
2021-05-08 15:22 ` [PATCH 2/2] [GSOC][RFC] ref-filter: introduce enum atom_type ZheNing Hu via GitGitGadget
2021-05-09  6:21   ` Christian Couder
2021-05-09  8:26     ` Junio C Hamano
2021-05-09 13:44       ` ZheNing Hu
2021-05-09 13:40     ` ZheNing Hu
2021-05-10 15:03 ` ZheNing Hu via GitGitGadget [this message]
2021-05-10 15:03   ` [PATCH v2 1/2] [GSOC] ref-filter: add objectsize to used_atom ZheNing Hu via GitGitGadget
2021-05-10 15:03   ` [PATCH v2 2/2] [GSOC] ref-filter: introduce enum atom_type ZheNing Hu via GitGitGadget
2021-05-11  2:14     ` Junio C Hamano
2021-05-11  5:51       ` Christian Couder
2021-05-11  6:12         ` Junio C Hamano
2021-05-11 12:53           ` ZheNing Hu
2021-05-11 12:37         ` ZheNing Hu
2021-05-11 13:05         ` Junio C Hamano
2021-05-11 12:18       ` ZheNing Hu
2021-05-12 12:11   ` [PATCH v3 0/2] [GSOC][RFC] " ZheNing Hu via GitGitGadget
2021-05-12 12:11     ` [PATCH v3 1/2] [GSOC] ref-filter: add objectsize to used_atom ZheNing Hu via GitGitGadget
2021-05-12 23:11       ` Junio C Hamano
2021-05-13  9:04         ` ZheNing Hu
2021-05-12 12:11     ` [PATCH v3 2/2] [GSOC] ref-filter: introduce enum atom_type ZheNing Hu via GitGitGadget
2021-05-12 23:21       ` Junio C Hamano
2021-05-13  9:25         ` ZheNing Hu
2021-05-13 15:15     ` [PATCH v4 0/2] [GSOC][RFC] " ZheNing Hu via GitGitGadget
2021-05-13 15:15       ` [PATCH v4 1/2] [GSOC] ref-filter: add objectsize to used_atom ZheNing Hu via GitGitGadget
2021-05-13 15:15       ` [PATCH v4 2/2] [GSOC] ref-filter: introduce enum atom_type ZheNing Hu via GitGitGadget

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=pull.951.v2.git.1620659000.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=adlternative@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=hariom18599@gmail.com \
    --cc=peff@peff.net \
    --subject='Re: [PATCH v2 0/2] [GSOC][RFC] ref-filter: introduce enum atom_type' \
    /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

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).