Skip to contentSkip to conversation

Add support for `git archive --submodules`

PATCH In review Lars Hjemli 3 participants 19 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

v3 cover Add support for `git archive --submodules`

This series teaches read_tree_recursive() how to traverse gitlink entries when explicitly instructed to do so (by the return value from the provided callback function) and then uses this functionallity in git-archive to implement a basic --submodules option (as suggested by René in
http://thread.gmane.org/gmane.comp.version-control.git/106167/focus=106235).

The commit message of the third patch has some suggestions on how the new feature may be extended to support more use cases - hopefully this will cover the issues mentioned by Johannes and Junio in the same thread.

Lars Hjemli (3):
tree.c: teach read_tree_recursive how to traverse gitlink entries
sha1_file: prepare for adding alternates on demand archive.c: add basic support for submodules

 Documentation/git-archive.txt |    3 +
 archive.c                     |   53 ++++++++++++++++++-
 archive.h                     |    1 +
 builtin-ls-tree.c             |    9 +---
 cache.h                       |    1 +
 merge-recursive.c             |    2 +-
 sha1_file.c                   |   40 +++++++++-----
 t/t5001-archive-submodules.sh |  121 +++++++++++++++++++++++++++++++++++++++++
 tree.c                        |   28 ++++++++++
 9 files changed, 236 insertions(+), 22 deletions(-)
 create mode 100755 t/t5001-archive-submodules.sh
#1 lore raw

PATCH v3 1/3 tree.c: teach read_tree_recursive how to traverse gitlink entries

When the callback function invoked from read_tree_recursive() returns READ_TREE_RECURSIVE for a gitlink entry, the traversal will now continue into the tree connected to the gitlinked commit. It is the responsibility of the callback function to somehow make the gitlinked commit (and corresponding tree/blob) objects available, possibly by inserting the submodule object database as an alternate odb.

Also, all existing callback function has been updated to only return READ_TREE_RECURSIVE for directory entries, so this patch should not introduce any changes to current behavior.

---
 archive.c         |    2 +-
 builtin-ls-tree.c |    9 ++-------
 merge-recursive.c |    2 +-
 tree.c            |   28 ++++++++++++++++++++++++++++
 4 files changed, 32 insertions(+), 9 deletions(-)
archive.c +1 -1
index 9ac455d..e6de039 100644
@@ -132,7 +132,7 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
 		err = write_entry(args, sha1, path.buf, path.len, mode, NULL, 0);
 		if (err)
 			return err;
-		return READ_TREE_RECURSIVE;
+		return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
 	}
 
 	buffer = sha1_file_to_archive(path_without_prefix, sha1, mode,
builtin-ls-tree.c +2 -7
index 5b63e6e..fca4631 100644
@@ -68,13 +68,8 @@ static int show_tree(const unsigned char *sha1, const char *base, int baselen,
 		 *
 		 * Something similar to this incomplete example:
 		 *
-		if (show_subprojects(base, baselen, pathname)) {
-			struct child_process ls_tree;
-
-			ls_tree.dir = base;
-			ls_tree.argv = ls-tree;
-			start_command(&ls_tree);
-		}
+		if (show_subprojects(base, baselen, pathname))
+			retval = READ_TREE_RECURSIVE;
 		 *
 		 */
 		type = commit_type;
merge-recursive.c +1 -1
index b97026b..ee853b9 100644
@@ -237,7 +237,7 @@ static int save_files_dirs(const unsigned char *sha1,
 		string_list_insert(newpath, &o->current_file_set);
 	free(newpath);
 
-	return READ_TREE_RECURSIVE;
+	return (S_ISDIR(mode) ? READ_TREE_RECURSIVE : 0);
 }
 
 static int get_files_dirs(struct merge_options *o, struct tree *tree)
tree.c +28 -0
index 03e782a..dfe4d5f 100644
@@ -131,6 +131,34 @@ int read_tree_recursive(struct tree *tree,
 			if (retval)
 				return -1;
 			continue;
+		} else if (S_ISGITLINK(entry.mode)) {
+			int retval;
+			struct strbuf path;
+			unsigned int entrylen;
+			struct commit *commit;
+
+			entrylen = tree_entry_len(entry.path, entry.sha1);
+			strbuf_init(&path, baselen + entrylen + 1);
+			strbuf_add(&path, base, baselen);
+			strbuf_add(&path, entry.path, entrylen);
+			strbuf_addch(&path, '/');
+
+			commit = lookup_commit(entry.sha1);
+			if (!commit)
+				die("Commit %s in submodule path %s not found",
+				    sha1_to_hex(entry.sha1), path.buf);
+
+			if (parse_commit(commit))
+				die("Invalid commit %s in submodule path %s",
+				    sha1_to_hex(entry.sha1), path.buf);
+
+			retval = read_tree_recursive(commit->tree,
+						     path.buf, path.len,
+						     stage, match, fn, context);
+			strbuf_release(&path);
+			if (retval)
+				return -1;
+			continue;
 		}
 	}
 	return 0;
Signature · 1 line
1.6.1.150.g5e733b
#2 lore raw

PATCH v3 2/3 sha1_file: prepare for adding alternates on demand

The new function add_alt_odb() can be used to add alternate object databases dynamically (i.e. after parsing of objects/info/alternates). It will be used by git-archive to implement inclusion of submodules by adding submodule object databases during tree traversal.

To make the function usable from call-sites which doesn't require the add_alt_odb() to succeed, it takes a 'quiet' parameter which is passed on to the underlying alt-odb-related functions.

---
 cache.h     |    1 +
 sha1_file.c |   40 +++++++++++++++++++++++++++-------------
 2 files changed, 28 insertions(+), 13 deletions(-)
cache.h +1 -0
index 8e1af26..ccfad5f 100644
@@ -724,6 +724,7 @@ extern struct alternate_object_database {
 	char base[FLEX_ARRAY]; /* more */
 } *alt_odb_list;
 extern void prepare_alt_odb(void);
+extern int add_alt_odb(char *path, int quiet);
 extern void add_to_alternates_file(const char *reference);
 typedef int alt_odb_fn(struct alternate_object_database *, void *);
 extern void foreach_alt_odb(alt_odb_fn, void*);
sha1_file.c +27 -13
index f08493f..8b5540d 100644
@@ -235,7 +235,7 @@ char *sha1_pack_index_name(const unsigned char *sha1)
 struct alternate_object_database *alt_odb_list;
 static struct alternate_object_database **alt_odb_tail;
 
-static void read_info_alternates(const char * alternates, int depth);
+static void read_info_alternates(const char * alternates, int depth, int quiet);
 
 /*
  * Prepare alternate object database registry.
@@ -252,7 +252,8 @@ static void read_info_alternates(const char * alternates, int depth);
  * SHA1, an extra slash for the first level indirection, and the
  * terminating NUL.
  */
-static int link_alt_odb_entry(const char * entry, int len, const char * relative_base, int depth)
+static int link_alt_odb_entry(const char * entry, int len,
+			      const char * relative_base, int depth, int quiet)
 {
 	const char *objdir = get_object_directory();
 	struct alternate_object_database *ent;
@@ -285,9 +286,10 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative
 
 	/* Detect cases where alternate disappeared */
 	if (!is_directory(ent->base)) {
-		error("object directory %s does not exist; "
-		      "check .git/objects/info/alternates.",
-		      ent->base);
+		if (!quiet)
+			error("object directory %s does not exist; "
+			      "check .git/objects/info/alternates.",
+			      ent->base);
 		free(ent);
 		return -1;
 	}
@@ -312,7 +314,7 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative
 	ent->next = NULL;
 
 	/* recursively add alternates */
-	read_info_alternates(ent->base, depth + 1);
+	read_info_alternates(ent->base, depth + 1, quiet);
 
 	ent->base[pfxlen] = '/';
 
@@ -320,7 +322,8 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative
 }
 
 static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
-				 const char *relative_base, int depth)
+				 const char *relative_base, int depth,
+				 int quiet)
 {
 	const char *cp, *last;
 
@@ -343,11 +346,12 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
 			cp++;
 		if (last != cp) {
 			if (!is_absolute_path(last) && depth) {
+				if (!quiet)
 				error("%s: ignoring relative alternate object store %s",
 						relative_base, last);
 			} else {
 				link_alt_odb_entry(last, cp - last,
-						relative_base, depth);
+						relative_base, depth, quiet);
 			}
 		}
 		while (cp < ep && *cp == sep)
