git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: stolee@gmail.com, avarab@gmail.com, gitster@pobox.com,
	zhiyou.jx@alibaba-inc.com, jonathantanmy@google.com,
	Jeff Hostetler <git@jeffhostetler.com>,
	Derrick Stolee <derrickstolee@github.com>,
	Derrick Stolee <derrickstolee@github.com>
Subject: [PATCH v2 06/12] MyFirstObjectWalk: update recommended usage
Date: Mon, 07 Mar 2022 21:50:34 +0000	[thread overview]
Message-ID: <efc03168818e9328d4d1f47f9d48fe2a46d1e2c9.1646689840.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1159.v2.git.1646689840.gitgitgadget@gmail.com>

From: Derrick Stolee <derrickstolee@github.com>

The previous change consolidated traverse_commit_list() and
traverse_commit_list_filtered(). This allows us to simplify the
recommended usage in MyFirstObjectWalk.txt to use this new set of
values.

While here, add some clarification on the difference between the two
methods.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
---
 Documentation/MyFirstObjectWalk.txt | 44 +++++++++++------------------
 1 file changed, 16 insertions(+), 28 deletions(-)

diff --git a/Documentation/MyFirstObjectWalk.txt b/Documentation/MyFirstObjectWalk.txt
index ca267941f3e..8d9e85566e6 100644
--- a/Documentation/MyFirstObjectWalk.txt
+++ b/Documentation/MyFirstObjectWalk.txt
@@ -522,24 +522,25 @@ 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
 the name, these functions traverse all kinds of objects. Let's have a look at
-the arguments to `traverse_commit_list_filtered()`, which are a superset of the
-arguments to the unfiltered version.
+the arguments to `traverse_commit_list()`.
 
-- `struct list_objects_filter_options *filter_options`: This is a struct which
-  stores a filter-spec as outlined in `Documentation/rev-list-options.txt`.
-- `struct rev_info *revs`: This is the `rev_info` used for the walk.
+- `struct rev_info *revs`: This is the `rev_info` used for the walk. If
+  its `filter` member is not `NULL`, then `filter` contains information for
+  how to filter the object list.
 - `show_commit_fn show_commit`: A callback which will be used to handle each
   individual commit object.
 - `show_object_fn show_object`: A callback which will be used to handle each
   non-commit object (so each blob, tree, or tag).
 - `void *show_data`: A context buffer which is passed in turn to `show_commit`
   and `show_object`.
+
+In addition, `traverse_commit_list_filtered()` has an additional paramter:
+
 - `struct oidset *omitted`: A linked-list of object IDs which the provided
   filter caused to be omitted.
 
-It looks like this `traverse_commit_list_filtered()` uses callbacks we provide
-instead of needing us to call it repeatedly ourselves. Cool! Let's add the
-callbacks first.
+It looks like these methods use callbacks we provide instead of needing us
+to call it repeatedly ourselves. Cool! Let's add the callbacks first.
 
 For the sake of this tutorial, we'll simply keep track of how many of each kind
 of object we find. At file scope in `builtin/walken.c` add the following
@@ -712,20 +713,9 @@ help understand. In our case, that means we omit trees and blobs not directly
 referenced by `HEAD` or `HEAD`'s history, because we begin the walk with only
 `HEAD` in the `pending` list.)
 
