git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Brandon Williams <bmwill@google.com>
To: git@vger.kernel.org
Cc: Brandon Williams <bmwill@google.com>,
	peff@peff.net, sbeller@google.com, jonathantanmy@google.com,
	gitster@pobox.com
Subject: [PATCH v6 2/6] submodules: load gitmodules file from commit sha1
Date: Wed, 30 Nov 2016 17:28:30 -0800	[thread overview]
Message-ID: <1480555714-186183-3-git-send-email-bmwill@google.com> (raw)
In-Reply-To: <1480555714-186183-1-git-send-email-bmwill@google.com>

teach submodules to load a '.gitmodules' file from a commit sha1.  This
enables the population of the submodule_cache to be based on the state
of the '.gitmodules' file from a particular commit.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 cache.h            |  2 ++
 config.c           |  8 ++++----
 submodule-config.c |  6 +++---
 submodule-config.h |  3 +++
 submodule.c        | 12 ++++++++++++
 submodule.h        |  1 +
 6 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/cache.h b/cache.h
index 1be6526..559a461 100644
--- a/cache.h
+++ b/cache.h
@@ -1690,6 +1690,8 @@ extern int git_default_config(const char *, const char *, void *);
 extern int git_config_from_file(config_fn_t fn, const char *, void *);
 extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
 					const char *name, const char *buf, size_t len, void *data);
+extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
+				     const unsigned char *sha1, void *data);
 extern void git_config_push_parameter(const char *text);
 extern int git_config_from_parameters(config_fn_t fn, void *data);
 extern void git_config(config_fn_t fn, void *);
diff --git a/config.c b/config.c
index 83fdecb..4d78e72 100644
--- a/config.c
+++ b/config.c
@@ -1214,10 +1214,10 @@ int git_config_from_mem(config_fn_t fn, const enum config_origin_type origin_typ
 	return do_config_from(&top, fn, data);
 }
 
-static int git_config_from_blob_sha1(config_fn_t fn,
-				     const char *name,
-				     const unsigned char *sha1,
-				     void *data)
+int git_config_from_blob_sha1(config_fn_t fn,
+			      const char *name,
+			      const unsigned char *sha1,
+			      void *data)
 {
 	enum object_type type;
 	char *buf;
diff --git a/submodule-config.c b/submodule-config.c
index 098085b..8b9a2ef 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -379,9 +379,9 @@ static int parse_config(const char *var, const char *value, void *data)
 	return ret;
 }
 
-static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
-				      unsigned char *gitmodules_sha1,
-				      struct strbuf *rev)
+int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
+			       unsigned char *gitmodules_sha1,
+			       struct strbuf *rev)
 {
 	int ret = 0;
 
diff --git a/submodule-config.h b/submodule-config.h
index d05c542..78584ba 100644
--- a/submodule-config.h
+++ b/submodule-config.h
@@ -29,6 +29,9 @@ const struct submodule *submodule_from_name(const unsigned char *commit_sha1,
 		const char *name);
 const struct submodule *submodule_from_path(const unsigned char *commit_sha1,
 		const char *path);
+extern int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
+				      unsigned char *gitmodules_sha1,
+				      struct strbuf *rev);
 void submodule_free(void);
 
 #endif /* SUBMODULE_CONFIG_H */
diff --git a/submodule.c b/submodule.c
index f336ca9..8516ab0 100644
--- a/submodule.c
+++ b/submodule.c
@@ -198,6 +198,18 @@ void gitmodules_config(void)
 	}
 }
 
+void gitmodules_config_sha1(const unsigned char *commit_sha1)
+{
+	struct strbuf rev = STRBUF_INIT;
+	unsigned char sha1[20];
+
+	if (gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
+		git_config_from_blob_sha1(submodule_config, rev.buf,
+					  sha1, NULL);
+	}
+	strbuf_release(&rev);
+}
+
 /*
  * Determine if a submodule has been initialized at a given 'path'
  */
diff --git a/submodule.h b/submodule.h
index 6ec5f2f..9203d89 100644
--- a/submodule.h
+++ b/submodule.h
@@ -37,6 +37,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
 		const char *path);
 int submodule_config(const char *var, const char *value, void *cb);
 void gitmodules_config(void);
