Update MyFirstContribution.adoc to current codebase
PATCH 1/1 Update MyFirstContribution.adoc to current codebase
This updates MyFirstContribution.adoc to correct outdated information, improve clarity for new contributors following the guide.
Key changes:
- Updated the function signature of cmd_psuh to match the current Git codebase, adding struct repository *repo as required.
- Added a note on using the UNUSED macro to suppress compiler warnings for unused function parameters.
- Replaced git_config(...) with repo_config(...) in documentation, aligning with modern Git practices.
- Removed mention of the deprecated [email protected].
- Renamed Documentation/git-psuh.txt to Documentation/git-psuh.adoc to follow the
correct documentation format.
- Updated .txt references to .adoc
wherever applicable for consistency.
These changes make it easier for
new contributors to follow the tutorial without running into compilation errors or outdated references.
--- Documentation/MyFirstContribution.adoc | 83 +++++++++++++++++--------- 1 file changed, 55 insertions(+), 28 deletions(-)
Documentation/MyFirstContribution.adoc +55 -28
@@ -13,6 +13,7 @@ the Git tree, sending it for review, and making changes based on comments. This tutorial assumes you're already fairly familiar with using Git to manage source code. The Git workflow steps will largely remain unexplained. +This tutorial also assumes you know/understand C programming language in a good capacity. [[related-reading]] === Related Reading
@@ -40,13 +41,6 @@ the list by sending an email to <[email protected]> The https://lore.kernel.org/git[archive] of this mailing list is available to view in a browser. -==== https://groups.google.com/forum/#!forum/git-mentoring[[email protected]] - -This mailing list is targeted to new contributors and was created as a place to -post questions and receive answers outside of the public eye of the main list. -Veteran contributors who are especially interested in helping mentor newcomers -are present on the list. In order to avoid search indexers, group membership is -required to view messages; anyone can join and no approval is required. ==== https://web.libera.chat/#git-devel[#git-devel] on Libera Chat
@@ -149,8 +143,14 @@ subcommand and contained within `builtin/`. So it makes sense to implement your command in `builtin/psuh.c`. Create that file, and within it, write the entry point for your command in a function matching the style and signature: +The following line represents the function signature for any builtin/<filename.c> file that we add: +---- +int cmd_psuh(int argc, const char **argv, const char *prefix, struct repository *repo) ---- -int cmd_psuh(int argc, const char **argv, const char *prefix) +Before proceeding further, we should use the UNUSED macro to suppress warnings about unused parameters in the function. +This prevents the compiler from generating warnings when certain parameters are not used within the function body: +---- +int cmd_psuh(int argc UNUSED, const char **argv UNUSED, const char *prefix UNUSED, struct repository *repo UNUSED) ---- We'll also need to add the declaration of psuh; open up `builtin.h`, find the
@@ -158,7 +158,7 @@ declaration for `cmd_pull`, and add a new line for `psuh` immediately before it, in order to keep the declarations alphabetically sorted: ---- -int cmd_psuh(int argc, const char **argv, const char *prefix); +int cmd_psuh(int argc, const char **argv, const char *prefix, struct repository *repo); ---- Be sure to `#include "builtin.h"` in your `psuh.c`. You'll also need to
@@ -174,7 +174,7 @@ Throughout the tutorial, we will mark strings for translation as necessary; you should also do so when writing your user-facing commands in the future. ---- -int cmd_psuh(int argc, const char **argv, const char *prefix) +int cmd_psuh(int argc UNUSED, const char **argv UNUSED, const char *prefix UNUSED, struct repository *repo UNUSED) { printf(_("Pony saying hello goes here.\n")); return 0;
@@ -205,6 +205,9 @@ with the command name, a function pointer to the command implementation, and a setup option flag. For now, let's keep mimicking `push`. Find the line where `cmd_push` is registered, copy it, and modify it for `cmd_psuh`, placing the new line in alphabetical order (immediately before `cmd_pull`). +---- +{ "psuh", cmd_psuh, RUN_SETUP} +---- The options are documented in `builtin.h` under "Adding a new built-in." Since we hope to print some data about the user's current workspace context later,
@@ -291,6 +294,8 @@ Modify your `cmd_psuh` implementation to dump the args you're passed, keeping existing `printf()` calls in place: ---- +int cmd_psuh(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) +{ int i; ...
@@ -304,6 +309,7 @@ existing `printf()` calls in place: printf(_("Your current working directory:\n<top-level>%s%s\n"), prefix ? "/" : "", prefix ? prefix : ""); + ... ----
@@ -312,26 +318,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" // Required for repo_config_get_string_tmp() -... +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]); + } + + printf(_("Your current working directory:\n<top-level>%s%s\n"), + prefix ? "/" : "", prefix ? prefix : ""); - 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); + 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:
@@ -379,8 +406,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); ...
@@ -1089,11 +1116,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
Signature · 1 line
2.48.1
Quoted 4 lines · K Jayatheerth
This updates MyFirstContribution.adoc to correct outdated information, improve clarity for new contributors following the guide.
Quoted 14 lines
Key changes:
- Updated the function signature ofcmd_psuhto match the current Git codebase, addingstruct repository *repoas required.
- Added a note on using theUNUSEDmacro to suppress compiler warnings for unused function parameters.
- Replacedgit_config(...)withrepo_config(...)in documentation, aligning with modern Git practices.
- Removed mention of the deprecated[email protected].
- RenamedDocumentation/git-psuh.txttoDocumentation/git-psuh.adocto follow the
correct documentation format.
- Updated.txtreferences to.adoc
wherever applicable for consistency.
I'm in a poor position to judge, but I suspect reviewing this commit would be easier if each bullet was a separate commit. See Documentation/SubmittingPatches [[separate-commits]] (HTML:
https://git-scm.com/docs/SubmittingPatches#separate-commits).
Quoted 4 lines
These changes make it easier for
new contributors to follow the tutorial without running into compilation errors or outdated references.
Agreed as discussed in the other thread, thanks for doing this!
Quoted 33 lines
Signed-off-by K Jayatheerth <[email protected]>--- Documentation/MyFirstContribution.adoc | 83 +++++++++++++++++--------- 1 file changed, 55 insertions(+), 28 deletions(-)Documentation/MyFirstContribution.adoc +1
-7@@ -13,6 +13,7 @@ the Git tree, sending it for review, and making changes based on comments. This tutorial assumes you're already fairly familiar with using Git to manage source code. The Git workflow steps will largely remain unexplained. +This tutorial also assumes you know/understand C programming language in a good capacity. [[related-reading]] === Related Reading@@ -40,13 +41,6 @@ the list by sending an email to <[email protected]> The https://lore.kernel.org/git[archive] of this mailing list is available to view in a browser. -==== https://groups.google.com/forum/#!forum/git-mentoring[[email protected]] - -This mailing list is targeted to new contributors and was created as a place to -post questions and receive answers outside of the public eye of the main list. -Veteran contributors who are especially interested in helping mentor newcomers -are present on the list. In order to avoid search indexers, group membership is -required to view messages; anyone can join and no approval is required. ==== https://web.libera.chat/#git-devel[#git-devel] on Libera Chat
Documentation/MyFirstContribution.adoc subcommand and contained within `builtin/`. So it makes sense to implement your · line 146
Quoted 4 lines
Documentation/MyFirstContribution.adoc +1
-0@@ -149,8 +143,14 @@ subcommand and contained within `builtin/`. So it makes sense to implement your command in `builtin/psuh.c`. Create that file, and within it, write the entry point for your command in a function matching the style and signature: +The following line represents the function signature for any builtin/<filename.c> file that we add:
This line doesn't look necessary, or should at least replace the sentence immediately prior (which shows up in the hunk context).
Quoted 147 lines
Documentation/MyFirstContribution.adoc +53
-22+---- +int cmd_psuh(int argc, const char **argv, const char *prefix, struct repository *repo) ---- -int cmd_psuh(int argc, const char **argv, const char *prefix) +Before proceeding further, we should use the UNUSED macro to suppress warnings about unused parameters in the function. +This prevents the compiler from generating warnings when certain parameters are not used within the function body: +---- +int cmd_psuh(int argc UNUSED, const char **argv UNUSED, const char *prefix UNUSED, struct repository *repo UNUSED) ---- We'll also need to add the declaration of psuh; open up `builtin.h`, find the@@ -158,7 +158,7 @@ declaration for `cmd_pull`, and add a new line for `psuh` immediately before it, in order to keep the declarations alphabetically sorted: ---- -int cmd_psuh(int argc, const char **argv, const char *prefix); +int cmd_psuh(int argc, const char **argv, const char *prefix, struct repository *repo); ---- Be sure to `#include "builtin.h"` in your `psuh.c`. You'll also need to@@ -174,7 +174,7 @@ Throughout the tutorial, we will mark strings for translation as necessary; you should also do so when writing your user-facing commands in the future. ---- -int cmd_psuh(int argc, const char **argv, const char *prefix) +int cmd_psuh(int argc UNUSED, const char **argv UNUSED, const char *prefix UNUSED, struct repository *repo UNUSED) { printf(_("Pony saying hello goes here.\n")); return 0;@@ -205,6 +205,9 @@ with the command name, a function pointer to the command implementation, and a setup option flag. For now, let's keep mimicking `push`. Find the line where `cmd_push` is registered, copy it, and modify it for `cmd_psuh`, placing the new line in alphabetical order (immediately before `cmd_pull`). +---- +{ "psuh", cmd_psuh, RUN_SETUP} +---- The options are documented in `builtin.h` under "Adding a new built-in." Since we hope to print some data about the user's current workspace context later,@@ -291,6 +294,8 @@ Modify your `cmd_psuh` implementation to dump the args you're passed, keeping existing `printf()` calls in place: ---- +int cmd_psuh(int argc, const char **argv, const char *prefix, struct repository *repo UNUSED) +{ int i;@@ -304,6 +309,7 @@ existing `printf()` calls in place: printf(_("Your current working directory:\n<top-level>%s%s\n"), prefix ? "/" : "", prefix ? prefix : ""); + ... ----@@ -312,26 +318,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" // Required for repo_config_get_string_tmp() -... +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]); + } + + printf(_("Your current working directory:\n<top-level>%s%s\n"), + prefix ? "/" : "", prefix ? prefix : ""); - 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); + 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:@@ -379,8 +406,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);@@ -1089,11 +1116,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
Signature · 1 line
D. Ben Knoble
Hey Ben,
thanks for the response
Quoted 6 lines
I'm in a poor position to judge, but I suspect reviewing this commit would be easier if each bullet was a separate commit. See
Documentation/SubmittingPatches[[separate-commits]] (HTML:
https://git-scm.com/docs/SubmittingPatches#separate-commits).
Actually that's an amazing point. I was thinking the same and will start a new patch with individual bullet patches within a thread as soon as possible.
Quoted 9 lines
Agreed as discussed in the other thread, thanks for doing this!
Quoted 6 lines
...
Documentation/MyFirstContribution.adoc +0
-0@@ -149,8 +143,14 @@ subcommand and contained within `builtin/`. So it makes sense to implement your command in `builtin/psuh.c`. Create that file, and within it, write the entry point for your command in a function matching the style and signature:
Quoted 5 lines
Documentation/MyFirstContribution.adoc subcommand and contained within `builtin/`. So it makes sense to implement your · line 146
Quoted 1 line
Documentation/MyFirstContribution.adoc +1
-0+The following line represents the function signature for any builtin/<filename.c> file that we add:This line doesn't look necessary, or should at least replace the sentence immediately prior (which shows up in the hunk context).
Ok I will once check and make sure the updated patch has this rectified. Thanks for the feedback
Quoted 6 lines
Review subcommand and contained within `builtin/`. So it makes sense to implement your · line 147
Quoted 1 line
(quoted diff) +1
-0+------
D. Ben Knoble
Thanks,
Jay