@@ -356,7 +360,8 @@ static void link_alt_odb_entries(const char *alt, const char *ep, int sep,
 	}
 }
 
-static void read_info_alternates(const char * relative_base, int depth)
+static void read_info_alternates(const char * relative_base, int depth,
+				 int quiet)
 {
 	char *map;
 	size_t mapsz;
@@ -380,7 +385,8 @@ static void read_info_alternates(const char * relative_base, int depth)
 	map = xmmap(NULL, mapsz, PROT_READ, MAP_PRIVATE, fd, 0);
 	close(fd);
 
-	link_alt_odb_entries(map, map + mapsz, '\n', relative_base, depth);
+	link_alt_odb_entries(map, map + mapsz, '\n', relative_base, depth,
+			     quiet);
 
 	munmap(map, mapsz);
 }
@@ -394,7 +400,7 @@ void add_to_alternates_file(const char *reference)
 	if (commit_lock_file(lock))
 		die("could not close alternates file");
 	if (alt_odb_tail)
-		link_alt_odb_entries(alt, alt + strlen(alt), '\n', NULL, 0);
+		link_alt_odb_entries(alt, alt + strlen(alt), '\n', NULL, 0, 0);
 }
 
 void foreach_alt_odb(alt_odb_fn fn, void *cb)
