From: Junio C Hamano <gitster@pobox.com>
To: Jacob Keller <jacob.e.keller@intel.com>
Cc: <git@vger.kernel.org>, Jacob Keller <jacob.keller@gmail.com>
Subject: Re: [PATCH v3 1/4] prefix_path: support prefixes not ending in trailing slash
Date: Tue, 20 May 2025 07:35:28 -0700 [thread overview]
Message-ID: <xmqqh61fl58v.fsf@gitster.g> (raw)
In-Reply-To: <20250520000125.2162144-2-jacob.e.keller@intel.com> (Jacob Keller's message of "Mon, 19 May 2025 17:01:22 -0700")
Jacob Keller <jacob.e.keller@intel.com> writes:
> From: Jacob Keller <jacob.keller@gmail.com>
>
> The prefix_path_gently() -- and its wrapper prefix_path() -- function
> normalizes the provided path and optionally adds the provided prefix to
> relative paths.
I find "optionally" confusing here. The original intended use case
of this function being that "the provided path", which comes from
the end user from the command line that names a file relative to the
directory the usre started the "git" command in, needs to be
adjusted after "git" chdir's up to the top-level of the working
tree, and the way to do so is to prepend the "prefix" computed by
"git" (which always ends with a slash). Adding the prefix to
relative paths is the central part of what it has to do. When the
end-user supplied path goes up e.g., "../file", we may have to lose
a level or more of the prefix before prepending, but that does not
change the fact that the helper function is about prepending the
prefix.
And as you can guess from the above description, if the caller
passes prefix that does not end in a trailing slash, the caller is
buggy.
> If the prefix does not end in a trailing slash, the
> function will combine the last component of the prefix with the first
> component of the relative path. This is unlikely to produce a desirable
> result.
True, and I do not mind being lenient to buggy callers, but given
that the majority of callers (i.e. all the existing callers) not
being buggy, I wonder if it is better to check and append a slash to
the end by a new caller that feeds a prefix that directly comes from
the end user?
Unlike prefix that is internally generated by Git, we'd need to be a
lot more careful if we are taking end-user input directly and
passing it as a "prefix" (I take that the possible lack of trailing
slash as a signal that you are doing something like that in this
series). We may need to check and correct that they do not contain
"./", "//", or "../", for example, anyway, and adding the required
trailing slash at the end sounds like something we may want to do as
part of that input validation and massaging _before_ calling these
helper functions.
next prev parent reply other threads:[~2025-05-20 14:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-20 0:01 [PATCH v3 0/4] diff: add pathspec support to --no-index Jacob Keller
2025-05-20 0:01 ` [PATCH v3 1/4] prefix_path: support prefixes not ending in trailing slash Jacob Keller
2025-05-20 14:35 ` Junio C Hamano [this message]
2025-05-20 22:34 ` Jacob Keller
2025-05-20 0:01 ` [PATCH v3 2/4] pathspec: expose match_pathspec_with_flags Jacob Keller
2025-05-20 14:39 ` Junio C Hamano
2025-05-20 22:38 ` Jacob Keller
2025-05-20 0:01 ` [PATCH v3 3/4] pathspec: add flag to indicate operation without repository Jacob Keller
2025-05-20 15:13 ` Junio C Hamano
2025-05-20 22:42 ` Jacob Keller
2025-05-21 23:05 ` Jacob Keller
2025-05-20 0:01 ` [PATCH v3 4/4] diff --no-index: support limiting by pathspec Jacob Keller
2025-05-20 16:30 ` Junio C Hamano
2025-05-20 22:45 ` Jacob Keller
2025-05-20 22:47 ` Jacob Keller
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=xmqqh61fl58v.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=jacob.keller@gmail.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;
as well as URLs for NNTP newsgroup(s).