Skip to contentSkip to conversation

submodule recursion in git-archive

PATCH In review Nick Townsend 5 participants 19 messages Jun 15, 2016 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 submodule recursion in git-archive

All,
My first git patch - so shout out if I’ve got the etiquette wrong! Or of course if I’ve missed something. I googled around looking for solutions to my problem but just came up with a few shell-scripts that didn’t quite get the functionality I needed.
The first patch fixes some typos that crept in to existing doc and declarations. It is required for the second which actually implements the changes.

All comments gratefully received!

Regards
Nick Townsend

Subject: [PATCH 1/2] submodule: add_submodule_odb() usability

Although add_submodule_odb() is documented as being externally usable, it is declared static and also has incorrect documentation.

This commit fixes those and makes no changes to
existing code using them. All tests still pass.

---
 Documentation/technical/api-ref-iteration.txt | 4 ++--
 submodule.c                                   | 2 +-
 submodule.h                                   | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)
Documentation/technical/api-ref-iteration.txt +2 -2
index aa1c50f..cbee624 100644
@@ -50,10 +50,10 @@ submodules object database. You can do this by a code-snippet like
 this:
 
 	const char *path = "path/to/submodule"
-	if (!add_submodule_odb(path))
+	if (add_submodule_odb(path))
 		die("Error submodule '%s' not populated.", path);
 
-`add_submodule_odb()` will return an non-zero value on success. If you
+`add_submodule_odb()` will return a zero value on success. If you
 do not do this you will get an error for each ref that it does not point
 to a valid object.
 
submodule.c +1 -1
index 1905d75..1ea46be 100644
@@ -143,7 +143,7 @@ void stage_updated_gitmodules(void)
 		die(_("staging updated .gitmodules failed"));
 }
 
-static int add_submodule_odb(const char *path)
+int add_submodule_odb(const char *path)
 {
 	struct strbuf objects_directory = STRBUF_INIT;
 	struct alternate_object_database *alt_odb;
submodule.h +1 -0
index 7beec48..3e3cdca 100644
@@ -41,5 +41,6 @@ int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_nam
 		struct string_list *needs_pushing);
 int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name);
 void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
+int add_submodule_odb(const char *path);
 
 #endif
Signature · 32 lines
1.8.3.4 (Apple Git-47)

Subject: [PATCH 2/2] archive: allow submodule recursion on git-archive

When using git-archive to produce a dump of a
repository, the existing code does not recurse
into a submodule when it encounters it in the tree
traversal. These changes add a command line flag
that permits this.

Note that the submodules must be updated in the
repository, otherwise this cannot take place.

The feature is disabled for remote repositories as
the git_work_tree fails. This is a possible future
enhancement.

Two additional fields are added to archiver_args:
  * recurse  - a boolean indicator
  * treepath - the path part of the tree-ish
               eg. the 'www' in HEAD:www

The latter is used within the archive writer to
determin the correct path for the submodule .git
file.

Signed-off-by: Nick Townsend <[email protected]>
---
 Documentation/git-archive.txt |  9 +++++++++
 archive.c                     | 38 ++++++++++++++++++++++++++++++++++++--
 archive.h                     |  2 ++
 3 files changed, 47 insertions(+), 2 deletions(-)
Documentation/git-archive.txt +9 -0
index b97aaab..b4df735 100644
@@ -11,6 +11,7 @@ SYNOPSIS
 [verse]
 'git archive' [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]
 	      [-o <file> | --output=<file>] [--worktree-attributes]
+	      [--recursive|--recurse-submodules]
 	      [--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>
 	      [<path>...]
 
@@ -51,6 +52,14 @@ OPTIONS
 --prefix=<prefix>/::
 	Prepend <prefix>/ to each filename in the archive.
 
+--recursive::
+--recurse-submodules::
+	Archive entries in submodules. Errors occur if the submodules
+	have not been initialized and updated.
+	Run `git submodule update --init --recursive` immediately after
+	the clone is finished to avoid this.
+	This option is not available with remote repositories.
+
 -o <file>::
 --output=<file>::
 	Write the archive to <file> instead of stdout.
archive.c +36 -2
index 346f3b2..f6313c9 100644
@@ -5,6 +5,7 @@
 #include "archive.h"
 #include "parse-options.h"
 #include "unpack-trees.h"
+#include "submodule.h"
 
 static char const * const archive_usage[] = {
 	N_("git archive [options] <tree-ish> [<path>...]"),
@@ -131,13 +132,32 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
 		args->convert = ATTR_TRUE(check[1].value);
 	}
 
+	if (S_ISGITLINK(mode) && args->recurse) {
+		const char *work_tree = get_git_work_tree();
+		if (!work_tree) {
+			  die("Can't go recursive when no work dir");
+		}
+		static struct strbuf dotgit = STRBUF_INIT;
+		strbuf_reset(&dotgit);
+		strbuf_grow(&dotgit, PATH_MAX);
+		strbuf_addstr(&dotgit, work_tree);
+		strbuf_addch(&dotgit, '/');
+		if (args->treepath) {
+			  strbuf_addstr(&dotgit, args->treepath);
+			  strbuf_addch(&dotgit, '/');
+		}
+		strbuf_add(&dotgit, path_without_prefix,strlen(path_without_prefix)-1);
+		if (add_submodule_odb(dotgit.buf))
+			  die("Can't add submodule: %s", dotgit.buf);
+		strbuf_release(&dotgit);
+	}
 	if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
 		if (args->verbose)
 			fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
 		err = write_entry(args, sha1, path.buf, path.len, mode);
 		if (err)
 			return err;
-		return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
+		return (S_ISGITLINK(mode) && !args->recurse) ? 0: READ_TREE_RECURSIVE;
 	}
 
 	if (args->verbose)
@@ -256,10 +276,16 @@ static void parse_treeish_arg(const char **argv,
 	const struct commit *commit;
 	unsigned char sha1[20];
 
+	const char *colon = strchr(name, ':');
+
+	/* Store the path on the ref for later (required for --recursive) */
+	char *treepath = NULL;
+	if (colon) {
+		treepath = strdup(colon+1);
+	}
 	/* Remotes are only allowed to fetch actual refs */
 	if (remote) {
 		char *ref = NULL;
-		const char *colon = strchr(name, ':');
 		int refnamelen = colon ? colon - name : strlen(name);
 
 		if (!dwim_ref(name, refnamelen, sha1, &ref))
@@ -296,9 +322,11 @@ static void parse_treeish_arg(const char **argv,
 		tree = parse_tree_indirect(tree_sha1);
 	}
 	ar_args->tree = tree;
+	ar_args->treepath = treepath;
 	ar_args->commit_sha1 = commit_sha1;
 	ar_args->commit = commit;
 	ar_args->time = archive_time;
+
 }
 
 #define OPT__COMPR(s, v, h, p) \
@@ -318,6 +346,7 @@ static int parse_archive_args(int argc, const char **argv,
 	const char *exec = NULL;
 	const char *output = NULL;
 	int compression_level = -1;
+	int recurse = 0;
 	int verbose = 0;
 	int i;
 	int list = 0;
@@ -331,6 +360,8 @@ static int parse_archive_args(int argc, const char **argv,
 			N_("write the archive to this file")),
 		OPT_BOOL(0, "worktree-attributes", &worktree_attributes,
 			N_("read .gitattributes in working directory")),
+		OPT_BOOL(0, "recursive", &recurse, N_("include submodules in archive")),
+		OPT_BOOL(0, "recurse-submodules", &recurse, N_("include submodules in archive")),
 		OPT__VERBOSE(&verbose, N_("report archived files on stderr")),
 		OPT__COMPR('0', &compression_level, N_("store only"), 0),
 		OPT__COMPR('1', &compression_level, N_("compress faster"), 1),
@@ -355,6 +386,8 @@ static int parse_archive_args(int argc, const char **argv,
 
 	argc = parse_options(argc, argv, NULL, opts, archive_usage, 0);
 
+	if (is_remote && recurse)
+		die("Cannot include submodules with option --remote");
 	if (remote)
 		die("Unexpected option --remote");
 	if (exec)
@@ -393,6 +426,7 @@ static int parse_archive_args(int argc, const char **argv,
 					format, compression_level);
 		}
 	}
+	args->recurse = recurse;
 	args->verbose = verbose;
 	args->base = base;
 	args->baselen = strlen(base);
archive.h +2 -0
index 4a791e1..577238d 100644
@@ -7,10 +7,12 @@ struct archiver_args {
 	const char *base;
 	size_t baselen;
 	struct tree *tree;
+	const char *treepath;
 	const unsigned char *commit_sha1;
 	const struct commit *commit;
 	time_t time;
 	struct pathspec pathspec;
+	unsigned int recurse : 1;
 	unsigned int verbose : 1;
 	unsigned int worktree_attributes : 1;
 	unsigned int convert : 1;
Signature · 1 line
1.8.3.4 (Apple Git-47)
#1 lore raw

Am 26.11.2013 01:04, schrieb Nick Townsend:

Quoted 2 lines

My first git patch - so shout out if I’ve got the etiquette wrong! Or of course if I’ve missed something.

Thanks for the patches! Please send only one per message (the second one as a reply to the first one, or both as replies to a cover letter), though -- that makes commenting on them much easier.

Side note: Documentation/SubmittingPatches doesn't mention that (yet), AFAICS.

Quoted 8 lines

Subject: [PATCH 1/2] submodule: add_submodule_odb() usability

Although add_submodule_odb() is documented as being externally usable, it is declared static and also has incorrect documentation.

This commit fixes those and makes no changes to
existing code using them. All tests still pass.

Sign-off missing (see Documentation/SubmittingPatches).

Quoted 11 lines
---
 Documentation/technical/api-ref-iteration.txt | 4 ++--
 submodule.c                                   | 2 +-
 submodule.h                                   | 1 +
 3 files changed, 4 insertions(+), 3 deletions(-)
Documentation/technical/api-ref-iteration.txt +0 -0
index aa1c50f..cbee624 100644

Documentation/technical/api-ref-iteration.txt submodules object database. You can do this by a code-snippet like · line 56

Quoted 9 lines
Documentation/technical/api-ref-iteration.txt +2 -2
@@ -50,10 +50,10 @@ submodules object database. You can do this by a code-snippet like
 this:
 
 	const char *path = "path/to/submodule"
-	if (!add_submodule_odb(path))
+	if (add_submodule_odb(path))
 		die("Error submodule '%s' not populated.", path);
 
-`add_submodule_odb()` will return an non-zero value on success. If you
+`add_submodule_odb()` will return a zero value on success. If you

"return zero on success" instead?

Quoted 36 lines
Documentation/technical/api-ref-iteration.txt +0 -0
 do not do this you will get an error for each ref that it does not point
 to a valid object.
 
submodule.c +1 -1
index 1905d75..1ea46be 100644
@@ -143,7 +143,7 @@ void stage_updated_gitmodules(void)
 		die(_("staging updated .gitmodules failed"));
 }
 
-static int add_submodule_odb(const char *path)
+int add_submodule_odb(const char *path)
 {
 	struct strbuf objects_directory = STRBUF_INIT;
 	struct alternate_object_database *alt_odb;
submodule.h +1 -0
index 7beec48..3e3cdca 100644
@@ -41,5 +41,6 @@ int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_nam
 		struct string_list *needs_pushing);
 int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name);
 void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
