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

Re: [PATCH v15 06/13] ref-filter: add option to filter out tags, branches and remotes

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 1, 2015, 21:30 UTC
Message-ID
<xmqqa8t5rfng.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1441131994-13508-7-git-send-email-Karthik.188@gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
Show 11 quoted lines
> +	if (!filter->kind)
>  		die("filter_refs: invalid type");
> +	else {
> +		if (filter->kind == FILTER_REFS_BRANCHES)
> +			ret = for_each_fullref_in("refs/heads/", ref_filter_handler, &ref_cbdata, broken);
> +		else if (filter->kind == FILTER_REFS_REMOTES)
> +			ret = for_each_fullref_in("refs/remotes/", ref_filter_handler, &ref_cbdata, broken);
> +		else if (filter->kind == FILTER_REFS_TAGS)
> +			ret = for_each_fullref_in("refs/tags/", ref_filter_handler, &ref_cbdata, broken);
> +		else if (filter->kind & FILTER_REFS_ALL)
> +			ret = for_each_fullref_in("", ref_filter_handler, &ref_cbdata, broken);
This if/else if/else if/ cascade and ...
Show 22 quoted lines
> +		if (!ret && (filter->kind & FILTER_REFS_DETACHED_HEAD))
> +			head_ref(ref_filter_handler, &ref_cbdata);
> +	}
> +
>  
>  	/*  Filters that need revision walking */
>  	if (filter->merge_commit)
> diff --git a/ref-filter.h b/ref-filter.h
> index 45026d0..0913ba9 100644
> --- a/ref-filter.h
> +++ b/ref-filter.h
> @@ -13,8 +13,15 @@
>  #define QUOTE_PYTHON 4
>  #define QUOTE_TCL 8
>  
> -#define FILTER_REFS_INCLUDE_BROKEN 0x1
> -#define FILTER_REFS_ALL 0x2
> +#define FILTER_REFS_INCLUDE_BROKEN 0x0001
> +#define FILTER_REFS_TAGS           0x0002
> +#define FILTER_REFS_BRANCHES       0x0004
> +#define FILTER_REFS_REMOTES        0x0008
> +#define FILTER_REFS_OTHERS         0x0010

... the bit assignment here conceptually do not mesh well with each other. These bits look as if I can ask for both tags and branches by passing 0x0006, and if the code above were

	empty the result set;
	if (filter->kind & FILTER_REFS_BRANCHES)
        	add in things from refs/heads/ to the result set;
	if (filter->kind & FILTER_REFS_TAGS)                
        	add in things from refs/tags/ to the result set;
	...
without "else if", that would conceptually make sense.

Alternatively, if the code does not (and will not ever) support such an arbitrary mixing of bits and intends to only allow "one of BRANCHES, REMOTES, TAGS or ALL, and no other choice", then it is wrong to pretend as if they can be mixed by defining the constant with values with non-overlapping bit patterns. If you defined these constants as

#define FILTER_REFS_TAGS 100 #define FILTER_REFS_BRANCHES 101 #define FILTER_REFS_REMOTES 102 #define FILTER_REFS_OTHERS 103

then nobody would be think that the function can collect both tags and branches by passing FILTER_REFS_TAGS|FILTER_REFS_BRANCHES.

The former, i.e. keep the bits distinct and allow them to be OR'ed together by updating the code to allow such callers, would be more preferrable, of course.

Previous: Karthik NayakNext: Karthik Nayak
Message 27 of 58 in “port builtin/tag.c to use ref-filter APIs.”
  1. 00/13 port builtin/tag.c to use ref-filter APIs.Karthik Nayak, Sep 1, 2015
  2. 01/13 ref-filter: move `struct atom_value` to ref-filter.cKarthik Nayak, Sep 1, 2015
  3. 02/13 ref-filter: introduce ref_formatting_state and ref_formatting_stackKarthik Nayak, Sep 1, 2015
  4. 03/13 utf8: add function to align a string into given strbufKarthik Nayak, Sep 1, 2015
  5. 04/13 ref-filter: introduce handler function for each atomKarthik Nayak, Sep 1, 2015
  6. 05/13 ref-filter: implement an `align` atomKarthik Nayak, Sep 1, 2015
  7. Junio C HamanoSep 1, 2015
  8. Karthik NayakSep 2, 2015
  9. Junio C HamanoSep 2, 2015
  10. Karthik NayakSep 2, 2015
  11. Junio C HamanoSep 2, 2015
  12. Karthik NayakSep 2, 2015
  13. Matthieu MoySep 2, 2015
  14. Junio C HamanoSep 2, 2015
  15. Karthik NayakSep 3, 2015
  16. Matthieu MoySep 2, 2015
  17. Matthieu MoySep 2, 2015
  18. Karthik NayakSep 2, 2015
  19. Matthieu MoySep 2, 2015
  20. Karthik NayakSep 2, 2015
  21. Matthieu MoySep 2, 2015
  22. Eric SunshineSep 3, 2015
  23. Karthik NayakSep 3, 2015
  24. Junio C HamanoSep 3, 2015
  25. Karthik NayakSep 4, 2015
  26. 06/13 ref-filter: add option to filter out tags, branches and remotesKarthik Nayak, Sep 1, 2015
  27. Junio C HamanoSep 1, 2015
  28. Karthik NayakSep 2, 2015
  29. Junio C HamanoSep 2, 2015
  30. Karthik NayakSep 2, 2015
  31. 07/13 ref-filter: add support for %(contents:lines=X)Karthik Nayak, Sep 1, 2015
  32. Matthieu MoySep 2, 2015
  33. Karthik NayakSep 2, 2015
  34. Matthieu MoySep 2, 2015
  35. Karthik NayakSep 3, 2015
  36. Karthik NayakSep 3, 2015
  37. Matthieu MoySep 3, 2015
  38. Karthik NayakSep 3, 2015
  39. Eric SunshineSep 3, 2015
  40. Eric SunshineSep 3, 2015
  41. Matthieu MoySep 3, 2015
  42. Karthik NayakSep 3, 2015
  43. Junio C HamanoSep 3, 2015
  44. Karthik NayakSep 4, 2015
  45. Matthieu MoySep 3, 2015
  46. Karthik NayakSep 3, 2015
  47. 08/13 ref-filter: add support to sort by versionKarthik Nayak, Sep 1, 2015
  48. 09/13 ref-filter: add option to match literal patternKarthik Nayak, Sep 1, 2015
  49. 10/13 tag.c: use 'ref-filter' data structuresKarthik Nayak, Sep 1, 2015
  50. 11/13 tag.c: use 'ref-filter' APIsKarthik Nayak, Sep 1, 2015
  51. Matthieu MoySep 2, 2015
  52. Junio C HamanoSep 2, 2015
  53. Karthik NayakSep 2, 2015
  54. Matthieu MoySep 2, 2015
  55. Junio C HamanoSep 2, 2015
  56. Karthik NayakSep 3, 2015
  57. 12/13 tag.c: implement '--format' optionKarthik Nayak, Sep 1, 2015
  58. 13/13 tag.c: implement '--merged' and '--no-merged' optionsKarthik Nayak, Sep 1, 2015

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.