From: Justin Tobler Date: Mon, 15 Jun 2026 17:18:18 GMT Subject: Re: [GSoC Patch v4 2/4] rev-parse: use append_formatted_path() for path formatting Message-ID: In-Reply-To: <20260615045112.50686-3-jayatheerthkulkarni2005@gmail.com> On 26/06/15 10:21AM, K Jayatheerth wrote: [snip] > -static void print_path(const char *path, const char *prefix, enum format_type format, enum default_type def) > +static void print_path(const char *path, const char *prefix, > + enum path_format arg_path_format, enum path_format def_format) > { > - char *cwd = NULL; > - /* > - * We don't ever produce a relative path if prefix is NULL, so set the > - * prefix to the current directory so that we can produce a relative > - * path whenever possible. If we're using RELATIVE_IF_SHARED mode, then > - * we want an absolute path unless the two share a common prefix, so don't > - * set it in that case, since doing so causes a relative path to always > - * be produced if possible. > - */ > - if (!prefix && (format != FORMAT_DEFAULT || def != DEFAULT_RELATIVE_IF_SHARED)) > - prefix = cwd = xgetcwd(); > - if (format == FORMAT_DEFAULT && def == DEFAULT_UNMODIFIED) { > - puts(path); > - } else if (format == FORMAT_RELATIVE || > - (format == FORMAT_DEFAULT && def == DEFAULT_RELATIVE)) { > - /* > - * In order for relative_path to work as expected, we need to > - * make sure that both paths are absolute paths. If we don't, > - * we can end up with an unexpected absolute path that the user > - * didn't want. > - */ > - struct strbuf buf = STRBUF_INIT, realbuf = STRBUF_INIT, prefixbuf = STRBUF_INIT; > - if (!is_absolute_path(path)) { > - strbuf_realpath_forgiving(&realbuf, path, 1); > - path = realbuf.buf; > - } > - if (!is_absolute_path(prefix)) { > - strbuf_realpath_forgiving(&prefixbuf, prefix, 1); > - prefix = prefixbuf.buf; > - } > - puts(relative_path(path, prefix, &buf)); > - strbuf_release(&buf); > - strbuf_release(&realbuf); > - strbuf_release(&prefixbuf); > - } else if (format == FORMAT_DEFAULT && def == DEFAULT_RELATIVE_IF_SHARED) { > - struct strbuf buf = STRBUF_INIT; > - puts(relative_path(path, prefix, &buf)); > - strbuf_release(&buf); > - } else { > - struct strbuf buf = STRBUF_INIT; > - strbuf_realpath_forgiving(&buf, path, 1); > - puts(buf.buf); > - strbuf_release(&buf); > - } > - free(cwd); > + struct strbuf sb = STRBUF_INIT; > + enum path_format fmt = (arg_path_format != PATH_FORMAT_DEFAULT) ? arg_path_format : def_format; Without context, it might be a bit confusing to readers as to why we override PATH_FORMAT_DEFAULT without our own provided default. It may be worth leaving a comment to provide some breadcrumbs. The rest of this patch looks good to me. -Justin