@@ -495,16 +495,6 @@ <h4 id="_gitvger_kernel_org"><a class="anchor" href="#_gitvger_kernel_org"></a><
495495</ div >
496496</ div >
497497< div class ="sect3 ">
498- < h4 id ="
_git_mentoringgooglegroups_com "
> < a class ="
anchor "
href ="
#_git_mentoringgooglegroups_com "
> </ a > < a href ="
https://groups.google.com/forum/#!forum/git-mentoring "
> [email protected] </ a > </ h4 > 499- < div class ="paragraph ">
500- < p > This mailing list is targeted to new contributors and was created as a place to
501- post questions and receive answers outside of the public eye of the main list.
502- Veteran contributors who are especially interested in helping mentor newcomers
503- are present on the list. In order to avoid search indexers, group membership is
504- required to view messages; anyone can join and no approval is required.</ p >
505- </ div >
506- </ div >
507- < div class ="sect3 ">
508498< h4 id ="_git_devel_on_libera_chat "> < a class ="anchor " href ="#_git_devel_on_libera_chat "> </ a > < a href ="https://web.libera.chat/#git-devel "> #git-devel</ a > on Libera Chat</ h4 >
509499< div class ="paragraph ">
510500< p > This IRC channel is for conversations between Git contributors. If someone is
@@ -642,17 +632,41 @@ <h3 id="add-new-command"><a class="anchor" href="#add-new-command"></a>Adding a
642632</ div >
643633< div class ="listingblock ">
644634< div class ="content ">
645- < pre > int cmd_psuh(int argc, const char **argv, const char *prefix)</ pre >
635+ < pre > int cmd_psuh(int argc UNUSED, const char **argv UNUSED,
636+ const char *prefix UNUSED, struct repository *repo UNUSED)</ pre >
646637</ div >
647638</ div >
648639< div class ="paragraph ">
640+ < p > A few things to note:</ p >
641+ </ div >
642+ < div class ="ulist ">
643+ < ul >
644+ < li >
645+ < p > A subcommand implementation takes its command line arguments
646+ in < code > int</ code > < code > argc</ code > + < code > const</ code > < code > char</ code > < code > **argv</ code > , like < code > main</ code > () would.</ p >
647+ </ li >
648+ < li >
649+ < p > It also takes two extra parameters, < code > prefix</ code > and < code > repo</ code > . What
650+ they mean will not be discussed until much later.</ p >
651+ </ li >
652+ < li >
653+ < p > Because this first example will not use any of the parameters,
654+ your compiler will give warnings on unused parameters. As the
655+ list of these four parameters is mandated by the API to add
656+ new built-in commands, you cannot omit them. Instead, you add
657+ < code > UNUSED</ code > to each of them to tell the compiler that you < strong > know</ strong >
658+ you are not (yet) using it.</ p >
659+ </ li >
660+ </ ul >
661+ </ div >
662+ < div class ="paragraph ">
649663< p > We’ll also need to add the declaration of psuh; open up < code > builtin.h</ code > , find the
650664declaration for < code > cmd_pull</ code > , and add a new line for < code > psuh</ code > immediately before it,
651665in order to keep the declarations alphabetically sorted:</ p >
652666</ div >
653667< div class ="listingblock ">
654668< div class ="content ">
655- < pre > int cmd_psuh(int argc, const char **argv, const char *prefix);</ pre >
669+ < pre > int cmd_psuh(int argc, const char **argv, const char *prefix, struct repository *repo );</ pre >
656670</ div >
657671</ div >
658672< div class ="paragraph ">
@@ -681,7 +695,8 @@ <h3 id="add-new-command"><a class="anchor" href="#add-new-command"></a>Adding a
681695</ div >
682696< div class ="listingblock ">
683697< div class ="content ">
684- < pre > int cmd_psuh(int argc, const char **argv, const char *prefix)
698+ < pre > int cmd_psuh(int argc UNUSED, const char **argv UNUSED,
699+ const char *prefix UNUSED, struct repository *repo UNUSED)
685700{
686701 printf(_("Pony saying hello goes here.\n"));
687702 return 0;
@@ -822,8 +837,9 @@ <h3 id="implementation"><a class="anchor" href="#implementation"></a>Implementat
822837Let’s start by having a look at everything we get.</ p >
823838</ div >
824839< div class ="paragraph ">
825- < p > Modify your < code > cmd_psuh</ code > implementation to dump the args you’re passed, keeping
826- existing < code > printf</ code > () calls in place:</ p >
840+ < p > Modify your < code > cmd_psuh</ code > implementation to dump the args you’re passed,
841+ keeping existing < code > printf</ code > () calls in place; because the args are now
842+ used, remove the < code > UNUSED</ code > macro from them:</ p >
827843</ div >
828844< div class ="listingblock ">
829845< div class ="content ">
@@ -849,7 +865,8 @@ <h3 id="implementation"><a class="anchor" href="#implementation"></a>Implementat
849865helpful. So what other context can we get?</ p >
850866</ div >
851867< div class ="paragraph ">
852- < p > Add a line to #include "config.< code > h</ code > ". Then, add the following bits to the
868+ < p > Add a line to #include "config.< code > h</ code > " and #include "repository.< code > h</ code > ".
869+ Then, add the following bits to the function body:
853870function body:</ p >
854871</ div >
855872< div class ="listingblock ">
@@ -858,19 +875,19 @@ <h3 id="implementation"><a class="anchor" href="#implementation"></a>Implementat
858875
859876...
860877
861- git_config( git_default_config, NULL);
862- if (git_config_get_string_tmp( "user.name", &cfg_name) > 0 )
878+ repo_config(repo, git_default_config, NULL);
879+ if (repo_config_get_string_tmp(repo, "user.name", &cfg_name))
863880 printf(_("No name is found in config\n"));
864881 else
865882 printf(_("Your name: %s\n"), cfg_name);</ pre >
866883</ div >
867884</ div >
868885< div class ="paragraph ">
869- < p > < code > git_config </ code > () will grab the configuration from config files known to Git and
870- apply standard precedence rules. < code > git_config_get_string_tmp </ code > () will look up
886+ < p > < code > repo_config </ code > () will grab the configuration from config files known to Git and
887+ apply standard precedence rules. < code > repo_config_get_string_tmp </ code > () will look up
871888a specific key ("user.name") and give you the value. There are a number of
872889single-key lookup functions like this one; you can see them all (and more info
873- about how to use < code > git_config </ code > ()) in < code > Documentation/technical/api-config.adoc</ code > .</ p >
890+ about how to use < code > repo_config </ code > ()) in < code > Documentation/technical/api-config.adoc</ code > .</ p >
874891</ div >
875892< div class ="paragraph ">
876893< p > You should see that the name printed matches the one you see when you run:</ p >
@@ -921,7 +938,7 @@ <h3 id="implementation"><a class="anchor" href="#implementation"></a>Implementat
921938</ div >
922939< div class ="paragraph ">
923940< p > But as we drill down, we can find that < code > status_init_config</ code > () wraps a call
924- to < code > git_config </ code > (). Let’s modify the code we wrote in the previous commit.</ p >
941+ to < code > repo_config </ code > (). Let’s modify the code we wrote in the previous commit.</ p >
925942</ div >
926943< div class ="paragraph ">
927944< p > Be sure to include the header to allow you to use < code > struct</ code > < code > wt_status</ code > :</ p >
@@ -941,8 +958,8 @@ <h3 id="implementation"><a class="anchor" href="#implementation"></a>Implementat
941958
942959...
943960
944- wt_status_prepare(the_repository , &status);
945- git_config( git_default_config, &status);
961+ wt_status_prepare(repo , &status);
962+ repo_config(repo, git_default_config, &status);
946963
947964...
948965
@@ -2239,7 +2256,7 @@ <h3 id="after-approval"><a class="anchor" href="#after-approval"></a>After Revie
22392256</ div >
22402257< div id ="footer ">
22412258< div id ="footer-text ">
2242- Last updated 2025-03-26 00:41:02 -0700
2259+ Last updated 2025-05-27 15:29:51 -0700
22432260</ div >
22442261</ div >
22452262</ body >
0 commit comments