Skip to content

Commit 7bb506d

Browse files
jayatheerthkulkarnigitster
authored andcommitted
Docs: Add cmd_psuh with repo and UNUSED removal
This commit improves the `cmd_psuh` documentation example by: Correcting the function signature to include struct repository *repo. Makes the signature accurate and consistent with typical Git built-in commands. Removing the `UNUSED` macros from the `cmd_psuh` function arguments (argc, argv, prefix, repo). This is done because the example now uses these arguments. Showing how to access the repository's Git directory (repo->gitdir) within the cmd_psuh function. This provides a practical example of how to use the repo argument and repository-related information. Keeps your existing printf() calls in place. This lets the users see the arguments which is given to the function. This enhanced example provides a more complete illustration of Adding a Git built-in command and use the repository argument. Signed-off-by: K Jayatheerth <[email protected]>
1 parent 2b3f23b commit 7bb506d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Documentation/MyFirstContribution.adoc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ declaration for `cmd_pull`, and add a new line for `psuh` immediately before it,
158158
in order to keep the declarations alphabetically sorted:
159159

160160
----
161-
int cmd_psuh(int argc, const char **argv, const char *prefix);
161+
int cmd_psuh(int argc, const char **argv, const char *prefix, struct repository *repo);
162162
----
163163

164164
Be sure to `#include "builtin.h"` in your `psuh.c`. You'll also need to
@@ -174,7 +174,8 @@ Throughout the tutorial, we will mark strings for translation as necessary; you
174174
should also do so when writing your user-facing commands in the future.
175175

176176
----
177-
int cmd_psuh(int argc, const char **argv, const char *prefix)
177+
int cmd_psuh(int argc UNUSED, const char **argv UNUSED,
178+
const char *prefix UNUSED, struct repository *repo UNUSED)
178179
{
179180
printf(_("Pony saying hello goes here.\n"));
180181
return 0;
@@ -287,10 +288,14 @@ on the reference implementation linked at the top of this document.
287288
It's probably useful to do at least something besides printing out a string.
288289
Let's start by having a look at everything we get.
289290

290-
Modify your `cmd_psuh` implementation to dump the args you're passed, keeping
291+
Modify your `cmd_psuh` implementation to dump the args you're passed
292+
and removing the UNUSED macro from them, keeping
291293
existing `printf()` calls in place:
292294

293295
----
296+
int cmd_psuh(int argc, const char **argv,
297+
const char *prefix, struct repository *repo)
298+
{
294299
int i;
295300
296301
...
@@ -305,6 +310,14 @@ existing `printf()` calls in place:
305310
printf(_("Your current working directory:\n<top-level>%s%s\n"),
306311
prefix ? "/" : "", prefix ? prefix : "");
307312
313+
if (repo && repo->gitdir) {
314+
printf(_("Git directory: %s\n"), repo->gitdir);
315+
} else {
316+
printf(_("No Git directory found.\n"));
317+
}
318+
319+
...
320+
}
308321
----
309322

310323
Build and try it. As you may expect, there's pretty much just whatever we give

0 commit comments

Comments
 (0)