diff mbox series

[12/12] upload-pack: move pack_objects_hook to upload_pack_data

Message ID 20200527164742.23067-13-chriscool@tuxfamily.org (mailing list archive)
State New, archived
Headers show
Series upload-pack: use 'struct upload_pack_data' thoroughly, part 2 | expand

Commit Message

Christian Couder May 27, 2020, 4:47 p.m. UTC
As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'pack_objects_hook' static
variable into this struct.

It is used by code common to protocol v0 and protocol v2.

While at it let's also free() it in upload_pack_data_clear().

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Jeff King May 27, 2020, 6:55 p.m. UTC | #1
On Wed, May 27, 2020 at 06:47:42PM +0200, Christian Couder wrote:

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's move the 'pack_objects_hook' static
> variable into this struct.
> 
> It is used by code common to protocol v0 and protocol v2.
> 
> While at it let's also free() it in upload_pack_data_clear().

Makes sense.

> @@ -133,6 +134,8 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
>  	object_array_clear(&data->shallows);
>  	string_list_clear(&data->deepen_not, 0);
>  	list_objects_filter_release(&data->filter_options);
> +
> +	free((char *)data->pack_objects_hook);

This cast is ugly, but unavoidable because git_config_string() takes a
pointer-to-const.

-Peff
diff mbox series

Patch

diff --git a/upload-pack.c b/upload-pack.c
index becefd5bdc..3e9ae53e6c 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -53,7 +53,6 @@  static timestamp_t oldest_have;
 static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
-static const char *pack_objects_hook;
 
 struct upload_pack_data {
 	struct string_list symref;
@@ -84,6 +83,8 @@  struct upload_pack_data {
 
 	struct packet_writer writer;
 
+	const char *pack_objects_hook;
+
 	unsigned stateless_rpc : 1;
 	unsigned daemon_mode : 1;
 
@@ -133,6 +134,8 @@  static void upload_pack_data_clear(struct upload_pack_data *data)
 	object_array_clear(&data->shallows);
 	string_list_clear(&data->deepen_not, 0);
 	list_objects_filter_release(&data->filter_options);
+
+	free((char *)data->pack_objects_hook);
 }
 
 static void reset_timeout(int timeout)
@@ -177,10 +180,10 @@  static void create_pack_file(struct upload_pack_data *pack_data)
 	int i;
 	FILE *pipe_fd;
 
-	if (!pack_objects_hook)
+	if (!pack_data->pack_objects_hook)
 		pack_objects.git_cmd = 1;
 	else {
-		argv_array_push(&pack_objects.args, pack_objects_hook);
+		argv_array_push(&pack_objects.args, pack_data->pack_objects_hook);
 		argv_array_push(&pack_objects.args, "git");
 		pack_objects.use_shell = 1;
 	}
@@ -1149,7 +1152,7 @@  static int upload_pack_config(const char *var, const char *value, void *cb_data)
 	if (current_config_scope() != CONFIG_SCOPE_LOCAL &&
 	current_config_scope() != CONFIG_SCOPE_WORKTREE) {
 		if (!strcmp("uploadpack.packobjectshook", var))
-			return git_config_string(&pack_objects_hook, var, value);
+			return git_config_string(&data->pack_objects_hook, var, value);
 	}
 
 	return parse_hide_refs_config(var, value, "uploadpack");