<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/abspath.c, branch jch</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=jch</id>
<link rel='self' href='https://git.shady.money/git/atom?h=jch'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2023-06-12T20:49:35Z</updated>
<entry>
<title>abspath: move related functions to abspath</title>
<updated>2023-06-12T20:49:35Z</updated>
<author>
<name>Calvin Wan</name>
<email>calvinwan@google.com</email>
</author>
<published>2023-06-06T19:48:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=5d1344b4973c8ea4904005f3bb51a47334ebb370'/>
<id>urn:sha1:5d1344b4973c8ea4904005f3bb51a47334ebb370</id>
<content type='text'>
Move abspath-related functions from strbuf.[ch] to abspath.[ch] so that
strbuf is focused on string manipulation routines with minimal
dependencies.

Signed-off-by: Calvin Wan &lt;calvinwan@google.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>abspath.h: move absolute path functions from cache.h</title>
<updated>2023-03-21T17:56:52Z</updated>
<author>
<name>Elijah Newren</name>
<email>newren@gmail.com</email>
</author>
<published>2023-03-21T06:25:58Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=0b027f6ca79cafbc14f36ff1741fc7378282f295'/>
<id>urn:sha1:0b027f6ca79cafbc14f36ff1741fc7378282f295</id>
<content type='text'>
This is another step towards letting us remove the include of cache.h in
strbuf.c.  It does mean that we also need to add includes of abspath.h
in a number of C files.

Signed-off-by: Elijah Newren &lt;newren@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>bundle: don't blindly apply prefix_filename() to "-"</title>
<updated>2023-03-06T21:12:56Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2023-03-04T10:27:56Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=a8bfa99d443d3c461217db4924f8eca24caa055a'/>
<id>urn:sha1:a8bfa99d443d3c461217db4924f8eca24caa055a</id>
<content type='text'>
A user can specify a filename to a command from the command line,
either as the value given to a command line option, or a command
line argument.  When it is given as a relative filename, in the
user's mind, it is relative to the directory "git" was started from,
but by the time the filename is used, "git" would almost always have
chdir()'ed up to the root level of the working tree.

The given filename, if it is relative, needs to be prefixed with the
path to the current directory, and it typically is done by calling
prefix_filename() helper function.  For commands that can also take
"-" to use the standard input or the standard output, however, this
needs to be done with care.

"git bundle create" uses the next word on the command line as the
output filename, and can take "-" to mean "write to the standard
output".  It blindly called prefix_filename(), so running it in a
subdirectory did not quite work as expected.

Introduce a new helper, prefix_filename_except_for_dash(), and use
it to help "git bundle create" codepath.

Reported-by: Michael Henry
Helped-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>abspath: add a function to resolve paths with missing components</title>
<updated>2020-12-13T07:35:47Z</updated>
<author>
<name>brian m. carlson</name>
<email>sandals@crustytoothpaste.net</email>
</author>
<published>2020-12-13T00:25:28Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=be6e0daee700b2ee28846b54ddfefe08cd4ec506'/>
<id>urn:sha1:be6e0daee700b2ee28846b54ddfefe08cd4ec506</id>
<content type='text'>
Currently, we have a function to resolve paths, strbuf_realpath.  This
function canonicalizes paths like realpath(3), but permits a trailing
component to be absent from the file system.  In other words, this is
the behavior of the GNU realpath(1) without any arguments.

In the future, we'll need this same behavior, except that we want to
allow for any number of missing trailing components, which is the
behavior of GNU realpath(1) with the -m option.  This is useful because
we'll want to canonicalize a path that may point to a not yet present
path under the .git directory.  For example, a user may want to know
where an arbitrary ref would be stored if it existed in the file system.

Let's refactor strbuf_realpath to move most of the code to an internal
function and then pass it two flags to control its behavior.  We'll add
a strbuf_realpath_forgiving function that has our new behavior, and
leave strbuf_realpath with the older, stricter behavior.

Signed-off-by: brian m. carlson &lt;sandals@crustytoothpaste.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>real_path_if_valid(): remove unsafe API</title>
<updated>2020-03-10T18:41:40Z</updated>
<author>
<name>Alexandr Miloslavskiy</name>
<email>alexandr.miloslavskiy@syntevo.com</email>
</author>
<published>2020-03-10T13:11:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=4530a85b4c34f009b5f190eb2dc8367801de5028'/>
<id>urn:sha1:4530a85b4c34f009b5f190eb2dc8367801de5028</id>
<content type='text'>
This commit continues the work started with previous commit.

