Skip to content

Commit 08c3aaf

Browse files
lucasoshirogitster
authored andcommitted
MyFirstContribution: use struct repository in examples
Add the parameter `struct repository *repo` to the cmd_walken function. Since commit 9b1cb50 (builtin: add a repository parameter for builtin functions, 2024-09-13), all the cmd_* have the `repo` parameter and new commands must follow this convention, so the documentation should also be changed. Change the `git_config` calls to `repo_config`, also passing the `repo` parameter, as since 036876a (config: hide functions using `the_repository` by default, 2024-08-13) the non-repo config functions are no longer recommended as they use the global `repository` variable. Helped-by: Karthik Nayak <[email protected]> Signed-off-by: Lucas Seiki Oshiro <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b07857f commit 08c3aaf

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Documentation/MyFirstObjectWalk.adoc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Open up a new file `builtin/walken.c` and set up the command handler:
4343
#include "builtin.h"
4444
#include "trace.h"
4545
46-
int cmd_walken(int argc, const char **argv, const char *prefix)
46+
int cmd_walken(int argc, const char **argv, const char *prefix, struct repository *repo)
4747
{
4848
trace_printf(_("cmd_walken incoming...\n"));
4949
return 0;
@@ -86,7 +86,7 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
8686
Also add the relevant line in `builtin.h` near `cmd_whatchanged()`:
8787

8888
----
89-
int cmd_walken(int argc, const char **argv, const char *prefix);
89+
int cmd_walken(int argc, const char **argv, const char *prefix, struct repository *repo);
9090
----
9191

9292
Include the command in `git.c` in `commands[]` near the entry for `whatchanged`,
@@ -193,7 +193,7 @@ initialization functions.
193193

194194
Next, we should have a look at any relevant configuration settings (i.e.,
195195
settings readable and settable from `git config`). This is done by providing a
196-
callback to `git_config()`; within that callback, you can also invoke methods
196+
callback to `repo_config()`; within that callback, you can also invoke methods
197197
from other components you may need that need to intercept these options. Your
198198
callback will be invoked once per each configuration value which Git knows about
199199
(global, local, worktree, etc.).
@@ -221,14 +221,14 @@ static int git_walken_config(const char *var, const char *value,
221221
}
222222
----
223223

224-
Make sure to invoke `git_config()` with it in your `cmd_walken()`:
224+
Make sure to invoke `repo_config()` with it in your `cmd_walken()`:
225225

226226
----
227-
int cmd_walken(int argc, const char **argv, const char *prefix)
227+
int cmd_walken(int argc, const char **argv, const char *prefix, struct repository *repo)
228228
{
229229
...
230230
231-
git_config(git_walken_config, NULL);
231+
repo_config(repo, git_walken_config, NULL);
232232
233233
...
234234
}
@@ -250,14 +250,14 @@ We'll also need to include the `revision.h` header:
250250
251251
...
252252
253-
int cmd_walken(int argc, const char **argv, const char *prefix)
253+
int cmd_walken(int argc, const char **argv, const char *prefix, struct repository *repo)
254254
{
255255
/* This can go wherever you like in your declarations.*/
256256
struct rev_info rev;
257257
...
258258
259-
/* This should go after the git_config() call. */
260-
repo_init_revisions(the_repository, &rev, prefix);
259+
/* This should go after the repo_config() call. */
260+
repo_init_revisions(repo, &rev, prefix);
261261
262262
...
263263
}
@@ -305,7 +305,7 @@ Then let's invoke `final_rev_info_setup()` after the call to
305305
`repo_init_revisions()`:
306306

307307
----
308-
int cmd_walken(int argc, const char **argv, const char *prefix)
308+
int cmd_walken(int argc, const char **argv, const char *prefix, struct repository *repo)
309309
{
310310
...
311311

0 commit comments

Comments
 (0)