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

[PATCH v3 2/3] docs: clarify cmd_psuh signature and explain UNUSED macro

From
K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Date
May 18, 2025, 07:34 UTC
Message-ID
<20250518073442.72666-3-jayatheerthkulkarni2005@gmail.com>
In-Reply-To
<20250518073442.72666-1-jayatheerthkulkarni2005@gmail.com>

The sample program, as written, would no longer build for at least two reasons:

    - Since this document was first written, the calling convention
      to subcommand implementation has changed, and now cmd_psuh()
      needs to accept the fourth parameter, repository.
    - These days, compiler warning options for developers include
      one that detects and complains about unused parameters, so
      ones that are deliberately unused have to be marked as such.

Update the old-style examples to adjust to the current practices, with explanations as needed.

Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
---
 Documentation/MyFirstContribution.adoc | 28 +++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/Documentation/MyFirstContribution.adoc b/Documentation/MyFirstContribution.adoc
index ef190d8748..da15d43d1f 100644
--- a/Documentation/MyFirstContribution.adoc
+++ b/Documentation/MyFirstContribution.adoc
@@ -142,15 +142,31 @@ 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:
 
 ----
-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)
 ----
 
+A few things to note:
+
+* A subcommand implementation takes its command line arguments
+  in `int argc` + `const char **argv`, like `main()` would.
+
+* It also takes two extra parameters, `prefix` and `repo`. What
+  they mean will not be discussed until much later.
+
+* Because this first example will not use any of the parameters,
+  your compiler will give warnings on unused parameters. As the
+  list of these four parameters is mandated by the API to add
+  new built-in commands, you cannot omit them. Instead, you add
+  `UNUSED` to each of them to tell the compiler that you *know*
+  you are not (yet) using it.
+
 We'll also need to add the declaration of psuh; open up `builtin.h`, find the
 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
@@ -166,7 +182,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;
@@ -279,8 +296,9 @@ 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
-existing `printf()` calls in place:
+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:
 
 ----
 	int i;
-- 
2.49.GIT
Previous: K JayatheerthNext: K Jayatheerth
Message 13 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.