# [PATCH 0/5] Fixes for Documentation/MyFirstObjectWalk.txt

11 messages from 2024-03-11 to 2024-03-12. Participants: Dirk Gouders, Junio C Hamano.
Thread: https://gitlist.dev/t/61095

## Dirk Gouders, 2024-03-11 21:36

Subject: [PATCH 0/5] Fixes for Documentation/MyFirstObjectWalk.txt
Message-ID: <cover.1710192973.git.dirk@gouders.net>
URL: https://gitlist.dev/e/cover.1710192973.git.dirk%40gouders.net

```
This series contains fixes for some problems in
Documentation/MyFirstObjectWalk.txt that I noticed while working
through that document.

All patches except [4/5] fix real errors that cause comilation
failures or don't produce the wanted output.
With the fix in [3/5] I'm rather uncertain if it is correct and I
would like to ask for special attention, here.

For this first round I send separate patches in the hope that
simplifies reviews and also, because the reasons for those problems
differ.  Finally, those patches could be merged into one should this be
more appropriate.

Dirk Gouders (5):
  MyFirstObjectWalk: use additional arg in config_fn_t
  MyFirstObjectWalk: fix misspelled "builtins/"
  MyFirstObjectWalk: fix filtered object walk
  MyFirstObjectWalk: fix description for counting omitted objects
  MyFirstObjectWalk: add stderr to pipe processing

 Documentation/MyFirstObjectWalk.txt | 36 ++++++++++++++++-------------
 1 file changed, 20 insertions(+), 16 deletions(-)

-- 
2.43.0

```

## Dirk Gouders, 2024-03-11 10:11

Subject: [PATCH 1/5] MyFirstObjectWalk: use additional arg in config_fn_t
Message-ID: <15b74566e07a39902556cd620e5cd6df1da3c7df.1710192973.git.dirk@gouders.net>
URL: https://gitlist.dev/e/15b74566e07a39902556cd620e5cd6df1da3c7df.1710192973.git.dirk%40gouders.net
In-Reply-To: <cover.1710192973.git.dirk@gouders.net>

```
Commit a4e7e317 (config: add ctx arg to config_fn_t) added a fourth
argument to config_fn_t but did not change relevant function calls
in Documentation/MyFirstObjectWalk.txt.

Fix those calls and the example git_walken_config() to use
that additional argument.

Fixes: a4e7e317 (config: add ctx arg to config_fn_t)
Cc: Glen Choo <glencbz@gmail.com>
Signed-off-by: Dirk Gouders <dirk@gouders.net>
---
 Documentation/MyFirstObjectWalk.txt | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt
index c68cdb11b9..cceac2df95 100644
--- a/Documentation/MyFirstObjectWalk.txt
+++ b/Documentation/MyFirstObjectWalk.txt
@@ -210,13 +210,14 @@ We'll also need to include the `config.h` header:
 
 ...
 
-static int git_walken_config(const char *var, const char *value, void *cb)
+static int git_walken_config(const char *var, const char *value,
+			     const struct config_context *ctx, void *cb)
 {
 	/*
 	 * For now, we don't have any custom configuration, so fall back to
 	 * the default config.
 	 */
-	return git_default_config(var, value, cb);
+	return git_default_config(var, value, ctx, cb);
 }
 ----
 
@@ -389,10 +390,11 @@ modifying `rev_info.grep_filter`, which is a `struct grep_opt`.
 First some setup. Add `grep_config()` to `git_walken_config()`:
 
 ----
-static int git_walken_config(const char *var, const char *value, void *cb)
+static int git_walken_config(const char *var, const char *value,
+			     const struct config_context *ctx, void *cb)
 {
-	grep_config(var, value, cb);
-	return git_default_config(var, value, cb);
+	grep_config(var, value, ctx, cb);
+	return git_default_config(var, value, ctx, cb);
 }
 ----
 
-- 
2.43.0


```

## Dirk Gouders, 2024-03-11 10:26

Subject: [PATCH 2/5] MyFirstObjectWalk: fix misspelled "builtins/"
Message-ID: <c1ac70584006f5a7906acf7ffbb88bfb11ca2c95.1710192973.git.dirk@gouders.net>
URL: https://gitlist.dev/e/c1ac70584006f5a7906acf7ffbb88bfb11ca2c95.1710192973.git.dirk%40gouders.net
In-Reply-To: <cover.1710192973.git.dirk@gouders.net>

```
pack-objects.c resides in builtin/ (not builtins/).

Fix the misspelled directory name.

Signed-off-by: Dirk Gouders <dirk@gouders.net>
---
 Documentation/MyFirstObjectWalk.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt
index cceac2df95..c33d22ae99 100644
--- a/Documentation/MyFirstObjectWalk.txt
+++ b/Documentation/MyFirstObjectWalk.txt
@@ -525,7 +525,7 @@ about each one.
 
 We can base our work on an example. `git pack-objects` prepares all kinds of
 objects for packing into a bitmap or packfile. The work we are interested in
-resides in `builtins/pack-objects.c:get_object_list()`; examination of that
+resides in `builtin/pack-objects.c:get_object_list()`; examination of that
 function shows that the all-object walk is being performed by
 `traverse_commit_list()` or `traverse_commit_list_filtered()`. Those two
 functions reside in `list-objects.c`; examining the source shows that, despite
-- 
2.43.0


```

## Dirk Gouders, 2024-03-11 12:47

Subject: [PATCH 3/5] MyFirstObjectWalk: fix filtered object walk
Message-ID: <0f67a161efc2635bb453eff2f6ab34b94c8794ae.1710192973.git.dirk@gouders.net>
URL: https://gitlist.dev/e/0f67a161efc2635bb453eff2f6ab34b94c8794ae.1710192973.git.dirk%40gouders.net
In-Reply-To: <cover.1710192973.git.dirk@gouders.net>

```
Commit f0d2f849 (MyFirstObjectWalk: update recommended usage)
changed a call of parse_list_objects_filter() in a way that
probably never worked: parse_list_objects_filter() always needed a
pointer as its first argument.

Fix this by removing the CALLOC_ARRAY and passing the address of
rev->filter to parse_list_objects_filter() in accordance to
such a call in revisions.c, for example.

Fixes: f0d2f849 (MyFirstObjectWalk: update recommended usage)
Cc: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Dirk Gouders <dirk@gouders.net>
---
 Documentation/MyFirstObjectWalk.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt
index c33d22ae99..a06c712e46 100644
--- a/Documentation/MyFirstObjectWalk.txt
+++ b/Documentation/MyFirstObjectWalk.txt
@@ -734,8 +734,8 @@ walk we've just performed:
 	} else {
 		trace_printf(
 			_("Filtered object walk with filterspec 'tree:1'.\n"));
-		CALLOC_ARRAY(rev->filter, 1);
-		parse_list_objects_filter(rev->filter, "tree:1");
+
+		parse_list_objects_filter(&rev->filter, "tree:1");
 	}
 	traverse_commit_list(rev, walken_show_commit,
 			     walken_show_object, NULL);
-- 
2.43.0


```

## Dirk Gouders, 2024-03-11 13:29

Subject: [PATCH 4/5] MyFirstObjectWalk: fix description for counting omitted objects
Message-ID: <637070dd48ceefc5c2b7a902dd5eb3ecde503894.1710192973.git.dirk@gouders.net>
URL: https://gitlist.dev/e/637070dd48ceefc5c2b7a902dd5eb3ecde503894.1710192973.git.dirk%40gouders.net
In-Reply-To: <cover.1710192973.git.dirk@gouders.net>

```
Before the changes to count omitted objects, the function
traverse_commit_list() was used and its call cannot be changed to pass
a pointer to an oidset to record omitted objects.

Fix the text to clarify that we now use another traversal function to
be able to pass the pointer to the introduced oidset.

Signed-off-by: Dirk Gouders <dirk@gouders.net>
---
 Documentation/MyFirstObjectWalk.txt | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt
index a06c712e46..981dbf917b 100644
--- a/Documentation/MyFirstObjectWalk.txt
+++ b/Documentation/MyFirstObjectWalk.txt
@@ -754,10 +754,11 @@ points to the same tree object as its grandparent.)
 === Counting Omitted Objects
 
 We also have the capability to enumerate all objects which were omitted by a
-filter, like with `git log --filter=<spec> --filter-print-omitted`. Asking
-`traverse_commit_list_filtered()` to populate the `omitted` list means that our
-object walk does not perform any better than an unfiltered object walk; all
-reachable objects are walked in order to populate the list.
+filter, like with `git log --filter=<spec> --filter-print-omitted`. We
+can ask `traverse_commit_list_filtered()` to populate the `omitted`
+list which means that our object walk does not perform any better than
+an unfiltered object walk; all reachable objects are walked in order
+to populate the list.
 
 First, add the `struct oidset` and related items we will use to iterate it:
 
@@ -778,8 +779,9 @@ static void walken_object_walk(
 	...
 ----
 
-Modify the call to `traverse_commit_list_filtered()` to include your `omitted`
-object:
+You need to replace the call to `traverse_commit_list()` to
+`traverse_commit_list_filtered()` to be able to pass a pointer to the
+oidset defined and initialized above:
 
 ----
 	...
-- 
2.43.0


```

## Dirk Gouders, 2024-03-11 21:00

Subject: [PATCH 5/5] MyFirstObjectWalk: add stderr to pipe processing
Message-ID: <a2d30eff217e560873c49fe45116c784dc12fd32.1710192973.git.dirk@gouders.net>
URL: https://gitlist.dev/e/a2d30eff217e560873c49fe45116c784dc12fd32.1710192973.git.dirk%40gouders.net
In-Reply-To: <cover.1710192973.git.dirk@gouders.net>

```
In the last chapter of this document, pipes are used in commands to
filter out the first/last trace messages.  But according to git(1),
trace messages are sent to stderr if GIT_TRACE is set to '1', so those
commands do not produce the described results.

Fix this by using the operator '|&' to additionally connect stderr to
stdin of the latter command.

Signed-off-by: Dirk Gouders <dirk@gouders.net>
---
 Documentation/MyFirstObjectWalk.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt
index 981dbf917b..b96724c4d7 100644
--- a/Documentation/MyFirstObjectWalk.txt
+++ b/Documentation/MyFirstObjectWalk.txt
@@ -847,7 +847,7 @@ those lines without having to recompile.
 With only that change, run again (but save yourself some scrollback):
 
 ----
-$ GIT_TRACE=1 ./bin-wrappers/git walken | head -n 10
+$ GIT_TRACE=1 ./bin-wrappers/git walken |& head -n 10
 ----
 
 Take a look at the top commit with `git show` and the object ID you printed; it
@@ -875,7 +875,7 @@ of the first handful:
 
 ----
 $ make
-$ GIT_TRACE=1 ./bin-wrappers git walken | tail -n 10
+$ GIT_TRACE=1 ./bin-wrappers git walken |& tail -n 10
 ----
 
 The last commit object given should have the same OID as the one we saw at the
-- 
2.43.0


```

## Junio C Hamano, 2024-03-12 00:13

Subject: Re: [PATCH 5/5] MyFirstObjectWalk: add stderr to pipe processing
Message-ID: <xmqqh6hcmhmu.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqh6hcmhmu.fsf%40gitster.g
In-Reply-To: <a2d30eff217e560873c49fe45116c784dc12fd32.1710192973.git.dirk@gouders.net>

```
Dirk Gouders <dirk@gouders.net> writes:

> In the last chapter of this document, pipes are used in commands to
> filter out the first/last trace messages.  But according to git(1),
> trace messages are sent to stderr if GIT_TRACE is set to '1', so those
> commands do not produce the described results.
>
> Fix this by using the operator '|&' to additionally connect stderr to
> stdin of the latter command.

Isn't |& a bash-ism?

    upstream command >&2 | downstream command

is how you would do the same more portably.

```

## Junio C Hamano, 2024-03-12 00:15

Subject: Re: [PATCH 0/5] Fixes for Documentation/MyFirstObjectWalk.txt
Message-ID: <xmqqcys0mhjp.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqcys0mhjp.fsf%40gitster.g
In-Reply-To: <cover.1710192973.git.dirk@gouders.net>

```
Dirk Gouders <dirk@gouders.net> writes:

> This series contains fixes for some problems in
> Documentation/MyFirstObjectWalk.txt that I noticed while working
> through that document.
>
> All patches except [4/5] fix real errors that cause comilation
> failures or don't produce the wanted output.
> With the fix in [3/5] I'm rather uncertain if it is correct and I
> would like to ask for special attention, here.
>
> For this first round I send separate patches in the hope that
> simplifies reviews and also, because the reasons for those problems
> differ.  Finally, those patches could be merged into one should this be
> more appropriate.
>
> Dirk Gouders (5):
>   MyFirstObjectWalk: use additional arg in config_fn_t
>   MyFirstObjectWalk: fix misspelled "builtins/"
>   MyFirstObjectWalk: fix filtered object walk
>   MyFirstObjectWalk: fix description for counting omitted objects
>   MyFirstObjectWalk: add stderr to pipe processing
>
>  Documentation/MyFirstObjectWalk.txt | 36 ++++++++++++++++-------------
>  1 file changed, 20 insertions(+), 16 deletions(-)

Emily, if I am not misremembering, this document came from your
direction, so perhaps you have enough familiarity to lend these
patches an eye or two to look them over?

Thanks.

```

