Git development
 help / color / mirror / Atom feed
* [Outreachy][PATCH v2] builtin/var: refactor to use parse-options API
       [not found] <1a146af667a8bcd4>
@ 2026-10-17  0:54 ` Keryle
  2026-10-17 11:25 ` kerylefondji7
  2026-10-17 12:20 ` kerylefondji7
  2 siblings, 0 replies; 4+ messages in thread
From: Keryle @ 2026-10-17  0:54 UTC (permalink / raw)
  To: git; +Cc: gitster, christiancouder, siddharthasthana31

From: keryle <kerylefondji7@gmail.com>

Migrate option handling in 'git var' to the parse-options API.
This update also aligns variable resolution with current Git configuration
and attribute handling.

Signed-off-by: Keryle <keryle@DESKTOP-0SUCFI3>

---
Range-diff against v1:
- Fixed whitespace damage and replaced space-indentation with proper tabs.
- Removed redundant inline comments as suggested.
- Enforced mutual exclusivity between '-l' and positional arguments.
- Aligned variable resolution with Git configuration and attribute handling.

 builtin/var.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/builtin/var.c b/builtin/var.c
index cc3a43cde2..b9234a55eb 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -3,11 +3,9 @@
  *
  * Copyright (C) Eric Biederman, 2005
  */
-
 #define USE_THE_REPOSITORY_VARIABLE
 
 #include "builtin.h"
-
 #include "attr.h"
 #include "config.h"
 #include "editor.h"
@@ -18,8 +16,12 @@
 #include "path.h"
 #include "strbuf.h"
 #include "run-command.h"
+#include "parse-options.h"
 
-static const char var_usage[] = "git var (-l | <variable>)";
+static const char * const var_usage[] = {
+	N_("git var (-l | <variable>)"),
+	NULL
+};
 
 static char *committer(int ident_flag)
 {
@@ -120,6 +122,7 @@ struct git_var {
 	char *(*read)(int);
 	int multivalued;
 };
+
 static struct git_var git_vars[] = {
 	{
 		.name = "GIT_COMMITTER_IDENT",
@@ -221,21 +224,32 @@ int cmd_var(int argc,
 {
 	const struct git_var *git_var;
 	char *val;
+	int list = 0;
 
-	show_usage_if_asked(argc, argv, var_usage);
-	if (argc != 2)
-		usage(var_usage);
+	struct option builtin_var_options[] = {
+		OPT_BOOL('l', "list", &list, N_("list builtin variables")),
+		OPT_END()
+	};
 
-	if (strcmp(argv[1], "-l") == 0) {
+	argc = parse_options(argc, argv, prefix, builtin_var_options,
+			     var_usage, 0);
+
+	if (list) {
+		if (argc > 0)
+			usage(var_usage[0]);
 		repo_config(the_repository, show_config, NULL);
 		list_vars();
 		return 0;
 	}
+
+	if (argc != 1)
+		usage(var_usage[0]);
+
 	repo_config(the_repository, git_default_config, NULL);
 
-	git_var = get_git_var(argv[1]);
+	git_var = get_git_var(argv[0]);
 	if (!git_var)
-		usage(var_usage);
+		usage(var_usage[0]);
 
 	val = git_var->read(IDENT_STRICT);
 	if (!val)
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Outreachy][PATCH v2] builtin/var: refactor to use parse-options API
       [not found] <1a146af667a8bcd4>
  2026-10-17  0:54 ` [Outreachy][PATCH v2] builtin/var: refactor to use parse-options API Keryle
