git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 2/2] [GSOC] ref-filter: introduce enum atom_type

From
Junio C Hamano <gitster@pobox.com>
Date
May 12, 2021, 23:21 UTC
Message-ID
<xmqqk0o3edxw.fsf@gitster.g>
In-Reply-To
<43400cac58e74a2acab15ace929481a9efb7978f.1620821464.git.gitgitgadget@gmail.com>
"ZheNing Hu via GitGitGadget" <gitgitgadget@gmail.com> writes:
> +/*
> + * The enum atom_type is used as the coordinates of valid_atom entry.

Usually we do not say "coordinates" when we talk about X of an array element A[X]. "... used as an index in the valid_atom[] array." perhaps.

> + * 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

You seem to like the verb "judge" (it was also seen in the proposed log message for 1/2) and tend to overuse it when we use other verbs; in this particular case, probably the right verb is to "check".

Show 16 quoted lines
> + * entry by `if (used_atom[i].atom_type == ATOM_*)`.
> + */
> +enum atom_type {
> +	ATOM_REFNAME,
> +...
> +	ATOM_ELSE,
> +};
> +
> @@ -119,6 +169,7 @@ 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;
OK.
Show 10 quoted lines
> @@ -506,47 +557,47 @@ static struct {
>  	int (*parser)(const struct ref_format *format, struct used_atom *atom,
>  		      const char *arg, struct strbuf *err);
>  } valid_atom[] = {
> -	{ "refname", SOURCE_NONE, FIELD_STR, refname_atom_parser },
> ...
> -	{ "else", SOURCE_NONE },
> +	[ATOM_REFNAME] = { "refname", SOURCE_NONE, FIELD_STR, refname_atom_parser },
> ...
> +	[ATOM_ELSE] = { "else", SOURCE_NONE },
Makes sense.
Show 5 quoted lines
> @@ -628,6 +679,7 @@ 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 = i;
Makes sense.
Show 12 quoted lines
>  	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;
> @@ -652,7 +704,7 @@ static int parse_ref_filter_atom(const struct ref_format *format,
>  		return -1;
>  	if (*atom == '*')
>  		need_tagged = 1;
> -	if (!strcmp(valid_atom[i].name, "symref"))
> +	if (i == ATOM_SYMREF)
>  		need_symref = 1;
>  	return at;
>  }
Nice.
Show 18 quoted lines
> @@ -965,14 +1017,15 @@ static void grab_common_values(struct atom_value *val, int deref, struct expand_
>  
>  	for (i = 0; i < used_atom_cnt; i++) {
>  		const char *name = used_atom[i].name;
> +		enum atom_type atom_type = used_atom[i].atom_type;
>  		struct atom_value *v = &val[i];
>  		if (!!deref != (*name == '*'))
>  			continue;
>  		if (deref)
>  			name++;
> -		if (!strcmp(name, "objecttype"))
> +		if (atom_type == ATOM_OBJECTTYPE)
>  			v->s = xstrdup(type_name(oi->type));
> -		else if (starts_with(name, "objectsize")) {
> +		else if (atom_type == ATOM_OBJECTSIZE) {
>  			if (used_atom[i].u.objectsize.option == O_SIZE_DISK) {
>  				v->value = oi->disk_size;
>  				v->s = xstrfmt("%"PRIuMAX, (uintmax_t)oi->disk_size);

Replacing !strcmp() with comparison with ATOM_* like the above is the best solution for this step, but I wonder if this part (or any other part that this patch touches) would benefit from using a switch statement on atom_type. Something to think about in the future, after the dust settles.

Thanks.
Previous: ZheNing Hu via GitGitGadgetNext: ZheNing Hu
Message 23 of 27 in “[GSOC][RFC] ref-filter: introduce enum atom_type”
  1. 0/2 [GSOC][RFC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 8, 2021
  2. 1/2 [GSOC] ref-filter: add objectsize to used_atomZheNing Hu via GitGitGadget, May 8, 2021
  3. 2/2 [GSOC][RFC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 8, 2021
  4. Christian CouderMay 9, 2021
  5. Junio C HamanoMay 9, 2021
  6. ZheNing HuMay 9, 2021
  7. ZheNing HuMay 9, 2021
  8. 0/2 [GSOC][RFC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 10, 2021
  9. 1/2 [GSOC] ref-filter: add objectsize to used_atomZheNing Hu via GitGitGadget, May 10, 2021
  10. 2/2 [GSOC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 10, 2021
  11. Junio C HamanoMay 11, 2021
  12. Christian CouderMay 11, 2021
  13. Junio C HamanoMay 11, 2021
  14. ZheNing HuMay 11, 2021
  15. ZheNing HuMay 11, 2021
  16. Junio C HamanoMay 11, 2021
  17. ZheNing HuMay 11, 2021
  18. 0/2 [GSOC][RFC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 12, 2021
  19. 1/2 [GSOC] ref-filter: add objectsize to used_atomZheNing Hu via GitGitGadget, May 12, 2021
  20. Junio C HamanoMay 12, 2021
  21. ZheNing HuMay 13, 2021
  22. 2/2 [GSOC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 12, 2021
  23. Junio C HamanoMay 12, 2021
  24. ZheNing HuMay 13, 2021
  25. 0/2 [GSOC][RFC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 13, 2021
  26. 1/2 [GSOC] ref-filter: add objectsize to used_atomZheNing Hu via GitGitGadget, May 13, 2021
  27. 2/2 [GSOC] ref-filter: introduce enum atom_typeZheNing Hu via GitGitGadget, May 13, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.