public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
To: git@vger.kernel.org
Cc: sandals@crustytoothpaste.net, kumarayushjha123@gmail.com,
	a3205153416@gmail.com, jayatheerthkulkarni2005@gmail.com,
	valusoutrik@gmail.com, pushkarkumarsingh1970@gmail.com,
	Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Subject: [PATCH 1/4] rev-parse: prepend `path_` to path-related enums
Date: Sat, 28 Feb 2026 19:05:55 -0300	[thread overview]
Message-ID: <20260228224252.72788-2-lucasseikioshiro@gmail.com> (raw)
In-Reply-To: <20260228224252.72788-1-lucasseikioshiro@gmail.com>

There are two enums used in rev-parse for deciding how paths will
be printed by the function `print_path`: `format_type` and
`default_type`. Even though there aren't any ambiguities yet, their
names aren't clear that those "types" are path types.

Rename both enums and their values by prepending the word `path_`,
to clarify that they are used for choosing path types.

Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 builtin/rev-parse.c | 56 ++++++++++++++++++++++-----------------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 9032cc6327..a2162ff39e 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -623,27 +623,27 @@ static void handle_ref_opt(const char *pattern, const char *prefix)
 	clear_ref_exclusions(&ref_excludes);
 }
 
-enum format_type {
+enum path_format_type {
 	/* We would like a relative path. */
-	FORMAT_RELATIVE,
+	PATH_FORMAT_RELATIVE,
 	/* We would like a canonical absolute path. */
-	FORMAT_CANONICAL,
+	PATH_FORMAT_CANONICAL,
 	/* We would like the default behavior. */
-	FORMAT_DEFAULT,
+	PATH_FORMAT_DEFAULT,
 };
 
-enum default_type {
+enum path_default_type {
 	/* Our default is a relative path. */
-	DEFAULT_RELATIVE,
+	PATH_DEFAULT_RELATIVE,
 	/* Our default is a relative path if there's a shared root. */
-	DEFAULT_RELATIVE_IF_SHARED,
+	PATH_DEFAULT_RELATIVE_IF_SHARED,
 	/* Our default is a canonical absolute path. */
-	DEFAULT_CANONICAL,
+	PATH_DEFAULT_CANONICAL,
 	/* Our default is not to modify the item. */
-	DEFAULT_UNMODIFIED,
+	PATH_DEFAULT_UNMODIFIED,
 };
 
-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_type format, enum path_default_type def)
 {
 	char *cwd = NULL;
 	/*
@@ -654,12 +654,12 @@ static void print_path(const char *path, const char *prefix, enum format_type fo
 	 * 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))
+	if (!prefix && (format != PATH_FORMAT_DEFAULT || def != PATH_DEFAULT_RELATIVE_IF_SHARED))
 		prefix = cwd = xgetcwd();
-	if (format == FORMAT_DEFAULT && def == DEFAULT_UNMODIFIED) {
+	if (format == PATH_FORMAT_DEFAULT && def == PATH_DEFAULT_UNMODIFIED) {
 		puts(path);
-	} else if (format == FORMAT_RELATIVE ||
-		  (format == FORMAT_DEFAULT && def == DEFAULT_RELATIVE)) {
+	} else if (format == PATH_FORMAT_RELATIVE ||
+		  (format == PATH_FORMAT_DEFAULT && def == PATH_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,
@@ -679,7 +679,7 @@ static void print_path(const char *path, const char *prefix, enum format_type fo
 		strbuf_release(&buf);
 		strbuf_release(&realbuf);
 		strbuf_release(&prefixbuf);
-	} else if (format == FORMAT_DEFAULT && def == DEFAULT_RELATIVE_IF_SHARED) {
+	} else if (format == PATH_FORMAT_DEFAULT && def == PATH_DEFAULT_RELATIVE_IF_SHARED) {
 		struct strbuf buf = STRBUF_INIT;
 		puts(relative_path(path, prefix, &buf));
 		strbuf_release(&buf);
@@ -708,7 +708,7 @@ int cmd_rev_parse(int argc,
 	const char *name = NULL;
 	struct strbuf buf = STRBUF_INIT;
 	int seen_end_of_options = 0;
-	enum format_type format = FORMAT_DEFAULT;
+	enum path_format_type format = PATH_FORMAT_DEFAULT;
 
 	show_usage_if_asked(argc, argv, builtin_rev_parse_usage);
 
@@ -789,7 +789,7 @@ int cmd_rev_parse(int argc,
 				print_path(repo_git_path_replace(the_repository, &buf,
 								 "%s", argv[i + 1]), prefix,
 						format,
-						DEFAULT_RELATIVE_IF_SHARED);
+					   PATH_DEFAULT_RELATIVE_IF_SHARED);
 				i++;
 				continue;
 			}
@@ -811,9 +811,9 @@ int cmd_rev_parse(int argc,
 				if (!arg)
 					die(_("--path-format requires an argument"));
 				if (!strcmp(arg, "absolute")) {
-					format = FORMAT_CANONICAL;
+					format = PATH_FORMAT_CANONICAL;
 				} else if (!strcmp(arg, "relative")) {
-					format = FORMAT_RELATIVE;
+					format = PATH_FORMAT_RELATIVE;
 				} else {
 					die(_("unknown argument to --path-format: %s"), arg);
 				}
@@ -977,7 +977,7 @@ int cmd_rev_parse(int argc,
 			if (!strcmp(arg, "--show-toplevel")) {
 				const char *work_tree = repo_get_work_tree(the_repository);
 				if (work_tree)
-					print_path(work_tree, prefix, format, DEFAULT_UNMODIFIED);
+					print_path(work_tree, prefix, format, PATH_DEFAULT_UNMODIFIED);
 				else
 					die(_("this operation must be run in a work tree"));
 				continue;
@@ -985,7 +985,7 @@ int cmd_rev_parse(int argc,
 			if (!strcmp(arg, "--show-superproject-working-tree")) {
 				struct strbuf superproject = STRBUF_INIT;
 				if (get_superproject_working_tree(&superproject))
-					print_path(superproject.buf, prefix, format, DEFAULT_UNMODIFIED);
+					print_path(superproject.buf, prefix, format, PATH_DEFAULT_UNMODIFIED);
 				strbuf_release(&superproject);
 				continue;
 			}
@@ -1020,18 +1020,18 @@ int cmd_rev_parse(int argc,
 				const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
 				char *cwd;
 				int len;
-				enum format_type wanted = format;
+				enum path_format_type wanted = format;
 				if (arg[2] == 'g') {	/* --git-dir */
 					if (gitdir) {
-						print_path(gitdir, prefix, format, DEFAULT_UNMODIFIED);
+						print_path(gitdir, prefix, format, PATH_DEFAULT_UNMODIFIED);
 						continue;
 					}
 					if (!prefix) {
-						print_path(".git", prefix, format, DEFAULT_UNMODIFIED);
+						print_path(".git", prefix, format, PATH_DEFAULT_UNMODIFIED);
 						continue;
 					}
 				} else {		/* --absolute-git-dir */
-					wanted = FORMAT_CANONICAL;
+					wanted = PATH_FORMAT_CANONICAL;
 					if (!gitdir && !prefix)
 						gitdir = ".git";
 					if (gitdir) {
@@ -1047,11 +1047,11 @@ int cmd_rev_parse(int argc,
 				strbuf_reset(&buf);
 				strbuf_addf(&buf, "%s%s.git", cwd, len && cwd[len-1] != '/' ? "/" : "");
 				free(cwd);
-				print_path(buf.buf, prefix, wanted, DEFAULT_CANONICAL);
+				print_path(buf.buf, prefix, wanted, PATH_DEFAULT_CANONICAL);
 				continue;
 			}
 			if (!strcmp(arg, "--git-common-dir")) {
-				print_path(repo_get_common_dir(the_repository), prefix, format, DEFAULT_RELATIVE_IF_SHARED);
+				print_path(repo_get_common_dir(the_repository), prefix, format, PATH_DEFAULT_RELATIVE_IF_SHARED);
 				continue;
 			}
 			if (!strcmp(arg, "--is-inside-git-dir")) {
@@ -1081,7 +1081,7 @@ int cmd_rev_parse(int argc,
 				if (the_repository->index->split_index) {
 					const struct object_id *oid = &the_repository->index->split_index->base_oid;
 					const char *path = repo_git_path_replace(the_repository, &buf, "sharedindex.%s", oid_to_hex(oid));
-					print_path(path, prefix, format, DEFAULT_RELATIVE);
+					print_path(path, prefix, format, PATH_DEFAULT_RELATIVE);
 				}
 				continue;
 			}
-- 
2.50.1 (Apple Git-155)


  reply	other threads:[~2026-02-28 22:44 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-28 22:05 [PATCH 0/4] repo: add support for path-related fields Lucas Seiki Oshiro
2026-02-28 22:05 ` Lucas Seiki Oshiro [this message]
2026-02-28 22:05 ` [PATCH 2/4] path: add new function strbuf_add_path Lucas Seiki Oshiro
2026-02-28 22:05 ` [PATCH 3/4] repo: add the --format-path flag Lucas Seiki Oshiro
2026-02-28 22:05 ` [PATCH 4/4] repo: add the field path.toplevel Lucas Seiki Oshiro
2026-03-01  4:24   ` Tian Yuchen
2026-03-01 20:21     ` Lucas Seiki Oshiro
2026-03-02  4:54       ` Tian Yuchen
2026-03-01  2:58 ` [PATCH 0/4] repo: add support for path-related fields JAYATHEERTH K
2026-03-01  5:45   ` Ayush Jha
2026-03-01  6:50     ` JAYATHEERTH K
2026-03-01 19:55     ` Lucas Seiki Oshiro
2026-03-03  3:27       ` Ayush Jha
2026-03-01 19:49   ` Lucas Seiki Oshiro
2026-03-01 10:44 ` Phillip Wood
2026-03-01 19:40   ` Lucas Seiki Oshiro
2026-03-01 21:25 ` brian m. carlson
2026-03-02 16:38   ` Junio C Hamano
2026-03-02 18:51     ` Tian Yuchen
2026-03-02 21:34       ` Junio C Hamano
2026-03-03  2:48       ` JAYATHEERTH K
2026-03-03  4:32         ` Tian Yuchen
2026-03-03  7:23           ` JAYATHEERTH K
2026-03-03  9:28             ` Tian Yuchen
2026-03-03 10:31               ` JAYATHEERTH K
2026-03-08  0:29   ` Lucas Seiki Oshiro

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=20260228224252.72788-2-lucasseikioshiro@gmail.com \
    --to=lucasseikioshiro@gmail.com \
    --cc=a3205153416@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jayatheerthkulkarni2005@gmail.com \
    --cc=kumarayushjha123@gmail.com \
    --cc=pushkarkumarsingh1970@gmail.com \
    --cc=sandals@crustytoothpaste.net \
    --cc=valusoutrik@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