diff mbox series

[RFC,11/13] walken: add filtered object walk

Message ID 20190607010811.52944-12-emilyshaffer@google.com (mailing list archive)
State New, archived
Headers show
Series example implementation of revwalk tutorial | expand

Commit Message

Emily Shaffer June 7, 2019, 1:08 a.m. UTC
Demonstrate how filter specs can be used when performing a revision walk
of all object types. In this case, tree depth is used. Contributors who
are following the revision walking tutorial will be encouraged to run
the revision walk with and without the filter in order to compare the
number of objects seen in each case.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
 builtin/walken.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

Comments

Jeff Hostetler June 7, 2019, 7:15 p.m. UTC | #1
On 6/6/2019 9:08 PM, Emily Shaffer wrote:
> Demonstrate how filter specs can be used when performing a revision walk
> of all object types. In this case, tree depth is used. Contributors who
> are following the revision walking tutorial will be encouraged to run
> the revision walk with and without the filter in order to compare the
> number of objects seen in each case.
> 
> Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
> ---
>   builtin/walken.c | 18 +++++++++++++++++-
>   1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/builtin/walken.c b/builtin/walken.c
> index 408af6c841..f2c98bcd6b 100644
> --- a/builtin/walken.c
> +++ b/builtin/walken.c
> @@ -13,6 +13,7 @@
>   #include "pretty.h"
>   #include "line-log.h"
>   #include "list-objects.h"
> +#include "list-objects-filter-options.h"
>   #include "grep.h"
>   
>   static const char * const walken_usage[] = {
> @@ -154,7 +155,22 @@ static int walken_object_walk(struct rev_info *rev)
>   	blob_count = 0;
>   	tree_count = 0;
>   
> -	traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL);
> +	if (1) {
> +		/* Unfiltered: */
> +		printf(_("Unfiltered object walk.\n"));
> +		traverse_commit_list(rev, walken_show_commit,
> +				walken_show_object, NULL);
> +	} else {
> +		printf(_("Filtered object walk with filterspec 'tree:1'.\n"));
> +		/*
> +		 * We can parse a tree depth of 1 to demonstrate the kind of
> +		 * filtering that could occur eg during shallow cloning.
> +		 */

I think I'd avoid the term "shallow clone" here.  Shallow clone
refers to getting a limited commit history.  That's orthogonal from
partial clone and the filtered tree walk that operates *within* a commit
or a series of commits.

Granted, a user might want to do both a shallow and partial clone (and
then later partial fetches), but I wouldn't mix the concepts here.


> +		parse_list_objects_filter(&filter_options, "tree:1");
> +
> +		traverse_commit_list_filtered(&filter_options, rev,
> +			walken_show_commit, walken_show_object, NULL, &omitted);
> +	}
>   
>   	printf(_("Object walk completed. Found %d commits, %d blobs, %d tags, "
>   	       "and %d trees.\n"), commit_count, blob_count, tag_count,
>
Emily Shaffer June 17, 2019, 8:30 p.m. UTC | #2
On Fri, Jun 07, 2019 at 03:15:53PM -0400, Jeff Hostetler wrote:
> 
> 
> On 6/6/2019 9:08 PM, Emily Shaffer wrote:
> > Demonstrate how filter specs can be used when performing a revision walk
> > of all object types. In this case, tree depth is used. Contributors who
> > are following the revision walking tutorial will be encouraged to run
> > the revision walk with and without the filter in order to compare the
> > number of objects seen in each case.
> > 
> > Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
> > ---
> >   builtin/walken.c | 18 +++++++++++++++++-
> >   1 file changed, 17 insertions(+), 1 deletion(-)
> > 
> > diff --git a/builtin/walken.c b/builtin/walken.c
> > index 408af6c841..f2c98bcd6b 100644
> > --- a/builtin/walken.c
> > +++ b/builtin/walken.c
> > @@ -13,6 +13,7 @@
> >   #include "pretty.h"
> >   #include "line-log.h"
> >   #include "list-objects.h"
> > +#include "list-objects-filter-options.h"
> >   #include "grep.h"
> >   static const char * const walken_usage[] = {
> > @@ -154,7 +155,22 @@ static int walken_object_walk(struct rev_info *rev)
> >   	blob_count = 0;
> >   	tree_count = 0;
> > -	traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL);
> > +	if (1) {
> > +		/* Unfiltered: */
> > +		printf(_("Unfiltered object walk.\n"));
> > +		traverse_commit_list(rev, walken_show_commit,
> > +				walken_show_object, NULL);
> > +	} else {
> > +		printf(_("Filtered object walk with filterspec 'tree:1'.\n"));
> > +		/*
> > +		 * We can parse a tree depth of 1 to demonstrate the kind of
> > +		 * filtering that could occur eg during shallow cloning.
> > +		 */
> 
> I think I'd avoid the term "shallow clone" here.  Shallow clone
> refers to getting a limited commit history.  That's orthogonal from
> partial clone and the filtered tree walk that operates *within* a commit
> or a series of commits.
> 
> Granted, a user might want to do both a shallow and partial clone (and
> then later partial fetches), but I wouldn't mix the concepts here.

It's a valid complaint. I removed the mention of shallow cloning and
replaced it with a reference to the documentation for --filter in
rev-list. Thanks.

 - Emily
diff mbox series

Patch

diff --git a/builtin/walken.c b/builtin/walken.c
index 408af6c841..f2c98bcd6b 100644
--- a/builtin/walken.c
+++ b/builtin/walken.c
@@ -13,6 +13,7 @@ 
 #include "pretty.h"
 #include "line-log.h"
 #include "list-objects.h"
+#include "list-objects-filter-options.h"
 #include "grep.h"
 
 static const char * const walken_usage[] = {
@@ -154,7 +155,22 @@  static int walken_object_walk(struct rev_info *rev)
 	blob_count = 0;
 	tree_count = 0;
 
-	traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL);
+	if (1) {
+		/* Unfiltered: */
+		printf(_("Unfiltered object walk.\n"));
+		traverse_commit_list(rev, walken_show_commit,
+				walken_show_object, NULL);
+	} else {
+		printf(_("Filtered object walk with filterspec 'tree:1'.\n"));
+		/*
+		 * We can parse a tree depth of 1 to demonstrate the kind of
+		 * filtering that could occur eg during shallow cloning.
+		 */
+		parse_list_objects_filter(&filter_options, "tree:1");
+
+		traverse_commit_list_filtered(&filter_options, rev,
+			walken_show_commit, walken_show_object, NULL, &omitted);
+	}
 
 	printf(_("Object walk completed. Found %d commits, %d blobs, %d tags, "
 	       "and %d trees.\n"), commit_count, blob_count, tag_count,