From: Stefan Beller <sbeller@google.com>
To: Jens.Lehmann@web.de, sschuberth@gmail.com
Cc: git@vger.kernel.org, Stefan Beller <sbeller@google.com>
Subject: [RFC_PATCHv4 3/7] submodule-config: add method to check for being labeled
Date: Mon, 21 Mar 2016 19:06:08 -0700 [thread overview]
Message-ID: <1458612372-10966-4-git-send-email-sbeller@google.com> (raw)
In-Reply-To: <1458612372-10966-1-git-send-email-sbeller@google.com>
In later patches we need to tell if a submodule is labeled by
the given labels.
Signed-off-by: Stefan Beller <sbeller@google.com>
---
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 */
--
2.7.0.rc0.45.g6b4c145
next prev parent reply other threads:[~2016-03-22 2:06 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-22 2:06 [RFC_PATCHv4 0/7] Git submodule labels Stefan Beller
2016-03-22 2:06 ` [RFC_PATCHv4 1/7] git submodule: teach `add` to label submodules Stefan Beller
2016-03-22 22:28 ` Junio C Hamano
2016-03-22 22:34 ` Junio C Hamano
2016-03-22 2:06 ` [RFC_PATCHv4 2/7] submodule-config: keep labels around Stefan Beller
2016-03-22 2:06 ` Stefan Beller [this message]
2016-03-22 22:30 ` [RFC_PATCHv4 3/7] submodule-config: add method to check for being labeled Junio C Hamano
2016-03-23 21:05 ` Stefan Beller
2016-03-22 2:06 ` [RFC_PATCHv4 4/7] submodule init: redirect stdout to stderr Stefan Beller
2016-03-22 7:46 ` Sebastian Schuberth
2016-03-22 16:14 ` Junio C Hamano
2016-03-22 16:47 ` Stefan Beller
2016-03-22 16:56 ` Sebastian Schuberth
2016-03-22 17:15 ` Junio C Hamano
2016-03-22 2:06 ` [RFC_PATCHv4 5/7] submodule update: respect submodule.actionOnLabel Stefan Beller
2016-03-22 22:40 ` Junio C Hamano
2016-03-23 23:21 ` Stefan Beller
2016-03-24 0:13 ` Junio C Hamano
2016-03-24 19:54 ` Stefan Beller
2016-03-24 21:14 ` Junio C Hamano
2016-03-22 2:06 ` [RFC_PATCHv4 6/7] clone: allow specification of submodules to be cloned Stefan Beller
2016-03-22 2:06 ` [RFC_PATCHv4 7/7] WIP status/diff: respect submodule.actionOnLabel Stefan Beller
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=1458612372-10966-4-git-send-email-sbeller@google.com \
--to=sbeller@google.com \
--cc=Jens.Lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=sschuberth@gmail.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).