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

Re: [RFC_PATCHv4 3/7] submodule-config: add method to check for being labeled

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 22, 2016, 22:30 UTC
Message-ID
<xmqqegb2f8nn.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1458612372-10966-4-git-send-email-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
Show 5 quoted lines
> In later patches we need to tell if a submodule is labeled by
> the given labels.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---

Hmph, I would have expected that something like this would touch the module_list() implementation. Probably that would happen in future steps, I guess?

Show 72 quoted lines
>  submodule-config.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  submodule-config.h |  3 +++
>  2 files changed, 51 insertions(+)
>
> diff --git a/submodule-config.c b/submodule-config.c
> index 7b48e59..b10a773 100644
> --- a/submodule-config.c
> +++ b/submodule-config.c
> @@ -493,3 +493,51 @@ void submodule_free(void)
>  	cache_free(&cache);
>  	is_cache_init = 0;
>  }
> +
> +int submodule_applicable_by_labels(const struct string_list *list,
> +				   const struct submodule *sub)
> +{
> +	int label_apply = 0;
> +	struct strbuf sb = STRBUF_INIT;
> +
> +	if (!list)
> +		return 1;
> +
> +	if (sub->labels) {
> +		struct string_list_item *item;
> +		for_each_string_list_item(item, sub->labels) {
> +			strbuf_reset(&sb);
> +			strbuf_addf(&sb, "*%s", item->string);
> +			if (string_list_has_string(list, sb.buf)) {
> +				label_apply = 1;
> +				break;
> +			}
> +		}
> +	}
> +	if (sub->path) {
> +		/*
> +		 * NEEDSWORK: This currently works only for
> +		 * exact paths, but we want to enable
> +		 * inexact matches such wildcards.
> +		 */
> +		strbuf_reset(&sb);
> +		strbuf_addf(&sb, "./%s", sub->path);
> +		if (string_list_has_string(list, sb.buf)) {
> +			label_apply = 1;
> +		}
> +	}
> +	if (sub->name) {
> +		/*
> +		 * NEEDSWORK: Same as with path. Do we want to
> +		 * support wildcards or such?
> +		 */
> +		strbuf_reset(&sb);
> +		strbuf_addf(&sb, ":%s", sub->name);
> +		if (string_list_has_string(list, sb.buf)) {
> +			label_apply = 1;
> +		}
> +	}
> +	strbuf_release(&sb);
> +
> +	return label_apply;
> +}
> diff --git a/submodule-config.h b/submodule-config.h
> index 8d61df3..d67f666 100644
> --- a/submodule-config.h
> +++ b/submodule-config.h
> @@ -30,4 +30,7 @@ const struct submodule *submodule_from_path(const unsigned char *commit_sha1,
>  		const char *path);
>  void submodule_free(void);
>  
> +int submodule_applicable_by_labels(const struct string_list *list,
> +				   const struct submodule *sub);
> +
>  #endif /* SUBMODULE_CONFIG_H */
Previous: Stefan BellerNext: Stefan Beller
Message 7 of 22 in “[RFC_PATCHv4 0/7] Git submodule labels”
  1. Stefan BellerMar 22, 2016
  2. 1/7 git submodule: teach `add` to label submodulesStefan Beller, Mar 22, 2016
  3. Junio C HamanoMar 22, 2016
  4. Junio C HamanoMar 22, 2016
  5. 2/7 submodule-config: keep labels aroundStefan Beller, Mar 22, 2016
  6. 3/7 submodule-config: add method to check for being labeledStefan Beller, Mar 22, 2016
  7. Junio C HamanoMar 22, 2016
  8. Stefan BellerMar 23, 2016
  9. 4/7 submodule init: redirect stdout to stderrStefan Beller, Mar 22, 2016
  10. Sebastian SchuberthMar 22, 2016
  11. Junio C HamanoMar 22, 2016
  12. Stefan BellerMar 22, 2016
  13. Sebastian SchuberthMar 22, 2016
  14. Junio C HamanoMar 22, 2016
  15. 5/7 submodule update: respect submodule.actionOnLabelStefan Beller, Mar 22, 2016
  16. Junio C HamanoMar 22, 2016
  17. Stefan BellerMar 23, 2016
  18. Junio C HamanoMar 24, 2016
  19. Stefan BellerMar 24, 2016
  20. Junio C HamanoMar 24, 2016
  21. 6/7 clone: allow specification of submodules to be clonedStefan Beller, Mar 22, 2016
  22. 7/7 WIP status/diff: respect submodule.actionOnLabelStefan Beller, Mar 22, 2016

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.