threads / patch / 61095

patch, 5 partsFixes for Documentation/MyFirstObjectWalk.txt

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

## tl;dr

11 messages between Mar 11, 2024 and Mar 12, 2024. Diffs are folded; open one to read it.

replies: 10people: 2as markdown or json

Dirk Gouders· Mar 11, 2024, 21:36 UTC · lore

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· Mar 11, 2024, 10:11 UTC · re: Dirk Gouders · lore

[PATCH 1/5] MyFirstObjectWalk: use additional arg in config_fn_t

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(-)
Show changes to Documentation/MyFirstObjectWalk.txt +7 −5
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
Junio C Hamano· Mar 12, 2024, 00:18 UTC · re: Dirk Gouders · lore

Re: [PATCH 1/5] MyFirstObjectWalk: use additional arg in config_fn_t

Dirk Gouders <dirk@gouders.net> writes:
Show 6 quoted lines
> 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 ;-)

Show 40 quoted lines
> 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· Mar 11, 2024, 10:26 UTC · re: Dirk Gouders · lore

[PATCH 2/5] MyFirstObjectWalk: fix misspelled "builtins/"

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(-)
Show changes to Documentation/MyFirstObjectWalk.txt +1 −1
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· Mar 11, 2024, 12:47 UTC · re: Dirk Gouders · lore

[PATCH 3/5] MyFirstObjectWalk: fix filtered object walk

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(-)
Show changes to Documentation/MyFirstObjectWalk.txt +2 −2
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· Mar 11, 2024, 13:29 UTC · re: Dirk Gouders · lore

[PATCH 4/5] MyFirstObjectWalk: fix description for counting omitted objects

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(-)
Show changes to Documentation/MyFirstObjectWalk.txt +8 −6
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· Mar 11, 2024, 21:00 UTC · re: Dirk Gouders · lore

[PATCH 5/5] MyFirstObjectWalk: add stderr to pipe processing

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(-)
Show changes to Documentation/MyFirstObjectWalk.txt +2 −2
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· Mar 12, 2024, 00:13 UTC · re: Dirk Gouders · lore

Re: [PATCH 5/5] MyFirstObjectWalk: add stderr to pipe processing

Dirk Gouders <dirk@gouders.net> writes:
Show 7 quoted lines
> 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.
Dirk Gouders· Mar 12, 2024, 14:27 UTC · re: Junio C Hamano · lore

Re: [PATCH 5/5] MyFirstObjectWalk: add stderr to pipe processing

Junio C Hamano <gitster@pobox.com> writes:
Show 15 quoted lines
> 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· Mar 12, 2024, 19:29 UTC · re: Dirk Gouders · lore

Re: [PATCH 5/5] MyFirstObjectWalk: add stderr to pipe processing

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
Junio C Hamano· Mar 12, 2024, 00:15 UTC · re: Dirk Gouders · lore

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

Dirk Gouders <dirk@gouders.net> writes:
Show 23 quoted lines
> 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.

← back to recent threads