From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Dominik Maier <dmnk@google.com>,
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 09:42:24 -0800 [thread overview]
Message-ID: <xmqqy0ag6c5b.fsf@gitster.g> (raw)
In-Reply-To: <16fa9275-b2d6-457a-ab30-932c98a52c1a@web.de> ("René Scharfe"'s message of "Wed, 25 Nov 2026 12:39:59 +0100")
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.
next prev parent reply other threads:[~2026-11-25 17:42 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
2026-11-25 17:42 ` Junio C Hamano [this message]
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=xmqqy0ag6c5b.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