+extern void gitmodules_config_sha1(const unsigned char *commit_sha1);
 extern int is_submodule_initialized(const char *path);
 extern int is_submodule_populated(const char *path);
 int parse_submodule_update_strategy(const char *value,
-- 
2.8.0.rc3.226.g39d4020


  parent reply	other threads:[~2016-12-01  1:28 UTC|newest]

Thread overview: 126+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-27 22:38 [RFC PATCH 0/5] recursively grep across submodules Brandon Williams
2016-10-27 22:38 ` [PATCH 1/5] submodules: add helper functions to determine presence of submodules Brandon Williams
2016-10-27 22:38 ` [PATCH 2/5] submodules: load gitmodules file from commit sha1 Brandon Williams
2016-10-27 22:38 ` [PATCH 3/5] grep: add submodules as a grep source type Brandon Williams
2016-10-27 22:38 ` [PATCH 4/5] grep: optionally recurse into submodules Brandon Williams
2016-11-05  5:09   ` Jonathan Tan
2016-10-27 22:38 ` [PATCH 5/5] grep: enable recurse-submodules to work on <tree> objects Brandon Williams
2016-10-28 19:35   ` Brandon Williams
2016-10-27 23:26 ` [RFC PATCH 0/5] recursively grep across submodules Junio C Hamano
2016-10-28  0:59   ` Stefan Beller
2016-10-28  2:50     ` Junio C Hamano
2016-10-28  3:46       ` Stefan Beller
2016-10-28 15:06       ` Philip Oakley
2016-10-28 17:02   ` Brandon Williams
2016-10-28 17:21     ` Junio C Hamano
2016-10-31 22:38 ` [PATCH v2 0/6] " Brandon Williams
2016-10-31 22:38   ` [PATCH v2 1/6] submodules: add helper functions to determine presence of submodules Brandon Williams
2016-10-31 23:34     ` Stefan Beller
2016-11-01 17:20       ` Junio C Hamano
2016-11-01 17:24         ` Brandon Williams
2016-11-01 17:31         ` Stefan Beller
2016-11-06  7:42           ` Jacob Keller
2016-11-01 17:23       ` Brandon Williams
2016-11-05  2:34     ` Jonathan Tan
2016-10-31 22:38   ` [PATCH v2 2/6] submodules: load gitmodules file from commit sha1 Brandon Williams
2016-11-01 16:39     ` Stefan Beller
2016-10-31 22:38   ` [PATCH v2 3/6] grep: add submodules as a grep source type Brandon Williams
2016-11-01 16:53     ` Stefan Beller
2016-11-01 17:31     ` Junio C Hamano
2016-10-31 22:38   ` [PATCH v2 4/6] grep: optionally recurse into submodules Brandon Williams
2016-11-01 17:26     ` Stefan Beller
2016-11-01 20:25       ` Brandon Williams
2016-10-31 22:38   ` [PATCH v2 5/6] grep: enable recurse-submodules to work on <tree> objects Brandon Williams
2016-11-11 23:09     ` Jonathan Tan
2016-10-31 22:38   ` [PATCH v2 6/6] grep: search history of moved submodules Brandon Williams
2016-11-11 23:51   ` [PATCH v3 0/6] recursively grep across submodules Brandon Williams
2016-11-11 23:51     ` [PATCH v3 1/6] submodules: add helper functions to determine presence of submodules Brandon Williams
2016-11-15 23:49       ` Stefan Beller
2016-11-11 23:51     ` [PATCH v3 2/6] submodules: load gitmodules file from commit sha1 Brandon Williams
2016-11-12  0:22       ` Stefan Beller
2016-11-11 23:51     ` [PATCH v3 3/6] grep: add submodules as a grep source type Brandon Williams
2016-11-11 23:51     ` [PATCH v3 4/6] grep: optionally recurse into submodules Brandon Williams
2016-11-16  0:07       ` Stefan Beller
2016-11-17 22:13         ` Brandon Williams
2016-11-11 23:51     ` [PATCH v3 5/6] grep: enable recurse-submodules to work on <tree> objects Brandon Williams
2016-11-14 18:10       ` Junio C Hamano
2016-11-14 18:44         ` Jonathan Tan
2016-11-14 18:56           ` Junio C Hamano
2016-11-14 19:08             ` Jonathan Tan
2016-11-14 19:14               ` Brandon Williams
2016-11-16  1:09       ` Stefan Beller
2016-11-17 23:34         ` Brandon Williams
2016-11-11 23:51     ` [PATCH v3 6/6] grep: search history of moved submodules Brandon Williams
2016-11-12  0:30       ` Stefan Beller
2016-11-14 17:43         ` Brandon Williams
2016-11-15 17:42     ` [PATCH v3 0/6] recursively grep across submodules Stefan Beller
2016-11-18 19:58     ` [PATCH v4 " Brandon Williams
2016-11-18 19:58       ` [PATCH v4 1/6] submodules: add helper functions to determine presence of submodules Brandon Williams
2016-11-18 19:58       ` [PATCH v4 2/6] submodules: load gitmodules file from commit sha1 Brandon Williams
2016-11-18 19:58       ` [PATCH v4 3/6] grep: add submodules as a grep source type Brandon Williams
2016-11-18 21:37         ` Junio C Hamano
2016-11-18 22:56           ` Brandon Williams
2016-11-18 19:58       ` [PATCH v4 4/6] grep: optionally recurse into submodules Brandon Williams
2016-11-18 21:48         ` Junio C Hamano
2016-11-18 22:01         ` Junio C Hamano
2016-11-18 22:14         ` Junio C Hamano
2016-11-18 22:58           ` Brandon Williams
2016-11-18 19:58       ` [PATCH v4 5/6] grep: enable recurse-submodules to work on <tree> objects Brandon Williams
2016-11-18 22:19         ` Junio C Hamano
2016-11-18 22:52           ` Brandon Williams
2016-11-21 18:14             ` Brandon Williams
2016-11-18 19:58       ` [PATCH v4 6/6] grep: search history of moved submodules Brandon Williams
2016-11-18 20:10       ` [PATCH v4 0/6] recursively grep across submodules Stefan Beller
2016-11-22 18:46       ` [PATCH v5 " Brandon Williams
2016-11-22 18:46         ` [PATCH v5 1/6] submodules: add helper functions to determine presence of submodules Brandon Williams
2016-11-22 18:46         ` [PATCH v5 2/6] submodules: load gitmodules file from commit sha1 Brandon Williams
2016-11-22 18:46         ` [PATCH v5 3/6] grep: add submodules as a grep source type Brandon Williams
2016-11-22 18:46         ` [PATCH v5 4/6] grep: optionally recurse into submodules Brandon Williams
2016-11-22 18:46         ` [PATCH v5 5/6] grep: enable recurse-submodules to work on <tree> objects Brandon Williams
2016-11-22 22:59           ` Junio C Hamano
2016-11-22 23:21             ` Brandon Williams
2016-11-22 23:28               ` Brandon Williams
2016-11-22 23:37                 ` Junio C Hamano
2016-11-22 23:54                   ` Brandon Williams
2016-11-22 18:46         ` [PATCH v5 6/6] grep: search history of moved submodules Brandon Williams
2016-12-01  1:28         ` [PATCH v6 0/6] recursively grep across submodules Brandon Williams
2016-12-01  1:28           ` [PATCH v6 1/6] submodules: add helper functions to determine presence of submodules Brandon Williams
2016-12-01  4:29             ` Jeff King
2016-12-01 18:31               ` Stefan Beller
2016-12-01 18:46               ` Junio C Hamano
2016-12-01 19:09                 ` Jeff King
2016-12-01 19:16                   ` Brandon Williams
2016-12-01 20:54                     ` Brandon Williams
2016-12-01 20:59                       ` Jeff King
2016-12-01 21:56                         ` Stefan Beller
2016-12-01 21:59                           ` Jeff King
2016-12-02 18:36                             ` Brandon Williams
2016-12-02 18:44                               ` Jacob Keller
2016-12-02 18:49                                 ` Brandon Williams
2016-12-02 19:20                                   ` Jacob Keller
2016-12-02 19:28                                     ` Stefan Beller
2016-12-02 21:31                                       ` Jacob Keller
2016-12-02 21:46                                         ` Brandon Williams
2016-12-02 21:45                                       ` Jeff King
2016-12-03  0:16                                         ` Brandon Williams
2016-12-01  1:28           ` Brandon Williams [this message]
2016-12-01  1:28           ` [PATCH v6 3/6] grep: add submodules as a grep source type Brandon Williams
2016-12-01  1:28           ` [PATCH v6 4/6] grep: optionally recurse into submodules Brandon Williams
2016-12-01  1:28           ` [PATCH v6 5/6] grep: enable recurse-submodules to work on <tree> objects Brandon Williams
2016-12-01  7:25             ` Johannes Sixt
2016-12-01 17:51               ` Brandon Williams
2016-12-01 18:49                 ` Junio C Hamano
2016-12-01 18:52                 ` Jeff King
2016-12-01  1:28           ` [PATCH v6 6/6] grep: search history of moved submodules Brandon Williams
2016-12-01  4:22           ` [PATCH v6 0/6] recursively grep across submodules Jeff King
2016-12-01 17:45             ` Brandon Williams
2016-12-01 19:03               ` Jeff King
2016-12-16 19:03           ` [PATCH v7 0/7] " Brandon Williams
2016-12-16 19:03             ` [PATCH v7 1/7] submodules: add helper to determine if a submodule is populated Brandon Williams
2016-12-16 19:03             ` [PATCH v7 2/7] submodules: add helper to determine if a submodule is initialized Brandon Williams
2016-12-16 19:03             ` [PATCH v7 3/7] submodules: load gitmodules file from commit sha1 Brandon Williams
2016-12-16 19:03             ` [PATCH v7 4/7] grep: add submodules as a grep source type Brandon Williams
2016-12-16 19:03             ` [PATCH v7 5/7] grep: optionally recurse into submodules Brandon Williams
2016-12-16 19:03             ` [PATCH v7 6/7] grep: enable recurse-submodules to work on <tree> objects Brandon Williams
2016-12-16 19:03             ` [PATCH v7 7/7] grep: search history of moved submodules Brandon Williams
2016-12-16 21:42             ` [PATCH v7 0/7] recursively grep across submodules Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1480555714-186183-3-git-send-email-bmwill@google.com \
    --to=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jonathantanmy@google.com \
    --cc=peff@peff.net \
    --cc=sbeller@google.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).