Skip to content

Commit 4697c8a

Browse files
committed
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
2 parents 39b2c6f + 95ab557 commit 4697c8a

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

Documentation/MyFirstObjectWalk.txt

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,14 @@ We'll also need to include the `config.h` header:
210210

211211
...
212212

213-
static int git_walken_config(const char *var, const char *value, void *cb)
213+
static int git_walken_config(const char *var, const char *value,
214+
const struct config_context *ctx, void *cb)
214215
{
215216
/*
216217
* For now, we don't have any custom configuration, so fall back to
217218
* the default config.
218219
*/
219-
return git_default_config(var, value, cb);
220+
return git_default_config(var, value, ctx, cb);
220221
}
221222
----
222223

@@ -389,10 +390,11 @@ modifying `rev_info.grep_filter`, which is a `struct grep_opt`.
389390
First some setup. Add `grep_config()` to `git_walken_config()`:
390391

391392
----
392-
static int git_walken_config(const char *var, const char *value, void *cb)
393+
static int git_walken_config(const char *var, const char *value,
394+
const struct config_context *ctx, void *cb)
393395
{
394-
grep_config(var, value, cb);
395-
return git_default_config(var, value, cb);
396+
grep_config(var, value, ctx, cb);
397+
return git_default_config(var, value, ctx, cb);
396398
}
397399
----
398400

@@ -523,7 +525,7 @@ about each one.
523525

524526
We can base our work on an example. `git pack-objects` prepares all kinds of
525527
objects for packing into a bitmap or packfile. The work we are interested in
526-
resides in `builtins/pack-objects.c:get_object_list()`; examination of that
528+
resides in `builtin/pack-objects.c:get_object_list()`; examination of that
527529
function shows that the all-object walk is being performed by
528530
`traverse_commit_list()` or `traverse_commit_list_filtered()`. Those two
529531
functions reside in `list-objects.c`; examining the source shows that, despite
@@ -732,8 +734,8 @@ walk we've just performed:
732734
} else {
733735
trace_printf(
734736
_("Filtered object walk with filterspec 'tree:1'.\n"));
735-
CALLOC_ARRAY(rev->filter, 1);
736-
parse_list_objects_filter(rev->filter, "tree:1");
737+
738+
parse_list_objects_filter(&rev->filter, "tree:1");
737739
}
738740
traverse_commit_list(rev, walken_show_commit,
739741
walken_show_object, NULL);
@@ -752,10 +754,12 @@ points to the same tree object as its grandparent.)
752754
=== Counting Omitted Objects
753755

754756
We also have the capability to enumerate all objects which were omitted by a
755-
filter, like with `git log --filter=<spec> --filter-print-omitted`. Asking
756-
`traverse_commit_list_filtered()` to populate the `omitted` list means that our
757-
object walk does not perform any better than an unfiltered object walk; all
758-
reachable objects are walked in order to populate the list.
757+
filter, like with `git log --filter=<spec> --filter-print-omitted`. To do this,
758+
change `traverse_commit_list()` to `traverse_commit_list_filtered()`, which is
759+
able to populate an `omitted` list. Asking for this list of filtered objects
760+
may cause performance degradations, however, because in this case, despite
761+
filtering objects, the possibly much larger set of all reachable objects must
762+
be processed in order to populate that list.
759763

760764
First, add the `struct oidset` and related items we will use to iterate it:
761765

@@ -776,8 +780,9 @@ static void walken_object_walk(
776780
...
777781
----
778782

779-
Modify the call to `traverse_commit_list_filtered()` to include your `omitted`
780-
object:
783+
Replace the call to `traverse_commit_list()` with
784+
`traverse_commit_list_filtered()` and pass a pointer to the `omitted` oidset
785+
defined and initialized above:
781786

782787
----
783788
...
@@ -843,7 +848,7 @@ those lines without having to recompile.
843848
With only that change, run again (but save yourself some scrollback):
844849

845850
----
846-
$ GIT_TRACE=1 ./bin-wrappers/git walken | head -n 10
851+
$ GIT_TRACE=1 ./bin-wrappers/git walken 2>&1 | head -n 10
847852
----
848853

849854
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:
871876

872877
----
873878
$ make
874-
$ GIT_TRACE=1 ./bin-wrappers git walken | tail -n 10
879+
$ GIT_TRACE=1 ./bin-wrappers/git walken 2>&1 | tail -n 10
875880
----
876881

877882
The last commit object given should have the same OID as the one we saw at the

0 commit comments

Comments
 (0)