Thread View: linux.kernel.git
2 messages
2 total messages
Started by Junio C Hamano
Wed, 25 Nov 2026 00:09
Re: [PATCH v2 1/2] archive-zip: fix prefix stripping for extra and virtual files
Author: Junio C Hamano
Date: Wed, 25 Nov 2026 00:09
Date: Wed, 25 Nov 2026 00:09
71 lines
15836 bytes
15836 bytes
Dominik Maier <dmnk@google.com> writes:
> write_zip_entry() unconditionally computes path + args->baselen before
> passing path_without_prefix to entry_is_binary(). That matches tracked
> tree entries, which always begin with the final --prefix stored in
> args->base.
>
> Extra files added via --add-file use the per-entry prefix recorded when
> the option was parsed (info->base), and entries from --add-virtual-file
> do not carry --prefix at all. When a later --prefix is longer than the
> extra or virtual file's archive path, path + args->baselen steps past
> the end of path (and for --add-virtual-file, looks up worktree
> gitattributes along an arbitrary virtual path).
Because by default parse_treeish_arg() directs attribute lookups to the
index with GIT_ATTR_INDEX, and only consults worktree attributes when
--worktree-attributes is passed, saying just "gitattributes", not
"worktree gitattributes", would be slightly more accurate, I think.
It does not affect the conclusion, though ;-)
> diff --git a/archive-zip.c b/archive-zip.c
> index 279c3a2d72..db4a96553b 100644
> --- a/archive-zip.c
> +++ b/archive-zip.c
> @@ -271,7 +271,8 @@ static int has_only_ascii(const char *s)
> static int entry_is_binary(struct index_state *istate, const char *path,
> const void *buffer, size_t size)
> {
> - struct userdiff_driver *driver = userdiff_find_by_path(istate, path);
> + struct userdiff_driver *driver = path ?
> + userdiff_find_by_path(istate, path) : NULL;
Checking path == NULL case here may make it easy for readers to see what
is going on, but because userdiff_find_by_path() already returns NULL
when path is NULL, the only effect of this change is that we now avoid
the overhead of initializing the static attr_check, when only virtual
files are checked, in userdiff_find_by_path().
As an optimizaiton, swapping the check of !path and one-time
initializing of attr_check in userdiff_find_by_path() may be more
effective.
Either way, falling back to the "default" driver (whose '.binary' is -1
unless configured) correctly drops through to buffer_is_binary().
> @@ -365,6 +367,8 @@ int write_archive_entries(struct archiver_args *args,
> canon_mode(info->stat.st_mode),
> content.buf, content.len);
> } else {
> + args->base = NULL;
> + args->baselen = 0;
> err = write_entry(args, &fake_oid,
> path, strlen(path),
> canon_mode(info->stat.st_mode),
For entries added by '--add-virtual-file', clearing '.base' to NULL
stops write_zip_entry() from doing path + args->baselen or attribute
lookup, and the next '--add-file' iteration restores '.base' and
'.baselen' if needed.
Mutating args->base and args->baselen inside this loop leaves them
pointing at the last extra file's prefix (or NULL) when
write_archive_entries() returns. None of the current callers in
archive-zip.c, archive-tar.c, or write_archive() inspect them afterward,
and extra_file_info_clear() runs only after write_archive() finishes, so
this is safe as-is, though saving and restoring them around the loop may
avoid surprising any future caller.
Overall, nicely done.
Re: [PATCH v2 1/2] archive-zip: fix prefix stripping for extra and virtual files
Author: Junio C Hamano
Date: Wed, 25 Nov 2026 17:42
Date: Wed, 25 Nov 2026 17:42
49 lines
15159 bytes
15159 bytes
RenΓ© Scharfe <l.s.r@web.de> writes: > On 11/25/26 1:09 AM, Junio C Hamano wrote: >> Dominik Maier <dmnk@google.com> writes: >> >>> write_zip_entry() unconditionally computes path + args->baselen before >>> passing path_without_prefix to entry_is_binary(). That matches tracked >>> tree entries, which always begin with the final --prefix stored in >>> args->base. >>> >>> Extra files added via --add-file use the per-entry prefix recorded when >>> the option was parsed (info->base), and entries from --add-virtual-file >>> do not carry --prefix at all. When a later --prefix is longer than the >>> extra or virtual file's archive path, path + args->baselen steps past >>> the end of path (and for --add-virtual-file, looks up worktree >>> gitattributes along an arbitrary virtual path). > > Oh, good find and straightforward fix. Indeed. > That would help workloads that only ever call userdiff_find_by_path() > without a path. "git archive --add-virtual-file=foo:bar $EMPTY_TREE" > is the only example I can come up with on the spot. It would also skip > the sanity checks in attr_check_initl() for those workloads. Not sure > if that's a good deal. I am not sure either. My point was that the above rewrite to avoid calling userdiff_find_by_path with path==NULL does not work as a great optimization (and if the author wanted an optimization, it should not be done here but in userdiff_find_by_path()). >> Mutating args->base and args->baselen inside this loop leaves them >> pointing at the last extra file's prefix (or NULL) when >> write_archive_entries() returns. None of the current callers in >> archive-zip.c, archive-tar.c, or write_archive() inspect them afterward, >> and extra_file_info_clear() runs only after write_archive() finishes, so >> this is safe as-is, though saving and restoring them around the loop may >> avoid surprising any future caller. > ... > I wonder if it's time for a struct archive_entry prepared by > write_archive_entry() to avoid per-entry changes to struct archiver_args > and pointer arithmetic in the tar and zip handlers. Out of scope for > this series, of course. Yes, but I suspect that it would be a good longer-term direction. Thanks.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads