docs: add headers in MyFirstObjectWalk
In several places, headers need to be included or else the code won't compile. Since this is the first object walk, it would be nice to include them in the tutorial to make it easier to follow. Signed-off-by: John Cai <johncai86@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
John Cai committed
Oct 29, 2021 at 19:52 UTC
7d1b866778043115c0f707cceb8d16e14ac93817
1 file changed
+24
-3
Documentation/MyFirstObjectWalk.txt
+24
-3
@@ -58,8 +58,13 @@ running, enable trace output by setting the environment variable `GIT_TRACE`.
58
59
Add usage text and `-h` handling, like all subcommands should consistently do
60
(our test suite will notice and complain if you fail to do so).
61
+We'll need to include the `parse-options.h` header.
62
63
----
64
+#include "parse-options.h"
65
+
66
+...
67
+
68
int cmd_walken(int argc, const char **argv, const char *prefix)
69
{
70
const char * const walken_usage[] = {
@@ -195,9 +200,14 @@ Similarly to the default values, we don't have anything to do here yet
200
ourselves; however, we should call `git_default_config()` if we aren't calling
201
any other existing config callbacks.
202
198
-Add a new function to `builtin/walken.c`:
203
+Add a new function to `builtin/walken.c`.
204
+We'll also need to include the `config.h` header:
205
206
----
207
+#include "config.h"
208
+
209
+...
210
+
211
static int git_walken_config(const char *var, const char *value, void *cb)
212
{
213
/*
@@ -229,8 +239,14 @@ typically done by calling `repo_init_revisions()` with the repository you intend
239
to target, as well as the `prefix` argument of `cmd_walken` and your `rev_info`
240
struct.
241
232
-Add the `struct rev_info` and the `repo_init_revisions()` call:
242
+Add the `struct rev_info` and the `repo_init_revisions()` call.
243
+We'll also need to include the `revision.h` header:
244
+
245
----
246
+#include "revision.h"
247
+
248
+...
249
+
250
int cmd_walken(int argc, const char **argv, const char *prefix)
251
{
252
/* This can go wherever you like in your declarations.*/
@@ -624,9 +640,14 @@ static void walken_object_walk(struct rev_info *rev)
640
----
641
642
Let's start by calling just the unfiltered walk and reporting our counts.
627
-Complete your implementation of `walken_object_walk()`:
643
+Complete your implementation of `walken_object_walk()`.
644
+We'll also need to include the `list-objects.h` header.
645
646
----
647
+#include "list-objects.h"
648
+
649
+...
650
+
651
traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL);
652
653
printf("commits %d\nblobs %d\ntags %d\ntrees %d\n", commit_count,