@@ -418,9 +424,9 @@ void prepare_alt_odb(void)
 	if (!alt) alt = "";
 
 	alt_odb_tail = &alt_odb_list;
-	link_alt_odb_entries(alt, alt + strlen(alt), PATH_SEP, NULL, 0);
+	link_alt_odb_entries(alt, alt + strlen(alt), PATH_SEP, NULL, 0, 0);
 
-	read_info_alternates(get_object_directory(), 0);
+	read_info_alternates(get_object_directory(), 0, 0);
 }
 
 static int has_loose_object_local(const unsigned char *sha1)
@@ -2573,3 +2579,11 @@ int read_pack_header(int fd, struct pack_header *header)
 		return PH_ERROR_PROTOCOL;
 	return 0;
 }
+
+int add_alt_odb(char *path, int quiet)
+{
+	int err = link_alt_odb_entry(path, strlen(path), NULL, 0, quiet);
+	if (!err)
+		prepare_packed_git_one(path, 0);
+	return err;
+}
Signature · 1 line
1.6.1.150.g5e733b
#3 lore raw

PATCH v3 3/3 archive.c: add basic support for submodules

The new --submodules option is used to trigger inclusion of checked out submodules in the archive.

The implementation currently does not verify that the submodule has been registered as 'interesting' in .git/config, neither does it resolve the currently checked out submodule HEAD but instead uses the commit SHA1 recorded in the gitlink entry to identify the submodule root tree.

The plan is to fix these limitations by extending --submodules to allow certain flags/options:

  a|c|r     include any|checked out|registered submodules
  H         resolve submodule HEAD to decide which tree to include
  g:<name>  only include submodules in group <name>

The syntax would then become '--submodules[=[a|c|r][H][g:<name>]]' and group membership could be specified in .git/config and/or .gitmodules. The current behavior would then match '--submodules=c' (which might be a sensible default when only --submodules is specified).

---
 Documentation/git-archive.txt |    3 +
 archive.c                     |   53 ++++++++++++++++++-
 archive.h                     |    1 +
 t/t5001-archive-submodules.sh |  121 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 177 insertions(+), 1 deletions(-)
 create mode 100755 t/t5001-archive-submodules.sh
Documentation/git-archive.txt +3 -0
index 41cbf9c..ddfa343 100644
@@ -51,6 +51,9 @@ OPTIONS
 	This can be any options that the archiver backend understand.
 	See next section.
 
