Merge branch 'dg/myfirstobjectwalk-updates'

Update a more recent tutorial doc.

* dg/myfirstobjectwalk-updates:
  MyFirstObjectWalk: add stderr to pipe processing
  MyFirstObjectWalk: fix description for counting omitted objects
  MyFirstObjectWalk: fix filtered object walk
  MyFirstObjectWalk: fix misspelled "builtins/"
  MyFirstObjectWalk: use additional arg in config_fn_t
This commit is contained in:
Junio C Hamano
2024-04-09 14:31:44 -07:00

View File

@ -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 * For now, we don't have any custom configuration, so fall back to
* the default config. * 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()`: 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); grep_config(var, value, ctx, cb);
return git_default_config(var, value, cb); return git_default_config(var, value, ctx, cb);
} }
---- ----
@ -523,7 +525,7 @@ about each one.
We can base our work on an example. `git pack-objects` prepares all kinds of 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 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 function shows that the all-object walk is being performed by
`traverse_commit_list()` or `traverse_commit_list_filtered()`. Those two `traverse_commit_list()` or `traverse_commit_list_filtered()`. Those two
functions reside in `list-objects.c`; examining the source shows that, despite functions reside in `list-objects.c`; examining the source shows that, despite
@ -732,8 +734,8 @@ walk we've just performed:
} else { } else {
trace_printf( trace_printf(
_("Filtered object walk with filterspec 'tree:1'.\n")); _("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, traverse_commit_list(rev, walken_show_commit,
walken_show_object, NULL); walken_show_object, NULL);
@ -752,10 +754,12 @@ points to the same tree object as its grandparent.)
=== Counting Omitted Objects === Counting Omitted Objects
We also have the capability to enumerate all objects which were omitted by a 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 filter, like with `git log --filter=<spec> --filter-print-omitted`. To do this,
`traverse_commit_list_filtered()` to populate the `omitted` list means that our change `traverse_commit_list()` to `traverse_commit_list_filtered()`, which is
object walk does not perform any better than an unfiltered object walk; all able to populate an `omitted` list. Asking for this list of filtered objects
reachable objects are walked in order to populate the list. may cause performance degradations, however, because in this case, despite
filtering objects, the possibly much larger set of all reachable objects must
be processed in order to populate that list.
First, add the `struct oidset` and related items we will use to iterate it: First, add the `struct oidset` and related items we will use to iterate it:
@ -776,8 +780,9 @@ static void walken_object_walk(
... ...
---- ----
Modify the call to `traverse_commit_list_filtered()` to include your `omitted` Replace the call to `traverse_commit_list()` with
object: `traverse_commit_list_filtered()` and pass a pointer to the `omitted` oidset
defined and initialized above:
---- ----
... ...
@ -843,7 +848,7 @@ those lines without having to recompile.
With only that change, run again (but save yourself some scrollback): 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 2>&1 | head -n 10
---- ----
Take a look at the top commit with `git show` and the object ID you printed; it Take a look at the top commit with `git show` and the object ID you printed; it
@ -871,7 +876,7 @@ of the first handful:
---- ----
$ make $ make
$ GIT_TRACE=1 ./bin-wrappers git walken | tail -n 10 $ GIT_TRACE=1 ./bin-wrappers/git walken 2>&1 | tail -n 10
---- ----
The last commit object given should have the same OID as the one we saw at the The last commit object given should have the same OID as the one we saw at the