+int add_submodule_odb(const char *path);
 
 #endif

Subject: [PATCH 2/2] archive: allow submodule recursion on git-archive

When using git-archive to produce a dump of a repository, the existing code does not recurse into a submodule when it encounters it in the tree traversal. These changes add a command line flag that permits this.

Quoted 6 lines

Note that the submodules must be updated in the
repository, otherwise this cannot take place.

The feature is disabled for remote repositories as the git_work_tree fails. This is a possible future enhancement.

Hmm, curious. Why does it fail? I guess that happens with bare repositories, only, right? (Which are the most likely kind of remote repos to encounter, of course.)

Quoted 21 lines

Two additional fields are added to archiver_args:
* recurse - a boolean indicator
* treepath - the path part of the tree-ish
eg. the 'www' in HEAD:www

The latter is used within the archive writer to
determin the correct path for the submodule .git
file.

---
 Documentation/git-archive.txt |  9 +++++++++
 archive.c                     | 38 ++++++++++++++++++++++++++++++++++++--
 archive.h                     |  2 ++
 3 files changed, 47 insertions(+), 2 deletions(-)
Documentation/git-archive.txt +0 -0
index b97aaab..b4df735 100644

Documentation/git-archive.txt SYNOPSIS · line 14

Quoted 4 lines
Documentation/git-archive.txt +1 -0
@@ -11,6 +11,7 @@ SYNOPSIS
 [verse]
 'git archive' [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]
 	      [-o <file> | --output=<file>] [--worktree-attributes]
+	      [--recursive|--recurse-submodules]

I'd expect git archive --recurse to add subdirectories and their contents, which it does right now, and --no-recurse to only archive the specified objects, which is not implemented. IAW: I wouldn't normally associate an option with that name with submodules. Would --recurse-submodules alone suffice?

Side note: With only one of the options defined you could shorten them on the command line to e.g. --rec; with both you'd need to type at least --recursi or --recurse to disambiguate -- even though they ultimately do the same.