-First, we'll need to `#include "list-objects-filter-options.h"` and set up the
-`struct list_objects_filter_options` at the top of the function.
-
-----
-static void walken_object_walk(struct rev_info *rev)
-{
-	struct list_objects_filter_options filter_options = { 0 };
-
-	...
-----
-
 For now, we are not going to track the omitted objects, so we'll replace those
 parameters with `NULL`. For the sake of simplicity, we'll add a simple
-build-time branch to use our filter or not. Replace the line calling
+build-time branch to use our filter or not. Preface the line calling
 `traverse_commit_list()` with the following, which will remind us which kind of
 walk we've just performed:
 
@@ -733,19 +723,17 @@ walk we've just performed:
 	if (0) {
 		/* Unfiltered: */
 		trace_printf(_("Unfiltered object walk.\n"));
-		traverse_commit_list(rev, walken_show_commit,
-				walken_show_object, NULL);
 	} else {
 		trace_printf(
 			_("Filtered object walk with filterspec 'tree:1'.\n"));
-		parse_list_objects_filter(&filter_options, "tree:1");
-
-		traverse_commit_list_filtered(&filter_options, rev,
-			walken_show_commit, walken_show_object, NULL, NULL);
+		CALLOC_ARRAY(rev->filter, 1);
+		parse_list_objects_filter(rev->filter, "tree:1");
 	}
+	traverse_commit_list(rev, walken_show_commit,
+			     walken_show_object, NULL);
 ----
 
-`struct list_objects_filter_options` is usually built directly from a command
+The `rev->filter` member is usually built directly from a command
 line argument, so the module provides an easy way to build one from a string.
 Even though we aren't taking user input right now, we can still build one with
 a hardcoded string using `parse_list_objects_filter()`.
@@ -784,7 +772,7 @@ object:
 ----
 	...
 
-		traverse_commit_list_filtered(&filter_options, rev,
+		traverse_commit_list_filtered(rev,
 			walken_show_commit, walken_show_object, NULL, &omitted);
 
 	...
-- 
gitgitgadget


  parent reply	other threads:[~2022-03-07 21:51 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-23 17:55 [PATCH 00/11] Partial bundles Derrick Stolee via GitGitGadget
2022-02-23 17:55 ` [PATCH 01/11] index-pack: document and test the --promisor option Derrick Stolee via GitGitGadget
2022-02-23 17:55 ` [PATCH 02/11] revision: put object filter into struct rev_info Derrick Stolee via GitGitGadget
2022-03-04 22:15   ` Junio C Hamano
2022-03-07 13:59     ` Derrick Stolee
2022-03-07 16:46       ` Junio C Hamano
2022-02-23 17:55 ` [PATCH 03/11] pack-objects: use rev.filter when possible Derrick Stolee via GitGitGadget
2022-03-04 22:25   ` Junio C Hamano
2022-02-23 17:55 ` [PATCH 04/11] pack-bitmap: drop filter in prepare_bitmap_walk() Derrick Stolee via GitGitGadget
2022-03-04 22:26   ` Junio C Hamano
2022-02-23 17:55 ` [PATCH 05/11] list-objects: consolidate traverse_commit_list[_filtered] Derrick Stolee via GitGitGadget
2022-03-04 22:30   ` Junio C Hamano
2022-02-23 17:55 ` [PATCH 06/11] MyFirstObjectWalk: update recommended usage Derrick Stolee via GitGitGadget
2022-03-04 22:33   ` Junio C Hamano
2022-03-07 14:05     ` Derrick Stolee
2022-03-07 16:47       ` Junio C Hamano
2022-02-23 17:55 ` [PATCH 07/11] bundle: safely handle --objects option Derrick Stolee via GitGitGadget
2022-02-28 16:00   ` Jeff Hostetler
2022-03-04 22:58     ` Junio C Hamano
2022-03-07 14:09       ` Derrick Stolee
2022-03-04 22:57   ` Junio C Hamano
2022-03-07 15:35   ` Ævar Arnfjörð Bjarmason
2022-02-23 17:55 ` [PATCH 08/11] bundle: parse filter capability Derrick Stolee via GitGitGadget
2022-03-07 15:38   ` Ævar Arnfjörð Bjarmason
2022-03-07 16:14     ` Derrick Stolee
2022-03-07 16:22       ` Ævar Arnfjörð Bjarmason
2022-03-07 16:29         ` Derrick Stolee
2022-03-07 15:55   ` Ævar Arnfjörð Bjarmason
2022-02-23 17:55 ` [PATCH 09/11] rev-list: move --filter parsing into revision.c Derrick Stolee via GitGitGadget
2022-02-23 17:55 ` [PATCH 10/11] bundle: create filtered bundles Derrick Stolee via GitGitGadget
2022-03-04 23:35   ` Junio C Hamano
2022-03-07 14:14     ` Derrick Stolee
2022-03-07 16:49       ` Junio C Hamano
2022-03-07 15:44   ` Ævar Arnfjörð Bjarmason
2022-02-23 17:55 ` [PATCH 11/11] bundle: unbundle promisor packs Derrick Stolee via GitGitGadget
2022-03-04 23:43   ` Junio C Hamano
2022-03-07 14:48     ` Derrick Stolee
2022-03-07 16:56       ` Junio C Hamano
2022-03-07 18:57         ` Derrick Stolee
2022-03-07 19:40           ` Junio C Hamano
2022-03-07 19:49             ` Derrick Stolee
2022-03-07 19:54               ` Junio C Hamano
2022-03-07 20:20                 ` Derrick Stolee
2022-03-07 21:35                   ` Junio C Hamano
2022-03-07 15:47   ` Ævar Arnfjörð Bjarmason
2022-03-07 16:10     ` Derrick Stolee
2022-02-28 17:00 ` [PATCH 00/11] Partial bundles Jeff Hostetler
2022-02-28 17:54   ` Derrick Stolee
2022-03-01 18:03     ` Jeff Hostetler
2022-03-04 19:19 ` Derrick Stolee
2022-03-07 14:55 ` Ævar Arnfjörð Bjarmason
2022-03-07 14:59   ` Derrick Stolee
2022-03-07 21:50 ` [PATCH v2 00/12] " Derrick Stolee via GitGitGadget
2022-03-07 21:50   ` [PATCH v2 01/12] index-pack: document and test the --promisor option Derrick Stolee via GitGitGadget
2022-03-07 21:50   ` [PATCH v2 02/12] revision: put object filter into struct rev_info Derrick Stolee via GitGitGadget
2022-03-07 21:50   ` [PATCH v2 03/12] pack-objects: use rev.filter when possible Derrick Stolee via GitGitGadget
2022-03-07 21:50   ` [PATCH v2 04/12] pack-bitmap: drop filter in prepare_bitmap_walk() Derrick Stolee via GitGitGadget
2022-03-07 21:50   ` [PATCH v2 05/12] list-objects: consolidate traverse_commit_list[_filtered] Derrick Stolee via GitGitGadget
2022-03-07 21:50   ` Derrick Stolee via GitGitGadget [this message]
2022-03-07 21:50   ` [PATCH v2 07/12] bundle: safely handle --objects option Derrick Stolee via GitGitGadget
2022-03-08  9:37     ` Ævar Arnfjörð Bjarmason
2022-03-08 13:45       ` Derrick Stolee
2022-03-08 13:53         ` Ævar Arnfjörð Bjarmason
2022-03-07 21:50   ` [PATCH v2 08/12] bundle: parse filter capability Derrick Stolee via GitGitGadget
2022-03-08  9:25     ` Ævar Arnfjörð Bjarmason
2022-03-08 13:43       ` Derrick Stolee
2022-03-07 21:50   ` [PATCH v2 09/12] rev-list: move --filter parsing into revision.c Derrick Stolee via GitGitGadget
2022-03-07 21:50   ` [PATCH v2 10/12] bundle: create filtered bundles Derrick Stolee via GitGitGadget
2022-03-07 21:50   ` [PATCH v2 11/12] bundle: unbundle promisor packs Derrick Stolee via GitGitGadget
2022-03-07 21:50   ` [PATCH v2 12/12] clone: fail gracefully when cloning filtered bundle Derrick Stolee via GitGitGadget
2022-03-07 22:11   ` [PATCH v2 00/12] Partial bundles Junio C Hamano
2022-03-08 14:39   ` [PATCH v3 " Derrick Stolee via GitGitGadget
2022-03-08 14:39     ` [PATCH v3 01/12] index-pack: document and test the --promisor option Derrick Stolee via GitGitGadget
2022-03-08 14:39     ` [PATCH v3 02/12] revision: put object filter into struct rev_info Derrick Stolee via GitGitGadget
2022-03-08 14:39     ` [PATCH v3 03/12] pack-objects: use rev.filter when possible Derrick Stolee via GitGitGadget
2022-03-08 14:39     ` [PATCH v3 04/12] pack-bitmap: drop filter in prepare_bitmap_walk() Derrick Stolee via GitGitGadget
2022-03-08 14:39     ` [PATCH v3 05/12] list-objects: consolidate traverse_commit_list[_filtered] Derrick Stolee via GitGitGadget
2022-03-09 13:24       ` Ævar Arnfjörð Bjarmason
2022-03-08 14:39     ` [PATCH v3 06/12] MyFirstObjectWalk: update recommended usage Derrick Stolee via GitGitGadget
2022-03-08 14:39     ` [PATCH v3 07/12] list-objects: handle NULL function pointers Ævar Arnfjörð Bjarmason via GitGitGadget
2022-03-08 17:26       ` Junio C Hamano
2022-03-09 13:40         ` Ævar Arnfjörð Bjarmason
2022-03-09 14:16           ` Derrick Stolee
2022-03-09 18:32           ` Junio C Hamano
2022-03-08 14:39     ` [PATCH v3 08/12] bundle: parse filter capability Derrick Stolee via GitGitGadget
2022-03-08 17:29       ` Junio C Hamano
2022-03-09 14:35         ` Derrick Stolee
2022-03-09 13:30       ` Ævar Arnfjörð Bjarmason
2022-03-08 14:39     ` [PATCH v3 09/12] rev-list: move --filter parsing into revision.c Derrick Stolee via GitGitGadget
2022-03-08 14:39     ` [PATCH v3 10/12] bundle: create filtered bundles Derrick Stolee via GitGitGadget
2022-03-08 14:39     ` [PATCH v3 11/12] bundle: unbundle promisor packs Derrick Stolee via GitGitGadget
2022-03-08 14:39     ` [PATCH v3 12/12] clone: fail gracefully when cloning filtered bundle Derrick Stolee via GitGitGadget
2022-03-08 16:10       ` Derrick Stolee
2022-03-08 17:19         ` Junio C Hamano
2022-03-09 16:01     ` [PATCH v4 00/13] Partial bundles Derrick Stolee via GitGitGadget
2022-03-09 16:01       ` [PATCH v4 01/13] index-pack: document and test the --promisor option Derrick Stolee via GitGitGadget
2022-03-09 16:01       ` [PATCH v4 02/13] list-objects-filter-options: create copy helper Derrick Stolee via GitGitGadget
2022-03-09 16:01       ` [PATCH v4 03/13] revision: put object filter into struct rev_info Derrick Stolee via GitGitGadget
2022-03-09 18:48         ` Junio C Hamano
2022-03-09 16:01       ` [PATCH v4 04/13] pack-objects: use rev.filter when possible Derrick Stolee via GitGitGadget
2022-03-10 13:11         ` Ævar Arnfjörð Bjarmason
2022-03-10 13:33           ` Derrick Stolee
2022-03-10 14:24             ` Ævar Arnfjörð Bjarmason
2022-03-09 16:01       ` [PATCH v4 05/13] pack-bitmap: drop filter in prepare_bitmap_walk() Derrick Stolee via GitGitGadget
2022-03-09 16:01       ` [PATCH v4 06/13] list-objects: consolidate traverse_commit_list[_filtered] Derrick Stolee via GitGitGadget
2022-03-09 16:01       ` [PATCH v4 07/13] MyFirstObjectWalk: update recommended usage Derrick Stolee via GitGitGadget
2022-03-09 16:01       ` [PATCH v4 08/13] list-objects: handle NULL function pointers Ævar Arnfjörð Bjarmason via GitGitGadget
2022-03-09 16:01       ` [PATCH v4 09/13] bundle: parse filter capability Derrick Stolee via GitGitGadget
2022-03-09 18:41         ` Junio C Hamano
2022-03-09 18:55           ` Derrick Stolee
2022-03-09 16:01       ` [PATCH v4 10/13] rev-list: move --filter parsing into revision.c Derrick Stolee via GitGitGadget
2022-03-09 16:01       ` [PATCH v4 11/13] bundle: create filtered bundles Derrick Stolee via GitGitGadget
2022-03-09 16:01       ` [PATCH v4 12/13] bundle: unbundle promisor packs Derrick Stolee via GitGitGadget
2022-03-09 16:01       ` [PATCH v4 13/13] clone: fail gracefully when cloning filtered bundle Derrick Stolee via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=efc03168818e9328d4d1f47f9d48fe2a46d1e2c9.1646689840.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=avarab@gmail.com \
    --cc=derrickstolee@github.com \
    --cc=git@jeffhostetler.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jonathantanmy@google.com \
    --cc=stolee@gmail.com \
    --cc=zhiyou.jx@alibaba-inc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).