## Junio C Hamano, 2024-03-12 00:18

Subject: Re: [PATCH 1/5] MyFirstObjectWalk: use additional arg in config_fn_t
Message-ID: <xmqq4jdcmhfm.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqq4jdcmhfm.fsf%40gitster.g
In-Reply-To: <15b74566e07a39902556cd620e5cd6df1da3c7df.1710192973.git.dirk@gouders.net>

```
Dirk Gouders <dirk@gouders.net> writes:

> Commit a4e7e317 (config: add ctx arg to config_fn_t) added a fourth
> argument to config_fn_t but did not change relevant function calls
> in Documentation/MyFirstObjectWalk.txt.
>
> Fix those calls and the example git_walken_config() to use
> that additional argument.


> Fixes: a4e7e317 (config: add ctx arg to config_fn_t)
> Cc: Glen Choo <glencbz@gmail.com>

I know what you wanted to convey with these, but in this project we
do not use them.  Both becomes unnecessary once you write the first
part of the log message above ;-)

> Signed-off-by: Dirk Gouders <dirk@gouders.net>
> ---
>  Documentation/MyFirstObjectWalk.txt | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt
> index c68cdb11b9..cceac2df95 100644
> --- a/Documentation/MyFirstObjectWalk.txt
> +++ b/Documentation/MyFirstObjectWalk.txt
> @@ -210,13 +210,14 @@ We'll also need to include the `config.h` header:
>  
>  ...
>  
> -static int git_walken_config(const char *var, const char *value, void *cb)
> +static int git_walken_config(const char *var, const char *value,
> +			     const struct config_context *ctx, void *cb)
>  {
>  	/*
>  	 * For now, we don't have any custom configuration, so fall back to
>  	 * the default config.
>  	 */
> -	return git_default_config(var, value, cb);
> +	return git_default_config(var, value, ctx, cb);
>  }
>  ----
>  
> @@ -389,10 +390,11 @@ modifying `rev_info.grep_filter`, which is a `struct grep_opt`.
>  First some setup. Add `grep_config()` to `git_walken_config()`:
>  
>  ----
> -static int git_walken_config(const char *var, const char *value, void *cb)
> +static int git_walken_config(const char *var, const char *value,
> +			     const struct config_context *ctx, void *cb)
>  {
> -	grep_config(var, value, cb);
> -	return git_default_config(var, value, cb);
> +	grep_config(var, value, ctx, cb);
> +	return git_default_config(var, value, ctx, cb);
>  }
>  ----

```

## Dirk Gouders, 2024-03-12 14:27

Subject: Re: [PATCH 5/5] MyFirstObjectWalk: add stderr to pipe processing
Message-ID: <ghbk7ja5k2.fsf@gouders.net>
URL: https://gitlist.dev/e/ghbk7ja5k2.fsf%40gouders.net
In-Reply-To: <xmqqh6hcmhmu.fsf@gitster.g>

```
Junio C Hamano <gitster@pobox.com> writes:

> Dirk Gouders <dirk@gouders.net> writes:
>
>> In the last chapter of this document, pipes are used in commands to
>> filter out the first/last trace messages.  But according to git(1),
>> trace messages are sent to stderr if GIT_TRACE is set to '1', so those
>> commands do not produce the described results.
>>
>> Fix this by using the operator '|&' to additionally connect stderr to
>> stdin of the latter command.
>
> Isn't |& a bash-ism?
>
>     upstream command >&2 | downstream command
>
> is how you would do the same more portably.

Ah yes, it is a bash-ism, thank you.

I guess you meant

        upstream command 2>&1 | downstream command

I will wait a bit (some days) for other comments
and then at least remove this bash-ism plus the wrong tags you also
mentioned -- also thanks for that.

Dirk

```

## Junio C Hamano, 2024-03-12 19:29

Subject: Re: [PATCH 5/5] MyFirstObjectWalk: add stderr to pipe processing
Message-ID: <xmqqwmq7jljk.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqwmq7jljk.fsf%40gitster.g
In-Reply-To: <ghbk7ja5k2.fsf@gouders.net>

```
Dirk Gouders <dirk@gouders.net> writes:

> Ah yes, it is a bash-ism, thank you.
>
> I guess you meant

Yup, thanks, that was a typo.

>         upstream command 2>&1 | downstream command

```