+--submodules::
+	Include all checked out submodules in the archive.
+
 --remote=<repo>::
 	Instead of making a tar archive from local repository,
 	retrieve a tar archive from a remote repository.
archive.c +52 -1

83 lines not on this page · raw message

archive.h +1 -0
index 0b15b35..aff3fcd 100644
@@ -11,6 +11,7 @@ struct archiver_args {
 	const char **pathspec;
 	unsigned int verbose : 1;
 	int compression_level;
+	int submodules;
 };
 
 typedef int (*write_archive_fn_t)(struct archiver_args *);
t/t5001-archive-submodules.sh new file +121 -0

121 lines not on this page · raw message

Signature · 1 line
1.6.1.150.g5e733b
#4 lore raw

Re: [RFC/PATCH v3 3/3] archive.c: add basic support for submodules

Hi,

Quoted 7 lines · Lars Hjemli

The new --submodules option is used to trigger inclusion of checked out submodules in the archive.

The implementation currently does not verify that the submodule has been registered as 'interesting' in .git/config, neither does it resolve the currently checked out submodule HEAD but instead uses the commit SHA1 recorded in the gitlink entry to identify the submodule root tree.

Please understand that I skipped the rest of the patch.

Ciao,
Dscho

#16 lore raw

Re: [RFC/PATCH v3 2/3] sha1_file: prepare for adding alternates on demand

In reply to Lars Hjemli

Hi,

Quoted 17 lines · Lars Hjemli
sha1_file.c +4 -3
@@ -285,9 +286,10 @@ static int link_alt_odb_entry(const char * entry, int len, const char * relative
 
 	/* Detect cases where alternate disappeared */
 	if (!is_directory(ent->base)) {
-		error("object directory %s does not exist; "
-		      "check .git/objects/info/alternates.",
-		      ent->base);
+		if (!quiet)
+			error("object directory %s does not exist; "
+			      "check .git/objects/info/alternates.",
+			      ent->base);
 		free(ent);
 		return -1;
 	}
[...]
@@ -2573,3 +2579,11 @@ int read_pack_header(int fd, struct pack_header *header)
 		return PH_ERROR_PROTOCOL;

sha1_file.c int read_pack_header(int fd, struct pack_header *header) · line 2589

Quoted 10 lines
sha1_file.c +8 -0
 	return 0;
 }
+
+int add_alt_odb(char *path, int quiet)
+{
+	int err = link_alt_odb_entry(path, strlen(path), NULL, 0, quiet);
+	if (!err)
+		prepare_packed_git_one(path, 0);
+	return err;
+}

FWIW my concern is not at all addressed. A future user of add_alt_odb() (and possibly your users in rare cases, too) can trigger the error that suggests looking into the alternates. Leaving the human user puzzled.

Ciao,
Dscho

#5 lore raw

Re: [RFC/PATCH v3 3/3] archive.c: add basic support for submodules

In reply to Johannes Schindelin
Quoted 11 lines · Johannes Schindelin
Quoted 7 lines · Lars Hjemli

The new --submodules option is used to trigger inclusion of checked out submodules in the archive.

The implementation currently does not verify that the submodule has been registered as 'interesting' in .git/config, neither does it resolve the currently checked out submodule HEAD but instead uses the commit SHA1 recorded in the gitlink entry to identify the submodule root tree.

Please understand that I skipped the rest of the patch.

That's too bad, I hoped on some feedback from you on the part of the commit message which you didn't quote:

Quoted 10 lines
Quoted 10 lines

The plan is to fix these limitations by extending --submodules to allow certain flags/options:

a|c|r     include any|checked out|registered submodules
H         resolve submodule HEAD to decide which tree to include
g:<name>  only include submodules in group <name>

The syntax would then become '--submodules[=[a|c|r][H][g:<name>]]' and group membership could be specified in .git/config and/or .gitmodules. The current behavior would then match '--submodules=c' (which might be a sensible default when only --submodules is specified).

