abspath: add a function to resolve paths with missing components
commitbe6e0daee700b2ee28846b54ddfefe08cd4ec506
authorbrian m. carlson <sandals@crustytoothpaste.net>
Sun, 13 Dec 2020 00:25:28 +0000 (13 00:25 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 13 Dec 2020 07:35:47 +0000 (12 23:35 -0800)
tree8a1e2f49bf04b541f314fe2aec632de921475d53
parent3cf59784d42c4152a0b3de7bb7a75d0071e5f878
abspath: add a function to resolve paths with missing components

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 <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
abspath.c
cache.h