From: "René Scharfe" <l.s.r@web.de>
To: Junio C Hamano <gitster@pobox.com>, Dominik Maier <dmnk@google.com>
Cc: git@vger.kernel.org, dmnk+artist@google.com
Subject: Re: [PATCH v2 1/2] archive-zip: fix prefix stripping for extra and virtual files
Date: Wed, 25 Nov 2026 12:39:59 +0100 [thread overview]
Message-ID: <16fa9275-b2d6-457a-ab30-932c98a52c1a@web.de> (raw)
In-Reply-To: <xmqqbj7dhiv8.fsf@gitster.g>
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.
> 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.
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.
> 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.
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.
René
next prev parent reply other threads:[~2026-11-25 11:40 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
2026-11-25 11:39 ` René Scharfe [this message]
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=16fa9275-b2d6-457a-ab30-932c98a52c1a@web.de \
--to=l.s.r@web.de \
--cc=dmnk+artist@google.com \
--cc=dmnk@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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