@@ -495,16 +495,6 @@ <h4 id="_gitvger_kernel_org"><a class="anchor" href="#_gitvger_kernel_org"></a><
495
495
</ div >
496
496
</ div >
497
497
< 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 ">
508
498
< 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 >
509
499
< div class ="paragraph ">
510
500
< 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
642
632
</ div >
643
633
< div class ="listingblock ">
644
634
< 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 >
646
637
</ div >
647
638
</ div >
648
639
< 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 ">
649
663
< p > We’ll also need to add the declaration of psuh; open up < code > builtin.h</ code > , find the
650
664
declaration for < code > cmd_pull</ code > , and add a new line for < code > psuh</ code > immediately before it,
651
665
in order to keep the declarations alphabetically sorted:</ p >
652
666
</ div >
653
667
< div class ="listingblock ">
654
668
< 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 >
656
670
</ div >
657
671
</ div >
658
672
< div class ="paragraph ">
@@ -681,7 +695,8 @@ <h3 id="add-new-command"><a class="anchor" href="#add-new-command"></a>Adding a
681
695
</ div >
682
696
< div class ="listingblock ">
683
697
< 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)
685
700
{
686
701
printf(_("Pony saying hello goes here.\n"));
687
702
return 0;
@@ -822,8 +837,9 @@ <h3 id="implementation"><a class="anchor" href="#implementation"></a>Implementat
822
837
Let’s start by having a look at everything we get.</ p >
823
838
</ div >
824
839
< 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 >
827
843
</ div >
828
844
< div class ="listingblock ">
829
845
< div class ="content ">
@@ -849,7 +865,8 @@ <h3 id="implementation"><a class="anchor" href="#implementation"></a>Implementat
849
865
helpful. So what other context can we get?</ p >
850
866
</ div >
851
867
< 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:
853
870
function body:</ p >
854
871
</ div >
855
872
< div class ="listingblock ">
@@ -858,19 +875,19 @@ <h3 id="implementation"><a class="anchor" href="#implementation"></a>Implementat
858
875
859
876
...
860
877
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))
863
880
printf(_("No name is found in config\n"));
864
881
else
865
882
printf(_("Your name: %s\n"), cfg_name);</ pre >
866
883
</ div >
867
884
</ div >
868
885
< 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
871
888
a specific key ("user.name") and give you the value. There are a number of
872
889
single-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 >
874
891
</ div >
875
892
< div class ="paragraph ">
876
893
< 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
921
938
</ div >
922
939
< div class ="paragraph ">
923
940
< 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 >
925
942
</ div >
926
943
< div class ="paragraph ">
927
944
< 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
941
958
942
959
...
943
960
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);
946
963
947
964
...
948
965
@@ -2239,7 +2256,7 @@ <h3 id="after-approval"><a class="anchor" href="#after-approval"></a>After Revie
2239
2256
</ div >
2240
2257
< div id ="footer ">
2241
2258
< div id ="footer-text ">
2242
- Last updated 2025-03-26 00:41:02 -0700
2259
+ Last updated 2025-05-27 15:29:51 -0700
2243
2260
</ div >
2244
2261
</ div >
2245
2262
</ body >
0 commit comments