Signed-off-by: Alexandr Miloslavskiy &lt;alexandr.miloslavskiy@syntevo.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>real_path: remove unsafe API</title>
<updated>2020-03-10T18:41:40Z</updated>
<author>
<name>Alexandr Miloslavskiy</name>
<email>alexandr.miloslavskiy@syntevo.com</email>
</author>
<published>2020-03-10T13:11:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3d7747e318532a36a263c61cdf92f2decb6424ff'/>
<id>urn:sha1:3d7747e318532a36a263c61cdf92f2decb6424ff</id>
<content type='text'>
Returning a shared buffer invites very subtle bugs due to reentrancy or
multi-threading, as demonstrated by the previous patch.

There was an unfinished effort to abolish this [1].

Let's finally rid of `real_path()`, using `strbuf_realpath()` instead.

This patch uses a local `strbuf` for most places where `real_path()` was
previously called.

However, two places return the value of `real_path()` to the caller. For
them, a `static` local `strbuf` was added, effectively pushing the
problem one level higher:
    read_gitfile_gently()
    get_superproject_working_tree()

[1] https://lore.kernel.org/git/1480964316-99305-1-git-send-email-bmwill@google.com/

Signed-off-by: Alexandr Miloslavskiy &lt;alexandr.miloslavskiy@syntevo.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>real_path: clarify return value ownership</title>
<updated>2017-09-27T00:13:47Z</updated>
<author>
<name>Han-Wen Nienhuys</name>
<email>hanwen@google.com</email>
</author>
<published>2017-09-26T11:21:48Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d83d846e84d6ba6c7c4221d2681dfde820949362'/>
<id>urn:sha1:d83d846e84d6ba6c7c4221d2681dfde820949362</id>
<content type='text'>
Signed-off-by: Han-Wen Nienhuys &lt;hanwen@google.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Spelling fixes</title>
<updated>2017-06-27T17:35:49Z</updated>
<author>
<name>Ville Skyttä</name>
<email>ville.skytta@iki.fi</email>
</author>
<published>2017-06-25T10:20:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=64127575149e35b409bc2f78962f86507346d604'/>
<id>urn:sha1:64127575149e35b409bc2f78962f86507346d604</id>
<content type='text'>
Signed-off-by: Ville Skyttä &lt;ville.skytta@iki.fi&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>prefix_filename: simplify windows #ifdef</title>
<updated>2017-03-21T18:18:41Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2017-03-21T01:30:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=af10e8b1559790d5c78fcc2a1aae5c42f3930a00'/>
<id>urn:sha1:af10e8b1559790d5c78fcc2a1aae5c42f3930a00</id>
<content type='text'>
The prefix_filename function used to do an early return when
there was no prefix on non-Windows platforms, but always
allocated on Windows so that it could call convert_slashes().

Now that the function always allocates, we can unify the
logic and make convert_slashes() the only conditional part.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>prefix_filename: return newly allocated string</title>
<updated>2017-03-21T18:18:41Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2017-03-21T01:28:49Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=e4da43b1f063d227b5f7d2922d27458748763a2d'/>
<id>urn:sha1:e4da43b1f063d227b5f7d2922d27458748763a2d</id>
<content type='text'>
The prefix_filename() function returns a pointer to static
storage, which makes it easy to use dangerously. We already
fixed one buggy caller in hash-object recently, and the
calls in apply.c are suspicious (I didn't dig in enough to
confirm that there is a bug, but we call the function once
in apply_all_patches() and then again indirectly from
parse_chunk()).

Let's make it harder to get wrong by allocating the return
value. For simplicity, we'll do this even when the prefix is
empty (and we could just return the original file pointer).
That will cause us to allocate sometimes when we wouldn't
otherwise need to, but this function isn't called in
performance critical code-paths (and it already _might_
allocate on any given call, so a caller that cares about
performance is questionable anyway).

The downside is that the callers need to remember to free()
the result to avoid leaking. Most of them already used
xstrdup() on the result, so we know they are OK. The
remainder have been converted to use free() as appropriate.

I considered retaining a prefix_filename_unsafe() for cases
where we know the static lifetime is OK (and handling the
cleanup is awkward). This is only a handful of cases,
though, and it's not worth the mental energy in worrying
about whether the "unsafe" variant is OK to use in any
situation.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