Quoted 31 lines
Documentation/git-archive.txt +8 -0
 	      [--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>
 	      [<path>...]
 
@@ -51,6 +52,14 @@ OPTIONS
 --prefix=<prefix>/::
 	Prepend <prefix>/ to each filename in the archive.
 
+--recursive::
+--recurse-submodules::
+	Archive entries in submodules. Errors occur if the submodules
+	have not been initialized and updated.
+	Run `git submodule update --init --recursive` immediately after
+	the clone is finished to avoid this.
+	This option is not available with remote repositories.
+
 -o <file>::
 --output=<file>::
 	Write the archive to <file> instead of stdout.
archive.c +1 -0
index 346f3b2..f6313c9 100644
@@ -5,6 +5,7 @@
 #include "archive.h"
 #include "parse-options.h"
 #include "unpack-trees.h"
+#include "submodule.h"
 
 static char const * const archive_usage[] = {
 	N_("git archive [options] <tree-ish> [<path>...]"),

archive.c static int write_archive_entry(const unsigned char *sha1, const char *base, · line 139

Quoted 8 lines
archive.c +5 -0
@@ -131,13 +132,32 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
 		args->convert = ATTR_TRUE(check[1].value);
 	}
 
+	if (S_ISGITLINK(mode) && args->recurse) {
+		const char *work_tree = get_git_work_tree();
+		if (!work_tree) {
+			  die("Can't go recursive when no work dir");
+		}

Style nit: No curly braces around single-line statements, please.

Perhaps mention submodules in the error message?

It would be nicer to get_git_work_tree right after the parameters have been parsed and before any archive contents have been written and error out early.

archive.c static int write_archive_entry(const unsigned char *sha1, const char *base, · line 140

Quoted 1 line
archive.c +1 -0
+		static struct strbuf dotgit = STRBUF_INIT;

We avoid declarations after statements because older compilers don't support it.

You release the memory at the end of this block; that means there's no advantage in making this strbuf static. Allocating and freeing the memory for the path of each submodule shouldn't cause any performance issues, so please just drop static from the declaration.

archive.c static int write_archive_entry(const unsigned char *sha1, const char *base, · line 141

Quoted 1 line
archive.c +1 -0
+		strbuf_reset(&dotgit);

... and then you don't need to reset anymore.

archive.c static int write_archive_entry(const unsigned char *sha1, const char *base, · line 142

Quoted 1 line
archive.c +1 -0
+		strbuf_grow(&dotgit, PATH_MAX);

I'd drop that as well; the number of submodules should be low enough that the possibly avoided reallocations by giving this hint shouldn't be noticeable.

archive.c static int write_archive_entry(const unsigned char *sha1, const char *base, · line 151

Quoted 9 lines
archive.c +9 -0
+		strbuf_addstr(&dotgit, work_tree);
+		strbuf_addch(&dotgit, '/');
+		if (args->treepath) {
+			  strbuf_addstr(&dotgit, args->treepath);
+			  strbuf_addch(&dotgit, '/');
+		}
+		strbuf_add(&dotgit, path_without_prefix,strlen(path_without_prefix)-1);
+		if (add_submodule_odb(dotgit.buf))
+			  die("Can't add submodule: %s", dotgit.buf);

Hmm, I wonder if we can traverse the tree and load all submodule object databases before traversing it again to actually write file contents. That would spare the user from getting half of an archive together with that error message.

archive.c static int write_archive_entry(const unsigned char *sha1, const char *base, · line 160

Quoted 10 lines
archive.c +3 -1
+		strbuf_release(&dotgit);
+	}
 	if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
 		if (args->verbose)
 			fprintf(stderr, "%.*s\n", (int)path.len, path.buf);
 		err = write_entry(args, sha1, path.buf, path.len, mode);
 		if (err)
 			return err;
-		return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
+		return (S_ISGITLINK(mode) && !args->recurse) ? 0: READ_TREE_RECURSIVE;

This line is longer than 80 characters, which we tend to avoid. How about this?

		if (ISGITLINK(mode) && !args->recurse)
			return 0;
		return READ_TREE_RECURSIVE;
Quoted 4 lines
archive.c +0 -0
 	}
 
 	if (args->verbose)

archive.c static void parse_treeish_arg(const char **argv, · line 285

Quoted 10 lines
archive.c +7 -0
@@ -256,10 +276,16 @@ static void parse_treeish_arg(const char **argv,
 	const struct commit *commit;
 	unsigned char sha1[20];
 
+	const char *colon = strchr(name, ':');
+
+	/* Store the path on the ref for later (required for --recursive) */
+	char *treepath = NULL;
+	if (colon) {
+		treepath = strdup(colon+1);
+	}

Style: No curly braces, space around operators, use wrapper functions for simple memory error handling:

	if (colon)
		treepath = xstrdup(colon + 1);
Quoted 8 lines
archive.c +0 -1
 	/* Remotes are only allowed to fetch actual refs */
 	if (remote) {
 		char *ref = NULL;
-		const char *colon = strchr(name, ':');
 		int refnamelen = colon ? colon - name : strlen(name);
 
 		if (!dwim_ref(name, refnamelen, sha1, &ref))

archive.c static void parse_treeish_arg(const char **argv, · line 330

Quoted 9 lines
archive.c +2 -0
@@ -296,9 +322,11 @@ static void parse_treeish_arg(const char **argv,
 		tree = parse_tree_indirect(tree_sha1);
 	}
 	ar_args->tree = tree;
+	ar_args->treepath = treepath;
 	ar_args->commit_sha1 = commit_sha1;
 	ar_args->commit = commit;
 	ar_args->time = archive_time;
+
 }

Please don't add empty lines before the end of a block.

Quoted 40 lines
archive.c +6 -0
 #define OPT__COMPR(s, v, h, p) \
@@ -318,6 +346,7 @@ static int parse_archive_args(int argc, const char **argv,
 	const char *exec = NULL;
 	const char *output = NULL;
 	int compression_level = -1;
+	int recurse = 0;
 	int verbose = 0;
 	int i;
 	int list = 0;
@@ -331,6 +360,8 @@ static int parse_archive_args(int argc, const char **argv,
 			N_("write the archive to this file")),
 		OPT_BOOL(0, "worktree-attributes", &worktree_attributes,
 			N_("read .gitattributes in working directory")),
+		OPT_BOOL(0, "recursive", &recurse, N_("include submodules in archive")),
+		OPT_BOOL(0, "recurse-submodules", &recurse, N_("include submodules in archive")),
 		OPT__VERBOSE(&verbose, N_("report archived files on stderr")),
 		OPT__COMPR('0', &compression_level, N_("store only"), 0),
 		OPT__COMPR('1', &compression_level, N_("compress faster"), 1),
@@ -355,6 +386,8 @@ static int parse_archive_args(int argc, const char **argv,
 
 	argc = parse_options(argc, argv, NULL, opts, archive_usage, 0);
 
+	if (is_remote && recurse)
+		die("Cannot include submodules with option --remote");
 	if (remote)
 		die("Unexpected option --remote");
 	if (exec)
@@ -393,6 +426,7 @@ static int parse_archive_args(int argc, const char **argv,
 					format, compression_level);
 		}
 	}
+	args->recurse = recurse;
 	args->verbose = verbose;
 	args->base = base;
 	args->baselen = strlen(base);
archive.h +0 -0
index 4a791e1..577238d 100644

archive.h struct archiver_args { · line 15

Quoted 9 lines
archive.h +2 -0
@@ -7,10 +7,12 @@ struct archiver_args {
 	const char *base;
 	size_t baselen;
 	struct tree *tree;
+	const char *treepath;
 	const unsigned char *commit_sha1;
 	const struct commit *commit;
 	time_t time;
 	struct pathspec pathspec;
+	unsigned int recurse : 1;

Name it recurse_submodules?

archive.h struct archiver_args {

Quoted 4 lines
archive.h +0 -1
 	unsigned int verbose : 1;
 	unsigned int worktree_attributes : 1;
 	unsigned int convert : 1;
-- 1.8.3.4 (Apple Git-47) 

A test script (t/t5005-archive-submodules.sh?) would be nice which exercises the new option.

René

#2 lore raw

Am 26.11.2013 16:17, schrieb René Scharfe:

Quoted 16 lines

Am 26.11.2013 01:04, schrieb Nick Townsend:

Documentation/git-archive.txt SYNOPSIS · line 14

Quoted 9 lines
Documentation/git-archive.txt +1 -0
index b97aaab..b4df735 100644
@@ -11,6 +11,7 @@ SYNOPSIS
 [verse]
 'git archive' [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]
 	      [-o <file> | --output=<file>] [--worktree-attributes]
+	      [--recursive|--recurse-submodules]

I'd expect git archive --recurse to add subdirectories and their contents, which it does right now, and --no-recurse to only archive the specified objects, which is not implemented. IAW: I wouldn't normally associate an option with that name with submodules. Would --recurse-submodules alone suffice?

It should. All new code recursing into submodules should not use --recursive but always --recurse-submodules, as --recursive means different things for different commands (the only exception being "git submodule", as --recursive is obvious here, and "git clone" for backward compatibility reasons).

But I really like what these patches are aiming at.

#3 lore raw
In reply to René Scharfe

Hi,

I like where this is going.

Quoted 15 lines · René Scharfe

Am 26.11.2013 01:04, schrieb Nick Townsend:

archive.c static int write_archive_entry(const unsigned char *sha1, const char *base, · line 151

Quoted 9 lines
archive.c +9 -0
+		strbuf_addstr(&dotgit, work_tree);
+		strbuf_addch(&dotgit, '/');
+		if (args->treepath) {
+			  strbuf_addstr(&dotgit, args->treepath);
+			  strbuf_addch(&dotgit, '/');
+		}
+		strbuf_add(&dotgit, path_without_prefix,strlen(path_without_prefix)-1);
+		if (add_submodule_odb(dotgit.buf))
+			  die("Can't add submodule: %s", dotgit.buf);

Hmm, I wonder if we can traverse the tree and load all submodule object databases before traversing it again to actually write file contents. That would spare the user from getting half of an archive together with that error message.

I am not sure whether we should die here. What about submodules that have not been initialized and or cloned? I think that is a quite regular use case for example for libraries that not everyone needs or big media submodules which only the design team uses. How about skipping them (maybe issuing a warning) by returning 0 here and proceeding?

Cheers Heiko

#4 lore raw
Quoted 21 lines · Heiko Voigt

Hi,

I like where this is going.

Quoted 15 lines · René Scharfe

Am 26.11.2013 01:04, schrieb Nick Townsend:

archive.c static int write_archive_entry(const unsigned char *sha1, const char *base, · line 151

Quoted 9 lines
archive.c +9 -0
+		strbuf_addstr(&dotgit, work_tree);
+		strbuf_addch(&dotgit, '/');
+		if (args->treepath) {
+			  strbuf_addstr(&dotgit, args->treepath);
+			  strbuf_addch(&dotgit, '/');
+		}
+		strbuf_add(&dotgit, path_without_prefix,strlen(path_without_prefix)-1);
+		if (add_submodule_odb(dotgit.buf))
+			  die("Can't add submodule: %s", dotgit.buf);

Hmm, I wonder if we can traverse the tree and load all submodule object databases before traversing it again to actually write file contents. That would spare the user from getting half of an archive together with that error message.

Quoted 7 lines

I am not sure whether we should die here. What about submodules that have not been initialized and or cloned? I think that is a quite regular use case for example for libraries that not everyone needs or big media submodules which only the design team uses. How about skipping them (maybe issuing a warning) by returning 0 here and proceeding?

Cheers Heiko

I agree that issuing a warning and continuing is best. If the submodule hasn’t been setup then we should respect that and keep the current behaviour (just archive the directory entry). There is some further debate to be had about the extent to which this should work with un-initialized submodules which I’ll discuss in other replies.

Thanks
Nick

#5 lore raw
In reply to René Scharfe
Quoted 6 lines · René Scharfe

Thanks for the patches! Please send only one per message (the second one as a reply to the first one, or both as replies to a cover letter), though -- that makes commenting on them much easier.

Side note: Documentation/SubmittingPatches doesn't mention that (yet), AFAICS.

OK, how about doing this then?

 Documentation/SubmittingPatches | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Documentation/SubmittingPatches +6 -1
index 7055576..304b3c0 100644
@@ -140,7 +140,12 @@ comment on the changes you are submitting.  It is important for
 a developer to be able to "quote" your changes, using standard
 e-mail tools, so that they may comment on specific portions of
 your code.  For this reason, all patches should be submitted
-"inline".  If your log message (including your name on the
+"inline".  A patch series that consists of N commits is sent as N
+separate e-mail messages, or a cover letter message (see below) with
+N separate e-mail messages, each being a response to the cover
+letter.
+
+If your log message (including your name on the
 Signed-off-by line) is not writable in ASCII, make sure that
 you send off a message in the correct encoding.
 
Quoted 7 lines
Quoted 3 lines

The feature is disabled for remote repositories as the git_work_tree fails. This is a possible future enhancement.

Hmm, curious. Why does it fail? I guess that happens with bare repositories, only, right? (Which are the most likely kind of remote repos to encounter, of course.)

Yeah, I do not think of a reason why it should fail in a bare repository, either. "git archive" is about writing out the contents of an already recorded tree, so there shouldn't be a reason to even call get_git_work_tree() in the first place.

Even if the code is run inside a repository with a working tree, when producing a tarball out of an ancient commit that had a submodule not at its current location, --recurse-submodules option should do the right thing, so asking for working tree location of that submodule to find its repository is wrong, I think. It may happen to find one if the archived revision is close enough to what is currently checked out, but that may not necessarily be the case.

At that point when the code discovers an S_ISGITLINK entry, it should have both a pathname to the submodule relative to the toplevel and the commit object name bound to that submodule location. What it should do, when it does not find the repository at the given path (maybe because there is no working tree, or the sudmodule directory has moved over time) is roughly:

- Read from .gitmodules at the top-level from the tree it is creating the tarball out of;

- Find "submodule.$name.path" entry that records that path to the submodule; and then

- Using that $name, find the stashed-away location of the submodule repository in $GIT_DIR/modules/$name.

or something like that.

This is a related tangent, but when used in a repository that people often use as their remote, the repository discovery may have to interact with the relative URL. People often ship .gitmodules with

	[submodule "bar"]
        	URL = ../bar.git
		path = barDir

for a top-level project "foo" that can be cloned thusly:

git clone git://site.xz/foo.git

and host bar.git to be clonable with

git clone git://site.xz/bar.git barDir/

inside the working tree of the foo project. In such a case, when "archive --recurse-submodules" is running, it would find the repository for the "bar" submodule at "../bar.git", I would think.

So this part needs a bit more thought, I am afraid.

Quoted 9 lines

Review

Quoted 3 lines

'git archive' [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]

(quoted diff) +1 -0
 	      [-o <file> | --output=<file>] [--worktree-attributes]
+	      [--recursive|--recurse-submodules]

I'd expect git archive --recurse to add subdirectories and their contents, which it does right now, and --no-recurse to only archive the specified objects, which is not implemented. IAW: I wouldn't normally associate an option with that name with submodules. Would --recurse-submodules alone suffice?

Jens already commented on this, and I agree that --recursive should be dropped from this patch.

#6 lore raw

Am 26.11.2013 23:18, schrieb Junio C Hamano:

Quoted 21 lines
Quoted 6 lines · René Scharfe

Thanks for the patches! Please send only one per message (the second one as a reply to the first one, or both as replies to a cover letter), though -- that makes commenting on them much easier.

Side note: Documentation/SubmittingPatches doesn't mention that (yet), AFAICS.

OK, how about doing this then?

 Documentation/SubmittingPatches | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Documentation/SubmittingPatches +0 -0
index 7055576..304b3c0 100644
@@ -140,7 +140,12 @@ comment on the changes you are submitting.  It is important for
 a developer to be able to "quote" your changes, using standard
 e-mail tools, so that they may comment on specific portions of

Documentation/SubmittingPatches comment on the changes you are submitting. It is important for · line 150

Quoted 10 lines
Documentation/SubmittingPatches +6 -1
 your code.  For this reason, all patches should be submitted
-"inline".  If your log message (including your name on the
+"inline".  A patch series that consists of N commits is sent as N
+separate e-mail messages, or a cover letter message (see below) with
+N separate e-mail messages, each being a response to the cover
+letter.
+
+If your log message (including your name on the
 Signed-off-by line) is not writable in ASCII, make sure that
 you send off a message in the correct encoding.

OK, but the repetition of "cover letter" and "e-mail messages" irritates me slightly for some reason. What about the following?

-- >8 --
Subject: [PATCH] SubmittingPatches: document how to handle multiple patches

---
 Documentation/SubmittingPatches |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
Documentation/SubmittingPatches +9 -2
index 7055576..e6d46ed 100644
@@ -139,8 +139,15 @@ People on the Git mailing list need to be able to read and
 comment on the changes you are submitting.  It is important for
 a developer to be able to "quote" your changes, using standard
 e-mail tools, so that they may comment on specific portions of
-your code.  For this reason, all patches should be submitted
-"inline".  If your log message (including your name on the
+your code.  For this reason, each patch should be submitted
+"inline" in a separate message.
+
+Multiple related patches should be grouped into their own e-mail
+thread to help readers find all parts of the series.  To that end,
+send them as replies to either an additional "cover letter" message
+(see below), the first patch, or the respective preceding patch.
+
+If your log message (including your name on the
 Signed-off-by line) is not writable in ASCII, make sure that
 you send off a message in the correct encoding.
 
Signature · 1 line
1.7.8
#7 lore raw
Quoted 63 lines · René Scharfe

Am 26.11.2013 23:18, schrieb Junio C Hamano:

Quoted 29 lines
Quoted 6 lines · René Scharfe

Thanks for the patches! Please send only one per message (the second one as a reply to the first one, or both as replies to a cover letter), though -- that makes commenting on them much easier.

Side note: Documentation/SubmittingPatches doesn't mention that (yet), AFAICS.

OK, how about doing this then?

Documentation/SubmittingPatches | 7 ++++++-

1 file changed, 6 insertions(+), 1 deletion(-)
Documentation/SubmittingPatches +0 -0
index 7055576..304b3c0 100644
@@ -140,7 +140,12 @@ comment on the changes you are submitting.  It is important for

a developer to be able to "quote" your changes, using standard e-mail tools, so that they may comment on specific portions of

your code.  For this reason, all patches should be submitted
-"inline".  If your log message (including your name on the
+"inline".  A patch series that consists of N commits is sent as N
Documentation/SubmittingPatches +5 -0
+separate e-mail messages, or a cover letter message (see below) with
+N separate e-mail messages, each being a response to the cover
+letter.
+
+If your log message (including your name on the
Quoted 2 lines

Signed-off-by line) is not writable in ASCII, make sure that you send off a message in the correct encoding.

OK, but the repetition of "cover letter" and "e-mail messages" irritates me slightly for some reason. What about the following?

-- >8 --
Subject: [PATCH] SubmittingPatches: document how to handle multiple patches

---
Documentation/SubmittingPatches | 11 +++++++++--

1 files changed, 9 insertions(+), 2 deletions(-)
Documentation/SubmittingPatches +0 -0
index 7055576..e6d46ed 100644
@@ -139,8 +139,15 @@ People on the Git mailing list need to be able to read and

comment on the changes you are submitting. It is important for a developer to be able to "quote" your changes, using standard e-mail tools, so that they may comment on specific portions of

Documentation/SubmittingPatches +9 -2
-your code.  For this reason, all patches should be submitted
-"inline".  If your log message (including your name on the
+your code.  For this reason, each patch should be submitted
+"inline" in a separate message.
+
+Multiple related patches should be grouped into their own e-mail
+thread to help readers find all parts of the series.  To that end,
+send them as replies to either an additional "cover letter" message
+(see below), the first patch, or the respective preceding patch.
+
+If your log message (including your name on the
Quoted 7 lines

Signed-off-by line) is not writable in ASCII, make sure that you send off a message in the correct encoding.

Signature · 1 line
1.7.8

That seems clear to me.
At any rate I’m going to rework this based on the collective input and will submit them again. Please check my other replies as there are some discussion points!

Nick

#8 lore raw
In reply to René Scharfe
Quoted 2 lines · René Scharfe

OK, but the repetition of "cover letter" and "e-mail messages" irritates me slightly for some reason. What about the following?

Looks good to me; will queue, thanks.

Quoted 29 lines

-- >8 --
Subject: [PATCH] SubmittingPatches: document how to handle multiple patches

---
 Documentation/SubmittingPatches |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
Documentation/SubmittingPatches +9 -2
index 7055576..e6d46ed 100644
@@ -139,8 +139,15 @@ People on the Git mailing list need to be able to read and
 comment on the changes you are submitting.  It is important for
 a developer to be able to "quote" your changes, using standard
 e-mail tools, so that they may comment on specific portions of
-your code.  For this reason, all patches should be submitted
-"inline".  If your log message (including your name on the
+your code.  For this reason, each patch should be submitted
+"inline" in a separate message.
+
+Multiple related patches should be grouped into their own e-mail
+thread to help readers find all parts of the series.  To that end,
+send them as replies to either an additional "cover letter" message
+(see below), the first patch, or the respective preceding patch.
+
+If your log message (including your name on the
 Signed-off-by line) is not writable in ASCII, make sure that
 you send off a message in the correct encoding.
#9 lore raw
In reply to Junio C Hamano
Quoted 37 lines · Junio C Hamano
Quoted 6 lines · René Scharfe

Thanks for the patches! Please send only one per message (the second one as a reply to the first one, or both as replies to a cover letter), though -- that makes commenting on them much easier.

Side note: Documentation/SubmittingPatches doesn't mention that (yet), AFAICS.

OK, how about doing this then?

Documentation/SubmittingPatches | 7 ++++++-

1 file changed, 6 insertions(+), 1 deletion(-)
Documentation/SubmittingPatches +0 -0
index 7055576..304b3c0 100644
@@ -140,7 +140,12 @@ comment on the changes you are submitting.  It is important for

a developer to be able to "quote" your changes, using standard e-mail tools, so that they may comment on specific portions of

your code.  For this reason, all patches should be submitted
-"inline".  If your log message (including your name on the
+"inline".  A patch series that consists of N commits is sent as N
Documentation/SubmittingPatches +5 -0
+separate e-mail messages, or a cover letter message (see below) with
+N separate e-mail messages, each being a response to the cover
+letter.
+
+If your log message (including your name on the

Signed-off-by line) is not writable in ASCII, make sure that you send off a message in the correct encoding.

Quoted 4 lines
Quoted 3 lines

The feature is disabled for remote repositories as the git_work_tree fails. This is a possible future enhancement.

Quoted 9 lines
Quoted 3 lines

Hmm, curious. Why does it fail? I guess that happens with bare repositories, only, right? (Which are the most likely kind of remote repos to encounter, of course.)

Yeah, I do not think of a reason why it should fail in a bare repository, either. "git archive" is about writing out the contents of an already recorded tree, so there shouldn't be a reason to even call get_git_work_tree() in the first place.

See below for a discussion of why I use the .git file in the work tree to load the objects for the submodule. I also thought it should work in a remote repository - but I ran it on a properly initialized remote repository and it failed. Since I didn’t need it for my immediate use-case I just decided to disable it with an error. I can look into this further, but we must decide about the question below first…

Quoted 40 lines

Even if the code is run inside a repository with a working tree, when producing a tarball out of an ancient commit that had a submodule not at its current location, --recurse-submodules option should do the right thing, so asking for working tree location of that submodule to find its repository is wrong, I think. It may happen to find one if the archived revision is close enough to what is currently checked out, but that may not necessarily be the case.

At that point when the code discovers an S_ISGITLINK entry, it should have both a pathname to the submodule relative to the toplevel and the commit object name bound to that submodule location. What it should do, when it does not find the repository at the given path (maybe because there is no working tree, or the sudmodule directory has moved over time) is roughly:

- Read from .gitmodules at the top-level from the tree it is creating the tarball out of;

- Find "submodule.$name.path" entry that records that path to the submodule; and then

- Using that $name, find the stashed-away location of the submodule repository in $GIT_DIR/modules/$name.

or something like that.

This is a related tangent, but when used in a repository that people often use as their remote, the repository discovery may have to interact with the relative URL. People often ship .gitmodules with

	[submodule "bar"]
       	URL = ../bar.git
		path = barDir

for a top-level project "foo" that can be cloned thusly:

git clone git://site.xz/foo.git

and host bar.git to be clonable with

Quoted 7 lines

git clone git://site.xz/bar.git barDir/

inside the working tree of the foo project. In such a case, when "archive --recurse-submodules" is running, it would find the repository for the "bar" submodule at "../bar.git", I would think.

So this part needs a bit more thought, I am afraid.

I see that there is a lot of potential complexity around setting up a submodule:
* The .gitmodules file can be dirty (easy to flag, but should we allow archive to proceed?)
* Users can mess with settings both prior to git submodule init and before git submodule update.
* What if it’s a raw clone and the user manually changes things between init and update?
* I’m not a git-internals expert but looking through the code I see that you can add additional object directories and change paths as you show above.

For those reasons I deliberately decided not to reproduce the above logic all by myself. On the other hand, what it *did* seem to me is that once you have the .git file then you know you’ve got all that covered. So I just used that. This restricts the function to working only on a properly setup repository - but that is my use case!

If you think that doing this more extensive setup is even *viable* given the space between init and update then I”m happy to try it. I didn’t want to start off on a fools errand.

Quoted 11 lines
Quoted 10 lines

Review

Quoted 4 lines

'git archive' [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]

	      [-o <file> | --output=<file>] [--worktree-attributes]
(quoted diff) +1 -0
+	      [--recursive|--recurse-submodules]

I'd expect git archive --recurse to add subdirectories and their contents, which it does right now, and --no-recurse to only archive the specified objects, which is not implemented. IAW: I wouldn't normally associate an option with that name with submodules. Would --recurse-submodules alone suffice?

Quoted 2 lines

Jens already commented on this, and I agree that --recursive should be dropped from this patch.

I only put —recursive because that is what git-clone has for it’s behaviour wrt submodules. If that flag is deprecated then I’m fine with using only —recurse-submodules Perhaps a deprecation flag or note in the code would help?

Overall I’m impressed by the speed and quality of the responses (and the codebase!) so am glad to move this forward. I look forward to your feedback.

Kind Regards
Nick

#10 lore raw
Quoted 44 lines · Nick Townsend
Quoted 42 lines · Junio C Hamano

Even if the code is run inside a repository with a working tree, when producing a tarball out of an ancient commit that had a submodule not at its current location, --recurse-submodules option should do the right thing, so asking for working tree location of that submodule to find its repository is wrong, I think. It may happen to find one if the archived revision is close enough to what is currently checked out, but that may not necessarily be the case.

At that point when the code discovers an S_ISGITLINK entry, it should have both a pathname to the submodule relative to the toplevel and the commit object name bound to that submodule location. What it should do, when it does not find the repository at the given path (maybe because there is no working tree, or the sudmodule directory has moved over time) is roughly:

- Read from .gitmodules at the top-level from the tree it is creating the tarball out of;

- Find "submodule.$name.path" entry that records that path to the submodule; and then

- Using that $name, find the stashed-away location of the submodule repository in $GIT_DIR/modules/$name.

or something like that.

This is a related tangent, but when used in a repository that people often use as their remote, the repository discovery may have to interact with the relative URL. People often ship .gitmodules with

	[submodule "bar"]
       	URL = ../bar.git
		path = barDir

for a top-level project "foo" that can be cloned thusly:

git clone git://site.xz/foo.git

and host bar.git to be clonable with

git clone git://site.xz/bar.git barDir/

Quoted 7 lines
Quoted 5 lines

inside the working tree of the foo project. In such a case, when "archive --recurse-submodules" is running, it would find the repository for the "bar" submodule at "../bar.git", I would think.

So this part needs a bit more thought, I am afraid.

I see that there is a lot of potential complexity around setting up a submodule:

No question about it.

Quoted 2 lines

* The .gitmodules file can be dirty (easy to flag, but should we allow archive to proceed?)

As we are discussing "archive", which takes a tree object from the top-level project that is recorded in the object database, the information _about_ the submodule in question should come from the given tree being archived. There is no reason for the .gitmodules file that happens to be sitting in the working tree of the top-level project to be involved in the decision, so its dirtyness should not matter, I think. If the tree being archived has a submodule whose name is "kernel" at path "linux/" (relative to the top-level project), its repository should be at .git/modules/kernel in the layout recent git-submodule prepares, and we should find that path-and-name mapping from .gitmodules recorded in that tree object we are archiving. The version that happens to be checked out to the working tree may have moved the submodule to a new path "linux-3.0/" and "linux-3.0/.git" may have "gitdir: .git/modules/kernel" in it, but when archiving a tree that has the submodule at "linux/", it would not help---we would not know to look at "linux-3.0/.git" to learn that information anyway because .gitmodules in the working tree would say that the submodule at path "linux-3.0/" is with name "kernel", and would not tell us anything about "linux/".

Quoted 2 lines

* Users can mess with settings both prior to git submodule init and before git submodule update.

I think this is irrelevant for exactly the same reason as above.

What makes this tricker, however, is how to deal with an old-style repository, where the submodule repositories are embedded in the working tree that happens to be checked out. In that case, we may have to read .gitmodules from two places, i.e.

(1) We are archiving a tree with a submodule at "linux/";

(2) We read .gitmodules from that tree and learn that the submodule

     has name "kernel";

(3) There is no ".git/modules/kernel" because the repository uses the old layout (if the user never was interested in this submodule, .git/modules/kernel may also be missing, and we should tell these two cases apart by checking .git/config to see if a corresponding entry for the "kernel" submodule exists there);

(4) In a repository that uses the old layout, there must be the repository somewhere embedded in the current working tree (this inability to remove is why we use the new layout these days). We can learn where it is by looking at .gitmodules in the working tree---map the name "kernel" we learned earlier, and map it to the current path ("linux-3.0/" if you have been following this example so far).

And in that fallback context, I would say that reading from a dirty (or "messed with by the user") .gitmodules is the right thing to do. Perhaps the user may be in the process of moving the submodule in his working tree with

    $ mv linux-3.0 linux-3.2
    $ git config -f .gitmodules submodule.kernel.path linux-3.2

but hasn't committed the change yet.

Quoted 2 lines

For those reasons I deliberately decided not to reproduce the above logic all by myself.

As I already hinted, I agree that the "how to find the location of submodule repository, given a particular tree in the top-level project the submodule belongs to and the path to the submodule in question" deserves a separate thread to discuss with area experts.

#11 lore raw
Quoted 64 lines · Junio C Hamano
Quoted 2 lines · Nick Townsend

* The .gitmodules file can be dirty (easy to flag, but should we allow archive to proceed?)

As we are discussing "archive", which takes a tree object from the top-level project that is recorded in the object database, the information _about_ the submodule in question should come from the given tree being archived. There is no reason for the .gitmodules file that happens to be sitting in the working tree of the top-level project to be involved in the decision, so its dirtyness should not matter, I think. If the tree being archived has a submodule whose name is "kernel" at path "linux/" (relative to the top-level project), its repository should be at .git/modules/kernel in the layout recent git-submodule prepares, and we should find that path-and-name mapping from .gitmodules recorded in that tree object we are archiving. The version that happens to be checked out to the working tree may have moved the submodule to a new path "linux-3.0/" and "linux-3.0/.git" may have "gitdir: .git/modules/kernel" in it, but when archiving a tree that has the submodule at "linux/", it would not help---we would not know to look at "linux-3.0/.git" to learn that information anyway because .gitmodules in the working tree would say that the submodule at path "linux-3.0/" is with name "kernel", and would not tell us anything about "linux/".

Quoted 2 lines

* Users can mess with settings both prior to git submodule init and before git submodule update.

I think this is irrelevant for exactly the same reason as above.

What makes this tricker, however, is how to deal with an old-style repository, where the submodule repositories are embedded in the working tree that happens to be checked out. In that case, we may have to read .gitmodules from two places, i.e.

(1) We are archiving a tree with a submodule at "linux/";

(2) We read .gitmodules from that tree and learn that the submodule

     has name "kernel";

(3) There is no ".git/modules/kernel" because the repository uses the old layout (if the user never was interested in this submodule, .git/modules/kernel may also be missing, and we should tell these two cases apart by checking .git/config to see if a corresponding entry for the "kernel" submodule exists there);

(4) In a repository that uses the old layout, there must be the repository somewhere embedded in the current working tree (this inability to remove is why we use the new layout these days). We can learn where it is by looking at .gitmodules in the working tree---map the name "kernel" we learned earlier, and map it to the current path ("linux-3.0/" if you have been following this example so far).

And in that fallback context, I would say that reading from a dirty (or "messed with by the user") .gitmodules is the right thing to do. Perhaps the user may be in the process of moving the submodule in his working tree with

    $ mv linux-3.0 linux-3.2
    $ git config -f .gitmodules submodule.kernel.path linux-3.2

but hasn't committed the change yet.

Quoted 7 lines
Quoted 2 lines

For those reasons I deliberately decided not to reproduce the above logic all by myself.

As I already hinted, I agree that the "how to find the location of submodule repository, given a particular tree in the top-level project the submodule belongs to and the path to the submodule in question" deserves a separate thread to discuss with area experts.

FYI, I already started to implement this lookup of submodule paths early this year[1] but have not found the time to proceed on that yet. I am planning to continue on that topic soonish. We need it to implement a correct recursive fetch with clone on-demand as a basis for the future recursive checkout.

During the work on this I hit too many open questions. Thats why I am currently working on a complete plan[2] so we can discuss and define how this needs to be implemented. It is an asciidoc document which I will send out once I am finished with it.

Cheers Heiko

[1] http://article.gmane.org/gmane.comp.version-control.git/217020
[2] https://github.com/hvoigt/git/wiki/submodule-fetch-config

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw

Hi,

Quoted 18 lines · Nick Townsend
Quoted 11 lines · Heiko Voigt

FYI, I already started to implement this lookup of submodule paths early this year[1] but have not found the time to proceed on that yet. I am planning to continue on that topic soonish. We need it to implement a correct recursive fetch with clone on-demand as a basis for the future recursive checkout.

During the work on this I hit too many open questions. Thats why I am currently working on a complete plan[2] so we can discuss and define how this needs to be implemented. It is an asciidoc document which I will send out once I am finished with it.

Quoted 4 lines

Cheers Heiko

[1] http://article.gmane.org/gmane.comp.version-control.git/217020
[2] https://github.com/hvoigt/git/wiki/submodule-fetch-config

Quoted 8 lines

It seems to me that the question that you are trying to solve is more complex than the problem I faced in git-archive, where we have a single commit of the top-level repository that we are chasing. Perhaps we should split the work into two pieces:

a. Identifying the complete submodule configuration for a single commit, and b. the complexity of behaviour when fetching and cloning recursively (which
of course requires a.)

You are right the latter (b) is a separate topic. So how about I extract the submodule config parsing part from the mentioned patch and you can then use that patch as a basis for your work? As far as I understand you only need to parse the .gitmodules file for one commit and then lookup the submodule names from paths right? That would simplify matters and we can postpone the caching of multiple commits for the time when I continue on b.

Quoted 4 lines

I’m very happy to work on the first, but the second seems to me to require more understanding than I currently possess. In order to do this it would help to have a place to discuss this. I see you have used the wiki of your fork of git on GitHub. Is that the right place to solicit input?

I only used that to collect all information into one place. I am not sure if thats actually necessary for the .gitmodules parsing you need.

I think we should discuss everything related to the design and patches here on the list. If you have questions regarding my code I am also happy to answer that via private mail.

Cheers Heiko

#14 lore raw

PATCH 1/1 implement reading of submodule .gitmodules configuration into cache

This submodule configuration cache allows us to lazily read .gitmodules configurations by commit into a runtime cache which can then be used to easily lookup values from it. Currently only the values for path or name are stored but it can be extended for any value needed.

This cache can be used for all purposes which need knowledge about submodule configurations.

It is expected that .gitmodules files do not change often between commits. Thats why we lookup the .gitmodules sha1 from a commit and then either lookup an already parsed configuration or parse and cache an unknown one for each sha1. The cache is lazily build on demand for each requested commit.

---

Quoted 10 lines · Heiko Voigt
Quoted 8 lines · Nick Townsend

It seems to me that the question that you are trying to solve is more complex than the problem I faced in git-archive, where we have a single commit of the top-level repository that we are chasing. Perhaps we should split the work into two pieces:

a. Identifying the complete submodule configuration for a single commit, and b. the complexity of behaviour when fetching and cloning recursively (which
of course requires a.)

Quoted 6 lines

You are right the latter (b) is a separate topic. So how about I extract the submodule config parsing part from the mentioned patch and you can then use that patch as a basis for your work? As far as I understand you only need to parse the .gitmodules file for one commit and then lookup the submodule names from paths right? That would simplify matters and we can postpone the caching of multiple commits for the time when I continue on b.

Ok and here is a patch that you can use as basis for your work. I looked into it and found that its actually easier to use the cache. Storing everything in a hashmap seems like overkill for your application but it is prepared for my usecase which actually needs to parse configurations for multiple commits.

Since this has not been discussed yet some details of my implementation might change.

The test I implemented is only for demonstration of usage and my quick manual testing. If we agree on going ahead with my patch I will extend that to a proper test. Or if anyone has an idea where we can plug that in to make a useful user interface we can also implement a test based on that.

Cheers Heiko

 .gitignore                    |   1 +
 Makefile                      |   2 +
 submodule-config-cache.c      |  96 ++++++++++++++++++++++++++++++++
 submodule-config-cache.h      |  33 +++++++++++
 submodule.c                   | 125 ++++++++++++++++++++++++++++++++++++++++++
 submodule.h                   |   4 ++
 test-submodule-config-cache.c |  45 +++++++++++++++
 7 files changed, 306 insertions(+)
 create mode 100644 submodule-config-cache.c
 create mode 100644 submodule-config-cache.h
 create mode 100644 test-submodule-config-cache.c
.gitignore +1 -0
index 66199ed..6c91e98 100644
@@ -200,6 +200,7 @@
 /test-sha1
 /test-sigchain
 /test-string-list
+/test-submodule-config-cache
 /test-subprocess
 /test-svn-fe
 /test-urlmatch-normalization
Makefile +2 -0
index af847f8..e3d869b 100644
@@ -572,6 +572,7 @@ TEST_PROGRAMS_NEED_X += test-scrap-cache-tree
 TEST_PROGRAMS_NEED_X += test-sha1
 TEST_PROGRAMS_NEED_X += test-sigchain
 TEST_PROGRAMS_NEED_X += test-string-list
+TEST_PROGRAMS_NEED_X += test-submodule-config-cache
 TEST_PROGRAMS_NEED_X += test-subprocess
 TEST_PROGRAMS_NEED_X += test-svn-fe
 TEST_PROGRAMS_NEED_X += test-urlmatch-normalization
@@ -872,6 +873,7 @@ LIB_OBJS += strbuf.o
 LIB_OBJS += streaming.o
 LIB_OBJS += string-list.o
 LIB_OBJS += submodule.o
+LIB_OBJS += submodule-config-cache.o
 LIB_OBJS += symlinks.o
 LIB_OBJS += tag.o
 LIB_OBJS += trace.o
submodule-config-cache.c new file +96 -0

96 lines not on this page · raw message

submodule-config-cache.h new file +33 -0
new file mode 100644
index 0000000..7bb79b9
@@ -0,0 +1,33 @@
+#ifndef SUBMODULE_CONFIG_CACHE_H
+#define SUBMODULE_CONFIG_CACHE_H
+
+#include "hash.h"
+#include "strbuf.h"
+
+struct submodule_config_cache {
+	struct hash_table for_path;
+	struct hash_table for_name;
+};
+
+/* one submodule_config_cache entry */
+struct submodule_config {
+	struct strbuf path;
+	struct strbuf name;
+	unsigned char gitmodule_sha1[20];
+	struct submodule_config *next;
+};
+
+void submodule_config_cache_init(struct submodule_config_cache *cache);
+void submodule_config_cache_free(struct submodule_config_cache *cache);
+
+void submodule_config_cache_update_path(struct submodule_config_cache *cache,
+		struct submodule_config *config);
+void submodule_config_cache_insert(struct submodule_config_cache *cache,
+		struct submodule_config *config);
+
+struct submodule_config *submodule_config_cache_lookup_path(struct submodule_config_cache *cache,
+	const unsigned char *gitmodule_sha1, const char *path);
+struct submodule_config *submodule_config_cache_lookup_name(struct submodule_config_cache *cache,
+	const unsigned char *gitmodule_sha1, const char *name);
+
+#endif /* SUBMODULE_CONFIG_CACHE_H */
submodule.c +125 -0

136 lines not on this page · raw message

submodule.h +4 -0
index 7beec48..a26cc34 100644
@@ -3,6 +3,8 @@
 
 struct diff_options;
 struct argv_array;
+struct submodule_config;
+struct submodule_config_cache;
 
 enum {
 	RECURSE_SUBMODULES_ON_DEMAND = -1,
@@ -41,5 +43,7 @@ int find_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_nam
 		struct string_list *needs_pushing);
 int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name);
 void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
+struct submodule_config *get_submodule_config_for_commit_path(struct submodule_config_cache *cache,
+		const unsigned char *commit_sha1, const char *path);
 
 #endif
test-submodule-config-cache.c new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
1.8.5.1.21.gee0ea2e
#15 lore raw

Re: [RFC/WIP PATCH] implement reading of submodule .gitmodules configuration into cache

Quoted 5 lines · Heiko Voigt

This submodule configuration cache allows us to lazily read .gitmodules configurations by commit into a runtime cache which can then be used to easily lookup values from it. Currently only the values for path or name are stored but it can be extended for any value needed.
...

Thanks.

Quoted 22 lines
submodule-config-cache.c new file +16 -0
new file mode 100644
index 0000000..7253fad
@@ -0,0 +1,96 @@
+#include "cache.h"
+#include "submodule-config-cache.h"
+#include "strbuf.h"
+#include "hash.h"
+
+void submodule_config_cache_init(struct submodule_config_cache *cache)
+{
+	init_hash(&cache->for_name);
+	init_hash(&cache->for_path);
+}
+
+static int free_one_submodule_config(void *ptr, void *data)
+{
+	struct submodule_config *entry = ptr;
+
+	strbuf_release(&entry->path);

submodule-config-cache.c line 26

Quoted 10 lines
submodule-config-cache.c new file +10 -0
+	strbuf_release(&entry->name);
+	free(entry);
+
+	return 0;
+}
+
+void submodule_config_cache_free(struct submodule_config_cache *cache)
+{
+	/* NOTE: its important to iterate over the name hash here
+	 * since paths might have multiple entries */

Style (multi-line comments).

This is interesting. I wonder what the practical consequence is to have a single submodule bound to the top-level tree more than once. Updating from one of the working tree will make the other working tree out of sync because the ultimate location of the submodule directory pointed at by the two .git gitdirs can only have a single HEAD, be it detached or on a branch, and a single index.

Not that the decision to enforce that names are unique in the top-level .gitmodules, and follow that decision in this part of the code to be defensive (not rely on the "one submodule can be bound only once to a top-level tree"), but shouldn't such a configuration to have a single submodule bound to more than one place in the top-level tree be forbidden?

Quoted 4 lines
submodule-config-cache.c new file +4 -0
+	for_each_hash(&cache->for_name, free_one_submodule_config, NULL);
+	free_hash(&cache->for_path);
+	free_hash(&cache->for_name);
+}

submodule-config-cache.c line 40

Quoted 10 lines
submodule-config-cache.c new file +10 -0
+
+static unsigned int hash_sha1_string(const unsigned char *sha1, const char *string)
+{
+	int c;
+	unsigned int hash, string_hash = 5381;
+	memcpy(&hash, sha1, sizeof(hash));
+
+	/* djb2 hash */
+	while ((c = *string++))
+		string_hash = ((string_hash << 5) + hash) + c; /* hash * 33 + c */

Hmm, the comment and the code does not seem to match in math here...

#16 lore raw

Re: Re: [RFC/WIP PATCH] implement reading of submodule .gitmodules configuration into cache

Quoted 6 lines · Junio C Hamano

submodule-config-cache.c line 26

Quoted 4 lines
submodule-config-cache.c new file +4 -0
+void submodule_config_cache_free(struct submodule_config_cache *cache)
+{
+	/* NOTE: its important to iterate over the name hash here
+	 * since paths might have multiple entries */

Style (multi-line comments).

Will fix.

Quoted 6 lines

This is interesting. I wonder what the practical consequence is to have a single submodule bound to the top-level tree more than once. Updating from one of the working tree will make the other working tree out of sync because the ultimate location of the submodule directory pointed at by the two .git gitdirs can only have a single HEAD, be it detached or on a branch, and a single index.

To clarify, when writing this comment I was not thinking about the same submodule with multiple paths in the same tree but rather with the same name under different paths in different commits.

Quoted 6 lines

Not that the decision to enforce that names are unique in the top-level .gitmodules, and follow that decision in this part of the code to be defensive (not rely on the "one submodule can be bound only once to a top-level tree"), but shouldn't such a configuration to have a single submodule bound to more than one place in the top-level tree be forbidden?

Yes IMO, that should be forbidden currently. I do not think we actually prevent the user from doing so but it can not happen by accident since we derive the initial name from the local path. Maybe we should be more strict about that and put more guards in place to avoid such configurations from entering the database.

Quoted 8 lines
Quoted 8 lines
submodule-config-cache.c new file +8 -0
+	for_each_hash(&cache->for_name, free_one_submodule_config, NULL);
+	free_hash(&cache->for_path);
+	free_hash(&cache->for_name);
+}
+
+static unsigned int hash_sha1_string(const unsigned char *sha1, const char *string)
+{
+	int c;
Quoted 8 lines

submodule-config-cache.c line 40

Quoted 6 lines
submodule-config-cache.c new file +6 -0
+	unsigned int hash, string_hash = 5381;
+	memcpy(&hash, sha1, sizeof(hash));
+
+	/* djb2 hash */
+	while ((c = *string++))
+		string_hash = ((string_hash << 5) + hash) + c; /* hash * 33 + c */

Hmm, the comment and the code does not seem to match in math here...

Yeah sorry that was a leftover from the code I started with. In the beginning it was a pure string hash. Will remove both comments (since its also not a pure djb2 hash anymore).

Cheers Heiko

#17 lore raw

PATCH 1/1 submodule recursion in git-archive

In reply to a message not in the archive

From: Nick Townsend <[email protected]>
Subject: Re: [PATCH] submodule recursion in git-archive
Date: 2 December 2013 15:55:36 GMT-8
To: Heiko Voigt <[email protected]>
Cc: Junio C Hamano <[email protected]>, René Scharfe <[email protected]>, Jens Lehmann <[email protected]>, [email protected], Jeff King <[email protected]>

Quoted 84 lines · Heiko Voigt
Quoted 64 lines · Junio C Hamano
Quoted 2 lines · Nick Townsend

* The .gitmodules file can be dirty (easy to flag, but should we allow archive to proceed?)

As we are discussing "archive", which takes a tree object from the top-level project that is recorded in the object database, the information _about_ the submodule in question should come from the given tree being archived. There is no reason for the .gitmodules file that happens to be sitting in the working tree of the top-level project to be involved in the decision, so its dirtyness should not matter, I think. If the tree being archived has a submodule whose name is "kernel" at path "linux/" (relative to the top-level project), its repository should be at .git/modules/kernel in the layout recent git-submodule prepares, and we should find that path-and-name mapping from .gitmodules recorded in that tree object we are archiving. The version that happens to be checked out to the working tree may have moved the submodule to a new path "linux-3.0/" and "linux-3.0/.git" may have "gitdir: .git/modules/kernel" in it, but when archiving a tree that has the submodule at "linux/", it would not help---we would not know to look at "linux-3.0/.git" to learn that information anyway because .gitmodules in the working tree would say that the submodule at path "linux-3.0/" is with name "kernel", and would not tell us anything about "linux/".

Quoted 2 lines

* Users can mess with settings both prior to git submodule init and before git submodule update.

I think this is irrelevant for exactly the same reason as above.

What makes this tricker, however, is how to deal with an old-style repository, where the submodule repositories are embedded in the working tree that happens to be checked out. In that case, we may have to read .gitmodules from two places, i.e.

(1) We are archiving a tree with a submodule at "linux/";

(2) We read .gitmodules from that tree and learn that the submodule

    has name "kernel";

(3) There is no ".git/modules/kernel" because the repository uses the old layout (if the user never was interested in this submodule, .git/modules/kernel may also be missing, and we should tell these two cases apart by checking .git/config to see if a corresponding entry for the "kernel" submodule exists there);

(4) In a repository that uses the old layout, there must be the repository somewhere embedded in the current working tree (this inability to remove is why we use the new layout these days). We can learn where it is by looking at .gitmodules in the working tree---map the name "kernel" we learned earlier, and map it to the current path ("linux-3.0/" if you have been following this example so far).

And in that fallback context, I would say that reading from a dirty (or "messed with by the user") .gitmodules is the right thing to do. Perhaps the user may be in the process of moving the submodule in his working tree with

   $ mv linux-3.0 linux-3.2
   $ git config -f .gitmodules submodule.kernel.path linux-3.2

but hasn't committed the change yet.

Quoted 7 lines
Quoted 2 lines

For those reasons I deliberately decided not to reproduce the above logic all by myself.

As I already hinted, I agree that the "how to find the location of submodule repository, given a particular tree in the top-level project the submodule belongs to and the path to the submodule in question" deserves a separate thread to discuss with area experts.

FYI, I already started to implement this lookup of submodule paths early this year[1] but have not found the time to proceed on that yet. I am planning to continue on that topic soonish. We need it to implement a correct recursive fetch with clone on-demand as a basis for the future recursive checkout.

During the work on this I hit too many open questions. Thats why I am currently working on a complete plan[2] so we can discuss and define how this needs to be implemented. It is an asciidoc document which I will send out once I am finished with it.

Quoted 4 lines

Cheers Heiko

[1] http://article.gmane.org/gmane.comp.version-control.git/217020
[2] https://github.com/hvoigt/git/wiki/submodule-fetch-config

Heiko
It seems to me that the question that you are trying to solve is more complex than the problem I faced in git-archive, where we have a single commit of the top-level repository that we are chasing. Perhaps we should split the work into two pieces:

a. Identifying the complete submodule configuration for a single commit, and b. the complexity of behaviour when fetching and cloning recursively (which
of course requires a.)

I’m very happy to work on the first, but the second seems to me to require more understanding than I currently possess. In order to do this it would help to have a place to discuss this. I see you have used the wiki of your fork of git on GitHub. Is that the right place to solicit input?

Kind Regards
Nick

#18 lore raw
In reply to Junio C Hamano
Quoted 119 lines · Junio C Hamano
Quoted 44 lines · Nick Townsend
Quoted 42 lines · Junio C Hamano

Even if the code is run inside a repository with a working tree, when producing a tarball out of an ancient commit that had a submodule not at its current location, --recurse-submodules option should do the right thing, so asking for working tree location of that submodule to find its repository is wrong, I think. It may happen to find one if the archived revision is close enough to what is currently checked out, but that may not necessarily be the case.

At that point when the code discovers an S_ISGITLINK entry, it should have both a pathname to the submodule relative to the toplevel and the commit object name bound to that submodule location. What it should do, when it does not find the repository at the given path (maybe because there is no working tree, or the sudmodule directory has moved over time) is roughly:

- Read from .gitmodules at the top-level from the tree it is creating the tarball out of;

- Find "submodule.$name.path" entry that records that path to the submodule; and then

- Using that $name, find the stashed-away location of the submodule repository in $GIT_DIR/modules/$name.

or something like that.

This is a related tangent, but when used in a repository that people often use as their remote, the repository discovery may have to interact with the relative URL. People often ship .gitmodules with

	[submodule "bar"]
      	URL = ../bar.git
		path = barDir

for a top-level project "foo" that can be cloned thusly:

git clone git://site.xz/foo.git

and host bar.git to be clonable with

git clone git://site.xz/bar.git barDir/

Quoted 7 lines
Quoted 5 lines

inside the working tree of the foo project. In such a case, when "archive --recurse-submodules" is running, it would find the repository for the "bar" submodule at "../bar.git", I would think.

So this part needs a bit more thought, I am afraid.

I see that there is a lot of potential complexity around setting up a submodule:

No question about it.

Quoted 2 lines

* The .gitmodules file can be dirty (easy to flag, but should we allow archive to proceed?)

As we are discussing "archive", which takes a tree object from the top-level project that is recorded in the object database, the information _about_ the submodule in question should come from the given tree being archived. There is no reason for the .gitmodules file that happens to be sitting in the working tree of the top-level project to be involved in the decision, so its dirtyness should not matter, I think. If the tree being archived has a submodule whose name is "kernel" at path "linux/" (relative to the top-level project), its repository should be at .git/modules/kernel in the layout recent git-submodule prepares, and we should find that path-and-name mapping from .gitmodules recorded in that tree object we are archiving. The version that happens to be checked out to the working tree may have moved the submodule to a new path "linux-3.0/" and "linux-3.0/.git" may have "gitdir: .git/modules/kernel" in it, but when archiving a tree that has the submodule at "linux/", it would not help---we would not know to look at "linux-3.0/.git" to learn that information anyway because .gitmodules in the working tree would say that the submodule at path "linux-3.0/" is with name "kernel", and would not tell us anything about "linux/".

Quoted 2 lines

* Users can mess with settings both prior to git submodule init and before git submodule update.

I think this is irrelevant for exactly the same reason as above.

What makes this tricker, however, is how to deal with an old-style repository, where the submodule repositories are embedded in the working tree that happens to be checked out. In that case, we may have to read .gitmodules from two places, i.e.

(1) We are archiving a tree with a submodule at "linux/";

(2) We read .gitmodules from that tree and learn that the submodule

    has name "kernel";

(3) There is no ".git/modules/kernel" because the repository uses the old layout (if the user never was interested in this submodule, .git/modules/kernel may also be missing, and we should tell these two cases apart by checking .git/config to see if a corresponding entry for the "kernel" submodule exists there);

(4) In a repository that uses the old layout, there must be the repository somewhere embedded in the current working tree (this inability to remove is why we use the new layout these days). We can learn where it is by looking at .gitmodules in the working tree---map the name "kernel" we learned earlier, and map it to the current path ("linux-3.0/" if you have been following this example so far).

And in that fallback context, I would say that reading from a dirty (or "messed with by the user") .gitmodules is the right thing to do. Perhaps the user may be in the process of moving the submodule in his working tree with

   $ mv linux-3.0 linux-3.2
   $ git config -f .gitmodules submodule.kernel.path linux-3.2

but hasn't committed the change yet.

Quoted 7 lines
Quoted 2 lines

For those reasons I deliberately decided not to reproduce the above logic all by myself.

As I already hinted, I agree that the "how to find the location of submodule repository, given a particular tree in the top-level project the submodule belongs to and the path to the submodule in question" deserves a separate thread to discuss with area experts.

As per my email to Heiko on this thread, I’m happy to start such
a discussion - I’ll use your notes as a starting point. I’m much more comfortable using a wiki for this - is this common or should I start a new mail thread with RFC in the title or similar?

I did complete my work on my version of git-archive (for internal use) and added some regression tests for current behaviour. Also the add_submodule_odb patch should IMHO be incorporated anyway. I’ll resubmit those two for consideration in a new thread.

Kind Regards
Nick Townsend

#19 lore raw

PATCH 1/1 submodule recursion in git-archive

Begin forwarded message:

Quoted 148 lines

From: Nick Townsend <[email protected]>
Subject: Re: [PATCH] submodule recursion in git-archive
Date: 2 December 2013 16:00:50 GMT-8
To: Junio C Hamano <[email protected]>
Cc: René Scharfe <[email protected]>, Jens Lehmann <[email protected]>, [email protected], Jeff King <[email protected]>

Quoted 119 lines · Junio C Hamano
Quoted 44 lines · Nick Townsend
Quoted 42 lines · Junio C Hamano

Even if the code is run inside a repository with a working tree, when producing a tarball out of an ancient commit that had a submodule not at its current location, --recurse-submodules option should do the right thing, so asking for working tree location of that submodule to find its repository is wrong, I think. It may happen to find one if the archived revision is close enough to what is currently checked out, but that may not necessarily be the case.

At that point when the code discovers an S_ISGITLINK entry, it should have both a pathname to the submodule relative to the toplevel and the commit object name bound to that submodule location. What it should do, when it does not find the repository at the given path (maybe because there is no working tree, or the sudmodule directory has moved over time) is roughly:

- Read from .gitmodules at the top-level from the tree it is creating the tarball out of;

- Find "submodule.$name.path" entry that records that path to the submodule; and then

- Using that $name, find the stashed-away location of the submodule repository in $GIT_DIR/modules/$name.

or something like that.

This is a related tangent, but when used in a repository that people often use as their remote, the repository discovery may have to interact with the relative URL. People often ship .gitmodules with

	[submodule "bar"]
     	URL = ../bar.git
		path = barDir

for a top-level project "foo" that can be cloned thusly:

git clone git://site.xz/foo.git

and host bar.git to be clonable with

git clone git://site.xz/bar.git barDir/

Quoted 7 lines
Quoted 5 lines

inside the working tree of the foo project. In such a case, when "archive --recurse-submodules" is running, it would find the repository for the "bar" submodule at "../bar.git", I would think.

So this part needs a bit more thought, I am afraid.

I see that there is a lot of potential complexity around setting up a submodule:

No question about it.

Quoted 2 lines

* The .gitmodules file can be dirty (easy to flag, but should we allow archive to proceed?)

As we are discussing "archive", which takes a tree object from the top-level project that is recorded in the object database, the information _about_ the submodule in question should come from the given tree being archived. There is no reason for the .gitmodules file that happens to be sitting in the working tree of the top-level project to be involved in the decision, so its dirtyness should not matter, I think. If the tree being archived has a submodule whose name is "kernel" at path "linux/" (relative to the top-level project), its repository should be at .git/modules/kernel in the layout recent git-submodule prepares, and we should find that path-and-name mapping from .gitmodules recorded in that tree object we are archiving. The version that happens to be checked out to the working tree may have moved the submodule to a new path "linux-3.0/" and "linux-3.0/.git" may have "gitdir: .git/modules/kernel" in it, but when archiving a tree that has the submodule at "linux/", it would not help---we would not know to look at "linux-3.0/.git" to learn that information anyway because .gitmodules in the working tree would say that the submodule at path "linux-3.0/" is with name "kernel", and would not tell us anything about "linux/".

Quoted 2 lines

* Users can mess with settings both prior to git submodule init and before git submodule update.

I think this is irrelevant for exactly the same reason as above.

What makes this tricker, however, is how to deal with an old-style repository, where the submodule repositories are embedded in the working tree that happens to be checked out. In that case, we may have to read .gitmodules from two places, i.e.

(1) We are archiving a tree with a submodule at "linux/";

(2) We read .gitmodules from that tree and learn that the submodule has name "kernel";

(3) There is no ".git/modules/kernel" because the repository uses the old layout (if the user never was interested in this submodule, .git/modules/kernel may also be missing, and we should tell these two cases apart by checking .git/config to see if a corresponding entry for the "kernel" submodule exists there);

(4) In a repository that uses the old layout, there must be the repository somewhere embedded in the current working tree (this inability to remove is why we use the new layout these days). We can learn where it is by looking at .gitmodules in the working tree---map the name "kernel" we learned earlier, and map it to the current path ("linux-3.0/" if you have been following this example so far).

And in that fallback context, I would say that reading from a dirty (or "messed with by the user") .gitmodules is the right thing to do. Perhaps the user may be in the process of moving the submodule in his working tree with

  $ mv linux-3.0 linux-3.2
  $ git config -f .gitmodules submodule.kernel.path linux-3.2

but hasn't committed the change yet.

Quoted 7 lines
Quoted 2 lines

For those reasons I deliberately decided not to reproduce the above logic all by myself.

As I already hinted, I agree that the "how to find the location of submodule repository, given a particular tree in the top-level project the submodule belongs to and the path to the submodule in question" deserves a separate thread to discuss with area experts.

As per my email to Heiko on this thread, I’m happy to start such
a discussion - I’ll use your notes as a starting point. I’m much more comfortable using a wiki for this - is this common or should I start a new mail thread with RFC in the title or similar?

I did complete my work on my version of git-archive (for internal use) and added some regression tests for current behaviour. Also the add_submodule_odb patch should IMHO be incorporated anyway. I’ll resubmit those two for consideration in a new thread.

Kind Regards
Nick Townsend