From: Junio C Hamano <gitster@pobox.com>
To: Dominik Maier <dmnk@google.com>
Cc: git@vger.kernel.org, "René Scharfe" <l.s.r@web.de>,
dmnk+artist@google.com
Subject: Re: [PATCH v2 1/2] archive-zip: fix prefix stripping for extra and virtual files
Date: Tue, 24 Nov 2026 16:09:31 -0800 [thread overview]
Message-ID: <xmqqbj7dhiv8.fsf@gitster.g> (raw)
In-Reply-To: <72c0d0c0a43cadcc61f0187c86b9bd9361079a42.1795543448.git.dmnk@google.com> (Dominik Maier's message of "Tue, 24 Nov 2026 18:05:49 +0000")
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.
next prev parent reply other threads:[~2026-11-25 0:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 19:23 [PATCH] archive: reject remote --add-file in callback Dominik Maier
2026-11-21 15:15 ` René Scharfe
2026-11-24 18:05 ` [PATCH v2 0/2] archive: defer --add-file stat() and fix zip extra-file prefix handling Dominik Maier
2026-11-24 18:05 ` [PATCH v2 1/2] archive-zip: fix prefix stripping for extra and virtual files Dominik Maier
2026-11-25 0:09 ` Junio C Hamano [this message]
2026-11-25 11:39 ` René Scharfe
2026-11-25 17:42 ` Junio C Hamano
2026-11-24 18:05 ` [PATCH v2 2/2] archive: defer --add-file stat() until after option parsing Dominik Maier
2026-11-25 0:24 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqbj7dhiv8.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=dmnk+artist@google.com \
--cc=dmnk@google.com \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox