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

Re: [PATCH] clean.c, ls-files.c: respect encapsulation of exclude_list_groups

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 16, 2013, 22:20 UTC
Message-ID
<7v1udkwz1f.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1358342758-30503-1-git-send-email-git@adamspiers.org>
Adam Spiers <git@adamspiers.org> writes:
Show 21 quoted lines
> Consumers of the dir.c traversal API should avoid assuming knowledge
> of the internal implementation of exclude_list_groups.  Therefore
> when adding items to an exclude list, it should be accessed via the
> pointer returned from add_exclude_list(), rather than by referencing
> a location within dir.exclude_list_groups[EXC_CMDL].
>
> Signed-off-by: Adam Spiers <git@adamspiers.org>
> ---
>  builtin/clean.c    |  6 +++---
>  builtin/ls-files.c | 15 ++++++++++-----
>  2 files changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/builtin/clean.c b/builtin/clean.c
> index b098288..b9cb7ad 100644
> --- a/builtin/clean.c
> +++ b/builtin/clean.c
> @@ -45,6 +45,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
>  	static const char **pathspec;
>  	struct strbuf buf = STRBUF_INIT;
>  	struct string_list exclude_list = STRING_LIST_INIT_NODUP;
> +	struct exclude_list *el;

When a type "exclude_list" exists and used in the same function, having a local variable of the same name but of a different type becomes a bit awkward.

builtin/ls-files.c shares the same structure. Does the file-scope "exclude_args" variable need to be a file-scope static over there? It seems that it is closely tied to the elements of the string list, so it may make sense to:

    * remove the file-scope static "exclude_args";
    * rename "exclude_list" string list variable to "exclude_args";
      and
    * replace "--exclude_args" in the loop that iterates over
      exclude_list (now exclude_args) with "-(i+1)" or something,
      just like you do in "builtin/clean.c" below.
Show 6 quoted lines
> -	add_exclude_list(&dir, EXC_CMDL, "--exclude option");
> +	el = add_exclude_list(&dir, EXC_CMDL, "--exclude option");
>  	for (i = 0; i < exclude_list.nr; i++)
> -		add_exclude(exclude_list.items[i].string, "", 0,
> -			    &dir.exclude_list_group[EXC_CMDL].el[0], -(i+1));
> +		add_exclude(exclude_list.items[i].string, "", 0, el, -(i+1));

We may want to use for_each_string_list_item() here and in the corresponding loop in builtin/ls-files.c, but because we do need to give the -(i + 1) label to each element, I think the code is OK as-is.

Previous: Junio C Hamano
Message 9 of 9 in “What's cooking in git.git (Jan 2013, #06; Mon, 14)”
  1. Junio C HamanoJan 14, 2013
  2. Junio C HamanoJan 15, 2013
  3. Chris RorvickJan 15, 2013
  4. Adam SpiersJan 16, 2013
  5. Junio C HamanoJan 16, 2013
  6. Adam SpiersJan 16, 2013
  7. clean.c, ls-files.c: respect encapsulation of exclude_list_groupsAdam Spiers, Jan 16, 2013
  8. Junio C HamanoJan 16, 2013
  9. Junio C HamanoJan 16, 2013

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.