@ 2026-10-17 11:25 ` kerylefondji7
  2026-10-17 11:45   ` Kristoffer Haugsbakk
  2026-10-17 12:20 ` kerylefondji7
  2 siblings, 1 reply; 4+ messages in thread
From: kerylefondji7 @ 2026-10-17 11:25 UTC (permalink / raw)
  To: gitster; +Cc: git, christiancouder, siddharthasthana31, kerylefondji

From: kerylefondji <kerylefondji7@gmail.com>

Migrate option handling in 'git var' to the parse-options API.
This update also aligns variable resolution with current Git configuration
and attribute handling.

Signed-off-by: Keryle Blondeau Fondji Tamekong <keryle@DESKTOP-0SUCFI3>
---
 builtin/var.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/builtin/var.c b/builtin/var.c
index cc3a43cde2..b9234a55eb 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -3,11 +3,9 @@
  *
  * Copyright (C) Eric Biederman, 2005
  */
-
 #define USE_THE_REPOSITORY_VARIABLE
 
 #include "builtin.h"
-
 #include "attr.h"
 #include "config.h"
 #include "editor.h"
@@ -18,8 +16,12 @@
 #include "path.h"
 #include "strbuf.h"
 #include "run-command.h"
+#include "parse-options.h"
 
-static const char var_usage[] = "git var (-l | <variable>)";
+static const char * const var_usage[] = {
+	N_("git var (-l | <variable>)"),
+	NULL
+};
 
 static char *committer(int ident_flag)
 {
@@ -120,6 +122,7 @@ struct git_var {
 	char *(*read)(int);
 	int multivalued;
 };
+
 static struct git_var git_vars[] = {
 	{
 		.name = "GIT_COMMITTER_IDENT",
@@ -221,21 +224,32 @@ int cmd_var(int argc,
 {
 	const struct git_var *git_var;
 	char *val;
+	int list = 0;
 
-	show_usage_if_asked(argc, argv, var_usage);
-	if (argc != 2)
-		usage(var_usage);
+	struct option builtin_var_options[] = {
+		OPT_BOOL('l', "list", &list, N_("list builtin variables")),
+		OPT_END()
+	};
 
-	if (strcmp(argv[1], "-l") == 0) {
+	argc = parse_options(argc, argv, prefix, builtin_var_options,
+			     var_usage, 0);
+
+	if (list) {
+		if (argc > 0)
+			usage(var_usage[0]);
 		repo_config(the_repository, show_config, NULL);
 		list_vars();
 		return 0;
 	}
+
+	if (argc != 1)
+		usage(var_usage[0]);
+
 	repo_config(the_repository, git_default_config, NULL);
 
-	git_var = get_git_var(argv[1]);
+	git_var = get_git_var(argv[0]);
 	if (!git_var)
-		usage(var_usage);
+		usage(var_usage[0]);
 
 	val = git_var->read(IDENT_STRICT);
 	if (!val)
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Outreachy][PATCH v2] builtin/var: refactor to use parse-options API
  2026-10-17 11:25 ` kerylefondji7
@ 2026-10-17 11:45   ` Kristoffer Haugsbakk
  0 siblings, 0 replies; 4+ messages in thread
From: Kristoffer Haugsbakk @ 2026-10-17 11:45 UTC (permalink / raw)
  To: kerylefondji7, Junio C Hamano; +Cc: git, christiancouder, Siddharth Asthana

On Sat, Oct 17, 2026, at 13:25, kerylefondji7@gmail.com wrote:
> From: kerylefondji <kerylefondji7@gmail.com>

The author part should generally be 
your real name FYI. See SubmittingsPatches
about name or “real name”.

>
> Migrate option handling in 'git var' to the parse-options API.
> This update also aligns variable resolution with current Git configuration
> and attribute handling.
>
> Signed-off-by: Keryle Blondeau Fondji Tamekong <keryle@DESKTOP-0SUCFI3>

This looks like a real name. But the email is
not real. It should be the gmail one from
the author part.


> ---
> [snip]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Outreachy][PATCH v2] builtin/var: refactor to use parse-options API
       [not found] <1a146af667a8bcd4>
  2026-10-17  0:54 ` [Outreachy][PATCH v2] builtin/var: refactor to use parse-options API Keryle
  2026-10-17 11:25 ` kerylefondji7
@ 2026-10-17 12:20 ` kerylefondji7
  2 siblings, 0 replies; 4+ messages in thread
From: kerylefondji7 @ 2026-10-17 12:20 UTC (permalink / raw)
  To: kristofferhaugsbakk; +Cc: git, christiancouder, siddharthasthana31

Hi Kristoffer,

Thank you very much for your feedback and pointing this out. I will fix this immediately with my correct email address for the next version.

Best regards,
Keryle

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-17 12:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1a146af667a8bcd4>
2026-10-17  0:54 ` [Outreachy][PATCH v2] builtin/var: refactor to use parse-options API Keryle
2026-10-17 11:25 ` kerylefondji7
2026-10-17 11:45   ` Kristoffer Haugsbakk
2026-10-17 12:20 ` kerylefondji7

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox