From: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
To: gitster@pobox.com
Cc: ben.knoble@gmail.com, git@vger.kernel.org,
jayatheerthkulkarni2005@gmail.com
Subject: [[GSOC][PATCH v4] 3/3] docs: replace git_config with repo_config
Date: Mon, 24 Mar 2025 18:33:43 +0530 [thread overview]
Message-ID: <20250324130343.113629-2-jayatheerthkulkarni2005@gmail.com> (raw)
In-Reply-To: <20250324130343.113629-1-jayatheerthkulkarni2005@gmail.com>
Refactor config handling by replacing git_config(...)
with repo_config(...) for better repository context
awareness and alignment with modern Git practices.
Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
---
Documentation/MyFirstContribution.adoc | 57 ++++++++++++++++++--------
1 file changed, 39 insertions(+), 18 deletions(-)
diff --git a/Documentation/MyFirstContribution.adoc b/Documentation/MyFirstContribution.adoc
index 45efe117ab..04c19ac0b2 100644
--- a/Documentation/MyFirstContribution.adoc
+++ b/Documentation/MyFirstContribution.adoc
@@ -316,26 +316,47 @@ on the command line, including the name of our command. (If `prefix` is empty
for you, try `cd Documentation/ && ../bin-wrappers/git psuh`). That's not so
helpful. So what other context can we get?
-Add a line to `#include "config.h"`. Then, add the following bits to the
+Add `#include "config.h"` and `#include "repository.h"`. Then, add the following bits to the
function body:
----
- const char *cfg_name;
+#include "builtin.h"
+#include "gettext.h"
+#include "config.h"
+#include "repository.h"
-...
+int cmd_psuh(int argc, const char **argv, const char *prefix, struct repository *repo)
+{
+ const char *cfg_name;
+
+ printf(Q_("Your args (there is %d):\n",
+ "Your args (there are %d):\n",
+ argc),
+ argc);
+
+ for (int i = 0; i < argc; i++) {
+ printf("%d: %s\n", i, argv[i]);
+ }
- git_config(git_default_config, NULL);
- if (git_config_get_string_tmp("user.name", &cfg_name) > 0)
- printf(_("No name is found in config\n"));
- else
- printf(_("Your name: %s\n"), cfg_name);
+ printf(_("Your current working directory:\n<top-level>%s%s\n"),
+ prefix ? "/" : "", prefix ? prefix : "");
+
+ repo_config(repo, git_default_config, NULL);
+
+ if (repo_config_get_string_tmp(repo, "user.name", &cfg_name))
+ printf(_("No name is found in config\n"));
+ else
+ printf(_("Your name: %s\n"), cfg_name);
+
+ return 0;
+}
----
-`git_config()` will grab the configuration from config files known to Git and
-apply standard precedence rules. `git_config_get_string_tmp()` will look up
+`repo_config()` will grab the configuration from config files known to Git and
+apply standard precedence rules. `repo_config_get_string_tmp()` will look up
a specific key ("user.name") and give you the value. There are a number of
single-key lookup functions like this one; you can see them all (and more info
-about how to use `git_config()`) in `Documentation/technical/api-config.adoc`.
+about how to use `repo_config()` ) in `Documentation/git-config.adoc`.
You should see that the name printed matches the one you see when you run:
@@ -383,8 +404,8 @@ prepare it, and print its contents:
...
- wt_status_prepare(the_repository, &status);
- git_config(git_default_config, &status);
+ wt_status_prepare(repo, &status);
+ repo_config(repo, git_default_config, &status);
...
@@ -1093,11 +1114,11 @@ The one generated for `psuh` from the sample implementation looks like this:
----
Documentation/git-psuh.adoc | 40 +++++++++++++++++++++
- Makefile | 1 +
- builtin.h | 1 +
- builtin/psuh.c | 73 ++++++++++++++++++++++++++++++++++++++
- git.c | 1 +
- t/t9999-psuh-tutorial.sh | 12 +++++++
+ Makefile | 1 +
+ builtin.h | 1 +
+ builtin/psuh.c | 73 ++++++++++++++++++++++++++++++++++++++
+ git.c | 1 +
+ t/t9999-psuh-tutorial.sh | 12 +++++++
6 files changed, 128 insertions(+)
create mode 100644 Documentation/git-psuh.adoc
create mode 100644 builtin/psuh.c
--
2.48.1
next prev parent reply other threads:[~2025-03-24 13:04 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-15 18:15 [GSOC][PATCH 1/3] Remove outdated mentoring mailing list reference and clarify tutorial prerequisites K Jayatheerth
2025-03-15 18:15 ` [GSOC][PATCH 2/3] Update function signature and UNUSED to include struct repository and modify builtin.h accordingly K Jayatheerth
2025-03-15 18:15 ` [GSOC][PATCH 3/3] Replace git_config(...) with repo_config(...) for modern Git compatibility K Jayatheerth
2025-03-15 18:21 ` JAYATHEERTH K
2025-03-17 21:57 ` [GSOC][PATCH 1/3] Remove outdated mentoring mailing list reference and clarify tutorial prerequisites Junio C Hamano
2025-03-19 17:02 ` [GSOC][PATCH v2] Remove outdated mentoring mailing list reference K Jayatheerth
2025-03-21 10:36 ` Junio C Hamano
2025-03-21 14:30 ` [[GSOC][PATCH v3] 1/3] docs: drop inactive mentoring list, add C prereq K Jayatheerth
2025-03-21 14:30 ` [[GSOC][PATCH v3] 2/3] docs: update function signature, add UNUSED macro K Jayatheerth
2025-03-23 22:08 ` Junio C Hamano
2025-03-21 14:30 ` [[GSOC][PATCH v3] 3/3] docs: replace git_config with repo_config K Jayatheerth
2025-03-23 22:08 ` Junio C Hamano
2025-03-24 1:42 ` JAYATHEERTH K
2025-03-24 4:46 ` Junio C Hamano
2025-03-24 13:03 ` [[GSOC][PATCH v4] 2/3] docs: update function signature, add UNUSED macro K Jayatheerth
2025-03-24 13:03 ` K Jayatheerth [this message]
2025-03-24 13:10 ` [[GSOC][PATCH v3] 3/3] docs: replace git_config with repo_config JAYATHEERTH K
2025-03-26 2:37 ` Junio C Hamano
2025-03-26 3:15 ` JAYATHEERTH K
2025-03-29 17:42 ` JAYATHEERTH K
2025-03-21 14:32 ` [GSOC][PATCH v2] Remove outdated mentoring mailing list reference JAYATHEERTH K
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=20250324130343.113629-2-jayatheerthkulkarni2005@gmail.com \
--to=jayatheerthkulkarni2005@gmail.com \
--cc=ben.knoble@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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;
as well as URLs for NNTP newsgroup(s).