Wouldn't such an option address your concern about the consistency/semantics of the --submodules operation?

--
larsh

#6 lore raw

Re: [RFC/PATCH v3 3/3] archive.c: add basic support for submodules

Quoted 4 lines · Lars Hjemli
Quoted 4 lines
Quoted 4 lines

The plan is to fix these limitations by extending --submodules to allow certain flags/options:
a|c|r include any|checked out|registered submodules
H resolve submodule HEAD to decide which tree to include

What do you mean by "decide"? If HEAD exists (iow, the submodule is checked out), the tree of the commit recorded in the superproject's gitlink entry is included in the result?

As I already said before, I doubt it makes much sense in the context of the current git-archive to base the choise on checkout status.

Unless you are extending git-archive and giving it an ability to write out the superproject index or the work tree as an archive, that is.

Just like git-grep lets you grep in the work tree files (limited to paths that appear in the index), or grep in the contents registered to the index when run with --cached, git-archive could make an archive out of your work tree files or your index contents. Such an extension to git-archive may be quite useful with or without submodules.

In such mode of operation, because you are dealing with the work tree when run without --cached, it would make sense to say "Ah, the superproject index wants v1.0 of the submodule, but the work tree has v2.0 of it checked out, and we are writing out the work tree, so let's include v2.0 instead", and as a side effect of deciding which commit's tree to include from each submodule, it naturally makes sense to exclude submodules that are not checked out.

But otherwise I am not so sure what the point of H option would be.

#7 lore raw

Re: [RFC/PATCH v3 3/3] archive.c: add basic support for submodules

Quoted 10 lines · Junio C Hamano
Quoted 4 lines · Lars Hjemli
Quoted 4 lines
Quoted 4 lines

The plan is to fix these limitations by extending --submodules to allow certain flags/options:
a|c|r include any|checked out|registered submodules
H resolve submodule HEAD to decide which tree to include

What do you mean by "decide"? If HEAD exists (iow, the submodule is checked out), the tree of the commit recorded in the superproject's gitlink entry is included in the result?

