git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/4] Docs: Add cmd_psuh with repo and UNUSED removal

From
Emily Shaffer <nasamuffin@google.com>
Date
May 16, 2025, 18:12 UTC
Message-ID
<aCeAIqwvEVOdrsMg@google.com>
In-Reply-To
<20250416061450.25695-4-jayatheerthkulkarni2005@gmail.com>
On Wed, Apr 16, 2025 at 11:44:49AM +0530, K Jayatheerth wrote:
Show 20 quoted lines
> 
> 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.

As I said for the prior patch, please revise the commit message; we don't need the line by line description of what you're doing in the diff below as we can read the diff :)

The important part is pointing out that the codebase has moved on to require UNUSED and passing around a repository object, and that it's interesting for newbies to see what's inside of `repo` in this learning exercise.

Show 36 quoted lines
> 
> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
> ---
>  Documentation/MyFirstContribution.adoc | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/MyFirstContribution.adoc b/Documentation/MyFirstContribution.adoc
> index b463d42f63..ed6dcc1fc6 100644
> --- a/Documentation/MyFirstContribution.adoc
> +++ b/Documentation/MyFirstContribution.adoc
> @@ -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,8 @@ 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;
> @@ -287,10 +288,14 @@ on the reference implementation linked at the top of this document.
>  It's probably useful to do at least something besides printing out a string.
>  Let's start by having a look at everything we get.
>  
> -Modify your `cmd_psuh` implementation to dump the args you're passed, keeping
> +Modify your `cmd_psuh` implementation to dump the args you're passed
> +and removing the UNUSED macro from them, keeping
"Modify ... and removing" mixes up tenses. Better to say,

Modify your `cmd_psuh` implementation to dump the args you're passed, keeping existing `printf()` calls in place; because the args are now used, remove the `UNUSED` macro from them:

Show 18 quoted lines
>  existing `printf()` calls in place:
>  
>  ----
> +int cmd_psuh(int argc, const char **argv, 
> +			const char *prefix, struct repository *repo)
> +{
>  	int i;
>  
>  	...
> @@ -305,6 +310,14 @@ existing `printf()` calls in place:
>  	printf(_("Your current working directory:\n<top-level>%s%s\n"),
>  	       prefix ? "/" : "", prefix ? prefix : "");
>  
> +	if (repo && repo->gitdir) {
> +        printf(_("Git directory: %s\n"), repo->gitdir);
> +    } else {
> +        printf(_("No Git directory found.\n"));
> +    }

Your whitespace is wonky here, Git uses tabs, not spaces. Double check it, please :)

Show 10 quoted lines
> +
> +	...
> +}
>  ----
>  
>  Build and try it. As you may expect, there's pretty much just whatever we give
> -- 
> 2.49.GIT
> 
> 
Previous: K JayatheerthNext: K Jayatheerth
Message 6 of 37 in “update MyFirstContribution with current code base”
  1. 0/4 update MyFirstContribution with current code baseK Jayatheerth, Apr 16, 2025
  2. 1/4 Remove unused git-mentoring mailing listK Jayatheerth, Apr 16, 2025
  3. 2/4 Docs: Correct cmd_psuh and Explain UNUSED macroK Jayatheerth, Apr 16, 2025
  4. Emily ShafferMay 16, 2025
  5. 3/4 Docs: Add cmd_psuh with repo and UNUSED removalK Jayatheerth, Apr 16, 2025
  6. Emily ShafferMay 16, 2025
  7. 1/3 docs: remove unused mentoring mailing list referenceK Jayatheerth, May 16, 2025
  8. 2/3 docs: clarify cmd_psuh signature and explain UNUSED macroK Jayatheerth, May 16, 2025
  9. Junio C HamanoMay 17, 2025
  10. Junio C HamanoMay 17, 2025
  11. 0/3 Update MyFirstContribution.adoc to follow modern practicesK Jayatheerth, May 18, 2025
  12. 1/3 docs: remove unused mentoring mailing list referenceK Jayatheerth, May 18, 2025
  13. 2/3 docs: clarify cmd_psuh signature and explain UNUSED macroK Jayatheerth, May 18, 2025
  14. 3/3 docs: replace git_config to repo_configK Jayatheerth, May 18, 2025
  15. JAYATHEERTH KMay 18, 2025
  16. 3/3 docs: replace git_config to repo_configK Jayatheerth, May 16, 2025
  17. Junio C HamanoMay 17, 2025
  18. Emily ShafferMay 16, 2025
  19. Junio C HamanoMay 17, 2025
  20. 0/3 Update MyFirstContribution.adoc to follow modern practicesK Jayatheerth, May 17, 2025
  21. 1/3 docs: remove unused mentoring mailing list referenceK Jayatheerth, May 17, 2025
  22. 2/3 docs: clarify cmd_psuh signature and explain UNUSED macroK Jayatheerth, May 17, 2025
  23. 3/3 docs: replace git_config to repo_configK Jayatheerth, May 17, 2025
  24. 4/4 cmd_psuh: Prefer repo_config for config lookupK Jayatheerth, Apr 16, 2025
  25. Emily ShafferMay 16, 2025
  26. JAYATHEERTH KMay 16, 2025
  27. Junio C HamanoApr 16, 2025
  28. JAYATHEERTH KApr 16, 2025
  29. JAYATHEERTH KMay 13, 2025
  30. Junio C HamanoMay 14, 2025
  31. JAYATHEERTH KMay 14, 2025
  32. Emily ShafferMay 15, 2025
  33. JAYATHEERTH KMay 16, 2025
  34. Junio C HamanoMay 16, 2025
  35. JAYATHEERTH KMay 16, 2025
  36. D. Ben KnobleMay 20, 2025
  37. Junio C HamanoMay 17, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.