threads / patch / 66950

patcharchive: pass export-subst attribute value as parameter

Subject: [PATCH] archive: pass export-subst attribute value as parameter

## tl;dr

René Scharfe's small refactor removes a misleadingly named member of struct archiver_args; Junio Hamano asks that the log message explain why it was misplaced. Read the story.

replies: 2people: 2as markdown or json

René Scharfe· Nov 28, 2026, 18:47 UTC · lore

The member "convert" of struct archiver_args is used to pass the value of blob attribute export-subst to object_file_to_archive(). That's an unusual place and a misleading name. Add and use an appropriately named parameter to that function instead.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 archive.c | 12 +++++++-----
 archive.h |  1 -
 2 files changed, 7 insertions(+), 6 deletions(-)
Show changes to 2 files +7 −6

archive.c, archive.h

diff --git a/archive.c b/archive.c
index 59790be986..0aa610b5c5 100644
--- a/archive.c
+++ b/archive.c
@@ -86,11 +86,12 @@ static void *object_file_to_archive(const struct archiver_args *args,
 				    const char *path,
 				    const struct object_id *oid,
 				    unsigned int mode,
+				    bool export_subst,
 				    enum object_type *type,
 				    size_t *sizep)
 {
 	void *buffer;
-	const struct commit *commit = args->convert ? args->commit : NULL;
+	const struct commit *commit = export_subst ? args->commit : NULL;
 	struct checkout_metadata meta;
 
 	init_checkout_metadata(&meta, args->refname,
@@ -161,8 +162,8 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
 	size_t size;
 	void *buffer;
 	enum object_type type;
+	bool export_subst = 0;
 
-	args->convert = 0;
 	strbuf_reset(&path);
 	strbuf_grow(&path, PATH_MAX);
 	strbuf_add(&path, args->base, args->baselen);
@@ -177,7 +178,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
 		check = get_archive_attrs(args->repo->index, path_without_prefix);
 		if (check_attr_export_ignore(check))
 			return 0;
-		args->convert = check_attr_export_subst(check);
+		export_subst = check_attr_export_subst(check);
 	}
 
 	if (args->prefix) {
@@ -214,12 +215,13 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
 	}
 
 	/* Stream it? */
-	if (S_ISREG(mode) && !args->convert &&
+	if (S_ISREG(mode) && !export_subst &&
 	    odb_read_object_info(args->repo->objects, oid, &size) == OBJ_BLOB &&
 	    size > repo_settings_get_big_file_threshold(the_repository))
 		return write_entry(args, oid, path.buf, path.len, mode, NULL, size);
 
-	buffer = object_file_to_archive(args, path.buf, oid, mode, &type, &size);
+	buffer = object_file_to_archive(args, path.buf, oid, mode, export_subst,
+					&type, &size);
 	if (!buffer)
 		return error(_("cannot read '%s'"), oid_to_hex(oid));
 	err = write_entry(args, oid, path.buf, path.len, mode, buffer, size);
diff --git a/archive.h b/archive.h
index bbe65ba0f9..e5ed3283c5 100644
--- a/archive.h
+++ b/archive.h
@@ -21,7 +21,6 @@ struct archiver_args {
 	struct pathspec pathspec;
 	unsigned int verbose : 1;
 	unsigned int worktree_attributes : 1;
-	unsigned int convert : 1;
 	int compression_level;
 	struct string_list extra_files;
 	struct pretty_print_context *pretty_ctx;
-- 
2.56.1
Junio C Hamano· Nov 28, 2026, 22:38 UTC · re: René Scharfe · lore

Re: [PATCH] archive: pass export-subst attribute value as parameter

René Scharfe <l.s.r@web.de> writes:
Show 10 quoted lines
> The member "convert" of struct archiver_args is used to pass the value
> of blob attribute export-subst to object_file_to_archive().  That's an
> unusual place and a misleading name.  Add and use an appropriately named
> parameter to that function instead.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
>  archive.c | 12 +++++++-----
>  archive.h |  1 -
>  2 files changed, 7 insertions(+), 6 deletions(-)

The name is misleading indeed. Why it is "an unusual place" needs a bit of explanation to convince others, I am afraid, so let me try to spell out the reason why, as I understand it, and see if that matches yours (and if so, "an unusual place" above may want to be strengthened by the reason why).

There are two ways this function and write_entry() (and possibly others) receive settings from their caller, write_archive_entry().

The archiver_args structure is meant to hold the settings common across different entries to be written. In addition, per-call parameters give information specific to each entry being written by a particular call, like the path of the entry and its file mode.

The 'export_subst' setting is per path and specified via attributes, so it definitely is not common across entries. It does not belong there, and making it a parameter passed to object_file_to_archive() moves it to the right place. And with a more correct name, which is very nice ;-)

Now, are there members other than '.convert' in the archiver_args that should be moved out of there for the same reason? The '.convert' member needs to be reset in write_archive_entry() for each and every path because of this misplacement. If there is no longer any member that is not common across entries, perhaps many of the consumers of 'struct archiver_args *' can take a const pointer, most notably the write_archive_entry() function? It needs to propagate the constness down to write_entry(), and is better left outside this patch, perhaps.

The patch of looks good to me.  Thanks.
René Scharfe· Nov 30, 2026, 15:55 UTC · re: Junio C Hamano · lore

Re: [PATCH] archive: pass export-subst attribute value as parameter

On 11/28/26 11:38 PM, Junio C Hamano wrote:
Show 31 quoted lines
> René Scharfe <l.s.r@web.de> writes:
> 
>> The member "convert" of struct archiver_args is used to pass the value
>> of blob attribute export-subst to object_file_to_archive().  That's an
>> unusual place and a misleading name.  Add and use an appropriately named
>> parameter to that function instead.
>>
>> Signed-off-by: René Scharfe <l.s.r@web.de>
>> ---
>>  archive.c | 12 +++++++-----
>>  archive.h |  1 -
>>  2 files changed, 7 insertions(+), 6 deletions(-)
> 
> The name is misleading indeed.  Why it is "an unusual place" needs a bit
> of explanation to convince others, I am afraid, so let me try to spell
> out the reason why, as I understand it, and see if that matches yours
> (and if so, "an unusual place" above may want to be strengthened by the
> reason why).
> 
> There are two ways this function and write_entry() (and possibly others)
> receive settings from their caller, write_archive_entry().
> 
> The archiver_args structure is meant to hold the settings common across
> different entries to be written.  In addition, per-call parameters give
> information specific to each entry being written by a particular call,
> like the path of the entry and its file mode.
> 
> The 'export_subst' setting is per path and specified via attributes, so
> it definitely is not common across entries.  It does not belong there,
> and making it a parameter passed to object_file_to_archive() moves it to
> the right place.  And with a more correct name, which is very nice ;-)

Right, that's what I mean: The value of the blob-specific attribute export-subst is passed in a struct for archiver options. They have different scopes and topics. There's only a single instance of struct archiver_args, so .convert has to be updated for each blob, of which there are usually many.

Show 8 quoted lines
> Now, are there members other than '.convert' in the archiver_args that
> should be moved out of there for the same reason?  The '.convert' member
> needs to be reset in write_archive_entry() for each and every path
> because of this misplacement.  If there is no longer any member that is
> not common across entries, perhaps many of the consumers of
> 'struct archiver_args *' can take a const pointer, most notably the
> write_archive_entry() function?  It needs to propagate the constness
> down to write_entry(), and is better left outside this patch, perhaps.

Good idea. 21d3cf2276 (archive-zip: fix prefix stripping for extra and virtual files, 2026-11-24) in next moves the members .base and .baselen into that category, though. We'd have to address that first, e.g. by adding a path_without_prefix parameter or a struct archive_entry that includes something like it.

René

← back to recent threads