Skip to contentSkip to conversation

RFC on packfile URIs and .gitmodules check

PATCH New Jonathan Tan 10 participants 229 messages Jan 15, 2021 – Mar 29, 2021 Page 2 of 2

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

PATCH 10/14 fsck.[ch]: move FOREACH_FSCK_MSG_ID & fsck_msg_id from *.c to *.h

In reply to Ævar Arnfjörð Bjarmason

Move the FOREACH_FSCK_MSG_ID macro and the fsck_msg_id enum it helps define from fsck.c to fsck.h. This is in preparation for having non-static functions take the fsck_msg_id as an argument.

---
 fsck.c | 66 ---------------------------------------------------------
 fsck.h | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 66 deletions(-)
fsck.c +0 -66
index 1730acd698d..980ef2cb8fa 100644
@@ -22,72 +22,6 @@
 static struct oidset gitmodules_found = OIDSET_INIT;
 static struct oidset gitmodules_done = OIDSET_INIT;
 
-#define FOREACH_FSCK_MSG_ID(FUNC) \
-	/* fatal errors */ \
-	FUNC(NUL_IN_HEADER, FATAL) \
-	FUNC(UNTERMINATED_HEADER, FATAL) \
-	/* errors */ \
-	FUNC(BAD_DATE, ERROR) \
-	FUNC(BAD_DATE_OVERFLOW, ERROR) \
-	FUNC(BAD_EMAIL, ERROR) \
-	FUNC(BAD_NAME, ERROR) \
-	FUNC(BAD_OBJECT_SHA1, ERROR) \
-	FUNC(BAD_PARENT_SHA1, ERROR) \
-	FUNC(BAD_TAG_OBJECT, ERROR) \
-	FUNC(BAD_TIMEZONE, ERROR) \
-	FUNC(BAD_TREE, ERROR) \
-	FUNC(BAD_TREE_SHA1, ERROR) \
-	FUNC(BAD_TYPE, ERROR) \
-	FUNC(DUPLICATE_ENTRIES, ERROR) \
-	FUNC(MISSING_AUTHOR, ERROR) \
-	FUNC(MISSING_COMMITTER, ERROR) \
-	FUNC(MISSING_EMAIL, ERROR) \
-	FUNC(MISSING_NAME_BEFORE_EMAIL, ERROR) \
-	FUNC(MISSING_OBJECT, ERROR) \
-	FUNC(MISSING_SPACE_BEFORE_DATE, ERROR) \
-	FUNC(MISSING_SPACE_BEFORE_EMAIL, ERROR) \
-	FUNC(MISSING_TAG, ERROR) \
-	FUNC(MISSING_TAG_ENTRY, ERROR) \
-	FUNC(MISSING_TREE, ERROR) \
-	FUNC(MISSING_TREE_OBJECT, ERROR) \
-	FUNC(MISSING_TYPE, ERROR) \
-	FUNC(MISSING_TYPE_ENTRY, ERROR) \
-	FUNC(MULTIPLE_AUTHORS, ERROR) \
-	FUNC(TREE_NOT_SORTED, ERROR) \
-	FUNC(UNKNOWN_TYPE, ERROR) \
-	FUNC(ZERO_PADDED_DATE, ERROR) \
-	FUNC(GITMODULES_MISSING, ERROR) \
-	FUNC(GITMODULES_BLOB, ERROR) \
-	FUNC(GITMODULES_LARGE, ERROR) \
-	FUNC(GITMODULES_NAME, ERROR) \
-	FUNC(GITMODULES_SYMLINK, ERROR) \
-	FUNC(GITMODULES_URL, ERROR) \
-	FUNC(GITMODULES_PATH, ERROR) \
-	FUNC(GITMODULES_UPDATE, ERROR) \
-	/* warnings */ \
-	FUNC(BAD_FILEMODE, WARN) \
-	FUNC(EMPTY_NAME, WARN) \
-	FUNC(FULL_PATHNAME, WARN) \
-	FUNC(HAS_DOT, WARN) \
-	FUNC(HAS_DOTDOT, WARN) \
-	FUNC(HAS_DOTGIT, WARN) \
-	FUNC(NULL_SHA1, WARN) \
-	FUNC(ZERO_PADDED_FILEMODE, WARN) \
-	FUNC(NUL_IN_COMMIT, WARN) \
-	/* infos (reported as warnings, but ignored by default) */ \
-	FUNC(GITMODULES_PARSE, INFO) \
-	FUNC(BAD_TAG_NAME, INFO) \
-	FUNC(MISSING_TAGGER_ENTRY, INFO) \
-	/* ignored (elevated when requested) */ \
-	FUNC(EXTRA_HEADER_ENTRY, IGNORE)
-
-#define MSG_ID(id, msg_type) FSCK_MSG_##id,
-enum fsck_msg_id {
-	FOREACH_FSCK_MSG_ID(MSG_ID)
-	FSCK_MSG_MAX
-};
-#undef MSG_ID
-
 #define STR(x) #x
 #define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
 static struct {
fsck.h +67 -0

73 lines not on this page · raw message

Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
#180 lore raw

PATCH 11/14 fsck.c: pass along the fsck_msg_id in the fsck_error callback

In reply to Ævar Arnfjörð Bjarmason

Change the fsck_error callback to also pass along the fsck_msg_id. Before this change the only way to get the message id was to parse it back out of the "message".

Let's pass it down explicitly for the benefit of callers that might want to use it, as discussed in [1].

Passing the msg_type is now redundant, as you can always get it back from the msg_id, but I'm not changing that convention. It's really common to need the msg_type, and the report() function itself (which calls "fsck_error") needs to call fsck_msg_type() to discover it. Let's not needlessly re-do that work in the user callback.

1. https://lore.kernel.org/git/[email protected]/

---
 builtin/fsck.c  | 4 +++-
 builtin/mktag.c | 1 +
 fsck.c          | 6 ++++--
 fsck.h          | 6 ++++--
 4 files changed, 12 insertions(+), 5 deletions(-)
builtin/fsck.c +3 -1
index d6d745dc702..b71fac4ceca 100644
@@ -89,7 +89,9 @@ static int objerror(struct object *obj, const char *err)
 static int fsck_error_func(struct fsck_options *o,
 			   const struct object_id *oid,
 			   enum object_type object_type,
-			   enum fsck_msg_type msg_type, const char *message)
+			   enum fsck_msg_type msg_type,
+			   enum fsck_msg_id msg_id,
+			   const char *message)
 {
 	switch (msg_type) {
 	case FSCK_WARN:
builtin/mktag.c +1 -0
index 1834394a9b6..dc989c356f5 100644
@@ -23,6 +23,7 @@ static int mktag_fsck_error_func(struct fsck_options *o,
 				 const struct object_id *oid,
 				 enum object_type object_type,
 				 enum fsck_msg_type msg_type,
+				 enum fsck_msg_id msg_id,
 				 const char *message)
 {
 	switch (msg_type) {
fsck.c +4 -2
index 980ef2cb8fa..007f02b556a 100644
@@ -247,7 +247,7 @@ static int report(struct fsck_options *options,
 	va_start(ap, fmt);
 	strbuf_vaddf(&sb, fmt, ap);
 	result = options->error_func(options, oid, object_type,
-				     msg_type, sb.buf);
+				     msg_type, msg_id, sb.buf);
 	strbuf_release(&sb);
 	va_end(ap);
 
@@ -1195,7 +1195,9 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
 int fsck_error_function(struct fsck_options *o,
 			const struct object_id *oid,
 			enum object_type object_type,
-			enum fsck_msg_type msg_type, const char *message)
+			enum fsck_msg_type msg_type,
+			enum fsck_msg_id msg_id,
+			const char *message)
 {
 	if (msg_type == FSCK_WARN) {
 		warning("object %s: %s", fsck_describe_object(o, oid), message);
fsck.h +4 -2
index b4c53aaa08c..56536d7f29e 100644
@@ -99,11 +99,13 @@ typedef int (*fsck_walk_func)(struct object *obj, enum object_type object_type,
 /* callback for fsck_object, type is FSCK_ERROR or FSCK_WARN */
 typedef int (*fsck_error)(struct fsck_options *o,
 			  const struct object_id *oid, enum object_type object_type,
-			  enum fsck_msg_type msg_type, const char *message);
+			  enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
+			  const char *message);
 
 int fsck_error_function(struct fsck_options *o,
 			const struct object_id *oid, enum object_type object_type,
-			enum fsck_msg_type msg_type, const char *message);
+			enum fsck_msg_type msg_type, enum fsck_msg_id msg_id,
+			const char *message);
 
 struct fsck_options {
 	fsck_walk_func walk;
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
#181 lore raw

PATCH 12/14 fsck.c: add an fsck_set_msg_type() API that takes enums

In reply to Ævar Arnfjörð Bjarmason

Change code I added in acf9de4c94e (mktag: use fsck instead of custom verify_tag(), 2021-01-05) to make use of a new API function that takes the fsck_msg_{id,type} types, instead of arbitrary strings that we'll (hopefully) parse into those types.

At the time that the fsck_set_msg_type() API was introduced in 0282f4dced0 (fsck: offer a function to demote fsck errors to warnings, 2015-06-22) it was only intended to be used to parse user-supplied data.

For things that are purely internal to the C code it makes sense to have the compiler check these arguments, and to skip the sanity checking of the data in fsck_set_msg_type() which is redundant to checks we get from the compiler.

---
 builtin/mktag.c |  3 ++-
 fsck.c          | 27 +++++++++++++++++----------
 fsck.h          |  3 +++
 3 files changed, 22 insertions(+), 11 deletions(-)
builtin/mktag.c +2 -1
index dc989c356f5..de67a94f24e 100644
@@ -93,7 +93,8 @@ int cmd_mktag(int argc, const char **argv, const char *prefix)
 		die_errno(_("could not read from stdin"));
 
 	fsck_options.error_func = mktag_fsck_error_func;
-	fsck_set_msg_type(&fsck_options, "extraheaderentry", "warn");
+	fsck_set_msg_type_from_ids(&fsck_options, FSCK_MSG_EXTRA_HEADER_ENTRY,
+				   FSCK_WARN);
 	/* config might set fsck.extraHeaderEntry=* again */
 	git_config(mktag_config, NULL);
 	if (fsck_tag_standalone(NULL, buf.buf, buf.len, &fsck_options,
fsck.c +17 -10
index 007f02b556a..54632404de5 100644
@@ -134,6 +134,22 @@ int is_valid_msg_type(const char *msg_id, const char *msg_type)
 	return 1;
 }
 
+void fsck_set_msg_type_from_ids(struct fsck_options *options,
+				enum fsck_msg_id msg_id,
+				enum fsck_msg_type msg_type)
+{
+	if (!options->msg_type) {
+		int i;
+		enum fsck_msg_type *tmp;
+		ALLOC_ARRAY(tmp, FSCK_MSG_MAX);
+		for (i = 0; i < FSCK_MSG_MAX; i++)
+			tmp[i] = fsck_msg_type(i, options);
+		options->msg_type = tmp;
+	}
+
+	options->msg_type[msg_id] = msg_type;
+}
+
 void fsck_set_msg_type(struct fsck_options *options,
 		const char *msg_id_str, const char *msg_type_str)
 {
@@ -146,16 +162,7 @@ void fsck_set_msg_type(struct fsck_options *options,
 	if (msg_type != FSCK_ERROR && msg_id_info[msg_id].msg_type == FSCK_FATAL)
 		die("Cannot demote %s to %s", msg_id_str, msg_type_str);
 
-	if (!options->msg_type) {
-		int i;
-		enum fsck_msg_type *tmp;
-		ALLOC_ARRAY(tmp, FSCK_MSG_MAX);
-		for (i = 0; i < FSCK_MSG_MAX; i++)
-			tmp[i] = fsck_msg_type(i, options);
-		options->msg_type = tmp;
-	}
-
-	options->msg_type[msg_id] = msg_type;
+	fsck_set_msg_type_from_ids(options, msg_id, msg_type);
 }
 
 void fsck_set_msg_types(struct fsck_options *options, const char *values)
fsck.h +3 -0
index 56536d7f29e..af145bb4596 100644
@@ -80,6 +80,9 @@ enum fsck_msg_id {
 struct fsck_options;
 struct object;
 
+void fsck_set_msg_type_from_ids(struct fsck_options *options,
+				enum fsck_msg_id msg_id,
+				enum fsck_msg_type msg_type);
 void fsck_set_msg_type(struct fsck_options *options,
 		       const char *msg_id, const char *msg_type);
 void fsck_set_msg_types(struct fsck_options *options, const char *values);
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
#182 lore raw

PATCH 13/14 fsck.h: update FSCK_OPTIONS_* for object_name

In reply to Ævar Arnfjörð Bjarmason

Add the object_name member to the initialization macro. This was omitted in 7b35efd734e (fsck_walk(): optionally name objects on the go, 2016-07-17) when the field was added.

---
 fsck.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fsck.h +2 -2
index af145bb4596..28137a77df0 100644
@@ -119,8 +119,8 @@ struct fsck_options {
 	kh_oid_map_t *object_names;
 };
 
-#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT }
-#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT }
+#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL }
+#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }
 
 /* descend in all linked child objects
  * the return value is:
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
#183 lore raw

PATCH 14/14 fsck.c: move gitmodules_{found,done} into fsck_options

In reply to Ævar Arnfjörð Bjarmason

Move the gitmodules_{found,done} static variables added in 159e7b080bf (fsck: detect gitmodules files, 2018-05-02) into the fsck_options struct. It makes sense to keep all the context in the same place.

---
 fsck.c | 19 ++++++++-----------
 fsck.h |  6 ++++--
 2 files changed, 12 insertions(+), 13 deletions(-)
fsck.c +8 -11
index 54632404de5..f344b6be3d3 100644
@@ -19,9 +19,6 @@
 #include "credential.h"
 #include "help.h"
 
-static struct oidset gitmodules_found = OIDSET_INIT;
-static struct oidset gitmodules_done = OIDSET_INIT;
-
 #define STR(x) #x
 #define MSG_ID(id, msg_type) { STR(id), NULL, NULL, FSCK_##msg_type },
 static struct {
@@ -621,7 +618,7 @@ static int fsck_tree(const struct object_id *oid,
 
 		if (is_hfs_dotgitmodules(name) || is_ntfs_dotgitmodules(name)) {
 			if (!S_ISLNK(mode))
-				oidset_insert(&gitmodules_found, oid);
+				oidset_insert(&options->gitmodules_found, oid);
 			else
 				retval += report(options,
 						 oid, OBJ_TREE,
@@ -635,7 +632,7 @@ static int fsck_tree(const struct object_id *oid,
 				has_dotgit |= is_ntfs_dotgit(backslash);
 				if (is_ntfs_dotgitmodules(backslash)) {
 					if (!S_ISLNK(mode))
-						oidset_insert(&gitmodules_found, oid);
+						oidset_insert(&options->gitmodules_found, oid);
 					else
 						retval += report(options, oid, OBJ_TREE,
 								 FSCK_MSG_GITMODULES_SYMLINK,
@@ -1147,9 +1144,9 @@ static int fsck_blob(const struct object_id *oid, const char *buf,
 	struct fsck_gitmodules_data data;
 	struct config_options config_opts = { 0 };
 
-	if (!oidset_contains(&gitmodules_found, oid))
+	if (!oidset_contains(&options->gitmodules_found, oid))
 		return 0;
-	oidset_insert(&gitmodules_done, oid);
+	oidset_insert(&options->gitmodules_done, oid);
 
 	if (object_on_skiplist(options, oid))
 		return 0;
@@ -1220,13 +1217,13 @@ int fsck_finish(struct fsck_options *options)
 	struct oidset_iter iter;
 	const struct object_id *oid;
 
-	oidset_iter_init(&gitmodules_found, &iter);
+	oidset_iter_init(&options->gitmodules_found, &iter);
 	while ((oid = oidset_iter_next(&iter))) {
 		enum object_type type;
 		unsigned long size;
 		char *buf;
 
-		if (oidset_contains(&gitmodules_done, oid))
+		if (oidset_contains(&options->gitmodules_done, oid))
 			continue;
 
 		buf = read_object_file(oid, &type, &size);
@@ -1251,8 +1248,8 @@ int fsck_finish(struct fsck_options *options)
 	}
 
 
-	oidset_clear(&gitmodules_found);
-	oidset_clear(&gitmodules_done);
+	oidset_clear(&options->gitmodules_found);
+	oidset_clear(&options->gitmodules_done);
 	return ret;
 }
 
fsck.h +4 -2
index 28137a77df0..99c77289688 100644
@@ -116,11 +116,13 @@ struct fsck_options {
 	unsigned strict:1;
 	enum fsck_msg_type *msg_type;
 	struct oidset skiplist;
+	struct oidset gitmodules_found;
+	struct oidset gitmodules_done;
 	kh_oid_map_t *object_names;
 };
 
-#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, NULL }
-#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, NULL }
+#define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT, OIDSET_INIT, OIDSET_INIT, NULL }
+#define FSCK_OPTIONS_STRICT { NULL, fsck_error_function, 1, NULL, OIDSET_INIT, OIDSET_INIT, OIDSET_INIT, NULL }
 
 /* descend in all linked child objects
  * the return value is:
Signature · 1 line
2.30.0.284.gd98b1dd5eaa7
#184 lore raw

Re: [PATCH 4/4] fetch-pack: print and use dangling .gitmodules

In reply to Ævar Arnfjörð Bjarmason
Quoted 10 lines
Quoted 5 lines

I tried that first, and the issue is that IDs like FSCK_MSG_GITMODULES_MISSING are internal to fsck.c. As for whether we should start exposing the IDs publicly, I think we should wait until a few new cases like this come up, so that we more fully understand the requirements first.

The requirement is that you want the objects ids we'd otherwise error about in fsck_finish(). Yeah we don't pass the "fsck_msg_id" down in the "report()" function, but you can reliably strstr() it out of the message.

We can't strstr() because of false positives (if, e.g. there is a submodule name that contains the string we're looking for), but looking at report() in fsck.c, the message ID is the very first thing appended, so I think we can use starts_with().

Quoted 2 lines

We document & hard rely on that already, since it's also a config key.

Ah, good point.

Quoted 5 lines

But yeah, we could just change the report function to pass down the id and move the relevant macros from fsck.c to fsck.h. I think that would be a smaller change conceptually than a special-case flag in fsck_options for something we could otherwise do with the error reporting.

I agree - I thought this wouldn't be possible, but like you said, we can reliably make use of the string in report() (or pass the ID, like your patch set [1] does) so we should do this.

What would be the best way to proceed, now that we have at least 2 patch sets (mine and yours) in play? I was thinking that I should update my one to use the string reported in report() (with starts_with()), so that both our patch sets can be reviewed and merged in parallel, and after that, update the fsck code to use the ID instead of the string.

[1] https://lore.kernel.org/git/[email protected]/

#185 lore raw

Re: [PATCH 4/4] fetch-pack: print and use dangling .gitmodules

In reply to Jonathan Tan

Documentation/git-index-pack.txt OPTIONS · line 86

Quoted 8 lines · Jonathan Tan

--fsck-objects::

Documentation/git-index-pack.txt +6 -1
-	Die if the pack contains broken objects. For internal use only.
+	For internal use only.
++
+Die if the pack contains broken objects. If the pack contains a tree
+pointing to a .gitmodules blob that does not exist, prints the hash of
+that blob (for the caller to check) after the hash that goes into the
+name of the pack/idx file (see "Notes").

[I should have waited a bit and sent one E-Mail]

Is this really generally usable as an IPC mechanism, what if we need another set of OIDs we care about? Shouldn't it at least be hidden behind some option so you don't get a deluge of output from index-pack if you're not in this packfile-uri mode?

But, along with my other E-Mail...

Quoted 11 lines

[...]

fetch-pack.c +10 -0
+static void parse_gitmodules_oids(int fd, struct oidset *gitmodules_oids)
+{
+	int len = the_hash_algo->hexsz + 1; /* hash + NL */
+
+	do {
+		char hex_hash[GIT_MAX_HEXSZ + 1];
+		int read_len = read_in_full(fd, hex_hash, len);
+		struct object_id oid;
+		const char *end;
+

fetch-pack.c static void write_promisor_file(const char *keep_name, · line 818

Quoted 10 lines
fetch-pack.c +10 -0
+		if (!read_len)
+			return;
+		if (read_len != len)
+			die("invalid length read %d", read_len);
+		if (parse_oid_hex(hex_hash, &oid, &end) || *end != '\n')
+			die("invalid hash");
+		oidset_insert(gitmodules_oids, &oid);
+	} while (1);
+}
+

Doesn't this IPC mechanism already exist in the form of fsck.skipList? See my 1f3299fda9 (fsck: make fsck_config() re-usable, 2021-01-05) on "next". I.e. as noted in my just-sent-E-Mail you could probably just re-use skiplist as-is.

Or if not it seems to me that this whole IPC mechanism would be better done with a tempfile and passing it along like we already pass the fsck.skipList between these processes.

I doubt it's going to be large enough to matter, we could just put it in .git/ somewhere, like we put gc.log etc (but created with a mktemp() name...).

Or if we want to keep the "print <list> | process" model we can refactor the existing fsck IPC noted in 1f3299fda9 a bit, so e.g. you pass some version of "lines prefixed with "fsck-skiplist: " go into list xyz via a command-line option. And then existing option(s) and your potential new list (which as noted, I think is probably redundant to the skiplist) can use it.

#186 lore raw

Re: [PATCH 4/4] fetch-pack: print and use dangling .gitmodules

Quoted 12 lines · Jonathan Tan

Documentation/git-index-pack.txt OPTIONS · line 86

Quoted 8 lines

--fsck-objects::

Documentation/git-index-pack.txt +6 -1
-	Die if the pack contains broken objects. For internal use only.
+	For internal use only.
++
+Die if the pack contains broken objects. If the pack contains a tree
+pointing to a .gitmodules blob that does not exist, prints the hash of
+that blob (for the caller to check) after the hash that goes into the
+name of the pack/idx file (see "Notes").

[I should have waited a bit and sent one E-Mail]

Quoted 4 lines

Is this really generally usable as an IPC mechanism, what if we need another set of OIDs we care about? Shouldn't it at least be hidden behind some option so you don't get a deluge of output from index-pack if you're not in this packfile-uri mode?

--fsck-objects is only for internal use, and it's only used by fetch-pack.c. So its only consumer does want the output.

Junio also mentioned the possibility of another set of OIDs, and I replied [1].

[1] https://lore.kernel.org/git/[email protected]/

Quoted 20 lines

But, along with my other E-Mail...

Quoted 18 lines

[...]

fetch-pack.c +17 -0
+static void parse_gitmodules_oids(int fd, struct oidset *gitmodules_oids)
+{
+	int len = the_hash_algo->hexsz + 1; /* hash + NL */
+
+	do {
+		char hex_hash[GIT_MAX_HEXSZ + 1];
+		int read_len = read_in_full(fd, hex_hash, len);
+		struct object_id oid;
+		const char *end;
+
+		if (!read_len)
+			return;
+		if (read_len != len)
+			die("invalid length read %d", read_len);
+		if (parse_oid_hex(hex_hash, &oid, &end) || *end != '\n')
+			die("invalid hash");
+		oidset_insert(gitmodules_oids, &oid);
Quoted 8 lines

fetch-pack.c static void write_promisor_file(const char *keep_name, · line 818

Quoted 3 lines
fetch-pack.c +3 -0
+	} while (1);
+}
+

Doesn't this IPC mechanism already exist in the form of fsck.skipList? See my 1f3299fda9 (fsck: make fsck_config() re-usable, 2021-01-05) on "next". I.e. as noted in my just-sent-E-Mail you could probably just re-use skiplist as-is.

I'm not sure how fsck.skipList could be used here. Before running fsck_finish() for the first time, we don't know which .gitmodules are missing and which are not. And when running fsck_finish() for the second time, we definitely do not want to skip any blobs.

Quoted 8 lines

Or if not it seems to me that this whole IPC mechanism would be better done with a tempfile and passing it along like we already pass the fsck.skipList between these processes.

I doubt it's going to be large enough to matter, we could just put it in .git/ somewhere, like we put gc.log etc (but created with a mktemp() name...).

Quoted 6 lines

Or if we want to keep the "print <list> | process" model we can refactor the existing fsck IPC noted in 1f3299fda9 a bit, so e.g. you pass some version of "lines prefixed with "fsck-skiplist: " go into list xyz via a command-line option. And then existing option(s) and your potential new list (which as noted, I think is probably redundant to the skiplist) can use it.

I think using stdout is superior to using a tempfile - we don't have to worry about interrupted invocations, for example.

What do you mean by "the existing fsck IPC noted in 1f3299fda9"? If you mean the ability to pass a list of OIDs, for example using "-c fsck.skipList=filename.txt", I'm not sure that it solves anything. Firstly, I don't think that the skipList is useful here (as I said earlier). And secondly, I don't think that OID input is the issue - right now, the design is a process (index-pack, calling fsck_finish()) writing to its output which is then picked up by the calling process (fetch-pack). We are not sending the dangling .gitmodules through stdin anywhere.

#187 lore raw

Re: [PATCH 4/4] fetch-pack: print and use dangling .gitmodules

Quoted 77 lines · Jonathan Tan
Quoted 12 lines · Jonathan Tan

Documentation/git-index-pack.txt OPTIONS · line 86

Quoted 8 lines

--fsck-objects::

Documentation/git-index-pack.txt +6 -1
-	Die if the pack contains broken objects. For internal use only.
+	For internal use only.
++
+Die if the pack contains broken objects. If the pack contains a tree
+pointing to a .gitmodules blob that does not exist, prints the hash of
+that blob (for the caller to check) after the hash that goes into the
+name of the pack/idx file (see "Notes").

[I should have waited a bit and sent one E-Mail]

Quoted 4 lines

Is this really generally usable as an IPC mechanism, what if we need another set of OIDs we care about? Shouldn't it at least be hidden behind some option so you don't get a deluge of output from index-pack if you're not in this packfile-uri mode?

--fsck-objects is only for internal use, and it's only used by fetch-pack.c. So its only consumer does want the output.

Junio also mentioned the possibility of another set of OIDs, and I replied [1].

[1] https://lore.kernel.org/git/[email protected]/

Quoted 20 lines

But, along with my other E-Mail...

Quoted 18 lines

[...]

fetch-pack.c +17 -0
+static void parse_gitmodules_oids(int fd, struct oidset *gitmodules_oids)
+{
+	int len = the_hash_algo->hexsz + 1; /* hash + NL */
+
+	do {
+		char hex_hash[GIT_MAX_HEXSZ + 1];
+		int read_len = read_in_full(fd, hex_hash, len);
+		struct object_id oid;
+		const char *end;
+
+		if (!read_len)
+			return;
+		if (read_len != len)
+			die("invalid length read %d", read_len);
+		if (parse_oid_hex(hex_hash, &oid, &end) || *end != '\n')
+			die("invalid hash");
+		oidset_insert(gitmodules_oids, &oid);
Quoted 8 lines

fetch-pack.c static void write_promisor_file(const char *keep_name, · line 818

Quoted 3 lines
fetch-pack.c +3 -0
+	} while (1);
+}
+

Doesn't this IPC mechanism already exist in the form of fsck.skipList? See my 1f3299fda9 (fsck: make fsck_config() re-usable, 2021-01-05) on "next". I.e. as noted in my just-sent-E-Mail you could probably just re-use skiplist as-is.

I'm not sure how fsck.skipList could be used here. Before running fsck_finish() for the first time, we don't know which .gitmodules are missing and which are not. And when running fsck_finish() for the second time, we definitely do not want to skip any blobs.

Quoted 8 lines

Or if not it seems to me that this whole IPC mechanism would be better done with a tempfile and passing it along like we already pass the fsck.skipList between these processes.

I doubt it's going to be large enough to matter, we could just put it in .git/ somewhere, like we put gc.log etc (but created with a mktemp() name...).

Quoted 6 lines

Or if we want to keep the "print <list> | process" model we can refactor the existing fsck IPC noted in 1f3299fda9 a bit, so e.g. you pass some version of "lines prefixed with "fsck-skiplist: " go into list xyz via a command-line option. And then existing option(s) and your potential new list (which as noted, I think is probably redundant to the skiplist) can use it.

I think using stdout is superior to using a tempfile - we don't have to worry about interrupted invocations, for example.

Quoted 9 lines

What do you mean by "the existing fsck IPC noted in 1f3299fda9"? If you mean the ability to pass a list of OIDs, for example using "-c fsck.skipList=filename.txt", I'm not sure that it solves anything. Firstly, I don't think that the skipList is useful here (as I said earlier). And secondly, I don't think that OID input is the issue - right now, the design is a process (index-pack, calling fsck_finish()) writing to its output which is then picked up by the calling process (fetch-pack). We are not sending the dangling .gitmodules through stdin anywhere.

Sorry for being unclear here. I don't think (honestly I don't remember, it's been almost a month) that I meant to you should use the skipList.

Looking at that code again we use object_on_skiplist() to do an early punt in report(), but also fsck_blob(), presumably you never want the latter, and that early punting wouldn't be needed if your report() function intercepted the modules blob id for stashing it away / later reporting / whatever.

So yeah, I'm 99% sure now that's not what I meant :)

What I meant with:

Or if we want to keep the "print <list> | process"[...]

Is that we have an existing ad-hoc IPC model for these commands in passing along the skipList, which is made more complex because sometimes the initial process reads the file, sometimes it passes it along as-is to the child.

And then there's this patch that passes OIDs too, but through a different mechanism.

I was suggesting that perhaps it made more sense to refactor both so they could use the same mechanism, because we're potentially passing two lists of OIDs between the two. Just one goes via line-at-a-time in the output, the other via a config option on the command-line.

#188 lore raw

Re: [PATCH 4/4] fetch-pack: print and use dangling .gitmodules

Quoted 20 lines

Sorry for being unclear here. I don't think (honestly I don't remember, it's been almost a month) that I meant to you should use the skipList.

Looking at that code again we use object_on_skiplist() to do an early punt in report(), but also fsck_blob(), presumably you never want the latter, and that early punting wouldn't be needed if your report() function intercepted the modules blob id for stashing it away / later reporting / whatever.

So yeah, I'm 99% sure now that's not what I meant :)

What I meant with:

Or if we want to keep the "print <list> | process"[...]

Is that we have an existing ad-hoc IPC model for these commands in passing along the skipList, which is made more complex because sometimes the initial process reads the file, sometimes it passes it along as-is to the child.

Quoted 7 lines

And then there's this patch that passes OIDs too, but through a different mechanism.

I was suggesting that perhaps it made more sense to refactor both so they could use the same mechanism, because we're potentially passing two lists of OIDs between the two. Just one goes via line-at-a-time in the output, the other via a config option on the command-line.

Thanks for your explanation. I still think that they are quite different
- skiplist is a user-written file containing a list of OIDs that will likely never change, whereas my list of dangling .gitmodules is a list of OIDs dynamically generated (and thus, always different) whenever a fetch is done. So I think it's quite reasonable to pass skiplist as a file name, and my list should be passed line-by-line.

#189 lore raw

Re: [PATCH 4/4] fetch-pack: print and use dangling .gitmodules

Quoted 28 lines · Jonathan Tan
Quoted 20 lines

Sorry for being unclear here. I don't think (honestly I don't remember, it's been almost a month) that I meant to you should use the skipList.

Looking at that code again we use object_on_skiplist() to do an early punt in report(), but also fsck_blob(), presumably you never want the latter, and that early punting wouldn't be needed if your report() function intercepted the modules blob id for stashing it away / later reporting / whatever.

So yeah, I'm 99% sure now that's not what I meant :)

What I meant with:

Or if we want to keep the "print <list> | process"[...]

Is that we have an existing ad-hoc IPC model for these commands in passing along the skipList, which is made more complex because sometimes the initial process reads the file, sometimes it passes it along as-is to the child.

Quoted 7 lines

And then there's this patch that passes OIDs too, but through a different mechanism.

I was suggesting that perhaps it made more sense to refactor both so they could use the same mechanism, because we're potentially passing two lists of OIDs between the two. Just one goes via line-at-a-time in the output, the other via a config option on the command-line.

Quoted 6 lines

Thanks for your explanation. I still think that they are quite different
- skiplist is a user-written file containing a list of OIDs that will likely never change, whereas my list of dangling .gitmodules is a list of OIDs dynamically generated (and thus, always different) whenever a fetch is done. So I think it's quite reasonable to pass skiplist as a file name, and my list should be passed line-by-line.

Sure, but I'm not talking about passing it as a tempfile.

Yes, I suggested that in the third-to-last paragraph of [1] but then went on to say that we could also move to some IPC mechanism where you spew in the list of dangling .gitmodules, and we also spew in the skipList and anything else we want to pass in.

I'm not saying this needs to be part of this series. But let me rephrase:

We now have some combination of {receive-pack,upload-pack,send-pack,fetch-pack,unpack-objects} that need to communicate locally or pass data back & forth, passing data either via a CLI option to read a file, packnames/refs on --stdin, or (now) a single list of OIDs on stdout.

Let's say we don't just need to pass the .gitmodules OIDs, but also e.g. .mailmap OIDs or whatever (due to some future vulnerability).

Would this IPC mechanism deal with that, or would we need to introduce a breaking change (Re: my recently send mail about concurrent updates of libexec programs)? Can we use soemething like pkt-line to talk back & forth in an extensible way?

Not needed now, just food for thought...

1. https://lore.kernel.org/git/[email protected]/

#190 lore raw

Re: [PATCH 4/4] fetch-pack: print and use dangling .gitmodules

In reply to Jonathan Tan
Quoted 24 lines · Jonathan Tan
builtin/index-pack.c +13 -2
index 557bd2f348..f995c15115 100644
@@ -1888,8 +1888,13 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 	else
 		close(input_fd);
 
-	if (do_fsck_object && fsck_finish(&fsck_options))
-		die(_("fsck error in pack objects"));
+	if (do_fsck_object) {
+		struct fsck_options fo = FSCK_OPTIONS_STRICT;
+
+		fo.print_dangling_gitmodules = 1;
+		if (fsck_finish(&fo))
+			die(_("fsck error in pack objects"));
+	}
[...]
+static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
+{
+	struct oidset_iter iter;
+	const struct object_id *oid;
+	struct fsck_options fo = FSCK_OPTIONS_STRICT;
+

builtin/index-pack.c int cmd_index_pack(int argc, const char **argv, const char *prefix)

Quoted 10 lines
builtin/index-pack.c +10 -0
+	if (!oidset_size(gitmodules_oids))
+		return;
+
+	oidset_iter_init(gitmodules_oids, &iter);
+	while ((oid = oidset_iter_next(&iter)))
+		register_found_gitmodules(oid);
+	if (fsck_finish(&fo))
+		die("fsck failed");
+}
+

What's the need for STRICT here & can't the former use the existing fsck_options in index-pack.c? With this on top we pass all tests:

builtin/index-pack.c +2 -4
index 18531199242..5464edf4778 100644
@@ -1933,10 +1933,8 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 		close(input_fd);
 
 	if (do_fsck_object) {
-		struct fsck_options fo = FSCK_OPTIONS_STRICT;
-
-		fo.print_dangling_gitmodules = 1;
-		if (fsck_finish(&fo))
+		fsck_options.print_dangling_gitmodules = 1;
+		if (fsck_finish(&fsck_options))
 			die(_("fsck error in pack objects"));
 	}
 
fetch-pack.c +1 -1
index 0a337a04f1f..a8754d97e3d 100644
@@ -997,7 +997,7 @@ static void fsck_gitmodules_oids(struct oidset *gitmodules_oids)
 {
 	struct oidset_iter iter;
 	const struct object_id *oid;
-	struct fsck_options fo = FSCK_OPTIONS_STRICT;
+	struct fsck_options fo = FSCK_OPTIONS_DEFAULT;
 
 	if (!oidset_size(gitmodules_oids))
 		return;
#191 lore raw

Re: [PATCH 4/4] fetch-pack: print and use dangling .gitmodules

Quoted 2 lines

What's the need for STRICT here & can't the former use the existing fsck_options in index-pack.c? With this on top we pass all tests:

[snip code]

Good point - I'll do that.

#192 lore raw

Re: [PATCH 0/4] Check .gitmodules when using packfile URIs

In reply to Jonathan Tan
Quoted 4 lines · Jonathan Tan

As part of this, index-pack has to output (1) the hash that goes into the name of the .pack/.idx file and (2) the hashes of all dangling .gitmodules. I just had (2) come after (1). If anyone has a better idea, I'm interested.

I have this feeling that the "blobs that need to be validated across packs" will *not* be the last enhancement we'd need to make to the output from index-pack to allow richer communication between it and its invoker. While there is no reason to change how the first line of the output looks like, we'd probably want to make sure that the future versions of Git can easily tell "list of blobs that require further validation" from other additional information.

I am not comfortable to recommend "ok, then let's add a delimiter line '---\n' if/when we need to have something after the list of blobs and append more stuff in future versions of Git", because we may find need to emit new kinds of info before the list of blobs that needs further validation, for example, in future versions of Git.

Having said all that, the internal communication between the index-pack and its caller do not need as much care about compatibility across versions as output visible to end-users, so when a future version of Git needs to send different kinds of information in different order from what you created here, we can do so pretty much freely, I would guess.

Thanks.

#193 lore raw

Re: [PATCH 0/4] Check .gitmodules when using packfile URIs

Quoted 22 lines
Quoted 4 lines · Jonathan Tan

As part of this, index-pack has to output (1) the hash that goes into the name of the .pack/.idx file and (2) the hashes of all dangling .gitmodules. I just had (2) come after (1). If anyone has a better idea, I'm interested.

I have this feeling that the "blobs that need to be validated across packs" will *not* be the last enhancement we'd need to make to the output from index-pack to allow richer communication between it and its invoker. While there is no reason to change how the first line of the output looks like, we'd probably want to make sure that the future versions of Git can easily tell "list of blobs that require further validation" from other additional information.

I am not comfortable to recommend "ok, then let's add a delimiter line '---\n' if/when we need to have something after the list of blobs and append more stuff in future versions of Git", because we may find need to emit new kinds of info before the list of blobs that needs further validation, for example, in future versions of Git.

Quoted 6 lines

Having said all that, the internal communication between the index-pack and its caller do not need as much care about compatibility across versions as output visible to end-users, so when a future version of Git needs to send different kinds of information in different order from what you created here, we can do so pretty much freely, I would guess.

Yeah, that's what I thought too - since this is an internal interface, we can evolve them in lockstep. If we're really worried about the Git binaries (on a user's system) getting out of sync, we could just make sure that subsequent updates to this protocol are non-backwards-compatible (e.g. have index-pack emit "foo <hash>", where "foo" is a string that describes the new check, so that current fetch-pack will reject "foo" since it is not a hash).

#194 lore raw

Re: [PATCH 0/4] Check .gitmodules when using packfile URIs

Quoted 29 lines · Jonathan Tan
Quoted 22 lines
Quoted 4 lines · Jonathan Tan

As part of this, index-pack has to output (1) the hash that goes into the name of the .pack/.idx file and (2) the hashes of all dangling .gitmodules. I just had (2) come after (1). If anyone has a better idea, I'm interested.

I have this feeling that the "blobs that need to be validated across packs" will *not* be the last enhancement we'd need to make to the output from index-pack to allow richer communication between it and its invoker. While there is no reason to change how the first line of the output looks like, we'd probably want to make sure that the future versions of Git can easily tell "list of blobs that require further validation" from other additional information.

I am not comfortable to recommend "ok, then let's add a delimiter line '---\n' if/when we need to have something after the list of blobs and append more stuff in future versions of Git", because we may find need to emit new kinds of info before the list of blobs that needs further validation, for example, in future versions of Git.

Quoted 6 lines

Having said all that, the internal communication between the index-pack and its caller do not need as much care about compatibility across versions as output visible to end-users, so when a future version of Git needs to send different kinds of information in different order from what you created here, we can do so pretty much freely, I would guess.

Quoted 3 lines

Yeah, that's what I thought too - since this is an internal interface, we can evolve them in lockstep. If we're really worried about the Git binaries (on a user's system) getting out of sync,

I'm thinking in reading "getting out of sync" that you may be missing an aspect of the issue here.

We're not talking about some abnormal error in some packaging system, but how we'd expect all installations of git to behave if you update them with *.rpm, *.deb etc, e.g. when your binaries are in /usr/libexec/git-core. I suppose NixOS or something where there's hash-based paths may be exempt from this.

On those systems if you've got a server serving concurrent traffic and update the "git" package you could expect failure if any git process invoked by another is incompatible during such an upgrade.

If you browse some of the recent GIT_CONFIG_PARAMETERS discussion this was discussed there. I.e. even if GIT_CONFIG_PARAMETERS is internal-only we bent over backwards not to change it in such a way as to have process A invoking process B and the two not understanding each other because of such an upgrade.

That's exactly because of this case, where receive-pack may be started on version A, someone runs "apt install git" in the background concurrently, and now a version A of that program is talking to a version B index-pack.

Quoted 4 lines

we could just make sure that subsequent updates to this protocol are non-backwards-compatible (e.g. have index-pack emit "foo <hash>", where "foo" is a string that describes the new check, so that current fetch-pack will reject "foo" since it is not a hash).

And then presumably index-pack would die and receive-pack would die on the push or whatever, so the push fails for the end user.

#195 lore raw

Re: [PATCH 0/4] Check .gitmodules when using packfile URIs

In reply to Jonathan Tan
Quoted 11 lines · Jonathan Tan

This patch set resolves the .gitmodules-and-tree-in-separate-packfiles issue I mentioned in [1] by having index-pack print out all dangling .gitmodules (instead of returning with an error code) and then teaching fetch-pack to read those and run its own fsck checks after all index-pack invocations are complete.

As part of this, index-pack has to output (1) the hash that goes into the name of the .pack/.idx file and (2) the hashes of all dangling .gitmodules. I just had (2) come after (1). If anyone has a better idea, I'm interested.

Quoted 7 lines

I also discovered a bug in that different index-pack arguments were used when processing the inline packfile and when processing the ones referenced by URIs. Patch 1-3 fixes that bug by passing the arguments to use as a space-separated URL-encoded list. (URL-encoded so that we can have spaces in the arguments.) Again, if anyone has a better idea, I'm interested. It is only in patch 4 that we have the dangling .gitmodules fix.

This seems to have been stalled but I think it would be a better approach to use a custom callback for error reporting, suggested by Ævar, which would be where his fsck API clean-up topic would lead to.

If it is not ultra-urgent, perhaps you can retract the ones that are queued right now, work with Ævar to finish the error-callback work and rebuild this topic on top of it? Thanks.

#196 lore raw

Re: [PATCH 0/4] Check .gitmodules when using packfile URIs

Quoted 8 lines

This seems to have been stalled but I think it would be a better approach to use a custom callback for error reporting, suggested by Ævar, which would be where his fsck API clean-up topic would lead to.

If it is not ultra-urgent, perhaps you can retract the ones that are queued right now, work with Ævar to finish the error-callback work and rebuild this topic on top of it? Thanks.

OK - that works. My original idea was to rewrite it using an error-callback but using starts_with() instead of the ID that Ævar's work will provide, but seeing that at least one other contributor (Peff) seems OK with the patches, rebasing mine on top of his works too. I'll also take a look at his patches.

#197 lore raw

Re: [PATCH 0/4] Check .gitmodules when using packfile URIs

Quoted 9 lines · Jonathan Tan
Quoted 8 lines

This seems to have been stalled but I think it would be a better approach to use a custom callback for error reporting, suggested by Ævar, which would be where his fsck API clean-up topic would lead to.

If it is not ultra-urgent, perhaps you can retract the ones that are queued right now, work with Ævar to finish the error-callback work and rebuild this topic on top of it? Thanks.

Quoted 5 lines

OK - that works. My original idea was to rewrite it using an error-callback but using starts_with() instead of the ID that Ævar's work will provide, but seeing that at least one other contributor (Peff) seems OK with the patches, rebasing mine on top of his works too. I'll also take a look at his patches.

Thanks, either way would work for me, but if the suggested route forces you review Ævar's code and work together, that would be a good bonus point ;-)

#198 lore raw

Re: [PATCH 0/4] Check .gitmodules when using packfile URIs

In reply to Junio C Hamano
Quoted 21 lines · Junio C Hamano
Quoted 11 lines · Jonathan Tan

This patch set resolves the .gitmodules-and-tree-in-separate-packfiles issue I mentioned in [1] by having index-pack print out all dangling .gitmodules (instead of returning with an error code) and then teaching fetch-pack to read those and run its own fsck checks after all index-pack invocations are complete.

As part of this, index-pack has to output (1) the hash that goes into the name of the .pack/.idx file and (2) the hashes of all dangling .gitmodules. I just had (2) come after (1). If anyone has a better idea, I'm interested.

Quoted 7 lines

I also discovered a bug in that different index-pack arguments were used when processing the inline packfile and when processing the ones referenced by URIs. Patch 1-3 fixes that bug by passing the arguments to use as a space-separated URL-encoded list. (URL-encoded so that we can have spaces in the arguments.) Again, if anyone has a better idea, I'm interested. It is only in patch 4 that we have the dangling .gitmodules fix.

Quoted 8 lines

This seems to have been stalled but I think it would be a better approach to use a custom callback for error reporting, suggested by Ævar, which would be where his fsck API clean-up topic would lead to.

If it is not ultra-urgent, perhaps you can retract the ones that are queued right now, work with Ævar to finish the error-callback work and rebuild this topic on top of it? Thanks.

If my vote counts for something I think it makes sense to have Jonathan's series go first and just ignore my fsck API improvement patches (well, the part of my v1[1] which conflicts with his work).

I'm also happy to help him queue his on top of a v1 version of my series.

But the end result of doing so (shown after the "--" in [1]) is just a small re-arrangement of code to get a cleaner fsck API use, it doesn't actually matter to anyone using git.

Whereas his patches actually do, we have in-the-wild server/repo/clone setups that are getting on-clone errors, and the window for 2.31 is getting closer.

We can always do the small API use refactoring later. My interest in barking up that tree was just that I've been poking at that part of the fsck API and have some follow-up work that hasn't made it onto the list yet that makes other use of the fsck API.

So in the longer term I wanted us to think about not needing N special cases like "print_dangling_gitmodules" if we could help it, but in the shorter term having it is a non-issue.

1. https://lore.kernel.org/git/[email protected]/

#199 lore raw

Re: [PATCH 0/4] Check .gitmodules when using packfile URIs

Quoted 11 lines · Ævar Arnfjörð Bjarmason
Quoted 8 lines · Junio C Hamano

This seems to have been stalled but I think it would be a better approach to use a custom callback for error reporting, suggested by Ævar, which would be where his fsck API clean-up topic would lead to.

If it is not ultra-urgent, perhaps you can retract the ones that are queued right now, work with Ævar to finish the error-callback work and rebuild this topic on top of it? Thanks.

Quoted 6 lines

If my vote counts for something I think it makes sense to have Jonathan's series go first and just ignore my fsck API improvement patches (well, the part of my v1[1] which conflicts with his work).

I'm also happy to help him queue his on top of a v1 version of my series.

Either would work for us, I would think.

Thanks.

#200 lore raw

v2 cover Check .gitmodules when using packfile URIs

In reply to Jonathan Tan

Here's v2. I think I've addressed all the review comments, including passing the index-pack args as separate arguments (to avoid the necessity to somehow encode in order to get rid of spaces), and by using a custom error function instead of a specific option in fsck.

This applies on master. I mentioned earlier [1] that I was planning to implement this on Ævar's fsck API improvements, but after looking at the latest v2, I see that it omits patch 11 from v1 (which is the one I need), so what I've done is to use a string check in the meantime.

[1] https://lore.kernel.org/git/[email protected]/

Jonathan Tan (4):
http: allow custom index-pack args
http-fetch: allow custom index-pack args
fetch-pack: with packfile URIs, use index-pack arg
fetch-pack: print and use dangling .gitmodules

 Documentation/git-http-fetch.txt |  10 ++-
 Documentation/git-index-pack.txt |   7 ++-
 builtin/index-pack.c             |  25 +++++++-
 builtin/receive-pack.c           |   2 +-
 fetch-pack.c                     | 103 ++++++++++++++++++++++++++-----
 fsck.c                           |   5 ++
 fsck.h                           |   2 +
 http-fetch.c                     |  20 +++++-
 http.c                           |  15 ++---
 http.h                           |  10 +--
 pack-write.c                     |   8 ++-
 pack.h                           |   2 +-
 t/t5550-http-fetch-dumb.sh       |   5 +-
 t/t5702-protocol-v2.sh           |  58 +++++++++++++++--
 14 files changed, 227 insertions(+), 45 deletions(-)

Range-diff against v1:

-:  ---------- > 1:  b7e376be16 http: allow custom index-pack args
1:  9fba6c9bcc ! 2:  57220ceb84 http-fetch: allow custom index-pack args
    @@ Documentation/git-http-fetch.txt: commit-id::
      
      --packfile=<hash>::
     -	Instead of a commit id on the command line (which is not expected in
    -+	For internal use only. Instead of a commit id on the command line (which is not expected in
    ++	For internal use only. Instead of a commit id on the command
    ++	line (which is not expected in
      	this case), 'git http-fetch' fetches the packfile directly at the given
      	URL and uses index-pack to generate corresponding .idx and .keep files.
      	The hash is used to determine the name of the temporary file and is
    @@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
      		strvec_pushf(&cmd.args, "--packfile=%.*s",
      			     (int) the_hash_algo->hexsz,
      			     packfile_uris.items[i].string);
    -+		strvec_push(&cmd.args, "--index-pack-args=index-pack --stdin --keep");
    ++		strvec_push(&cmd.args, "--index-pack-arg=index-pack");
    ++		strvec_push(&cmd.args, "--index-pack-arg=--stdin");
    ++		strvec_push(&cmd.args, "--index-pack-arg=--keep");
      		strvec_push(&cmd.args, uri);
      		cmd.git_cmd = 1;
      		cmd.no_stdin = 1;
    @@ http-fetch.c: int cmd_main(int argc, const char **argv)
      	int packfile = 0;
      	int nongit;
      	struct object_id packfile_hash;
    -+	const char *index_pack_args = NULL;
    ++	struct strvec index_pack_args = STRVEC_INIT;
      
      	setup_git_directory_gently(&nongit);
      
    @@ http-fetch.c: int cmd_main(int argc, const char **argv)
      			packfile = 1;
      			if (parse_oid_hex(p, &packfile_hash, &end) || *end)
      				die(_("argument to --packfile must be a valid hash (got '%s')"), p);
    -+		} else if (skip_prefix(argv[arg], "--index-pack-args=", &p)) {
    -+			index_pack_args = p;
    ++		} else if (skip_prefix(argv[arg], "--index-pack-arg=", &p)) {
    ++			strvec_push(&index_pack_args, p);
      		}
      		arg++;
      	}
    @@ http-fetch.c: int cmd_main(int argc, const char **argv)
      
      	if (packfile) {
     -		fetch_single_packfile(&packfile_hash, argv[arg]);
    -+		struct strvec encoded = STRVEC_INIT;
    -+		char **raw;
    -+		int i;
    -+
    -+		if (!index_pack_args)
    ++		if (!index_pack_args.nr)
     +			die(_("--packfile requires --index-pack-args"));
     +
    -+		strvec_split(&encoded, index_pack_args);
    -+
    -+		CALLOC_ARRAY(raw, encoded.nr + 1);
    -+		for (i = 0; i < encoded.nr; i++)
    -+			raw[i] = url_percent_decode(encoded.v[i]);
    -+
     +		fetch_single_packfile(&packfile_hash, argv[arg],
    -+				      (const char **) raw);
    -+
    -+		for (i = 0; i < encoded.nr; i++)
    -+			free(raw[i]);
    -+		free(raw);
    -+		strvec_clear(&encoded);
    ++				      index_pack_args.v);
     +
      		return 0;
      	}
      
    -+	if (index_pack_args)
    ++	if (index_pack_args.nr)
     +		die(_("--index-pack-args can only be used with --packfile"));
     +
      	if (commits_on_stdin) {
    @@ t/t5550-http-fetch-dumb.sh: test_expect_success 'http-fetch --packfile' '
      	p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && ls objects/pack/pack-*.pack) &&
     -	git -C packfileclient http-fetch --packfile=$ARBITRARY "$HTTPD_URL"/dumb/repo_pack.git/$p >out &&
     +	git -C packfileclient http-fetch --packfile=$ARBITRARY \
    -+		--index-pack-args="index-pack --stdin --keep" "$HTTPD_URL"/dumb/repo_pack.git/$p >out &&
    ++		--index-pack-arg=index-pack --index-pack-arg=--stdin \
    ++		--index-pack-arg=--keep \
    ++		"$HTTPD_URL"/dumb/repo_pack.git/$p >out &&
      
      	grep "^keep.[0-9a-f]\{16,\}$" out &&
      	cut -c6- out >packhash &&
2:  7c3244e79f ! 3:  aa87335464 fetch-pack: with packfile URIs, use index-pack arg
    @@ fetch-pack.c: static void write_promisor_file(const char *keep_name,
     - * Pass 1 as "only_packfile" if the pack received is the only pack in this
     - * fetch request (that is, if there were no packfile URIs provided).
     + * If packfile URIs were provided, pass a non-NULL pointer to index_pack_args.
    -+ * The string to pass as the --index-pack-args argument to http-fetch will be
    ++ * The strings to pass as the --index-pack-arg arguments to http-fetch will be
     + * stored there. (It must be freed by the caller.)
       */
      static int get_pack(struct fetch_pack_args *args,
      		    int xd[2], struct string_list *pack_lockfiles,
     -		    int only_packfile,
    -+		    char **index_pack_args,
    ++		    struct strvec *index_pack_args,
      		    struct ref **sought, int nr_sought)
      {
      	struct async demux;
    @@ fetch-pack.c: static int get_pack(struct fetch_pack_args *args,
      	}
      
     +	if (index_pack_args) {
    -+		struct strbuf joined = STRBUF_INIT;
     +		int i;
     +
    -+		for (i = 0; i < cmd.args.nr; i++) {
    -+			if (i)
    -+				strbuf_addch(&joined, ' ');
    -+			strbuf_addstr_urlencode(&joined, cmd.args.v[i],
    -+						is_rfc3986_unreserved);
    -+		}
    -+		*index_pack_args = strbuf_detach(&joined, NULL);
    ++		for (i = 0; i < cmd.args.nr; i++)
    ++			strvec_push(index_pack_args, cmd.args.v[i]);
     +	}
     +
      	cmd.in = demux.out;
    @@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
      	int seen_ack = 0;
      	struct string_list packfile_uris = STRING_LIST_INIT_DUP;
      	int i;
    -+	char *index_pack_args = NULL;
    ++	struct strvec index_pack_args = STRVEC_INIT;
      
      	negotiator = &negotiator_alloc;
      	fetch_negotiator_init(r, negotiator);
    @@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
      				die(_("git fetch-pack: fetch failed."));
      			do_check_stateless_delimiter(args, &reader);
      
    +@@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
    + 	}
    + 
    + 	for (i = 0; i < packfile_uris.nr; i++) {
    ++		int j;
    + 		struct child_process cmd = CHILD_PROCESS_INIT;
    + 		char packname[GIT_MAX_HEXSZ + 1];
    + 		const char *uri = packfile_uris.items[i].string +
     @@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
      		strvec_pushf(&cmd.args, "--packfile=%.*s",
      			     (int) the_hash_algo->hexsz,
      			     packfile_uris.items[i].string);
    --		strvec_push(&cmd.args, "--index-pack-args=index-pack --stdin --keep");
    -+		strvec_pushf(&cmd.args, "--index-pack-args=%s", index_pack_args);
    +-		strvec_push(&cmd.args, "--index-pack-arg=index-pack");
    +-		strvec_push(&cmd.args, "--index-pack-arg=--stdin");
    +-		strvec_push(&cmd.args, "--index-pack-arg=--keep");
    ++		for (j = 0; j < index_pack_args.nr; j++)
    ++			strvec_pushf(&cmd.args, "--index-pack-arg=%s",
    ++				     index_pack_args.v[j]);
      		strvec_push(&cmd.args, uri);
      		cmd.git_cmd = 1;
      		cmd.no_stdin = 1;
    @@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
      						 packname));
      	}
      	string_list_clear(&packfile_uris, 0);
    -+	FREE_AND_NULL(index_pack_args);
    ++	strvec_clear(&index_pack_args);
      
      	if (negotiator)
      		negotiator->release(negotiator);
3:  384c9d1c73 ! 4:  e8b18d02e6 fetch-pack: print and use dangling .gitmodules
    @@ Documentation/git-index-pack.txt: OPTIONS
      	Specifies the number of threads to spawn when resolving
     
      ## builtin/index-pack.c ##
    +@@ builtin/index-pack.c: static void show_pack_info(int stat_only)
    + 	}
    + }
    + 
    ++static int print_dangling_gitmodules(struct fsck_options *o,
    ++				     const struct object_id *oid,
    ++				     enum object_type object_type,
    ++				     int msg_type, const char *message)
    ++{
    ++	/*
    ++	 * NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
    ++	 * instead of relying on this string check.
    ++	 */
    ++	if (starts_with(message, "gitmodulesMissing")) {
    ++		printf("%s\n", oid_to_hex(oid));
    ++		return 0;
    ++	}
    ++	return fsck_error_function(o, oid, object_type, msg_type, message);
    ++}
    ++
    + int cmd_index_pack(int argc, const char **argv, const char *prefix)
    + {
    + 	int i, fix_thin_pack = 0, verify = 0, stat_only = 0;
     @@ builtin/index-pack.c: int cmd_index_pack(int argc, const char **argv, const char *prefix)
      	else
      		close(input_fd);
    @@ builtin/index-pack.c: int cmd_index_pack(int argc, const char **argv, const char
     -	if (do_fsck_object && fsck_finish(&fsck_options))
     -		die(_("fsck error in pack objects"));
     +	if (do_fsck_object) {
    -+		struct fsck_options fo = FSCK_OPTIONS_STRICT;
    ++		struct fsck_options fo = fsck_options;
     +
    -+		fo.print_dangling_gitmodules = 1;
    ++		fo.error_func = print_dangling_gitmodules;
     +		if (fsck_finish(&fo))
     +			die(_("fsck error in pack objects"));
     +	}
    @@ fetch-pack.c: static void write_promisor_file(const char *keep_name,
     +
      /*
       * If packfile URIs were provided, pass a non-NULL pointer to index_pack_args.
    -  * The string to pass as the --index-pack-args argument to http-fetch will be
    +  * The strings to pass as the --index-pack-arg arguments to http-fetch will be
     @@ fetch-pack.c: static void write_promisor_file(const char *keep_name,
      static int get_pack(struct fetch_pack_args *args,
      		    int xd[2], struct string_list *pack_lockfiles,
    - 		    char **index_pack_args,
    + 		    struct strvec *index_pack_args,
     -		    struct ref **sought, int nr_sought)
     +		    struct ref **sought, int nr_sought,
     +		    struct oidset *gitmodules_oids)
    @@ fetch-pack.c: static struct ref *do_fetch_pack(struct fetch_pack_args *args,
     @@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
      	struct string_list packfile_uris = STRING_LIST_INIT_DUP;
      	int i;
    - 	char *index_pack_args = NULL;
    + 	struct strvec index_pack_args = STRVEC_INIT;
     +	struct oidset gitmodules_oids = OIDSET_INIT;
      
      	negotiator = &negotiator_alloc;
    @@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
      		if (finish_command(&cmd))
     @@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
      	string_list_clear(&packfile_uris, 0);
    - 	FREE_AND_NULL(index_pack_args);
    + 	strvec_clear(&index_pack_args);
      
     +	fsck_gitmodules_oids(&gitmodules_oids);
     +
    @@ fsck.c: int fsck_error_function(struct fsck_options *o,
      int fsck_finish(struct fsck_options *options)
      {
      	int ret = 0;
    -@@ fsck.c: int fsck_finish(struct fsck_options *options)
    - 		if (!buf) {
    - 			if (is_promisor_object(oid))
    - 				continue;
    --			ret |= report(options,
    --				      oid, OBJ_BLOB,
    --				      FSCK_MSG_GITMODULES_MISSING,
    --				      "unable to read .gitmodules blob");
    -+			if (options->print_dangling_gitmodules)
    -+				printf("%s\n", oid_to_hex(oid));
    -+			else
    -+				ret |= report(options,
    -+					      oid, OBJ_BLOB,
    -+					      FSCK_MSG_GITMODULES_MISSING,
    -+					      "unable to read .gitmodules blob");
    - 			continue;
    - 		}
    - 
     
      ## fsck.h ##
    -@@ fsck.h: struct fsck_options {
    - 	int *msg_type;
    - 	struct oidset skiplist;
    - 	kh_oid_map_t *object_names;
    -+
    -+	/*
    -+	 * If 1, print the hashes of missing .gitmodules blobs instead of
    -+	 * considering them to be errors.
    -+	 */
    -+	unsigned print_dangling_gitmodules:1;
    - };
    - 
    - #define FSCK_OPTIONS_DEFAULT { NULL, fsck_error_function, 0, NULL, OIDSET_INIT }
     @@ fsck.h: int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
      int fsck_object(struct object *obj, void *data, unsigned long size,
      	struct fsck_options *options);
    @@ pack.h: int verify_pack_index(struct packed_git *);
       * The "hdr" output buffer should be at least this big, which will handle sizes
     
      ## t/t5702-protocol-v2.sh ##
    +@@ t/t5702-protocol-v2.sh: test_expect_success 'part of packfile response provided as URI' '
    + 	test -f hfound &&
    + 	test -f h2found &&
    + 
    +-	# Ensure that there are exactly 6 files (3 .pack and 3 .idx).
    +-	ls http_child/.git/objects/pack/* >filelist &&
    ++	# Ensure that there are exactly 3 packfiles with associated .idx
    ++	ls http_child/.git/objects/pack/*.pack \
    ++	    http_child/.git/objects/pack/*.idx >filelist &&
    + 	test_line_count = 6 filelist
    + '
    + 
    +@@ t/t5702-protocol-v2.sh: test_expect_success 'packfile-uri with transfer.fsckobjects' '
    + 		-c fetch.uriprotocols=http,https \
    + 		clone "$HTTPD_URL/smart/http_parent" http_child &&
    + 
    +-	# Ensure that there are exactly 4 files (2 .pack and 2 .idx).
    +-	ls http_child/.git/objects/pack/* >filelist &&
    ++	# Ensure that there are exactly 2 packfiles with associated .idx
    ++	ls http_child/.git/objects/pack/*.pack \
    ++	    http_child/.git/objects/pack/*.idx >filelist &&
    + 	test_line_count = 4 filelist
    + '
    + 
     @@ t/t5702-protocol-v2.sh: test_expect_success 'packfile-uri with transfer.fsckobjects fails on bad object'
      	test_i18ngrep "invalid author/committer line - missing email" error
      '
    @@ t/t5702-protocol-v2.sh: test_expect_success 'packfile-uri with transfer.fsckobje
     +		-c fetch.uriprotocols=http,https \
     +		clone "$HTTPD_URL/smart/http_parent" http_child &&
     +
    -+	# Ensure that there are exactly 4 files (2 .pack and 2 .idx).
    -+	ls http_child/.git/objects/pack/* >filelist &&
    ++	# Ensure that there are exactly 2 packfiles with associated .idx
    ++	ls http_child/.git/objects/pack/*.pack \
    ++	    http_child/.git/objects/pack/*.idx >filelist &&
     +	test_line_count = 4 filelist
     +'
     +

4: da0d7b38ae < -: ---------- SQUASH??? test fix

Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
#201 lore raw

PATCH v2 1/4 http: allow custom index-pack args

Currently, when fetching, packfiles referenced by URIs are run through index-pack without any arguments other than --stdin and --keep, no matter what arguments are used for the packfile that is inline in the fetch response. As a preparation for ensuring that all packs (whether inline or not) use the same index-pack arguments, teach the http subsystem to allow custom index-pack arguments.

http-fetch has been updated to use the new API. For now, it passes --keep alone instead of --keep with a process ID, but this is only temporary because http-fetch itself will be taught to accept index-pack parameters (instead of using a hardcoded constant) in a subsequent commit.

---
 http-fetch.c |  6 +++++-
 http.c       | 15 ++++++++-------
 http.h       | 10 +++++-----
 3 files changed, 18 insertions(+), 13 deletions(-)
http-fetch.c +5 -1
index c4ccc5fea9..2d1d9d054f 100644
@@ -43,6 +43,9 @@ static int fetch_using_walker(const char *raw_url, int get_verbosely,
 	return rc;
 }
 
+static const char *index_pack_args[] =
+	{"index-pack", "--stdin", "--keep", NULL};
+
 static void fetch_single_packfile(struct object_id *packfile_hash,
 				  const char *url) {
 	struct http_pack_request *preq;
@@ -55,7 +58,8 @@ static void fetch_single_packfile(struct object_id *packfile_hash,
 	if (preq == NULL)
 		die("couldn't create http pack request");
 	preq->slot->results = &results;
-	preq->generate_keep = 1;
+	preq->index_pack_args = index_pack_args;
+	preq->preserve_index_pack_stdout = 1;
 
 	if (start_active_slot(preq->slot)) {
 		run_active_slot(preq->slot);
http.c +8 -7
index 8b23a546af..f8ea28bb2e 100644
@@ -2259,6 +2259,9 @@ void release_http_pack_request(struct http_pack_request *preq)
 	free(preq);
 }
 
+static const char *default_index_pack_args[] =
+	{"index-pack", "--stdin", NULL};
+
 int finish_http_pack_request(struct http_pack_request *preq)
 {
 	struct child_process ip = CHILD_PROCESS_INIT;
@@ -2270,17 +2273,15 @@ int finish_http_pack_request(struct http_pack_request *preq)
 
 	tmpfile_fd = xopen(preq->tmpfile.buf, O_RDONLY);
 
-	strvec_push(&ip.args, "index-pack");
-	strvec_push(&ip.args, "--stdin");
 	ip.git_cmd = 1;
 	ip.in = tmpfile_fd;
-	if (preq->generate_keep) {
-		strvec_pushf(&ip.args, "--keep=git %"PRIuMAX,
-			     (uintmax_t)getpid());
+	ip.argv = preq->index_pack_args ? preq->index_pack_args
+					: default_index_pack_args;
+
+	if (preq->preserve_index_pack_stdout)
 		ip.out = 0;
-	} else {
+	else
 		ip.no_stdout = 1;
-	}
 
 	if (run_command(&ip)) {
 		ret = -1;
http.h +5 -5
index 5de792ef3f..bf3d1270ad 100644
@@ -218,12 +218,12 @@ struct http_pack_request {
 	char *url;
 
 	/*
-	 * If this is true, finish_http_pack_request() will pass "--keep" to
-	 * index-pack, resulting in the creation of a keep file, and will not
-	 * suppress its stdout (that is, the "keep\t<hash>\n" line will be
-	 * printed to stdout).
+	 * index-pack command to run. Must be terminated by NULL.
+	 *
+	 * If NULL, defaults to	{"index-pack", "--stdin", NULL}.
 	 */
-	unsigned generate_keep : 1;
+	const char **index_pack_args;
+	unsigned preserve_index_pack_stdout : 1;
 
 	FILE *packfile;
 	struct strbuf tmpfile;
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
#202 lore raw

PATCH v2 2/4 http-fetch: allow custom index-pack args

In reply to Jonathan Tan

This is the next step in teaching fetch-pack to pass its index-pack arguments when processing packfiles referenced by URIs.

The "--keep" in fetch-pack.c will be replaced with a full message in a subsequent commit.

---
 Documentation/git-http-fetch.txt | 10 ++++++++--
 fetch-pack.c                     |  3 +++
 http-fetch.c                     | 20 +++++++++++++++-----
 t/t5550-http-fetch-dumb.sh       |  5 ++++-
 4 files changed, 30 insertions(+), 8 deletions(-)
Documentation/git-http-fetch.txt +8 -2
index 4deb4893f5..9fa17b60e4 100644
@@ -41,11 +41,17 @@ commit-id::
 		<commit-id>['\t'<filename-as-in--w>]
 
 --packfile=<hash>::
-	Instead of a commit id on the command line (which is not expected in
+	For internal use only. Instead of a commit id on the command
+	line (which is not expected in
 	this case), 'git http-fetch' fetches the packfile directly at the given
 	URL and uses index-pack to generate corresponding .idx and .keep files.
 	The hash is used to determine the name of the temporary file and is
-	arbitrary. The output of index-pack is printed to stdout.
+	arbitrary. The output of index-pack is printed to stdout. Requires
+	--index-pack-args.
+
+--index-pack-args=<args>::
+	For internal use only. The command to run on the contents of the
+	downloaded pack. Arguments are URL-encoded separated by spaces.
 
 --recover::
 	Verify that everything reachable from target is fetched.  Used after
fetch-pack.c +3 -0
index 876f90c759..aeac010b0b 100644
@@ -1645,6 +1645,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 		strvec_pushf(&cmd.args, "--packfile=%.*s",
 			     (int) the_hash_algo->hexsz,
 			     packfile_uris.items[i].string);
+		strvec_push(&cmd.args, "--index-pack-arg=index-pack");
+		strvec_push(&cmd.args, "--index-pack-arg=--stdin");
+		strvec_push(&cmd.args, "--index-pack-arg=--keep");
 		strvec_push(&cmd.args, uri);
 		cmd.git_cmd = 1;
 		cmd.no_stdin = 1;
http-fetch.c +15 -5
index 2d1d9d054f..fa642462a9 100644
@@ -3,6 +3,7 @@
 #include "exec-cmd.h"
 #include "http.h"
 #include "walker.h"
+#include "strvec.h"
 
 static const char http_fetch_usage[] = "git http-fetch "
 "[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin | --packfile=hash | commit-id] url";
@@ -43,11 +44,9 @@ static int fetch_using_walker(const char *raw_url, int get_verbosely,
 	return rc;
 }
 
-static const char *index_pack_args[] =
-	{"index-pack", "--stdin", "--keep", NULL};
-
 static void fetch_single_packfile(struct object_id *packfile_hash,
-				  const char *url) {
+				  const char *url,
+				  const char **index_pack_args) {
 	struct http_pack_request *preq;
 	struct slot_results results;
 	int ret;
@@ -90,6 +89,7 @@ int cmd_main(int argc, const char **argv)
 	int packfile = 0;
 	int nongit;
 	struct object_id packfile_hash;
+	struct strvec index_pack_args = STRVEC_INIT;
 
 	setup_git_directory_gently(&nongit);
 
@@ -116,6 +116,8 @@ int cmd_main(int argc, const char **argv)
 			packfile = 1;
 			if (parse_oid_hex(p, &packfile_hash, &end) || *end)
 				die(_("argument to --packfile must be a valid hash (got '%s')"), p);
+		} else if (skip_prefix(argv[arg], "--index-pack-arg=", &p)) {
+			strvec_push(&index_pack_args, p);
 		}
 		arg++;
 	}
@@ -128,10 +130,18 @@ int cmd_main(int argc, const char **argv)
 	git_config(git_default_config, NULL);
 
 	if (packfile) {
-		fetch_single_packfile(&packfile_hash, argv[arg]);
+		if (!index_pack_args.nr)
+			die(_("--packfile requires --index-pack-args"));
+
+		fetch_single_packfile(&packfile_hash, argv[arg],
+				      index_pack_args.v);
+
 		return 0;
 	}
 
+	if (index_pack_args.nr)
+		die(_("--index-pack-args can only be used with --packfile"));
+
 	if (commits_on_stdin) {
 		commits = walker_targets_stdin(&commit_id, &write_ref);
 	} else {
t/t5550-http-fetch-dumb.sh +4 -1
index 483578b2d7..358b322e05 100755
@@ -224,7 +224,10 @@ test_expect_success 'http-fetch --packfile' '
 
 	git init packfileclient &&
 	p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && ls objects/pack/pack-*.pack) &&
-	git -C packfileclient http-fetch --packfile=$ARBITRARY "$HTTPD_URL"/dumb/repo_pack.git/$p >out &&
+	git -C packfileclient http-fetch --packfile=$ARBITRARY \
+		--index-pack-arg=index-pack --index-pack-arg=--stdin \
+		--index-pack-arg=--keep \
+		"$HTTPD_URL"/dumb/repo_pack.git/$p >out &&
 
 	grep "^keep.[0-9a-f]\{16,\}$" out &&
 	cut -c6- out >packhash &&
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
#203 lore raw

Re: [PATCH v2 2/4] http-fetch: allow custom index-pack args

Quoted 29 lines · Jonathan Tan
Documentation/git-http-fetch.txt +8 -2
index 4deb4893f5..9fa17b60e4 100644
@@ -41,11 +41,17 @@ commit-id::
 		<commit-id>['\t'<filename-as-in--w>]
 
 --packfile=<hash>::
-	Instead of a commit id on the command line (which is not expected in
+	For internal use only. Instead of a commit id on the command
+	line (which is not expected in
 	this case), 'git http-fetch' fetches the packfile directly at the given
 	URL and uses index-pack to generate corresponding .idx and .keep files.
 	The hash is used to determine the name of the temporary file and is
-	arbitrary. The output of index-pack is printed to stdout.
+	arbitrary. The output of index-pack is printed to stdout. Requires
+	--index-pack-args.
+
+--index-pack-args=<args>::
+	For internal use only. The command to run on the contents of the
+	downloaded pack. Arguments are URL-encoded separated by spaces.
 
 --recover::
 	Verify that everything reachable from target is fetched.  Used after
fetch-pack.c +0 -0
index 876f90c759..aeac010b0b 100644

fetch-pack.c static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, · line 1650

Quoted 6 lines
fetch-pack.c +3 -0
@@ -1645,6 +1645,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 		strvec_pushf(&cmd.args, "--packfile=%.*s",
 			     (int) the_hash_algo->hexsz,
 			     packfile_uris.items[i].string);
+		strvec_push(&cmd.args, "--index-pack-arg=index-pack");
+		strvec_push(&cmd.args, "--index-pack-arg=--stdin");
+		strvec_push(&cmd.args, "--index-pack-arg=--keep");

The docs say --*-args, but the code checks --*arg, that seems like a mistake that should be fixed to make the code/tests use the plural form, no?

#204 lore raw

Re: [PATCH v2 2/4] http-fetch: allow custom index-pack args

Quoted 31 lines
Quoted 31 lines
Documentation/git-http-fetch.txt +8 -2
index 4deb4893f5..9fa17b60e4 100644
@@ -41,11 +41,17 @@ commit-id::
 		<commit-id>['\t'<filename-as-in--w>]
 
 --packfile=<hash>::
-	Instead of a commit id on the command line (which is not expected in
+	For internal use only. Instead of a commit id on the command
+	line (which is not expected in
 	this case), 'git http-fetch' fetches the packfile directly at the given
 	URL and uses index-pack to generate corresponding .idx and .keep files.
 	The hash is used to determine the name of the temporary file and is
-	arbitrary. The output of index-pack is printed to stdout.
+	arbitrary. The output of index-pack is printed to stdout. Requires
+	--index-pack-args.
+
+--index-pack-args=<args>::
+	For internal use only. The command to run on the contents of the
+	downloaded pack. Arguments are URL-encoded separated by spaces.
 
 --recover::
 	Verify that everything reachable from target is fetched.  Used after
fetch-pack.c +0 -0
index 876f90c759..aeac010b0b 100644
@@ -1645,6 +1645,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 		strvec_pushf(&cmd.args, "--packfile=%.*s",
 			     (int) the_hash_algo->hexsz,
Quoted 8 lines

fetch-pack.c static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, · line 1650

Quoted 4 lines
fetch-pack.c +3 -0
 			     packfile_uris.items[i].string);
+		strvec_push(&cmd.args, "--index-pack-arg=index-pack");
+		strvec_push(&cmd.args, "--index-pack-arg=--stdin");
+		strvec_push(&cmd.args, "--index-pack-arg=--keep");

The docs say --*-args, but the code checks --*arg, that seems like a mistake that should be fixed to make the code/tests use the plural form, no?

Thanks for catching that. Originally it was plural since this single argument would give multiple arguments to index-pack, but now each argument gives only a single argument, so "arg" is correct. I'll update it in the next version.

#205 lore raw

Re: [PATCH v2 2/4] http-fetch: allow custom index-pack args

In reply to Jonathan Tan

Hi Jonathan,

Quoted 6 lines · Jonathan Tan

This is the next step in teaching fetch-pack to pass its index-pack arguments when processing packfiles referenced by URIs.

The "--keep" in fetch-pack.c will be replaced with a full message in a subsequent commit.

Quoted 8 lines
---
 Documentation/git-http-fetch.txt | 10 ++++++++--
 fetch-pack.c                     |  3 +++
 http-fetch.c                     | 20 +++++++++++++++-----
 t/t5550-http-fetch-dumb.sh       |  5 ++++-
 4 files changed, 30 insertions(+), 8 deletions(-)

This is producing an interesting symptom for me:

git init repro
cd repro
git config fetch.uriprotocols https
git config remote.origin.url https://fuchsia.googlesource.com/fuchsia
git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/* git fetch -p origin

Expected result: fetches

Actual result:

fatal: pack has bad object at offset 12: unknown object type 5
fatal: finish_http_pack_request gave result -1
fatal: fetch-pack: expected keep then TAB at start of http-fetch output

Thanks to Nathan Mulcahey (cc-ed) for a clear report.

Bisects to b664e9ffa153189dae9b88f32d1c5fedcf85056a, which is part of "next" and 2.31.0-rc1. Another report of the same is at
https://crbug.com/1184814.

Known problem?

Thanks,
Jonathan

#206 lore raw

PATCH 1/1 fetch-pack: do not mix --pack_header and packfile uri

When fetching (as opposed to cloning) from a repository with packfile URIs enabled, an error like this may occur:

fatal: pack has bad object at offset 12: unknown object type 5
fatal: finish_http_pack_request gave result -1
fatal: fetch-pack: expected keep then TAB at start of http-fetch output

This bug was introduced in b664e9ffa1 ("fetch-pack: with packfile URIs, use index-pack arg", 2021-02-22), when the index-pack args used when processing the inline packfile of a fetch response and when processing packfile URIs were unified.

This bug happens because fetch, by default, partially reads (and consumes) the header of the inline packfile to determine if it should store the downloaded objects as a packfile or loose objects, and thus passes --pack_header=<...> to index-pack to inform it that some bytes are missing. However, when it subsequently fetches the additional packfiles linked by URIs, it reuses the same index-pack arguments, thus wrongly passing --index-pack-arg=--pack_header=<...> when no bytes are missing.

This does not happen when cloning because "git clone" always passes do_keep, which instructs the fetch mechanism to always retain the packfile, eliminating the need to read the header.

There are a few ways to fix this, including filtering out pack_header arguments when downloading the additional packfiles, but I decided to stick to always using index-pack throughout when packfile URIs are present - thus, Git no longer needs to read the bytes, and no longer needs --pack_header here.

---
Here's a fix for this issue.

This is on jt/transfer-fsck-across-packs.

One simplification that we could do is to eliminate the unpack-objects codepath. As far as I understand, the main advantage of writing loose objects is that we have automatic SHA-1 collision detection, but we have such mitigations when writing packs too, so that might not be as large a benefit as we think. This simplification would have enabled us to avoid this bug, I think.

---
 fetch-pack.c           |  4 ++--
 t/t5702-protocol-v2.sh | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
fetch-pack.c +2 -2
index f9def5ac74..e990607742 100644
@@ -852,7 +852,7 @@ static int get_pack(struct fetch_pack_args *args,
 	else
 		demux.out = xd[0];
 
-	if (!args->keep_pack && unpack_limit) {
+	if (!args->keep_pack && unpack_limit && !index_pack_args) {
 
 		if (read_pack_header(demux.out, &header))
 			die(_("protocol error: bad pack header"));
@@ -885,7 +885,7 @@ static int get_pack(struct fetch_pack_args *args,
 			strvec_push(&cmd.args, "-v");
 		if (args->use_thin_pack)
 			strvec_push(&cmd.args, "--fix-thin");
-		if (do_keep && (args->lock_pack || unpack_limit)) {
+		if ((do_keep || index_pack_args) && (args->lock_pack || unpack_limit)) {
 			char hostname[HOST_NAME_MAX + 1];
 			if (xgethostname(hostname, sizeof(hostname)))
 				xsnprintf(hostname, sizeof(hostname), "localhost");
t/t5702-protocol-v2.sh +21 -0
index b1bc73a9a9..9df1ec82ca 100755
@@ -853,6 +853,27 @@ test_expect_success 'part of packfile response provided as URI' '
 	test_line_count = 6 filelist
 '
 
+test_expect_success 'packfile URIs with fetch instead of clone' '
+	P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
+	rm -rf "$P" http_child log &&
+
+	git init "$P" &&
+	git -C "$P" config "uploadpack.allowsidebandall" "true" &&
+
+	echo my-blob >"$P/my-blob" &&
+	git -C "$P" add my-blob &&
+	git -C "$P" commit -m x &&
+
+	configure_exclusion "$P" my-blob >h &&
+
+	git init http_child &&
+
+	GIT_TEST_SIDEBAND_ALL=1 \
+	git -C http_child -c protocol.version=2 \
+		-c fetch.uriprotocols=http,https \
+		fetch "$HTTPD_URL/smart/http_parent"
+'
+
 test_expect_success 'fetching with valid packfile URI but invalid hash fails' '
 	P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
 	rm -rf "$P" http_child log &&
Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog
#207 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

Quoted 6 lines · Jonathan Tan

One simplification that we could do is to eliminate the unpack-objects codepath. As far as I understand, the main advantage of writing loose objects is that we have automatic SHA-1 collision detection, but we have such mitigations when writing packs too, so that might not be as large a benefit as we think. This simplification would have enabled us to avoid this bug, I think.

My understanding is that the primary advantage of loose objects codepath is to help us avoid having too many little packs (instead, we can accumulate enough objects in the loose form and let GC pack them, at least the ones among them that are still reachable, into a single pack). Historically, the only mode of operation "repack" offers that reduces the number of remaining packs has been "do full reachability of the entire history, and pack everything into one", so avoiding creation of little packs and leaving things loose until we accumulate enough used to matter.

With the geometric rolling repacking, it may not matter as much, and keeping everything packed, even in a small pack, might start to be overall win. So I am not opposed to such a simplification; we may not be ready for it right now, but I think it would be a sensible future direction.

#208 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

In reply to Jonathan Tan
Quoted 12 lines · Jonathan Tan

When fetching (as opposed to cloning) from a repository with packfile URIs enabled, an error like this may occur:

fatal: pack has bad object at offset 12: unknown object type 5
fatal: finish_http_pack_request gave result -1
fatal: fetch-pack: expected keep then TAB at start of http-fetch output

This bug was introduced in b664e9ffa1 ("fetch-pack: with packfile URIs, use index-pack arg", 2021-02-22), when the index-pack args used when processing the inline packfile of a fetch response and when processing packfile URIs were unified.

Quoted 5 lines

This bug happens because fetch, by default, partially reads (and consumes) the header of the inline packfile to determine if it should store the downloaded objects as a packfile or loose objects, and thus passes --pack_header=<...> to index-pack to inform it that some bytes are missing.

... and what the values in them are.

Quoted 11 lines

However, when it subsequently fetches the additional packfiles linked by URIs, it reuses the same index-pack arguments, thus wrongly passing --index-pack-arg=--pack_header=<...> when no bytes are missing.

This does not happen when cloning because "git clone" always passes do_keep, which instructs the fetch mechanism to always retain the packfile, eliminating the need to read the header.

There are a few ways to fix this, including filtering out pack_header arguments when downloading the additional packfiles, but ...

Avoiding the condition that exhibits the breakage is possible, and I think it is what is done here, but I actually think that the only right fix is to pass correct argument to commands we invoke in the first place. Why are we reusing the same argument array to begin with?

... goes back and reads the offending commit ...

commit b664e9ffa153189dae9b88f32d1c5fedcf85056a

Author: Jonathan Tan <[email protected]>
Date:   Mon Feb 22 11:20:08 2021 -0800

fetch-pack: with packfile URIs, use index-pack arg

Unify the index-pack arguments used when processing the inline pack and when downloading packfiles referenced by URIs. This is done by teaching get_pack() to also store the index-pack arguments whenever at least one packfile URI is given, and then when processing the packfile URI(s), using the stored arguments.

THis makes it sound like the entire idea of this offending commit was wrong, and before it, the codepath that processed the packfile fetched from the packfile URI were using the index-pack correctly by using index-pack arguments that are independent from the one that is used to process the packfile given in-stream. Why isn't the fix just a straight revert of the commit???

Quoted 1 line

This is on jt/transfer-fsck-across-packs.

Ouch. This definitely is an -rc material.

fetch-pack.c static int get_pack(struct fetch_pack_args *args, · line 855

Quoted 2 lines
fetch-pack.c +1 -1
-	if (!args->keep_pack && unpack_limit) {
+	if (!args->keep_pack && unpack_limit && !index_pack_args) {

This one makes sense as an "avoid conditions that reveals how badly the code is broken" band-aid. When we have index-pack related arguments, we cannot use the unpack-objects codepath even if we are being fed a tiny pack, so there is no point peeking at the beginning of the pack stream to find out how many objects it has. OK.

fetch-pack.c static int get_pack(struct fetch_pack_args *args, · line 891

Quoted 9 lines
fetch-pack.c +1 -1
@@ -885,7 +885,7 @@ static int get_pack(struct fetch_pack_args *args,
 			strvec_push(&cmd.args, "-v");
 		if (args->use_thin_pack)
 			strvec_push(&cmd.args, "--fix-thin");
-		if (do_keep && (args->lock_pack || unpack_limit)) {
+		if ((do_keep || index_pack_args) && (args->lock_pack || unpack_limit)) {
 			char hostname[HOST_NAME_MAX + 1];
 			if (xgethostname(hostname, sizeof(hostname)))
 				xsnprintf(hostname, sizeof(hostname), "localhost");

I do not quite get what this hunk is doing. Care to explain?

Thanks.

Quoted 32 lines
t/t5702-protocol-v2.sh +21 -0
index b1bc73a9a9..9df1ec82ca 100755
@@ -853,6 +853,27 @@ test_expect_success 'part of packfile response provided as URI' '
 	test_line_count = 6 filelist
 '
 
+test_expect_success 'packfile URIs with fetch instead of clone' '
+	P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
+	rm -rf "$P" http_child log &&
+
+	git init "$P" &&
+	git -C "$P" config "uploadpack.allowsidebandall" "true" &&
+
+	echo my-blob >"$P/my-blob" &&
+	git -C "$P" add my-blob &&
+	git -C "$P" commit -m x &&
+
+	configure_exclusion "$P" my-blob >h &&
+
+	git init http_child &&
+
+	GIT_TEST_SIDEBAND_ALL=1 \
+	git -C http_child -c protocol.version=2 \
+		-c fetch.uriprotocols=http,https \
+		fetch "$HTTPD_URL/smart/http_parent"
+'
+
 test_expect_success 'fetching with valid packfile URI but invalid hash fails' '
 	P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" &&
 	rm -rf "$P" http_child log &&
#209 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

Quoted 20 lines · Junio C Hamano

Avoiding the condition that exhibits the breakage is possible, and I think it is what is done here, but I actually think that the only right fix is to pass correct argument to commands we invoke in the first place. Why are we reusing the same argument array to begin with?

... goes back and reads the offending commit ...

commit b664e9ffa153189dae9b88f32d1c5fedcf85056a

Author: Jonathan Tan <[email protected]>
Date:   Mon Feb 22 11:20:08 2021 -0800

fetch-pack: with packfile URIs, use index-pack arg

Unify the index-pack arguments used when processing the inline pack and when downloading packfiles referenced by URIs. This is done by teaching get_pack() to also store the index-pack arguments whenever at least one packfile URI is given, and then when processing the packfile URI(s), using the stored arguments.

Quoted 6 lines

THis makes it sound like the entire idea of this offending commit was wrong, and before it, the codepath that processed the packfile fetched from the packfile URI were using the index-pack correctly by using index-pack arguments that are independent from the one that is used to process the packfile given in-stream. Why isn't the fix just a straight revert of the commit???

By the way, the band-aid in this patch may be OK for the upcoming release (purely because it is easy to see that is sufficient for today's codebase), but I said the above because I worry about the health of the codebase in the longer term. The "pass_header" may not stay to be the only difference between the URI packfile and in-stream packfile in the way they make index-pack invocations.

Quoted 3 lines
Quoted 1 line

This is on jt/transfer-fsck-across-packs.

Ouch. This definitely is an -rc material.

Thanks.

#210 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

Quoted 6 lines

By the way, the band-aid in this patch may be OK for the upcoming release (purely because it is easy to see that is sufficient for today's codebase), but I said the above because I worry about the health of the codebase in the longer term. The "pass_header" may not stay to be the only difference between the URI packfile and in-stream packfile in the way they make index-pack invocations.

That is true, but at the same time, I think it's better to have the arguments be the same because there are options (e.g. --promisor and --fsck-objects) that have to be duplicated, and I think that for the most part, the URI packfiles and the inline packfile will be processed identically.

#211 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

In reply to Junio C Hamano
Quoted 7 lines · Junio C Hamano
Quoted 6 lines

THis makes it sound like the entire idea of this offending commit was wrong, and before it, the codepath that processed the packfile fetched from the packfile URI were using the index-pack correctly by using index-pack arguments that are independent from the one that is used to process the packfile given in-stream. Why isn't the fix just a straight revert of the commit???

Quoted 6 lines

By the way, the band-aid in this patch may be OK for the upcoming release (purely because it is easy to see that is sufficient for today's codebase), but I said the above because I worry about the health of the codebase in the longer term. The "pass_header" may not stay to be the only difference between the URI packfile and in-stream packfile in the way they make index-pack invocations.

For example, the URI one presumably is a CDN hosted long term one, which may be a good candidate to --keep, and in-stream one, especially when packfile URI feature is used, can be expected to be recent small leftover bits that it is likely that we do not want to keep (in fact, if they are small enough, we'd prefer to keep them loose).

#212 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

In reply to Junio C Hamano
Quoted 14 lines
Quoted 11 lines · Jonathan Tan

When fetching (as opposed to cloning) from a repository with packfile URIs enabled, an error like this may occur:

fatal: pack has bad object at offset 12: unknown object type 5
fatal: finish_http_pack_request gave result -1
fatal: fetch-pack: expected keep then TAB at start of http-fetch output

This bug was introduced in b664e9ffa1 ("fetch-pack: with packfile URIs, use index-pack arg", 2021-02-22), when the index-pack args used when processing the inline packfile of a fetch response and when processing packfile URIs were unified.

Quoted 7 lines
Quoted 5 lines

This bug happens because fetch, by default, partially reads (and consumes) the header of the inline packfile to determine if it should store the downloaded objects as a packfile or loose objects, and thus passes --pack_header=<...> to index-pack to inform it that some bytes are missing.

... and what the values in them are.

Ah, that's true.

Quoted 32 lines
Quoted 11 lines

However, when it subsequently fetches the additional packfiles linked by URIs, it reuses the same index-pack arguments, thus wrongly passing --index-pack-arg=--pack_header=<...> when no bytes are missing.

This does not happen when cloning because "git clone" always passes do_keep, which instructs the fetch mechanism to always retain the packfile, eliminating the need to read the header.

There are a few ways to fix this, including filtering out pack_header arguments when downloading the additional packfiles, but ...

Avoiding the condition that exhibits the breakage is possible, and I think it is what is done here, but I actually think that the only right fix is to pass correct argument to commands we invoke in the first place. Why are we reusing the same argument array to begin with?

... goes back and reads the offending commit ...

commit b664e9ffa153189dae9b88f32d1c5fedcf85056a

Author: Jonathan Tan <[email protected]>
Date:   Mon Feb 22 11:20:08 2021 -0800

fetch-pack: with packfile URIs, use index-pack arg

Unify the index-pack arguments used when processing the inline pack and when downloading packfiles referenced by URIs. This is done by teaching get_pack() to also store the index-pack arguments whenever at least one packfile URI is given, and then when processing the packfile URI(s), using the stored arguments.

Quoted 6 lines

THis makes it sound like the entire idea of this offending commit was wrong, and before it, the codepath that processed the packfile fetched from the packfile URI were using the index-pack correctly by using index-pack arguments that are independent from the one that is used to process the packfile given in-stream. Why isn't the fix just a straight revert of the commit???

I should probably have written more in the commit message to justify the unification, but it is also part of a bug fix (in particular, --fsck-objects wasn't being passed to the index-pack that indexed the packfiles linked by URI) and for code health purposes (to prevent future bugs by eliminating the divergence). So reverting that commit would reintroduce another bug.

Quoted 11 lines

fetch-pack.c static int get_pack(struct fetch_pack_args *args, · line 891

Quoted 9 lines
fetch-pack.c +1 -1
@@ -885,7 +885,7 @@ static int get_pack(struct fetch_pack_args *args,
 			strvec_push(&cmd.args, "-v");
 		if (args->use_thin_pack)
 			strvec_push(&cmd.args, "--fix-thin");
-		if (do_keep && (args->lock_pack || unpack_limit)) {
+		if ((do_keep || index_pack_args) && (args->lock_pack || unpack_limit)) {
 			char hostname[HOST_NAME_MAX + 1];
 			if (xgethostname(hostname, sizeof(hostname)))
 				xsnprintf(hostname, sizeof(hostname), "localhost");

I do not quite get what this hunk is doing. Care to explain?

The "do_keep" part was unnecessarily restrictive and I used a band-aid solution to loosen it. I think this started from 88e2f9ed8e ("introduce
fetch-object: fetch one promisor object", 2017-12-05) where I might have misunderstood what do_keep was meant to do, and taught fetch-pack to use "index-pack" if do_keep is true or args->from_promisor is true. What I should have done is to set do_keep to true if args->from_promisor is true. Future commits continued to do that with fsck_objects and index_pack_args.

Maybe what I can do is to refactor get_pack() so that do_keep retains its original meaning of whether to use "index-pack" or "unpack-objects", and then we wouldn't need this line. What do you think (code-wise and whether this fits in with the release schedule, if we want to get this in before release)?

#213 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

Quoted 6 lines · Jonathan Tan

I should probably have written more in the commit message to justify the unification, but it is also part of a bug fix (in particular, --fsck-objects wasn't being passed to the index-pack that indexed the packfiles linked by URI) and for code health purposes (to prevent future bugs by eliminating the divergence). So reverting that commit would reintroduce another bug.

Not necessarily. Unifying two that do not inherently have to be identical makes it impossible to pass two different things, and that is what we are seeing in the bug this patch is trying to fix (by forcing the two to be identical by eliminating the unpack-objects codepath in certain cases).

The right "fix" for the original bug would have been to keep them still separate yet making it easy to pass args that must be used in both of them, no?

Quoted 17 lines
Quoted 7 lines

fetch-pack.c static int get_pack(struct fetch_pack_args *args, · line 891

Quoted 5 lines
fetch-pack.c +1 -1
-		if (do_keep && (args->lock_pack || unpack_limit)) {
+		if ((do_keep || index_pack_args) && (args->lock_pack || unpack_limit)) {
 			char hostname[HOST_NAME_MAX + 1];
 			if (xgethostname(hostname, sizeof(hostname)))
 				xsnprintf(hostname, sizeof(hostname), "localhost");

I do not quite get what this hunk is doing. Care to explain?

The "do_keep" part was unnecessarily restrictive and I used a band-aid solution to loosen it. I think this started from 88e2f9ed8e ("introduce
fetch-object: fetch one promisor object", 2017-12-05) where I might have misunderstood what do_keep was meant to do, and taught fetch-pack to use "index-pack" if do_keep is true or args->from_promisor is true. What I should have done is to set do_keep to true if args->from_promisor is true. Future commits continued to do that with fsck_objects and index_pack_args.

Quoted 5 lines

Maybe what I can do is to refactor get_pack() so that do_keep retains its original meaning of whether to use "index-pack" or "unpack-objects", and then we wouldn't need this line. What do you think (code-wise and whether this fits in with the release schedule, if we want to get this in before release)?

How bad is the breakage this one is trying to fix? I know it would only affect folks who have to interact with the server that uses packfile URI feature, but do they have a workaround, perhaps with a configuration knob or command line option to ignore the packfile URI, and how large is the affected population?

I cannot shake the feeling that we are seeing band-aid on top of band-aid forced by having chosen to go in a wrong direction in the beginning X-<, and prefer to see the code drift even further into the same direction; hence my earlier suggestion to go back to the root cause by first reverting the wrong fix that introduced this bug and fixing the original bug in a different way.

I dunno how involved the necessary surgery would be, though. If this is easy to work around, perhaps it might be a better option for the overall project to ship the upcoming release with this listed as a known breakage.

Thanks.

#214 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

Quoted 15 lines
Quoted 6 lines · Jonathan Tan

I should probably have written more in the commit message to justify the unification, but it is also part of a bug fix (in particular, --fsck-objects wasn't being passed to the index-pack that indexed the packfiles linked by URI) and for code health purposes (to prevent future bugs by eliminating the divergence). So reverting that commit would reintroduce another bug.

Not necessarily. Unifying two that do not inherently have to be identical makes it impossible to pass two different things, and that is what we are seeing in the bug this patch is trying to fix (by forcing the two to be identical by eliminating the unpack-objects codepath in certain cases).

Quoted 3 lines

The right "fix" for the original bug would have been to keep them still separate yet making it easy to pass args that must be used in both of them, no?

OK - I'll do this.

Quoted 23 lines
Quoted 17 lines
Quoted 7 lines

fetch-pack.c static int get_pack(struct fetch_pack_args *args, · line 891

Quoted 5 lines
fetch-pack.c +1 -1
-		if (do_keep && (args->lock_pack || unpack_limit)) {
+		if ((do_keep || index_pack_args) && (args->lock_pack || unpack_limit)) {
 			char hostname[HOST_NAME_MAX + 1];
 			if (xgethostname(hostname, sizeof(hostname)))
 				xsnprintf(hostname, sizeof(hostname), "localhost");

I do not quite get what this hunk is doing. Care to explain?

The "do_keep" part was unnecessarily restrictive and I used a band-aid solution to loosen it. I think this started from 88e2f9ed8e ("introduce
fetch-object: fetch one promisor object", 2017-12-05) where I might have misunderstood what do_keep was meant to do, and taught fetch-pack to use "index-pack" if do_keep is true or args->from_promisor is true. What I should have done is to set do_keep to true if args->from_promisor is true. Future commits continued to do that with fsck_objects and index_pack_args.

Quoted 5 lines

Maybe what I can do is to refactor get_pack() so that do_keep retains its original meaning of whether to use "index-pack" or "unpack-objects", and then we wouldn't need this line. What do you think (code-wise and whether this fits in with the release schedule, if we want to get this in before release)?

Quoted 5 lines

How bad is the breakage this one is trying to fix? I know it would only affect folks who have to interact with the server that uses packfile URI feature, but do they have a workaround, perhaps with a configuration knob or command line option to ignore the packfile URI,

Yes, there's a workaround (to disable packfile URIs from the client side using a config variable).

Quoted 1 line

and how large is the affected population?

The only issues I've seen are within $DAYJOB, and there, we can carry our own patch to fix this issue. So the affected population (right now) is probably not much (if it even exists).

Quoted 11 lines

I cannot shake the feeling that we are seeing band-aid on top of band-aid forced by having chosen to go in a wrong direction in the beginning X-<, and prefer to see the code drift even further into the same direction; hence my earlier suggestion to go back to the root cause by first reverting the wrong fix that introduced this bug and fixing the original bug in a different way.

I dunno how involved the necessary surgery would be, though. If this is easy to work around, perhaps it might be a better option for the overall project to ship the upcoming release with this listed as a known breakage.

I don't think it's too difficult - I think we'll only need to filter out the --pack_header when we figure out the arguments to pass for the packfiles given by URI. I'll take a look.

#215 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

Quoted 8 lines · Jonathan Tan
Quoted 4 lines

I dunno how involved the necessary surgery would be, though. If this is easy to work around, perhaps it might be a better option for the overall project to ship the upcoming release with this listed as a known breakage.

I don't think it's too difficult - I think we'll only need to filter out the --pack_header when we figure out the arguments to pass for the packfiles given by URI. I'll take a look.

What you sent earlier is a much better band-aid than "keep the single args array but filter an element out in only one codepath" band-aid, I would think.

Any change that is more involved than a single-liner trivial bugfix would be too late for this cycle, as we'd be cutting -rc2 by the end of tomorrow.

Thanks.

#216 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Jonathan Tan
Quoted 4 lines

I dunno how involved the necessary surgery would be, though. If this is easy to work around, perhaps it might be a better option for the overall project to ship the upcoming release with this listed as a known breakage.

I don't think it's too difficult - I think we'll only need to filter out the --pack_header when we figure out the arguments to pass for the packfiles given by URI. I'll take a look.

Quoted 7 lines

What you sent earlier is a much better band-aid than "keep the single args array but filter an element out in only one codepath" band-aid, I would think.

Any change that is more involved than a single-liner trivial bugfix would be too late for this cycle, as we'd be cutting -rc2 by the end of tomorrow.

I was looking at the index_pack_args vs pass_header codepath in fetch-pack.c again after finishing the -rc2 stuff, and noticed something curious.

Before running the command to process in-stream packdata, we have this bit:

	if (index_pack_args) {
		int i;

		for (i = 0; i < cmd.args.nr; i++)
			strvec_push(index_pack_args, cmd.args.v[i]);
	}

where cmd.args is what the original code (before the "we need to prepare the index pack arguments for the offline HTTP transfer" logic was bolted onto this codepath), so it could of course have things like "--fix-thin", "--promisor", when we are processing an in-stream packfile that has sufficiently large number of objects and choose "index-pack" to process it. None of them should be given to the "index-pack" that processes the offline packfile that is given via the packfile URI mechanism.

Also, because this loop copies everything in cmd.args, if our in-stream packdata is small, cmd.args.v[0] would be "unpack-objects", and we end up asking the command to explode the (presumably large enough to be worth pre-generating and serving via CDN) packfile that is given via the packfile URI mechanism.

What I think I am seeing in the code is that there are many things other than "pass_header" that fundamentally cannot be reused between the processing of the in-stream packdata and the offline packfile given by the packfile URI (e.g. the in-stream one may want to use "unpack-objects" to avoid accumulating too many tiny packs, so there is nothing to be shared with "index-pack" that will always be used for the offline one), and any attempt to "reuse" cmd.args while "filtering out" inappropriate bits is fragile and unfruitful.

Instead, I think we should not touch index_pack in the earlier part of the function at all (both reading, writing, or even checking for NULL-ness), and use the "if (index_pack_args)" block we already have (i.e. the one before we call start_command() to process the in-stream packdata) to decide what the command line to process the offline pack should look like. That way, we won't ever risk such a confusion like running "unpack-objects" instead of "index-pack" (but we can choose to do so deliberately, of course---the important point is to recognise that the in-stream pack and the offline one are independant and we should decide how to cook them separately).

#217 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

Quoted 3 lines · Junio C Hamano

Instead, I think we should not touch index_pack in the earlier part of the function at all (both reading, writing, or even checking for NULL-ness), ...

I have to take the "NULL-ness" part back. As the NULL-ness of the variable is also used to convey that URI packfile is in use, which in turn means we have to tell "index-pack" we are going to use for processing in-stream packfile that the objects in the pack may be pointing at objects that are not yet available. So we do need to check for the NULL-ness in order to decide what command line to use to process the in-stream packdata.

#218 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

In reply to Junio C Hamano
Quoted 14 lines

I was looking at the index_pack_args vs pass_header codepath in fetch-pack.c again after finishing the -rc2 stuff, and noticed something curious.

Before running the command to process in-stream packdata, we have this bit:

	if (index_pack_args) {
		int i;

		for (i = 0; i < cmd.args.nr; i++)
			strvec_push(index_pack_args, cmd.args.v[i]);
	}
Quoted 8 lines

where cmd.args is what the original code (before the "we need to prepare the index pack arguments for the offline HTTP transfer" logic was bolted onto this codepath), so it could of course have things like "--fix-thin", "--promisor", when we are processing an in-stream packfile that has sufficiently large number of objects and choose "index-pack" to process it. None of them should be given to the "index-pack" that processes the offline packfile that is given via the packfile URI mechanism.

Thanks for continuing to take a look at this. My thinking is that all packfiles (inline or through URI) should be processed in as similar a manner as possible. Looking at the potential arguments passed to index-pack:

1. --shallow-file (before "index-pack", that is, an argument passed to "git" itself and not the subcommand)

 2.  index-pack
 3.  --stdin
 4.  -v
 5.  --fix-thin
 6.  --keep
 7.  [--check-self-contained-and-connected is guarded by !index_pack_args

so we won't be passing it]
8. --promisor
9. --pack_header
10. --fsck_objects
11. [--strict appears in an "else" block opposite index_pack_args so we won't be passing it]

You mentioned --fix-thin (5) and --promisor (8). Why do you think that none of these should be given to the "index-pack" that processes the packfiles given by URI? Perhaps it could be argued that these extra packfiles don't need --fix-thin (but I would say that I think servers should be allowed to serve thin packfiles through URI too), but I think that --promisor is necessary (so that a server could, for example, offload all trees and commits to a packfile in a CDN, and offload all blobs to a separate packfile in a CDN).

Looking at this list, I think that all the arguments (except 9, which has been fixed) are necessary (or at least useful) for indexing a packfile given by URI.

Quoted 5 lines

Also, because this loop copies everything in cmd.args, if our in-stream packdata is small, cmd.args.v[0] would be "unpack-objects", and we end up asking the command to explode the (presumably large enough to be worth pre-generating and serving via CDN) packfile that is given via the packfile URI mechanism.

I specifically guard against this through the "if (do_keep || args->from_promisor || index_pack_args || fsck_objects) {" line (which is a complicated line, unfortunately).

Quoted 9 lines

What I think I am seeing in the code is that there are many things other than "pass_header" that fundamentally cannot be reused between the processing of the in-stream packdata and the offline packfile given by the packfile URI (e.g. the in-stream one may want to use "unpack-objects" to avoid accumulating too many tiny packs, so there is nothing to be shared with "index-pack" that will always be used for the offline one), and any attempt to "reuse" cmd.args while "filtering out" inappropriate bits is fragile and unfruitful.

Quoted 10 lines

Instead, I think we should not touch index_pack in the earlier part of the function at all (both reading, writing, or even checking for NULL-ness), and use the "if (index_pack_args)" block we already have (i.e. the one before we call start_command() to process the in-stream packdata) to decide what the command line to process the offline pack should look like. That way, we won't ever risk such a confusion like running "unpack-objects" instead of "index-pack" (but we can choose to do so deliberately, of course---the important point is to recognise that the in-stream pack and the offline one are independant and we should decide how to cook them separately).

We could do that, although I'm concerned that we would be repeating logic a lot (deciding whether or not to pass an argument). One other approach is for each "strvec.push?(&cmd.args" to also have another line that pushes to index_pack_args if it's relevant. But as I said earlier, I think that all or nearly all arguments will be relevant to both.

#219 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

Quoted 3 lines · Jonathan Tan

You mentioned --fix-thin (5) and --promisor (8). Why do you think that none of these should be given to the "index-pack" that processes the packfiles given by URI?

Actually, --fix-thin is probably even worse than that.

As the code processes the in-stream packdata before processing or even downloading the pregenerated URI packfile, the objects necessary to fix a "thin" in-stream packdata are likely to be unavailable (it is exactly the same problem as the one that made us to delay the fsckobjects done in index-pack when URI packfile is involved, isn't it?). Even if the client asks --thin, the server side shouldn't produce a thin pack for in-stream packdata, no?

Quoted 3 lines

Perhaps it could be argued that these extra
packfiles don't need --fix-thin (but I would say that I think servers should be allowed to serve thin packfiles through URI too),

I agree that URI packfile could be thin; after all, the server end chooses, based on what the client claims to have, which pregenerated packfile to hand out, so it is perfectly fine to hand out a pregenerated packfile that is thin if the client asks for a thin pack and says it has base objects missing from that packfile. And because it is (assumed to be) pregenerated, we can make a requirement that no URI packfile should depend on objects that are created later that that (which means it won't depend on in-stream packdata).

But we cannot process a thin in-stream packdata, if we are to process it first, right?

Quoted 4 lines

but I think
that --promisor is necessary (so that a server could, for example, offload all trees and commits to a packfile in a CDN, and offload all blobs to a separate packfile in a CDN).

Yes, both packfiles conceptually are given by that same server who promises to be always available to feed us everything we'd need later, so both packfiles should be marked to have come from the same promisor. So this is one example that happens to be sharable between the two.

But I do not see it as an indication that the two packs inherently must be processed with the same options.

Quoted 3 lines

Looking at this list, I think that all the arguments (except 9, which has been fixed) are necessary (or at least useful) for indexing a packfile given by URI.

I have to say that this is focusing too much on the current need by going through how the current code handles two packs. Of course, if we start from "two must be the same" viewpoint, and restrict what the code can do by "guarding" bits that require the two to be different out based on "if (index_pack_args)", then the resulting code would invoke two index-pack the same way.

I am more worried about the longer term code health, so "currently mostly the same" does not make a convincing argument for the future why the two must be processed the same way.

Quoted 9 lines
Quoted 5 lines

Also, because this loop copies everything in cmd.args, if our in-stream packdata is small, cmd.args.v[0] would be "unpack-objects", and we end up asking the command to explode the (presumably large enough to be worth pre-generating and serving via CDN) packfile that is given via the packfile URI mechanism.

I specifically guard against this through the "if (do_keep || args->from_promisor || index_pack_args || fsck_objects) {" line (which is a complicated line, unfortunately).

I am aware of that line that forbids the in-stream packdata from getting unpacked into loose objects. But unless we were told to keep the resulting pack, or run fsck-objects via the index-pack, I do not see an inherent reason why the "most recent leftover bits that are not in the pregenerated pack offloaded to CDN" objects must be kept in a separate packfile, especially if the number of objects in it is smaller than the unpack limit threshold. In other words, I view that "guard" as one of the things that blinds us into thinking that the two packs should be handled the same way. It is the other way around---the guard is there only because the code wanted to handle the two packs the same way.

When cloning from a server that offers bulk of old history in a URI packfile and an in-stream packfile, shouldn't the result be like cloning from the server back when it had only the objects in the URI packfile, and then fetching from it again when it acquired objects that came in the in-stream packfile? The objects that come during the second fetch would be left loose if there aren't that many, so that the third and subsequent fetches and local activity can accumulate enough loose objects to be packed into a single new pack, avoiding accumulation of too many tiny packs. And the "guard" breaks that only because this codepath wants to reuse cmd.args that is unrelated to populate index_pack_args. Isn't that an artificial limitation that we may want to eventually fix?

When we want to fix that, the "options are mostly the same when we use the index-pack command for both packdata, so let's copy the entire command line" would come back and haunt us. The person who is doing the fix may be somebody other than you, so it may not matter to you today, but it will hurt somebody tomorrow.

I already said that I think 2aec3bc4 (fetch-pack: do not mix --pack_header and packfile uri, 2021-03-04) is OK as a short-term fix for the upcoming release, but it does not change the fact that it is piling technical debt on top of existing technical debt.

And that is why I am reacting against your earlier mention of "filering out" rather strongly. The approach continues the "keep the single args array in the belief that two must be mostly the same", which I view as a misguided starting point that must be rethought.

Thanks.

#220 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

Quoted 10 lines · Junio C Hamano

I already said that I think 2aec3bc4 (fetch-pack: do not mix --pack_header and packfile uri, 2021-03-04) is OK as a short-term fix for the upcoming release, but it does not change the fact that it is piling technical debt on top of existing technical debt.

And that is why I am reacting against your earlier mention of "filering out" rather strongly. The approach continues the "keep the single args array in the belief that two must be mostly the same", which I view as a misguided starting point that must be rethought.

Another way to think about the codepath is this.

Can the bulk of get_pack() that deals with a single incoming packfile (from the part that makes the decision to use either index-pack or unpack-objects and chooses what options to pass to the command, to the part that actually calls run_command() and feeds the packdata to the command) be made into a helper function that handles one packdata stream and nothing else? Such a helper would most likely take as its parameters

- a stream to read the packdata from (for in-stream packfile that is handled by get_pack(), we already have it available)

- fetch_pack_args and other options that are meant to affect the operation of fetch-pack, among which are two bits that are of interest in this topic: if we want to run fsck-objects and if the entire fetch-pack is dealing with more than one packfile (currently, the only source of need to process multiple packfiles is packfile URI mechanism, but that does not have to stay that way).

Then get_pack() can move a lot of code out of it to this helper and just call it. The processing the other packfile obtained by the packfile URI mechanism out of band can open the packstream and call the helper the same way. When packfile URI mechanism is in use, both invocations of the helper would get "you are not alone so fsck may hit missing objects" bit, if fsck-objects are asked for.

That would avoid the "duplicated logic" and still allow the code to choose the best disposition of the incoming packdata per packfile.

In an extreme case, it is not hard to imagine that somebody prepares a very small base packfile and feed it via packfile URI mechanism, but have accumulated so many objects that are not yet rolled into an updated base packfile---cloning from such a repository may result in running unpack-objects for the packfile that came out of band, while processing the in-stream packfile with index-pack.

Hmm?

#221 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

Quoted 26 lines
Quoted 10 lines · Junio C Hamano

I already said that I think 2aec3bc4 (fetch-pack: do not mix --pack_header and packfile uri, 2021-03-04) is OK as a short-term fix for the upcoming release, but it does not change the fact that it is piling technical debt on top of existing technical debt.

And that is why I am reacting against your earlier mention of "filering out" rather strongly. The approach continues the "keep the single args array in the belief that two must be mostly the same", which I view as a misguided starting point that must be rethought.

Another way to think about the codepath is this.

Can the bulk of get_pack() that deals with a single incoming packfile (from the part that makes the decision to use either index-pack or unpack-objects and chooses what options to pass to the command, to the part that actually calls run_command() and feeds the packdata to the command) be made into a helper function that handles one packdata stream and nothing else? Such a helper would most likely take as its parameters

- a stream to read the packdata from (for in-stream packfile that is handled by get_pack(), we already have it available)

Quoted 7 lines

- fetch_pack_args and other options that are meant to affect the operation of fetch-pack, among which are two bits that are of interest in this topic: if we want to run fsck-objects and if the entire fetch-pack is dealing with more than one packfile (currently, the only source of need to process multiple packfiles is packfile URI mechanism, but that does not have to stay that way).

This probably means that fetch-pack.c itself (instead of finish_http_pack_request(), currently being called from a separate http_fetch process) should call index-pack for the out-of-band packfiles, which is conceptually reasonable. This means that finish_http_pack_request() will need to be able to refrain from running index-pack itself and instead just return where the pack was downloaded.

Quoted 10 lines

Then get_pack() can move a lot of code out of it to this helper and just call it. The processing the other packfile obtained by the packfile URI mechanism out of band can open the packstream and call the helper the same way. When packfile URI mechanism is in use, both invocations of the helper would get "you are not alone so fsck may hit missing objects" bit, if fsck-objects are asked for.

That would avoid the "duplicated logic" and still allow the code to choose the best disposition of the incoming packdata per packfile.

Quoted 8 lines

In an extreme case, it is not hard to imagine that somebody prepares a very small base packfile and feed it via packfile URI mechanism, but have accumulated so many objects that are not yet rolled into an updated base packfile---cloning from such a repository may result in running unpack-objects for the packfile that came out of band, while processing the in-stream packfile with index-pack.

Hmm?

Your suggestion (as opposed to the current situation, in which we're locked into using index-pack for the out-of-band packfiles) would make this possible, yes.

#222 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

Quoted 17 lines · Jonathan Tan
Quoted 17 lines

Then get_pack() can move a lot of code out of it to this helper and just call it. The processing the other packfile obtained by the packfile URI mechanism out of band can open the packstream and call the helper the same way. When packfile URI mechanism is in use, both invocations of the helper would get "you are not alone so fsck may hit missing objects" bit, if fsck-objects are asked for.

That would avoid the "duplicated logic" and still allow the code to choose the best disposition of the incoming packdata per packfile.

In an extreme case, it is not hard to imagine that somebody prepares a very small base packfile and feed it via packfile URI mechanism, but have accumulated so many objects that are not yet rolled into an updated base packfile---cloning from such a repository may result in running unpack-objects for the packfile that came out of band, while processing the in-stream packfile with index-pack.

Quoted 5 lines
Quoted 1 line

Hmm?

Your suggestion (as opposed to the current situation, in which we're locked into using index-pack for the out-of-band packfiles) would make this possible, yes.

Just to make sure, I am not interested in running unpack-objects on oob packfiles, as they are expected to be "so old, big and not changing that it is worth pre-generating" packfiles, so "yes the approach would make that useless thing possible" is not a useful criteria to judge how good the alternative approach would be. If the approach results in a cleaner design that gives us more flexibility without risking unnecessary code duplication, it would be a good sign that the approach is more sound than the direction we took so far, though.

Thanks.

#223 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

In reply to Jonathan Tan
Quoted 6 lines · Jonathan Tan

This probably means that fetch-pack.c itself (instead of finish_http_pack_request(), currently being called from a separate http_fetch process) should call index-pack for the out-of-band packfiles, which is conceptually reasonable. This means that finish_http_pack_request() will need to be able to refrain from running index-pack itself and instead just return where the pack was downloaded.

The HTTP downloading for packfile specified via the packfile URI mechansim is so different from the rest of the HTTP codepaths in nature, isn't it? It is a straight "download a static file over the web, and we could even afford to resume, or send multiple requests to gain throughput" usecase, which does not exist anywhere else in Git (eh, other than the dumb HTTP protocol nobody sane should be using anymore).

Since we are not in the business of writing a performant HTTP downloader, if we can update the codepath not to rely on our http.c code, and instead spawn one of the command line tools written specifically for the "download a single large file over HTTP" usecase (like curl, wget or aria2c), wait for it to do its thing and then concentrate on the processing specific to Git (like running index-pack with various options), it would take us closer to the "make clone resumable" dream, wouldn't it?

Thanks.

#224 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

Quoted 9 lines
Quoted 6 lines · Jonathan Tan

This probably means that fetch-pack.c itself (instead of finish_http_pack_request(), currently being called from a separate http_fetch process) should call index-pack for the out-of-band packfiles, which is conceptually reasonable. This means that finish_http_pack_request() will need to be able to refrain from running index-pack itself and instead just return where the pack was downloaded.

Quoted 7 lines

The HTTP downloading for packfile specified via the packfile URI mechansim is so different from the rest of the HTTP codepaths in nature, isn't it? It is a straight "download a static file over the web, and we could even afford to resume, or send multiple requests to gain throughput" usecase, which does not exist anywhere else in Git (eh, other than the dumb HTTP protocol nobody sane should be using anymore).

Yes - and I also noticed that finish_http_pack_request() is also used in http-push.c, but I'm not familiar with that.

Quoted 10 lines

Since we are not in the business of writing a performant HTTP downloader, if we can update the codepath not to rely on our http.c code, and instead spawn one of the command line tools written specifically for the "download a single large file over HTTP" usecase (like curl, wget or aria2c), wait for it to do its thing and then concentrate on the processing specific to Git (like running index-pack with various options), it would take us closer to the "make clone resumable" dream, wouldn't it?

Thanks.

We would have to figure out how to communicate any Git HTTP config variables to curl/wget etc. (and also declare a dependency on such a tool), but that could be done.

#225 lore raw

Re: [PATCH] fetch-pack: do not mix --pack_header and packfile uri

Quoted 9 lines · Jonathan Tan
Quoted 9 lines

Since we are not in the business of writing a performant HTTP downloader, if we can update the codepath not to rely on our http.c code, and instead spawn one of the command line tools written specifically for the "download a single large file over HTTP" usecase (like curl, wget or aria2c), wait for it to do its thing and then concentrate on the processing specific to Git (like running index-pack with various options), it would take us closer to the "make clone resumable" dream, wouldn't it?

Quoted 5 lines
Quoted 1 line

Thanks.

We would have to figure out how to communicate any Git HTTP config variables to curl/wget etc. (and also declare a dependency on such a tool), but that could be done.

Sure, and we do not have to go all the way there in a single step.

We'd likely need to ship with a basic "download from this URL and store it in this specified temporary file" (or "to this fd") and use it as the default downloader. We just need to design the interface to that downloader (i.e. which we want to make replaceable) to be not too intimate with the details of the side that spawns the downloader (i.e. git and git-fetch), and other people can write replacement as a thin wrapper around curl/wget etc. to contribute to us.

Thanks.

#226 lore raw

PATCH v2 3/4 fetch-pack: with packfile URIs, use index-pack arg

In reply to Jonathan Tan

Unify the index-pack arguments used when processing the inline pack and when downloading packfiles referenced by URIs. This is done by teaching get_pack() to also store the index-pack arguments whenever at least one packfile URI is given, and then when processing the packfile URI(s), using the stored arguments.

---
 fetch-pack.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)
fetch-pack.c +23 -11
index aeac010b0b..dd0a6c4b34 100644
@@ -797,12 +797,13 @@ static void write_promisor_file(const char *keep_name,
 }
 
 /*
- * Pass 1 as "only_packfile" if the pack received is the only pack in this
- * fetch request (that is, if there were no packfile URIs provided).
+ * If packfile URIs were provided, pass a non-NULL pointer to index_pack_args.
+ * The strings to pass as the --index-pack-arg arguments to http-fetch will be
+ * stored there. (It must be freed by the caller.)
  */
 static int get_pack(struct fetch_pack_args *args,
 		    int xd[2], struct string_list *pack_lockfiles,
-		    int only_packfile,
+		    struct strvec *index_pack_args,
 		    struct ref **sought, int nr_sought)
 {
 	struct async demux;
@@ -845,7 +846,7 @@ static int get_pack(struct fetch_pack_args *args,
 		strvec_push(&cmd.args, alternate_shallow_file);
 	}
 
-	if (do_keep || args->from_promisor) {
+	if (do_keep || args->from_promisor || index_pack_args) {
 		if (pack_lockfiles)
 			cmd.out = -1;
 		cmd_name = "index-pack";
@@ -863,7 +864,7 @@ static int get_pack(struct fetch_pack_args *args,
 				     "--keep=fetch-pack %"PRIuMAX " on %s",
 				     (uintmax_t)getpid(), hostname);
 		}
-		if (only_packfile && args->check_self_contained_and_connected)
+		if (!index_pack_args && args->check_self_contained_and_connected)
 			strvec_push(&cmd.args, "--check-self-contained-and-connected");
 		else
 			/*
@@ -901,7 +902,7 @@ static int get_pack(struct fetch_pack_args *args,
 	    : transfer_fsck_objects >= 0
 	    ? transfer_fsck_objects
 	    : 0) {
-		if (args->from_promisor || !only_packfile)
+		if (args->from_promisor || index_pack_args)
 			/*
 			 * We cannot use --strict in index-pack because it
 			 * checks both broken objects and links, but we only
@@ -913,6 +914,13 @@ static int get_pack(struct fetch_pack_args *args,
 				     fsck_msg_types.buf);
 	}
 
+	if (index_pack_args) {
+		int i;
+
+		for (i = 0; i < cmd.args.nr; i++)
+			strvec_push(index_pack_args, cmd.args.v[i]);
+	}
+
 	cmd.in = demux.out;
 	cmd.git_cmd = 1;
 	if (start_command(&cmd))
@@ -1084,7 +1092,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
 		alternate_shallow_file = setup_temporary_shallow(si->shallow);
 	else
 		alternate_shallow_file = NULL;
-	if (get_pack(args, fd, pack_lockfiles, 1, sought, nr_sought))
+	if (get_pack(args, fd, pack_lockfiles, NULL, sought, nr_sought))
 		die(_("git fetch-pack: fetch failed."));
 
  all_done:
@@ -1535,6 +1543,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 	int seen_ack = 0;
 	struct string_list packfile_uris = STRING_LIST_INIT_DUP;
 	int i;
+	struct strvec index_pack_args = STRVEC_INIT;
 
 	negotiator = &negotiator_alloc;
 	fetch_negotiator_init(r, negotiator);
@@ -1624,7 +1633,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 				receive_packfile_uris(&reader, &packfile_uris);
 			process_section_header(&reader, "packfile", 0);
 			if (get_pack(args, fd, pack_lockfiles,
-				     !packfile_uris.nr, sought, nr_sought))
+				     packfile_uris.nr ? &index_pack_args : NULL,
+				     sought, nr_sought))
 				die(_("git fetch-pack: fetch failed."));
 			do_check_stateless_delimiter(args, &reader);
 
@@ -1636,6 +1646,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 	}
 
 	for (i = 0; i < packfile_uris.nr; i++) {
+		int j;
 		struct child_process cmd = CHILD_PROCESS_INIT;
 		char packname[GIT_MAX_HEXSZ + 1];
 		const char *uri = packfile_uris.items[i].string +
@@ -1645,9 +1656,9 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 		strvec_pushf(&cmd.args, "--packfile=%.*s",
 			     (int) the_hash_algo->hexsz,
 			     packfile_uris.items[i].string);
-		strvec_push(&cmd.args, "--index-pack-arg=index-pack");
-		strvec_push(&cmd.args, "--index-pack-arg=--stdin");
-		strvec_push(&cmd.args, "--index-pack-arg=--keep");
+		for (j = 0; j < index_pack_args.nr; j++)
+			strvec_pushf(&cmd.args, "--index-pack-arg=%s",
+				     index_pack_args.v[j]);
 		strvec_push(&cmd.args, uri);
 		cmd.git_cmd = 1;
 		cmd.no_stdin = 1;
@@ -1683,6 +1694,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
 						 packname));
 	}
 	string_list_clear(&packfile_uris, 0);
+	strvec_clear(&index_pack_args);
 
 	if (negotiator)
 		negotiator->release(negotiator);
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
#227 lore raw

PATCH v2 4/4 fetch-pack: print and use dangling .gitmodules

In reply to Jonathan Tan

Teach index-pack to print dangling .gitmodules links after its "keep" or "pack" line instead of declaring an error, and teach fetch-pack to check such lines printed.

This allows the tree side of the .gitmodules link to be in one packfile and the blob side to be in another without failing the fsck check, because it is now fetch-pack which checks such objects after all packfiles have been downloaded and indexed (and not index-pack on an individual packfile, as it is before this commit).

---
 Documentation/git-index-pack.txt |  7 ++-
 builtin/index-pack.c             | 25 +++++++++-
 builtin/receive-pack.c           |  2 +-
 fetch-pack.c                     | 78 +++++++++++++++++++++++++++-----
 fsck.c                           |  5 ++
 fsck.h                           |  2 +
 pack-write.c                     |  8 +++-
 pack.h                           |  2 +-
 t/t5702-protocol-v2.sh           | 58 ++++++++++++++++++++++--
 9 files changed, 165 insertions(+), 22 deletions(-)
Documentation/git-index-pack.txt +6 -1
index af0c26232c..e74a4a1eda 100644
@@ -78,7 +78,12 @@ OPTIONS
 	Die if the pack contains broken links. For internal use only.
 
 --fsck-objects::
-	Die if the pack contains broken objects. For internal use only.
+	For internal use only.
++
+Die if the pack contains broken objects. If the pack contains a tree
+pointing to a .gitmodules blob that does not exist, prints the hash of
+that blob (for the caller to check) after the hash that goes into the
+name of the pack/idx file (see "Notes").
 
 --threads=<n>::
 	Specifies the number of threads to spawn when resolving
builtin/index-pack.c +23 -2
index 557bd2f348..0444febeee 100644
@@ -1693,6 +1693,22 @@ static void show_pack_info(int stat_only)
 	}
 }
 
+static int print_dangling_gitmodules(struct fsck_options *o,
+				     const struct object_id *oid,
+				     enum object_type object_type,
+				     int msg_type, const char *message)
+{
+	/*
+	 * NEEDSWORK: Plumb the MSG_ID (from fsck.c) here and use it
+	 * instead of relying on this string check.
+	 */
+	if (starts_with(message, "gitmodulesMissing")) {
+		printf("%s\n", oid_to_hex(oid));
+		return 0;
+	}
+	return fsck_error_function(o, oid, object_type, msg_type, message);
+}
+
 int cmd_index_pack(int argc, const char **argv, const char *prefix)
 {
 	int i, fix_thin_pack = 0, verify = 0, stat_only = 0;
@@ -1888,8 +1904,13 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 	else
 		close(input_fd);
 
-	if (do_fsck_object && fsck_finish(&fsck_options))
-		die(_("fsck error in pack objects"));
+	if (do_fsck_object) {
+		struct fsck_options fo = fsck_options;
+
+		fo.error_func = print_dangling_gitmodules;
+		if (fsck_finish(&fo))
+			die(_("fsck error in pack objects"));
+	}
 
 	free(objects);
 	strbuf_release(&index_name_buf);
builtin/receive-pack.c +1 -1
index d49d050e6e..ed2c9b42e9 100644
@@ -2275,7 +2275,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
 		status = start_command(&child);
 		if (status)
 			return "index-pack fork failed";
-		pack_lockfile = index_pack_lockfile(child.out);
+		pack_lockfile = index_pack_lockfile(child.out, NULL);
 		close(child.out);
 		status = finish_command(&child);
 		if (status)
fetch-pack.c +66 -12

159 lines not on this page · raw message

fsck.c +5 -0
index f82e2fe9e3..49ef6569e8 100644
@@ -1243,6 +1243,11 @@ int fsck_error_function(struct fsck_options *o,
 	return 1;
 }
 
+void register_found_gitmodules(const struct object_id *oid)
+{
+	oidset_insert(&gitmodules_found, oid);
+}
+
 int fsck_finish(struct fsck_options *options)
 {
 	int ret = 0;
fsck.h +2 -0
index 69cf715e79..d75b723bd5 100644
@@ -62,6 +62,8 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options);
 int fsck_object(struct object *obj, void *data, unsigned long size,
 	struct fsck_options *options);
 
+void register_found_gitmodules(const struct object_id *oid);
+
 /*
  * Some fsck checks are context-dependent, and may end up queued; run this
  * after completing all fsck_object() calls in order to resolve any remaining
pack-write.c +7 -1
index 3513665e1e..f66ea8e5a1 100644
@@ -272,7 +272,7 @@ void fixup_pack_header_footer(int pack_fd,
 	fsync_or_die(pack_fd, pack_name);
 }
 
-char *index_pack_lockfile(int ip_out)
+char *index_pack_lockfile(int ip_out, int *is_well_formed)
 {
 	char packname[GIT_MAX_HEXSZ + 6];
 	const int len = the_hash_algo->hexsz + 6;
@@ -286,11 +286,17 @@ char *index_pack_lockfile(int ip_out)
 	 */
 	if (read_in_full(ip_out, packname, len) == len && packname[len-1] == '\n') {
 		const char *name;
+
+		if (is_well_formed)
+			*is_well_formed = 1;
 		packname[len-1] = 0;
 		if (skip_prefix(packname, "keep\t", &name))
 			return xstrfmt("%s/pack/pack-%s.keep",
 				       get_object_directory(), name);
+		return NULL;
 	}
+	if (is_well_formed)
+		*is_well_formed = 0;
 	return NULL;
 }
 
pack.h +1 -1
index 9fc0945ac9..09cffec395 100644
@@ -85,7 +85,7 @@ int verify_pack_index(struct packed_git *);
 int verify_pack(struct repository *, struct packed_git *, verify_fn fn, struct progress *, uint32_t);
 off_t write_pack_header(struct hashfile *f, uint32_t);
 void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);
-char *index_pack_lockfile(int fd);
+char *index_pack_lockfile(int fd, int *is_well_formed);
 
 /*
  * The "hdr" output buffer should be at least this big, which will handle sizes
t/t5702-protocol-v2.sh +54 -4

76 lines not on this page · raw message

Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
#228 lore raw

Re: [PATCH v2 0/4] Check .gitmodules when using packfile URIs

In reply to Jonathan Tan
Quoted 11 lines · Jonathan Tan

Here's v2. I think I've addressed all the review comments, including passing the index-pack args as separate arguments (to avoid the necessity to somehow encode in order to get rid of spaces), and by using a custom error function instead of a specific option in fsck.

This applies on master. I mentioned earlier [1] that I was planning to implement this on Ævar's fsck API improvements, but after looking at the latest v2, I see that it omits patch 11 from v1 (which is the one I need), so what I've done is to use a string check in the meantime.

[1] https://lore.kernel.org/git/[email protected]/

I only looked at the difference between this round and what is in 'seen', but everything looked reasonable to me (including the code that is near NEEDSWORK comment, and what the comment said).

Will queue. Thanks.