No, when H is specified the tree of the currently checked out submodule commit would be included (this obviously shouldn't be the default mode of operation, hence a flag to trigger it if that is what the user wants).

Quoted 4 lines

As I already said before, I doubt it makes much sense in the context of the current git-archive to base the choise on checkout status.

Quoted 8 lines

Unless you are extending git-archive and giving it an ability to write out the superproject index or the work tree as an archive, that is.

Just like git-grep lets you grep in the work tree files (limited to paths that appear in the index), or grep in the contents registered to the index when run with --cached, git-archive could make an archive out of your work tree files or your index contents. Such an extension to git-archive may be quite useful with or without submodules.

Absolutely.

Quoted 10 lines

In such mode of operation, because you are dealing with the work tree when run without --cached, it would make sense to say "Ah, the superproject index wants v1.0 of the submodule, but the work tree has v2.0 of it checked out, and we are writing out the work tree, so let's include v2.0 instead", and as a side effect of deciding which commit's tree to include from each submodule, it naturally makes sense to exclude submodules that are not checked out.

But otherwise I am not so sure what the point of H option would be.

I would find the H flag practical for my own usage of submodules. I almost never modify the content of the currently checked out submodule but I often check out a different HEAD than what is registered in the gitlink in the superproject (typically due to testing the superproject against different versions of the submodule). And for such a use case, being able to create a tarball of my currently checked out state seems useful to me.

Anyways, if we get as far as adding a --submodules option to git archive, I believe its default mode should be to archive the superproject HEAD state together with the gitlink'd state of each submodule registered in .git/config instead of --submodules=c which is what this patch implements. But I wanted to get some feedback on this plan before trying to implement it.

--
larsh

#8 lore raw

Re: [RFC/PATCH v3 3/3] archive.c: add basic support for submodules

Quoted 8 lines · Lars Hjemli
Quoted 7 lines · Junio C Hamano
Quoted 4 lines · Lars Hjemli
Quoted 4 lines
Quoted 4 lines

The plan is to fix these limitations by extending --submodules to allow certain flags/options:
a|c|r include any|checked out|registered submodules
H resolve submodule HEAD to decide which tree to include

Quoted 6 lines
Quoted 3 lines

What do you mean by "decide"? If HEAD exists (iow, the submodule is checked out), the tree of the commit recorded in the superproject's gitlink entry is included in the result?

No, when H is specified the tree of the currently checked out submodule commit would be included.

That makes even less sense. At that point you are mixing a tree with random state from a work tree, and doing so only for submodules. If you want a work tree snapshot, it should be a work tree snapshot, and should not be labelled as a snapshot out of a tree object of the superproject.

Quoted 7 lines

I would find the H flag practical for my own usage of submodules. I almost never modify the content of the currently checked out submodule but I often check out a different HEAD than what is registered in the gitlink in the superproject (typically due to testing the superproject against different versions of the submodule). And for such a use case, being able to create a tarball of my currently checked out state seems useful to me.

That would be more like an enhanced version of "git archive" that takes the work tree state, similar to how "git grep" operates on the work tree today.

I agree that would be useful, but I have a moderately strong suspition that your "H" hack that includes the work tree state for checked out submodules into a view that is primarily about the "tree" object in the superproject, without the same "take from the work tree" semantics for paths in the superproject, is more harmful than being helpful to the users in the longer term. It might be simple to implement, but I do not think its semantics can be explained sanely.

#9 lore raw

Re: [RFC/PATCH v3 3/3] archive.c: add basic support for submodules

Quoted 13 lines · Junio C Hamano
Quoted 7 lines · Lars Hjemli

I would find the H flag practical for my own usage of submodules. I almost never modify the content of the currently checked out submodule but I often check out a different HEAD than what is registered in the gitlink in the superproject (typically due to testing the superproject against different versions of the submodule). And for such a use case, being able to create a tarball of my currently checked out state seems useful to me.

That would be more like an enhanced version of "git archive" that takes the work tree state, similar to how "git grep" operates on the work tree today.

Quoted 7 lines

I agree that would be useful, but I have a moderately strong suspition that your "H" hack that includes the work tree state for checked out submodules into a view that is primarily about the "tree" object in the superproject, without the same "take from the work tree" semantics for paths in the superproject, is more harmful than being helpful to the users in the longer term. It might be simple to implement, but I do not think its semantics can be explained sanely.

Ok. When someone gets the itch for 'git archive --worktree', it would be easy enough to resurrect the idea of including the tree of the currently checked out HEAD in selected submodules.

Do you think the other options makes any sense, i.e. is it any point in me trying to implement this?

--
larsh

#10 lore raw

Re: [RFC/PATCH v3 3/3] archive.c: add basic support for submodules

In reply to Lars Hjemli

Hi,

Quoted 13 lines · Lars Hjemli
Quoted 11 lines · Johannes Schindelin
Quoted 8 lines · Lars Hjemli

The new --submodules option is used to trigger inclusion of checked out submodules in the archive.

The implementation currently does not verify that the submodule has been registered as 'interesting' in .git/config, neither does it resolve the currently checked out submodule HEAD but instead uses the commit SHA1 recorded in the gitlink entry to identify the submodule root tree.

Quoted 4 lines
Quoted 1 line

Please understand that I skipped the rest of the patch.

That's too bad, I hoped on some feedback from you on the part of the commit message which you didn't quote:

Well, you ignored my comments, so what do you expect me to do? Be happy?

There are two issues there:

- presence of a specific commit object being present in the repository does not necessarily mean that it is reachable by any ref, and therefore can mean that the tree/blob objects are not reachable, because it could be an interrupted fetch; in all of Git, we try to assume that only reachable objects are valid objects.

- presence of a specific commit in the supermodule is a _lousy_ indicator that the user wants to include that submodule in the archive.

Until both issues are addresse, I will not dance a little song and be merry over this issue.

Ciao,
Dscho

#11 lore raw

Re: [RFC/PATCH v3 3/3] archive.c: add basic support for submodules

Quoted 7 lines · Johannes Schindelin
Quoted 3 lines · Lars Hjemli

That's too bad, I hoped on some feedback from you on the part of the commit message which you didn't quote:

Well, you ignored my comments,

I might have misunderstood your comments, but I certainly didn't ignore them. I actually tried to come up with a solution that would solve your concerns about which submodules to include in the archive (which is why I hoped for some feedback on that proposal).

Quoted 8 lines

so what do you expect me to do? Be happy?

There are two issues there:

- presence of a specific commit object being present in the repository does not necessarily mean that it is reachable by any ref, and therefore can mean that the tree/blob objects are not reachable, because it could be an interrupted fetch;

This part I agree with.

Quoted 2 lines

in all of Git, we try to assume that only
reachable objects are valid objects.

I don't think this is true (most git commands accepts their arguments as valid objects without verifying if they are reachable from a ref). Do you feel it is necessary to perform a reachability check of the gitlink'd commit before traversing into a submodule tree?

Quoted 2 lines

- presence of a specific commit in the supermodule is a _lousy_ indicator that the user wants to include that submodule in the archive.

This is the issue I tried to address with my --submodules=[a|c|r][g:<name>] proposal in the commit message for this patch. I hoped you would find it interesting, given your comments in http://thread.gmane.org/gmane.comp.version-control.git/106167/focus=106235
(i.e. my 'a' flag would match your 'look-in-superprojects-odb', while the 'c', 'r' and 'g' options would address your issues about how to select the correct set of submodules).

--
larsh

#12 lore raw

Re: [RFC/PATCH v3 3/3] archive.c: add basic support for submodules

Hi,

Quoted 8 lines · Lars Hjemli
Quoted 3 lines · Johannes Schindelin

in all of Git, we try to assume that only reachable objects are valid objects.

I don't think this is true (most git commands accepts their arguments as valid objects without verifying if they are reachable from a ref).

The fact that a user can ask for some object directly, and that we do not try to validate it in that case has nothing to do with said assumption.

If something is pushed to a remote, and the connection fails, some commit could be pushed already, but some of its reachable objects lacking.

The user on the remote side can still try to salvage parts by accessing the objects directly, by their name.

But the only guarantee that the objects are reachable is to start from a ref.

Concretely, if your patch is applied as-is, such a half-pushed state could affect git-archive in a nasty way: even if the user started from a ref, there could be missing objects!

Quoted 2 lines

Do you feel it is necessary to perform a reachability check of the gitlink'd commit before traversing into a submodule tree?

No. Because HEAD is a ref, too.

Now, there is still a problem when your submodule is missing the objects for the commit your superproject is referring to.

IMO that is a serious issue, as it just asks for confused users.

Quoted 7 lines
Quoted 3 lines

- presence of a specific commit in the supermodule is a _lousy_ indicator that the user wants to include that submodule in the archive.

This is the issue I tried to address with my --submodules=[a|c|r][g:<name>] proposal in the commit message for this patch.

Nope, doing this "in the future" does not please me one bit.

Besides, I find the semantics, uhm, "interesting". (The other word would be "unintuitive". Why do you have to be so cryptic that I have to read the proposal to understand what the heck "c" is about?)

Ciao,
Dscho

#13 lore raw

Re: [RFC/PATCH v3 3/3] archive.c: add basic support for submodules

Quoted 5 lines · Johannes Schindelin

Now, there is still a problem when your submodule is missing the objects for the commit your superproject is referring to.

IMO that is a serious issue, as it just asks for confused users.

This made me finally understand your concern (sorry for being slow):
you want the command to behave in a predictable/consistent way while my implementation would end up making an archive with basically random content.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

- presence of a specific commit in the supermodule is a _lousy_ indicator that the user wants to include that submodule in the archive.

This is the issue I tried to address with my --submodules=[a|c|r][g:<name>] proposal in the commit message for this patch.

Quoted 5 lines

Nope, doing this "in the future" does not please me one bit.

Besides, I find the semantics, uhm, "interesting". (The other word would be "unintuitive". Why do you have to be so cryptic that I have to read the proposal to understand what the heck "c" is about?)

I thought it would be nifty to be able to combine different flags which would affect the behaviour/semantics of the command, but given the comments from you and Junio, I think I'll end up with something like this:

$ git archive --submodules <tree-ish>: Create an archive which
includes the trees of all gitlink entries in <tree-ish>, fail unless
all the required objects are available.
$ git archive --submodules=<group>: Same as above, but only traverse
submodules in the specified group (as defined in $GIT_CONFIG).

--
larsh

#14 lore raw

Re: [RFC/PATCH v3 3/3] archive.c: add basic support for submodules

Hi,

Quoted 6 lines · Lars Hjemli
$ git archive --submodules <tree-ish>: Create an archive which
includes the trees of all gitlink entries in <tree-ish>, fail unless
all the required objects are available.
$ git archive --submodules=<group>: Same as above, but only traverse
submodules in the specified group (as defined in $GIT_CONFIG).

How about having the former with --submodules='*' and let --submodules without argument include those submodules that are checked out (none in a bare repository)?

Thanks,
Dscho

#15 lore raw

Re: [RFC/PATCH v3 3/3] archive.c: add basic support for submodules

Quoted 8 lines · Johannes Schindelin

Hi,

Quoted 4 lines · Lars Hjemli
$ git archive --submodules <tree-ish>: Create an archive which
includes the trees of all gitlink entries in <tree-ish>, fail unless
all the required objects are available.
Quoted 6 lines
Quoted 2 lines
$ git archive --submodules=<group>: Same as above, but only traverse
submodules in the specified group (as defined in $GIT_CONFIG).

How about having the former with --submodules='*' and let --submodules without argument include those submodules that are checked out (none in a bare repository)?

Yeah, that might make more sense (since you'd normally not have access to the content of non-checked out submodules). I'm also considering something like --submodules[=(all|checkedout|[group:]<name>)], i.e. the 'group:'-part could be optional as long as <name> is unambiguous.

--
larsh

#17 lore raw

Re: [RFC/PATCH v3 2/3] sha1_file: prepare for adding alternates on demand

In reply to Johannes Schindelin
Quoted 9 lines · Johannes Schindelin

sha1_file.c static int link_alt_odb_entry(const char * entry, int len, const char * relative · line 292

Quoted 4 lines · Lars Hjemli
sha1_file.c +4 -0
+             if (!quiet)
+                     error("object directory %s does not exist; "
+                           "check .git/objects/info/alternates.",
+                           ent->base);

FWIW my concern is not at all addressed. A future user of add_alt_odb() (and possibly your users in rare cases, too) can trigger the error that suggests looking into the alternates. Leaving the human user puzzled.

Is it the phrasing of the error message that concerns you (when invoked from add_alt_odb())?

If so, would something like this be ok/better?

Quoted 3 lines

sha1_file.c static int link_alt_odb_entry(const char * entry, int len, const char * relative · line 292

Quoted 3 lines
sha1_file.c +3 -0
+             if (!quiet)
+                     error("Alternate object directory %s does not exist ",
+                           ent->base);

--
larsh

#18 lore raw

Re: [RFC/PATCH v3 2/3] sha1_file: prepare for adding alternates on demand

Hi,

Quoted 8 lines · Lars Hjemli
Quoted 6 lines · Johannes Schindelin
Quoted 4 lines · Lars Hjemli
sha1_file.c +4 -0
+             if (!quiet)
+                     error("object directory %s does not exist; "
+                           "check .git/objects/info/alternates.",
+                           ent->base);
Quoted 12 lines
Quoted 3 lines

FWIW my concern is not at all addressed. A future user of add_alt_odb() (and possibly your users in rare cases, too) can trigger the error that suggests looking into the alternates. Leaving the human user puzzled.

Is it the phrasing of the error message that concerns you (when invoked from add_alt_odb())?

If so, would something like this be ok/better?

Quoted 3 lines
Quoted 3 lines
sha1_file.c +3 -0
+             if (!quiet)
+                     error("Alternate object directory %s does not exist ",
+                           ent->base);

That would almost certainly be better.

Ciao,
Dscho