Skip to contentSkip to conversation

documentation: add tutorial for revision walking

PATCH Superseded Emily Shaffer 8 participants 102 messages Jun 7, 2019 – Oct 11, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 documentation: add tutorial for revision walking

Existing documentation on revision walks seems to be primarily intended as a reference for those already familiar with the procedure. This tutorial attempts to give an entry-level guide to a couple of bare-bones revision walks so that new Git contributors can learn the concepts without having to wade through options parsing or special casing.

The target audience is a Git contributor who is just getting started with the concept of revision walking. The goal is to prepare this contributor to be able to understand and modify existing commands which perform revision walks more easily, although it will also prepare contributors to create new commands which perform walks.

The tutorial covers a basic overview of the structs involved during revision walk, setting up a basic commit walk, setting up a basic all-object walk, and adding some configuration changes to both walk types. It intentionally does not cover how to create new commands or search for options from the command line or gitconfigs.

There is an associated patchset at
https://github.com/nasamuffin/git/tree/revwalk that contains a reference implementation of the code generated by this tutorial.

---

This one is longer than the MyFirstContribution one, thanks in advance to anybody with the wherewithal to review this.

I'll also be mailing an RFC patchset In-Reply-To this message; the RFC patchset should not be merged to Git, as I intend to host it in my own mirror as an example. I hosted a similar example for the MyFirstContribution tutorial; it's visible at
https://github.com/nasamuffin/git/tree/psuh. There might be a better place to host these so I don't "own" them but I'm not sure what it is; keeping them as a live branch somewhere struck me as an okay way to keep them from getting stale.

Looking forward to hearing everyone's comments!
- Emily

 Documentation/.gitignore         |   1 +
 Documentation/Makefile           |   1 +
 Documentation/MyFirstRevWalk.txt | 826 +++++++++++++++++++++++++++++++
 3 files changed, 828 insertions(+)
 create mode 100644 Documentation/MyFirstRevWalk.txt
Documentation/.gitignore +1 -0
index 9022d48355..0e3df737c5 100644
@@ -12,6 +12,7 @@ cmds-*.txt
 mergetools-*.txt
 manpage-base-url.xsl
 SubmittingPatches.txt
+MyFirstRevWalk.txt
 tmp-doc-diff/
 GIT-ASCIIDOCFLAGS
 /GIT-EXCLUDED-PROGRAMS
Documentation/Makefile +1 -0
index dbf5a0f276..d57b80962f 100644
@@ -77,6 +77,7 @@ API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technica
 SP_ARTICLES += $(API_DOCS)
 
 TECH_DOCS += SubmittingPatches
+TECH_DOCS += MyFirstRevWalk
 TECH_DOCS += technical/hash-function-transition
 TECH_DOCS += technical/http-protocol
 TECH_DOCS += technical/index-format
Documentation/MyFirstRevWalk.txt new file +826 -0

826 lines not on this page · raw message

Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#1 lore raw

cover example implementation of revwalk tutorial

This patchset is NOT intended to be merged to the Git project!

This patchset should indicate what a contributor would generate by following the MyFirstRevWalk tutorial.

I intend to push a feature branch with these patches to my own mirror of Git on Github (github.com/nasamuffin/git/tree/revwalk). I'm sending them for review by the list to check for consistency with the Git codebase, so they aren't a bad example for new contributors.

Thanks for any reviews, all!
- Emily

Emily Shaffer (13):
walken: add infrastructure for revwalk demo
walken: add usage to enable -h
walken: add placeholder to initialize defaults
walken: add handler to git_config
walken: configure rev_info and prepare for walk
walken: perform our basic revision walk
walken: filter for authors from gmail address
walken: demonstrate various topographical sorts
walken: demonstrate reversing a revision walk list
walken: add unfiltered object walk from HEAD
walken: add filtered object walk
walken: count omitted objects
walken: reverse the object walk order

 Makefile         |   1 +
 builtin.h        |   1 +
 builtin/walken.c | 263 +++++++++++++++++++++++++++++++++++++++++++++++
 git.c            |   1 +
 4 files changed, 266 insertions(+)
 create mode 100644 builtin/walken.c
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#2 lore raw

RFC PATCH 1/13 walken: add infrastructure for revwalk demo

Begin to add scaffolding for git walken, a toy command which we will teach to perform a number of revision walks, in order to demonstrate the mechanics of revision walking for developers new to the Git project.

This commit is the beginning of an educational series which correspond to the tutorial in Documentation/MyFirstRevWalk.txt.

---
 Makefile         |  1 +
 builtin.h        |  1 +
 builtin/walken.c | 14 ++++++++++++++
 3 files changed, 16 insertions(+)
 create mode 100644 builtin/walken.c
Makefile +1 -0
index 8a7e235352..a25d46c7a3 100644
@@ -1143,6 +1143,7 @@ BUILTIN_OBJS += builtin/var.o
 BUILTIN_OBJS += builtin/verify-commit.o
 BUILTIN_OBJS += builtin/verify-pack.o
 BUILTIN_OBJS += builtin/verify-tag.o
+BUILTIN_OBJS += builtin/walken.o
 BUILTIN_OBJS += builtin/worktree.o
 BUILTIN_OBJS += builtin/write-tree.o
 
builtin.h +1 -0
index ec7e0954c4..c919736c36 100644
@@ -242,6 +242,7 @@ int cmd_var(int argc, const char **argv, const char *prefix);
 int cmd_verify_commit(int argc, const char **argv, const char *prefix);
 int cmd_verify_tag(int argc, const char **argv, const char *prefix);
 int cmd_version(int argc, const char **argv, const char *prefix);
+int cmd_walken(int argc, const char **argv, const char *prefix);
 int cmd_whatchanged(int argc, const char **argv, const char *prefix);
 int cmd_worktree(int argc, const char **argv, const char *prefix);
 int cmd_write_tree(int argc, const char **argv, const char *prefix);
builtin/walken.c new file +14 -0
new file mode 100644
index 0000000000..bfeaa5188d
@@ -0,0 +1,14 @@
+/*
+ * "git walken"
+ *
+ * Part of the "My First Revision Walk" tutorial.
+ */
+
+#include <stdio.h>
+#include "builtin.h"
+
+int cmd_walken(int argc, const char **argv, const char *prefix)
+{
+	printf(_("cmd_walken incoming...\n"));
+	return 0;
+}
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#3 lore raw

RFC PATCH 2/13 walken: add usage to enable -h

In reply to Emily Shaffer

One requirement of the Git test suite is that all commands support '-h', which is captured by parse_options(). In order to support this flag, add a short usage text to walken.c and invoke parse_options().

With this change, we can now add cmd_walken to the builtins set and expect tests to pass, so we'll do so - cmd_walken is now open for business.

---
 builtin/walken.c | 12 ++++++++++++
 git.c            |  1 +
 2 files changed, 13 insertions(+)
builtin/walken.c +12 -0
index bfeaa5188d..5ae7c7d93f 100644
@@ -6,9 +6,21 @@
 
 #include <stdio.h>
 #include "builtin.h"
+#include "parse-options.h"
+
+static const char * const walken_usage[] = {
+	N_("git walken"),
+	NULL,
+};
 
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
+	struct option options[] = {
+		OPT_END()
+	};
+
+	argc = parse_options(argc, argv, prefix, options, walken_usage, 0);
+
 	printf(_("cmd_walken incoming...\n"));
 	return 0;
 }
git.c +1 -0
index 1bf9c94550..209c42836f 100644
@@ -600,6 +600,7 @@ static struct cmd_struct commands[] = {
 	{ "verify-pack", cmd_verify_pack },
 	{ "verify-tag", cmd_verify_tag, RUN_SETUP },
 	{ "version", cmd_version },
+	{ "walken", cmd_walken, RUN_SETUP },
 	{ "whatchanged", cmd_whatchanged, RUN_SETUP },
 	{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT },
 	{ "write-tree", cmd_write_tree, RUN_SETUP },
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#4 lore raw

RFC PATCH 3/13 walken: add placeholder to initialize defaults

In reply to Emily Shaffer

Eventually, we will want a good place to initialize default variables for use during our revision walk(s) in git walken. For now, there's nothing to do here, but let's add the scaffolding so that it's easy to tell where to put the setup later on.

---
 builtin/walken.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
builtin/walken.c +13 -0
index 5ae7c7d93f..dcee906556 100644
@@ -13,6 +13,18 @@ static const char * const walken_usage[] = {
 	NULL,
 };
 
+/*
+ * Within init_walken_defaults() we can call into other useful defaults to set
+ * in the global scope or on the_repository. It's okay to borrow from other
+ * functions which are doing something relatively similar to yours.
+ */
+static void init_walken_defaults(void)
+{
+	/* We don't actually need the same components `git log` does; leave this
+	 * empty for now.
+	 */
+}
+
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
 	struct option options[] = {
@@ -21,6 +33,7 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 
 	argc = parse_options(argc, argv, prefix, options, walken_usage, 0);
 
+	init_walken_defaults();
 	printf(_("cmd_walken incoming...\n"));
 	return 0;
 }
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#5 lore raw

RFC PATCH 4/13 walken: add handler to git_config

In reply to Emily Shaffer

For now, we have no configuration options we want to set up for ourselves, but in the future we may need to. At the very least, we should invoke git_default_config() for each config option; we will do so inside of a skeleton config callback so that we know where to add configuration handling later on when we need it.

---
 builtin/walken.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
builtin/walken.c +26 -0
index dcee906556..5d1666a5da 100644
@@ -6,6 +6,7 @@
 
 #include <stdio.h>
 #include "builtin.h"
+#include "config.h"
 #include "parse-options.h"
 
 static const char * const walken_usage[] = {
@@ -25,6 +26,28 @@ static void init_walken_defaults(void)
 	 */
 }
 
+/*
+ * This method will be called back by git_config(). It is used to gather values
+ * from the configuration files available to Git.
+ *
+ * Each time git_config() finds a configuration file entry, it calls this
+ * callback. Then, this function should compare it to entries which concern us,
+ * and make settings changes as necessary.
+ *
+ * If we are called with a config setting we care about, we should use one of
+ * the helpers which exist in config.h to pull out the value for ourselves, i.e.
+ * git_config_string(...) or git_config_bool(...).
+ *
+ * If we don't match anything, we should pass it along to another stakeholder
+ * who may otherwise care - in log's case, grep, gpg, and diff-ui. For our case,
+ * we'll ignore everybody else.
+ */
+static int git_walken_config(const char *var, const char *value, void *cb)
+{
+	/* For now, let's not bother with anything. */
+	return git_default_config(var, value, cb);
+}
+
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
 	struct option options[] = {
@@ -34,6 +57,9 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, prefix, options, walken_usage, 0);
 
 	init_walken_defaults();
+
+	git_config(git_walken_config, NULL);
+
 	printf(_("cmd_walken incoming...\n"));
 	return 0;
 }
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#6 lore raw

RFC PATCH 5/13 walken: configure rev_info and prepare for walk

In reply to Emily Shaffer

struct rev_info is what's used by the struct itself. repo_init_revisions() initializes the struct; then we need to set it up for the walk we want to perform, which is done in final_rev_info_setup().

The most important step here is adding the first object we want to walk to the pending array. Here, we take the easy road and use add_head_to_pending(); there is also a way to do it with setup_revision_opt() and setup_revisions() which we demonstrate but do not use. If we were to forget this step, the walk would do nothing - the pending queue would be checked, determined to be empty, and the walk would terminate immediately.

---
 builtin/walken.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
builtin/walken.c +42 -0
index 5d1666a5da..c101db38c7 100644
@@ -6,6 +6,7 @@
 
 #include <stdio.h>
 #include "builtin.h"
+#include "revision.h"
 #include "config.h"
 #include "parse-options.h"
 
@@ -26,6 +27,35 @@ static void init_walken_defaults(void)
 	 */
 }
 
+/*
+ * cmd_log calls a second set of init after the repo_init_revisions call. We'll
+ * mirror those settings in post_repo_init_init.
+ */
+static void final_rev_info_setup(int argc, const char **argv, const char *prefix,
+		struct rev_info *rev)
+{
+	struct setup_revision_opt opt;
+
+	/* setup_revision_opt is used to pass options to the setup_revisions()
+	 * call. It's got some special items for submodules and other types of
+	 * optimizations, but for now, we'll just point it to HEAD and call it
+	 * good. First we should make sure to reset it. TODO: This is useful for
+	 * more complicated stuff revisions, but a decent shortcut for the first
+	 * pass is add_head_to_pending().
+	 */
+	memset(&opt, 0, sizeof(opt));
+	opt.def = "HEAD";
+	opt.revarg_opt = REVARG_COMMITTISH;
+	//setup_revisions(argc, argv, rev, &opt);
+
+	/* Let's force oneline format. */
+	get_commit_format("oneline", rev);
+	rev->verbose_header = 1;
+	
+	/* add the HEAD to pending so we can start */
+	add_head_to_pending(rev);
+}
+
 /*
  * This method will be called back by git_config(). It is used to gather values
  * from the configuration files available to Git.
@@ -54,12 +84,24 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	struct rev_info rev;
+
 	argc = parse_options(argc, argv, prefix, options, walken_usage, 0);
 
 	init_walken_defaults();
 
 	git_config(git_walken_config, NULL);
 
+	/* Time to set up the walk. repo_init_revisions sets up rev_info with
+	 * the defaults, but then you need to make some configuration settings
+	 * to make it do what's special about your walk.
+	 */
+	repo_init_revisions(the_repository, &rev, prefix);
+
+	/* Before we do the walk, we need to set a starting point. It's not
+	 * coming from opt. */
+	final_rev_info_setup(argc, argv, prefix, &rev);
+
 	printf(_("cmd_walken incoming...\n"));
 	return 0;
 }
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#7 lore raw

RFC PATCH 6/13 walken: perform our basic revision walk

In reply to Emily Shaffer

Add the final steps needed and implement the walk loop itself. We add a method walken_commit_walk() which performs the final setup to revision.c and then iterates over commits from get_revision().

This basic walk only prints the subject line of each commit in the history. It is nearly equivalent to git log --oneline.

---
 builtin/walken.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
builtin/walken.c +41 -0
index c101db38c7..9cf19a24ab 100644
@@ -7,8 +7,11 @@
 #include <stdio.h>
 #include "builtin.h"
 #include "revision.h"
+#include "commit.h"
 #include "config.h"
 #include "parse-options.h"
+#include "pretty.h"
+#include "line-log.h"
 
 static const char * const walken_usage[] = {
 	N_("git walken"),
@@ -78,6 +81,39 @@ static int git_walken_config(const char *var, const char *value, void *cb)
 	return git_default_config(var, value, cb);
 }
 
+/*
+ * walken_commit_walk() is invoked by cmd_walken() after initialization. It
+ * does the commit walk only.
+ */
+static int walken_commit_walk(struct rev_info *rev)
+{
+	struct commit *commit;
+	struct strbuf prettybuf;
+
+	strbuf_init(&prettybuf, 0);
+
+
+	/* prepare_revision_walk() gets the final steps ready for a revision
+	 * walk. We check the return value for errors. */
+	if (prepare_revision_walk(rev)) {
+		die(_("revision walk setup failed"));
+	}
+
+	/* Now we can start the real commit walk. get_revision grabs the next
+	 * revision based on the contents of rev.
+	 */
+	rev->diffopt.close_file = 0;
+	while ((commit = get_revision(rev)) != NULL) {
+		if (commit == NULL)
+			continue;
+		strbuf_reset(&prettybuf);
+		pp_commit_easy(CMIT_FMT_ONELINE, commit, &prettybuf);
+		printf(_("%s\n"), prettybuf.buf);
+
+	}
+	return 0;
+}
+
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
 	struct option options[] = {
@@ -98,10 +134,15 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 	 */
 	repo_init_revisions(the_repository, &rev, prefix);
 
+	/* We can set our traversal flags here. */
+	rev.always_show_header = 1;
+
 	/* Before we do the walk, we need to set a starting point. It's not
 	 * coming from opt. */
 	final_rev_info_setup(argc, argv, prefix, &rev);
 
+	walken_commit_walk(&rev);
+
 	printf(_("cmd_walken incoming...\n"));
 	return 0;
 }
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#8 lore raw

RFC PATCH 7/13 walken: filter for authors from gmail address

In reply to Emily Shaffer

In order to demonstrate how to create grep filters for revision walks, filter the walk performed by cmd_walken() to print only commits which are authored by someone with a gmail address.

This commit demonstrates how to append a grep pattern to a rev_info.grep_filter, to teach new contributors how to create their own more generalized grep filters during revision walks.

---
 builtin/walken.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
builtin/walken.c +8 -4
index 9cf19a24ab..6c0f4e7b7a 100644
@@ -12,6 +12,7 @@
 #include "parse-options.h"
 #include "pretty.h"
 #include "line-log.h"
+#include "grep.h"
 
 static const char * const walken_usage[] = {
 	N_("git walken"),
@@ -25,9 +26,8 @@ static const char * const walken_usage[] = {
  */
 static void init_walken_defaults(void)
 {
-	/* We don't actually need the same components `git log` does; leave this
-	 * empty for now.
-	 */
+	/* Needed by our grep filter. */
+	init_grep_defaults(the_repository);
 }
 
 /*
@@ -51,6 +51,10 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
 	opt.revarg_opt = REVARG_COMMITTISH;
 	//setup_revisions(argc, argv, rev, &opt);
 
+	/* Add a grep pattern to the author line in the header. */
+	append_header_grep_pattern(&rev->grep_filter, GREP_HEADER_AUTHOR, "gmail");
+	compile_grep_patterns(&rev->grep_filter);
+
 	/* Let's force oneline format. */
 	get_commit_format("oneline", rev);
 	rev->verbose_header = 1;
@@ -77,7 +81,7 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
  */
 static int git_walken_config(const char *var, const char *value, void *cb)
 {
-	/* For now, let's not bother with anything. */
+	grep_config(var, value, cb);
 	return git_default_config(var, value, cb);
 }
 
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#9 lore raw

RFC PATCH 8/13 walken: demonstrate various topographical sorts

In reply to Emily Shaffer

Order the revision walk by author or commit dates, to demonstrate how to apply topo_sort to a revision walk.

While following the tutorial, new contributors are guided to run a walk with each sort and compare the results.

---
 builtin/walken.c | 5 +++++
 1 file changed, 5 insertions(+)
builtin/walken.c +5 -0
index 6c0f4e7b7a..716d31f04e 100644
@@ -61,6 +61,11 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
 	
 	/* add the HEAD to pending so we can start */
 	add_head_to_pending(rev);
+	
+	/* Let's play with the sort order. */
+	rev->topo_order = 1;
+	rev->sort_order = REV_SORT_BY_COMMIT_DATE;
+	/* rev->sort_order = REV_SORT_BY_AUTHOR_DATE; */
 }
 
 /*
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#10 lore raw

RFC PATCH 9/13 walken: demonstrate reversing a revision walk list

In reply to Emily Shaffer

The final installment in the tutorial about sorting revision walk outputs. This commit reverses the commit list, so that we see newer commits last (handy since we aren't using a pager).

It's important to note that rev->reverse needs to be set after add_head_to_pending() or before setup_revisions(). (This is mentioned in the accompanying tutorial.)

---
 builtin/walken.c | 3 +++
 1 file changed, 3 insertions(+)
builtin/walken.c +3 -0
index 716d31f04e..86c8d29c48 100644
@@ -61,6 +61,9 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
 	
 	/* add the HEAD to pending so we can start */
 	add_head_to_pending(rev);
+
+	/* Reverse the order */
+	rev->reverse = 1;
 	
 	/* Let's play with the sort order. */
 	rev->topo_order = 1;
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#11 lore raw

RFC PATCH 10/13 walken: add unfiltered object walk from HEAD

In reply to Emily Shaffer

Provide a demonstration of a revision walk which traverses all types of object, not just commits. This type of revision walk is used for operations such as creating packfiles and performing fetches or clones, so it's useful to teach new developers how it works. For starters, only demonstrate the unfiltered version, as this will make the tutorial easier to follow.

This commit is part of a tutorial on revision walking.

---
 builtin/walken.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 77 insertions(+), 2 deletions(-)
builtin/walken.c +77 -2
index 86c8d29c48..408af6c841 100644
@@ -12,6 +12,7 @@
 #include "parse-options.h"
 #include "pretty.h"
 #include "line-log.h"
+#include "list-objects.h"
 #include "grep.h"
 
 static const char * const walken_usage[] = {
@@ -19,6 +20,11 @@ static const char * const walken_usage[] = {
 	NULL,
 };
 
+static int commit_count;
+static int tag_count;
+static int blob_count;
+static int tree_count;
+
 /*
  * Within init_walken_defaults() we can call into other useful defaults to set
  * in the global scope or on the_repository. It's okay to borrow from other
@@ -93,6 +99,70 @@ static int git_walken_config(const char *var, const char *value, void *cb)
 	return git_default_config(var, value, cb);
 }
 
+static void walken_show_commit(struct commit *cmt, void *buf)
+{
+	commit_count++;
+}
+
+static void walken_show_object(struct object *obj, const char *str, void *buf)
+{
+	switch (obj->type) {
+	case OBJ_TREE:
+		tree_count++;
+		break;
+	case OBJ_BLOB:
+		blob_count++;
+		break;
+	case OBJ_TAG:
+		tag_count++;
+		break;
+	case OBJ_COMMIT:
+		printf(_("Unexpectedly encountered a commit in "
+			 "walken_show_object!\n"));
+		commit_count++;
+		break;
+	default:
+		printf(_("Unexpected object type %s!\n"),
+		       type_name(obj->type));
+		break;
+	}
+}
+
+/*
+ * walken_object_walk() is invoked by cmd_walken() after initialization. It does
+ * a walk of all object types.
+ */
+static int walken_object_walk(struct rev_info *rev)
+{
+	struct list_objects_filter_options filter_options = {};
+	struct oidset omitted;
+	oidset_init(&omitted, 0);
+
+	printf("walken_object_walk beginning...\n");
+
+	rev->tree_objects = 1;
+	rev->blob_objects = 1;
+	rev->tag_objects = 1;
+	rev->tree_blobs_in_commit_order = 1;
+	rev->exclude_promisor_objects = 1;
+
+	if (prepare_revision_walk(rev))
+		die(_("revision walk setup failed"));
+
+	commit_count = 0;
+	tag_count = 0;
+	blob_count = 0;
+	tree_count = 0;
+
+	traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL);
+
+	printf(_("Object walk completed. Found %d commits, %d blobs, %d tags, "
+	       "and %d trees.\n"), commit_count, blob_count, tag_count,
+	       tree_count);
+
+	return 0;
+}
+
 /*
  * walken_commit_walk() is invoked by cmd_walken() after initialization. It
  * does the commit walk only.
@@ -151,9 +221,14 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 
 	/* Before we do the walk, we need to set a starting point. It's not
 	 * coming from opt. */
-	final_rev_info_setup(argc, argv, prefix, &rev);
 
-	walken_commit_walk(&rev);
+	if (1) {
+		add_head_to_pending(&rev);
+		walken_object_walk(&rev);
+	} else {
+		final_rev_info_setup(argc, argv, prefix, &rev);
+		walken_commit_walk(&rev);
+	}
 
 	printf(_("cmd_walken incoming...\n"));
 	return 0;
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#12 lore raw

RFC PATCH 11/13 walken: add filtered object walk

In reply to Emily Shaffer

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.

---
 builtin/walken.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
builtin/walken.c +17 -1
index 408af6c841..f2c98bcd6b 100644
@@ -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,
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#13 lore raw

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

Quoted 29 lines · Emily Shaffer

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.

---
  builtin/walken.c | 18 +++++++++++++++++-
  1 file changed, 17 insertions(+), 1 deletion(-)
builtin/walken.c +2 -1
index 408af6c841..f2c98bcd6b 100644
@@ -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) {

builtin/walken.c static int walken_object_walk(struct rev_info *rev) · line 168

Quoted 10 lines
builtin/walken.c +10 -0
+		/* 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.

Quoted 9 lines
builtin/walken.c +5 -0
+		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,
#14 lore raw

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

Quoted 46 lines · Jeff Hostetler
Quoted 27 lines · Emily Shaffer

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.

---
  builtin/walken.c | 18 +++++++++++++++++-
  1 file changed, 17 insertions(+), 1 deletion(-)
builtin/walken.c +2 -1
index 408af6c841..f2c98bcd6b 100644
@@ -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) {

builtin/walken.c static int walken_object_walk(struct rev_info *rev) · line 167

Quoted 10 lines
builtin/walken.c +10 -0
+		/* 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.

Quoted 2 lines

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

#15 lore raw

RFC PATCH 12/13 walken: count omitted objects

In reply to Emily Shaffer

It may be illuminating to see which objects were not included within a given filter. This also demonstrates, since filter-spec "tree:1" is used, that the 'omitted' list contains all objects which are omitted, not just the first objects which were omitted - that is, it continues to dereference omitted trees and commits.

This is part of a tutorial on performing revision walks.

---
 builtin/walken.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
builtin/walken.c +11 -2
index f2c98bcd6b..d93725ee88 100644
@@ -137,6 +137,9 @@ static int walken_object_walk(struct rev_info *rev)
 {
 	struct list_objects_filter_options filter_options = {};
 	struct oidset omitted;
+	struct oidset_iter oit;
+	struct object_id *oid = NULL;
+	int omitted_count = 0;
 	oidset_init(&omitted, 0);
 
 	printf("walken_object_walk beginning...\n");
@@ -172,9 +175,15 @@ static int walken_object_walk(struct rev_info *rev)
 			walken_show_commit, walken_show_object, NULL, &omitted);
 	}
 
+	/* Count the omitted objects. */
+	oidset_iter_init(&omitted, &oit);
+
+	while ((oid = oidset_iter_next(&oit)))
+		omitted_count++;
+
 	printf(_("Object walk completed. Found %d commits, %d blobs, %d tags, "
-	       "and %d trees.\n"), commit_count, blob_count, tag_count,
-	       tree_count);
+	       "and %d trees; %d omitted objects.\n"), commit_count,
+	       blob_count, tag_count, tree_count, omitted_count);
 
 	return 0;
 }
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#16 lore raw

RFC PATCH 13/13 walken: reverse the object walk order

In reply to Emily Shaffer

Demonstrate that just like commit walks, object walks can have their order reversed. Additionally, add verbose logging of objects encountered in order to let contributors prove to themselves that the walk has actually been reversed. With this commit, git walken becomes extremely chatty - it's recommended to pipe the output through head or tail or to redirect it into a file.

---
 builtin/walken.c | 3 +++
 1 file changed, 3 insertions(+)
builtin/walken.c +3 -0
index d93725ee88..4bfee3a2d7 100644
@@ -102,11 +102,13 @@ static int git_walken_config(const char *var, const char *value, void *cb)
 
 static void walken_show_commit(struct commit *cmt, void *buf)
 {
+	printf(_("commit: %s\n"), oid_to_hex(&cmt->object.oid));
 	commit_count++;
 }
 
 static void walken_show_object(struct object *obj, const char *str, void *buf)
 {
+	printf(_("%s: %s\n"), type_name(obj->type), oid_to_hex(&obj->oid));
 	switch (obj->type) {
 	case OBJ_TREE:
 		tree_count++;
@@ -149,6 +151,7 @@ static int walken_object_walk(struct rev_info *rev)
 	rev->tag_objects = 1;
 	rev->tree_blobs_in_commit_order = 1;
 	rev->exclude_promisor_objects = 1;
+	rev->reverse = 1;
 
 	if (prepare_revision_walk(rev))
 		die(_("revision walk setup failed"));
Signature · 1 line
2.22.0.rc1.311.g5d7573a151-goog
#17 lore raw
In reply to Emily Shaffer

Documentation/.gitignore cmds-*.txt · line 13

Quoted 13 lines · Emily Shaffer

[...]
The tutorial covers a basic overview of the structs involved during revision walk, setting up a basic commit walk, setting up a basic all-object walk, and adding some configuration changes to both walk types. It intentionally does not cover how to create new commands or search for options from the command line or gitconfigs.

---

Documentation/.gitignore +1 -0
@@ -12,6 +12,7 @@ cmds-*.txt
 SubmittingPatches.txt
+MyFirstRevWalk.txt

The new file itself is named Documentation/MyFirstRevWalk.txt, so why add it to .gitignore?

Documentation/MyFirstRevWalk.txt line 6

Quoted 8 lines
Documentation/MyFirstRevWalk.txt +6 -0
@@ -0,0 +1,826 @@
+== What's a Revision Walk?
+
+The revision walk is a key concept in Git - this is the process that underpins
+operations like `git log`, `git blame`, and `git reflog`. Beginning at HEAD, the
+list of objects is found by walking parent relationships between objects. The
+revision walk can also be usedto determine whether or not a given object is

s/usedto/used to/

Quoted 4 lines
Documentation/MyFirstRevWalk.txt +4 -0
+reachable from the current HEAD pointer.
+
+We'll put our fiddling into a new command. For fun, let's name it `git walken`.
+Open up a new file `builtin/walken.c` and set up the command handler:

Documentation/MyFirstRevWalk.txt line 40

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +10 -0
+
+----
+/*
+ * "git walken"
+ *
+ * Part of the "My First Revision Walk" tutorial.
+ */
+
+#include <stdio.h>
+#include "builtin.h"

Git source files must always include cache.h or git-compat-util.h (or, for builtins, builtin.h) as the very first header since those headers take care of differences which might crop up as problems with system headers on various platforms. System headers are included after Git headers. So, stdio.h should be included after builtin.h. In this case, however, stdio.h will get pulled in by git-compat-util.h anyhow, so you need not include it here.

Documentation/MyFirstRevWalk.txt line 55

Quoted 7 lines
Documentation/MyFirstRevWalk.txt +7 -0
+Add usage text and `-h` handling, in order to pass the test suite:
+
+----
+static const char * const walken_usage[] = {
+       N_("git walken"),
+       NULL,
+}

Unless you plan on referencing this from functions other than cmd_walken(), it need not be global.

Documentation/MyFirstRevWalk.txt line 65

Quoted 9 lines
Documentation/MyFirstRevWalk.txt +9 -0
+int cmd_walken(int argc, const char **argv, const char *prefix)
+{
+       struct option options[] = {
+               OPT_END()
+       };
+
+       argc = parse_options(argc, argv, prefix, options, walken_usage, 0);
+
+       ...

Perhaps comment out the "..." or remove it altogether to avoid having the compiler barf when the below instructions tell the reader to build the command.

Documentation/MyFirstRevWalk.txt line 69

Quoted 3 lines
Documentation/MyFirstRevWalk.txt +3 -0
+}
+
+Also add the relevant line in builtin.h near `cmd_whatchanged()`:

s/builtin.h/&/

Documentation/MyFirstRevWalk.txt line 91

Quoted 5 lines
Documentation/MyFirstRevWalk.txt +5 -0
+Build and test out your command, without forgetting to ensure the `DEVELOPER`
+flag is set:
+
+----
+echo DEVELOPER=1 >config.mak

This will blast existing content of 'config.mak' which could be dangerous. It might be better to suggest >> instead.

Documentation/MyFirstRevWalk.txt line 122

Quoted 4 lines
Documentation/MyFirstRevWalk.txt +4 -0
+`name` is the SHA-1 of the object - a 40-digit hex string you may be familiar
+with from using Git to organize your source in the past. Check the tutorial
+mentioned above towards the top for a discussion of where the SHA-1 can come
+from.

With all the recent work to move away from SHA-1 and to support other hash functions, perhaps just call this "object ID" rather than SHA-1, and drop mention of it being exactly 40 digits. Instead, perhaps say something like "...is the hexadecimal representation of the object ID...".

Documentation/MyFirstRevWalk.txt line 148

Quoted 8 lines
Documentation/MyFirstRevWalk.txt +8 -0
+== Basic Commit Walk
+
+First, let's see if we can replicate the output of `git log --oneline`. We'll
+refer back to the implementation frequently to discover norms when performing
+a revision walk of our own.
+
+We'll need all the commits, in order, which preceded our current commit. We will
+also need to know the name and subject.

This paragraph confused me. I read it as these being prerequisites I would somehow have to provide in order to write the code. Perhaps it can be rephrased to state that this is what the code will be doing.
Maybe: "To do this, we will find all the commits, in order, which precede the current commit, and extract from them the name and subject [of the commit message]" or something.

Documentation/MyFirstRevWalk.txt line 161

Quoted 9 lines
Documentation/MyFirstRevWalk.txt +9 -0
+=== Setting Up
+
+Preparing for your revision walk has some distinct stages.
+
+1. Perform default setup for this mode, and others which may be invoked.
+2. Check configuration files for relevant settings.
+3. Set up the rev_info struct.
+4. Tweak the initialized rev_info to suit the current walk.
+5. Prepare the rev_info for the walk.

s/rev_info/&/ in the above three lines.

Documentation/MyFirstRevWalk.txt line 172

Quoted 9 lines
Documentation/MyFirstRevWalk.txt +9 -0
+==== Default Setups
+
+Before you begin to examine user configuration for your revision walk, it's
+common practice for you to initialize to default any switches that your command
+may have, as well as ask any other components you may invoke to initialize as
+well. `git log` does this in `init_log_defaults()`; in that case, one global
+`decoration_style` is initialized, as well as the grep and diff-UI components.
+
+For our purposes, within `git walken`, for the first example we do we don't

"we do we don't"?

Documentation/MyFirstRevWalk.txt line 173

Quoted 1 line
Documentation/MyFirstRevWalk.txt +1 -0
+intend to invoke anything, and we don't have any configuration to do. However,

"invoke anything" is pretty nebulous, as is the earlier "components you may invoke". A newcomer is unlikely to know what this means, so perhaps it needs an example (even if just a short parenthetical comment).

Documentation/MyFirstRevWalk.txt line 183

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +10 -0
+we may want to add some later, so for now, we can add an empty placeholder.
+Create a new function in `builtin/walken.c`:
+
+----
+static void init_walken_defaults(void)
+{
+       /* We don't actually need the same components `git log` does; leave this
+        * empty for now.
+        */
+}

/*
* Git multi-line comments
* are formatted like this.
*/

Documentation/MyFirstRevWalk.txt line 217

Quoted 8 lines
Documentation/MyFirstRevWalk.txt +8 -0
+Add a new function to `builtin/walken.c`:
+
+----
+static int git_walken_config(const char *var, const char *value, void *cb)
+{
+       /* For now, let's not bother with anything. */
+       return git_default_config(var, value, cb);
+}

Comment is somewhat confusing. Perhaps say instead "We don't currently have custom configuration, so fall back to git_default_config()" or something.

Documentation/MyFirstRevWalk.txt line 238

Quoted 6 lines
Documentation/MyFirstRevWalk.txt +6 -0
+==== Setting Up `rev_info`
+
+Now that we've gathered external configuration and options, it's time to
+initialize the `rev_info` object which we will use to perform the walk. This is
+typically done by calling `repo_init_revisions()` with the repository you intend
+to target, as well as the prefix and your `rev_info` struct.

Maybe: s/the prefix/the & argument of cmd_walken/

Documentation/MyFirstRevWalk.txt line 246

Quoted 7 lines
Documentation/MyFirstRevWalk.txt +7 -0
+Add the `struct rev_info` and the `repo_init_revisions()` call:
+----
+int cmd_walken(int argc, const char **argv, const char *prefix)
+{
+       /* This can go wherever you like in your declarations.*/
+       struct rev_info rev;
+       ...

A less verbose way to indicate the same without using a /* comment */:

    ...
    struct rev_info rev;
    ...

Documentation/MyFirstRevWalk.txt line 263

Quoted 8 lines
Documentation/MyFirstRevWalk.txt +8 -0
+       /* This should go after the git_config() call. */
+       repo_init_revisions(the_repository, &rev, prefix);
+}
+----
+static void final_rev_info_setup(struct rev_info *rev)
+{
+       /* We want to mimick the appearance of `git log --oneline`, so let's
+        * force oneline format. */

s/mimick/mimic/

/*
* Multi-line
* comment.
*/

Documentation/MyFirstRevWalk.txt line 313

Quoted 12 lines
Documentation/MyFirstRevWalk.txt +12 -0
+==== Preparing `rev_info` For the Walk
+
+Now that `rev` is all initialized and configured, we've got one more setup step
+before we get rolling. We can do this in a helper, which will both prepare the
+`rev_info` for the walk, and perform the walk itself. Let's start the helper
+with the call to `prepare_revision_walk()`.
+
+----
+static int walken_commit_walk(struct rev_info *rev)
+{
+       /* prepare_revision_walk() gets the final steps ready for a revision
+        * walk. We check the return value for errors. */

Not at all sure what this comment is trying to say. Also, the second sentence adds no value to what the code itself already says clearly by actually checking the return value.

Quoted 7 lines
Documentation/MyFirstRevWalk.txt +7 -0
+       if (prepare_revision_walk(rev))
+               die(_("revision walk setup failed"));
+}
+==== Performing the Walk!
+
+Finally! We are ready to begin the walk itself. Now we can see that `rev_info`
+can also be used as an iterator; we move to the next item in the walk by using

Documentation/MyFirstRevWalk.txt line 332

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +10 -0
+`get_revision()` repeatedly. Add the listed variable declarations at the top and
+the walk loop below the `prepare_revision_walk()` call within your
+`walken_commit_walk()`:
+
+----
+static int walken_commit_walk(struct rev_info *rev)
+{
+       struct commit *commit;
+       struct strbuf prettybuf;
+       strbuf_init(&prettybuf, 0);

More idiomatic:

    struct strbuf prettybuf = STRBUF_INIT;

Documentation/MyFirstRevWalk.txt line 338

Quoted 3 lines
Documentation/MyFirstRevWalk.txt +3 -0
+       while ((commit = get_revision(rev)) != NULL) {
+               if (commit == NULL)
+                       continue;

Idiomatic Git code doesn't mention NULL explicitly in conditionals, so:

    while ((commit = get_revision(rev))) {
        if (!commit)
            continue;

Documentation/MyFirstRevWalk.txt line 341

Quoted 2 lines
Documentation/MyFirstRevWalk.txt +2 -0
+               strbuf_reset(&prettybuf);
+               pp_commit_easy(CMIT_FMT_ONELINE, commit, &prettybuf);

Earlier, you talked about calling get_commit_format("oneline",...) to get "oneline" output, so what is the purpose of CMIT_FMT_ONELINE here? The text should explain more clearly what these two different "online"-related bits mean.

Documentation/MyFirstRevWalk.txt line 342

Quoted 1 line
Documentation/MyFirstRevWalk.txt +1 -0
+               printf(_("%s\n"), prettybuf.buf);

There is nothing here to localize, so drop _(...):

    printf("%s\n", prettybuf.buf);

or perhaps just:

    puts(prettybuf.buf);

Documentation/MyFirstRevWalk.txt line 346

Quoted 4 lines
Documentation/MyFirstRevWalk.txt +4 -0
+       }
+
+       return 0;
+}

What does the return value signify?

Documentation/MyFirstRevWalk.txt line 389

Quoted 5 lines
Documentation/MyFirstRevWalk.txt +5 -0
+=== Adding a Filter
+
+Next, we can modify the `grep_filter`. This is done with convenience functions
+found in `grep.h`. For fun, we're filtering to only commits from folks using a
+gmail.com email address - a not-very-precise guess at who may be working on Git

Perhaps? s/gmail.com/&/

Documentation/MyFirstRevWalk.txt line 438

Quoted 12 lines
Documentation/MyFirstRevWalk.txt +12 -0
+=== Changing the Order
+
+Let's see what happens when we run with `REV_SORT_BY_COMMIT_DATE` as opposed to
+`REV_SORT_BY_AUTHOR_DATE`. Add the following:
+
+static void final_rev_info_setup(int argc, const char **argv,
+                const char *prefix, struct rev_info *rev)
+{
+       ...
+
+       rev->topo_order = 1;
+       rev->sort_order = REV_SORT_BY_COMMIT_DATE;

The assignment to rev->sort_order is obvious enough, but the rev->topo_order assignment is quite mysterious to someone coming to this tutorial to learn about revision walking, thus some commentary explaining 'topo_order' would be a good idea.

Documentation/MyFirstRevWalk.txt line 480

Quoted 9 lines
Documentation/MyFirstRevWalk.txt +9 -0
+Finally, compare the two. This is a little less helpful without object names or
+dates, but hopefully we get the idea.
+
+----
+$ diff -u commit-date.txt author-date.txt
+----
+
+This display is an indicator for the latency between publishing a commit for
+review the first time, and getting it actually merged into master.

Perhaps: s/master/&/

Even as a long-time contributor to the project, I had to pause over this statement for several seconds before figuring out what it was talking about. Without a long-winded explanation of how topics progress from submission through 'pu' through 'next' through 'master' and finally into a release, the above statement is likely to be mystifying to a newcomer. Perhaps it should be dropped.

Documentation/MyFirstRevWalk.txt line 483

Quoted 2 lines
Documentation/MyFirstRevWalk.txt +2 -0
+Let's try one more reordering of commits. `rev_info` exposes a `reverse` flag.
+However, it needs to be applied after `add_head_to_pending()` is called. Find

This leaves the reader hanging, wondering why 'reverse' needs to be assigned after add_head_to_pending().

Documentation/MyFirstRevWalk.txt line 559

Quoted 11 lines
Documentation/MyFirstRevWalk.txt +11 -0
+== Basic Object Walk
+
+static void walken_show_commit(struct commit *cmt, void *buf)
+{
+        commit_count++;
+}
+----
+
+Since we have the `struct commit` object, we can look at all the same parts that
+we looked at in our earlier commit-only walk. For the sake of this tutorial,
+though, we'll just increment the commit counter and move on.

This leaves the reader wondering what 'buf' is and what it's used for. Presumably this is the 'show_data' context mentioned earlier? If so, perhaps name this 'ctxt' or 'context' or something and, because this is a tutorial trying to teach revision walking, say a quick word about how it might be used.

Quoted 5 lines
Documentation/MyFirstRevWalk.txt +5 -0
+static void walken_show_object(struct object *obj, const char *str, void *buf)
+{
+        switch (obj->type) {
+        [...]
+        case OBJ_COMMIT:

Documentation/MyFirstRevWalk.txt line 587

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +10 -0
+                printf(_("Unexpectedly encountered a commit in "
+                         "walken_show_object!\n"));
+                commit_count++;
+                break;
+        default:
+                printf(_("Unexpected object type %s!\n"),
+                       type_name(obj->type));
+                break;
+        }
+}

Modern practice in this project is to start error messages with lowercase and to not punctuate the end (no need for "!").

Also, same complaint about the mysterious 'str' argument to the callback as for 'buf' mentioned above.

Documentation/MyFirstRevWalk.txt line 592

Quoted 3 lines
Documentation/MyFirstRevWalk.txt +3 -0
+To help assure us that we aren't double-counting commits, we'll include some
+complaining if a commit object is routed through our non-commit callback; we'll
+also complain if we see an invalid object type.

Are these two error cases "impossible" conditions or can they
actually arise in practice? If the former, use die() instead and drop use of _(...) so as to avoid confusing the reader into thinking that the behavior is indeterminate.

Documentation/MyFirstRevWalk.txt line 603

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +10 -0
+Our main object walk implementation is substantially different from our commit
+walk implementation, so let's make a new function to perform the object walk. We
+can perform setup which is applicable to all objects here, too, to keep separate
+from setup which is applicable to commit-only walks.
+
+----
+static int walken_object_walk(struct rev_info *rev)
+{
+}
+----

This skeleton function definition is populated immediately below, so it's not clear why it needs to be shown here.

Quoted 14 lines
Documentation/MyFirstRevWalk.txt +14 -0
+We'll start by enabling all types of objects in the `struct rev_info`, and
+asking to have our trees and blobs shown in commit order. We'll also exclude
+promisors as the walk becomes more complicated with those types of objects. When
+our settings are ready, we'll perform the normal revision walk setup and
+initialize our tracking variables.
+
+----
+static int walken_object_walk(struct rev_info *rev)
+{
+        rev->tree_objects = 1;
+        rev->blob_objects = 1;
+        rev->tag_objects = 1;
+        rev->tree_blobs_in_commit_order = 1;
+        rev->exclude_promisor_objects = 1;

Documentation/MyFirstRevWalk.txt line 635

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +10 -0
+        [...]
+----
+
+Unless you cloned or fetched your repository earlier with a filter,
+`exclude_promisor_objects` is unlikely to make a difference, but we'll turn it
+on just to make sure our lives are simple.  We'll also turn on
+`tree_blobs_in_commit_order`, which means that we will walk a commit's tree and
+everything it points to immediately after we find each commit, as opposed to
+waiting for the end and walking through all trees after the commit history has
+been discovered.

This paragraph is repeating much of the information in the paragraph just above the code snippet. One or the other should be dropped or thinned to avoid the duplication.

Documentation/MyFirstRevWalk.txt line 645

Quoted 9 lines
Documentation/MyFirstRevWalk.txt +9 -0
+Let's start by calling just the unfiltered walk and reporting our counts.
+Complete your implementation of `walken_object_walk()`:
+
+----
+       traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL);
+
+       printf(_("Object walk completed. Found %d commits, %d blobs, %d tags, "
+                "and %d trees.\n"), commit_count, blob_count, tag_count,
+              tree_count);

Or make the output more useful by having it be machine-parseable (and not localized):

printf("commits %d\nblobs %d\ntags %d\ntrees %d\n",
commit_count, blob_count, tag_cont, tree_count);

Documentation/MyFirstRevWalk.txt line 255

Quoted 2 lines
Documentation/MyFirstRevWalk.txt +2 -0
+       return 0;
+}

What does the return value signify?

Quoted 5 lines
Documentation/MyFirstRevWalk.txt +5 -0
+Now we can try to run our command! It should take noticeably longer than the
+commit walk, but an examination of the output will give you an idea why - for
+example:
+
+----

Documentation/MyFirstRevWalk.txt line 686

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +10 -0
+Object walk completed. Found 55733 commits, 100274 blobs, 0 tags, and 104210 trees.
+----
+
+This makes sense. We have more trees than commits because the Git project has
+lots of subdirectories which can change, plus at least one tree per commit. We
+have no tags because we started on a commit (`HEAD`) and while tags can point to
+commits, commits can't point to tags.
+
+NOTE: You will have different counts when you run this yourself! The number of
+objects grows along with the Git project.

Not sure if this NOTE is useful; after all, you introduced the output by saying "for example".

Documentation/MyFirstRevWalk.txt line 697

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +10 -0
+=== Adding a Filter
+
+There are a handful of filters that we can apply to the object walk laid out in
+`Documentation/rev-list-options.txt`. These filters are typically useful for
+operations such as creating packfiles or performing a partial or shallow clone.
+They are defined in `list-objects-filter-options.h`. For the purposes of this
+tutorial we will use the "tree:1" filter, which causes the walk to omit all
+trees and blobs which are not directly referenced by commits reachable from the
+commit in `pending` when the walk begins. (In our case, that means we omit trees
+and blobs not directly referenced by HEAD or HEAD's history.)

Need some explanation of what 'pending' is, as it's just mysterious as written.

Documentation/MyFirstRevWalk.txt line 709

Quoted 11 lines
Documentation/MyFirstRevWalk.txt +11 -0
+First, we'll need to `#include "list-objects-filter-options.h`". Then, we can
+set up the `struct list_objects_filter_options` and `struct oidset` at the top
+of `walken_object_walk()`:
+
+----
+static int walken_object_walk(struct rev_info *rev)
+{
+        struct list_objects_filter_options filter_options = {};
+        struct oidset omitted;
+        oidset_init(&omitted, 0);
+       ...

This 'omitted' is so far removed from the description of the 'omitted' argument to traverse_commit_list_filtered() way earlier in the tutorial that a reader is likely to have forgotten what it's about (indeed, I did). Some explanation, even if superficial, is likely warranted here or at least mention that it is explained in more detail below (as I discovered).

Documentation/MyFirstRevWalk.txt line 743

Quoted 4 lines
Documentation/MyFirstRevWalk.txt +4 -0
+After we run `traverse_commit_list_filtered()` we would also be able to examine
+`omitted`, which is a linked-list of all objects we did not include in our walk.
+Since all omitted objects are included, the performance of
+`traverse_commit_list_filtered()` with a non-null `omitted` arument is equitable

s/arument/argument/

Documentation/MyFirstRevWalk.txt line 746

Quoted 3 lines
Documentation/MyFirstRevWalk.txt +3 -0
+with the performance of `traverse_commit_list()`; so for our purposes, we leave
+it null. It's easy to provide one and iterate over it, though - check `oidset.h`
+for the declaration of the accessor methods for `oidset`.

I'm confused. What are we leaving NULL here?

Documentation/MyFirstRevWalk.txt line 757

Quoted 5 lines
Documentation/MyFirstRevWalk.txt +5 -0
+=== Changing the Order
+
+Finally, let's demonstrate that you can also reorder walks of all objects, not
+just walks of commits. First, we'll make our handlers chattier - modify
+`walken_show_commit()` and `walken_show_object` to print the object as they go:

s/walken_show_object/&()/

Documentation/MyFirstRevWalk.txt line 764

Quoted 5 lines
Documentation/MyFirstRevWalk.txt +5 -0
+static void walken_show_commit(struct commit *cmt, void *buf)
+{
+        printf(_("commit: %s\n"), oid_to_hex(&cmt->object.oid));
+        commit_count++;
+}

Is there a bunch of trailing whitespace on these lines of the code sample (and in some lines below)?

Documentation/MyFirstRevWalk.txt line 768

Quoted 3 lines
Documentation/MyFirstRevWalk.txt +3 -0
+static void walken_show_object(struct object *obj, const char *str, void *buf)
+{
+        printf(_("%s: %s\n"), type_name(obj->type), oid_to_hex(&obj->oid));

Localizing "%s: %s\n" via _(...) probably doesn't add value, which implies that you might not want to be localizing "commit" above either.

Documentation/MyFirstRevWalk.txt line 782

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +10 -0
+(Try to leave the counter increment logic in place in `walken_show_object()`.)
+
+With only that change, run again (but save yourself some scrollback):
+
+----
+$ ./bin-wrappers/git walken | head -n 10
+----
+
+Take a look at the top commit with `git show` and the OID you printed; it should
+be the same as the output of `git show HEAD`.

I think this is the first use of "OID", which might be mysterious and confusing to a newcomer. Earlier, you used SHA-1 and I suggested "object ID" instead. Perhaps use the same here, or define OID earlier in the document in place of SHA-1.

Documentation/MyFirstRevWalk.txt line 787

Quoted 4 lines
Documentation/MyFirstRevWalk.txt +4 -0
+Next, let's change a setting on our `struct rev_info` within
+`walken_object_walk()`. Find where you're changing the other settings on `rev`,
+such as `rev->tree_objects` and `rev->tree_blobs_in_commit_order`, and add
+another setting at the bottom:

Instead of nebulous "another setting", mentioning 'reverse' explicitly would make this clearer.

Quoted 6 lines
Documentation/MyFirstRevWalk.txt +6 -0
+        rev->tree_objects = 1;
+        rev->blob_objects = 1;
+        rev->tag_objects = 1;
+        rev->tree_blobs_in_commit_order = 1;
+        rev->exclude_promisor_objects = 1;
+        rev->reverse = 1;
#18 lore raw
Quoted 6 lines · Eric Sunshine
Quoted 6 lines
Documentation/MyFirstRevWalk.txt new file +6 -0
+/*
+ * "git walken"
+ *
+ * Part of the "My First Revision Walk" tutorial.
+ */
+
Quoted 8 lines

Documentation/MyFirstRevWalk.txt line 40

Quoted 2 lines
Documentation/MyFirstRevWalk.txt new file +2 -0
+#include <stdio.h>
+#include "builtin.h"

Git source files must always include cache.h or git-compat-util.h (or, for builtins, builtin.h) as the very first header since those headers take care of differences which might crop up as problems with system headers on various platforms. System headers are included after Git headers. So, stdio.h should be included after builtin.h. In this case,

Actually the idea is that platform agnostic part of the codebase should not have to include _any_ system header themselves; instead, including git-compat-util.h should take care of the system header files *including* the funky ordering requirements some platforms may have. So, we'd want to go stronger than "should be included after"; it shouldn't have to be included or our git-compat-util.h is wrong.

I've started reading the patch myself, but it seems that you've already done a lot more thorough read-thru than I would have done, so thank you very much for that.

#19 lore raw
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Eric Sunshine

Documentation/MyFirstRevWalk.txt line 40

Quoted 2 lines
Documentation/MyFirstRevWalk.txt new file +2 -0
+#include <stdio.h>
+#include "builtin.h"

Git source files must always include cache.h or git-compat-util.h (or, for builtins, builtin.h) as the very first header since those headers take care of differences which might crop up as problems with system headers on various platforms. System headers are included after Git headers. So, stdio.h should be included after builtin.h. In this case,

Quoted 6 lines

Actually the idea is that platform agnostic part of the codebase should not have to include _any_ system header themselves; instead, including git-compat-util.h should take care of the system header files *including* the funky ordering requirements some platforms may have. So, we'd want to go stronger than "should be included after"; it shouldn't have to be included or our git-compat-util.h is wrong.

Thanks for clarifying that.

#20 lore raw
In reply to Eric Sunshine
Quoted 17 lines · Eric Sunshine

Documentation/.gitignore cmds-*.txt · line 13

Quoted 13 lines · Emily Shaffer

[...]
The tutorial covers a basic overview of the structs involved during revision walk, setting up a basic commit walk, setting up a basic all-object walk, and adding some configuration changes to both walk types. It intentionally does not cover how to create new commands or search for options from the command line or gitconfigs.

---

Documentation/.gitignore +1 -0
@@ -12,6 +12,7 @@ cmds-*.txt
 SubmittingPatches.txt
+MyFirstRevWalk.txt

The new file itself is named Documentation/MyFirstRevWalk.txt, so why add it to .gitignore?

Yep, fixed. Holdover from an initial attempt which named the file MyFirstRevWalk (no extension), which was then corrected for the earlier tutorial I sent. Thanks.

Quoted 11 lines

Documentation/MyFirstRevWalk.txt line 6

Quoted 9 lines
Documentation/MyFirstRevWalk.txt +6 -0
@@ -0,0 +1,826 @@
+== What's a Revision Walk?
+
+The revision walk is a key concept in Git - this is the process that underpins
+operations like `git log`, `git blame`, and `git reflog`. Beginning at HEAD, the
+list of objects is found by walking parent relationships between objects. The
+revision walk can also be usedto determine whether or not a given object is

s/usedto/used to/

Done.

Quoted 16 lines
Quoted 5 lines
Documentation/MyFirstRevWalk.txt +4 -0
+reachable from the current HEAD pointer.
+
+We'll put our fiddling into a new command. For fun, let's name it `git walken`.
+Open up a new file `builtin/walken.c` and set up the command handler:

Documentation/MyFirstRevWalk.txt line 40

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +10 -0
+
+----
+/*
+ * "git walken"
+ *
+ * Part of the "My First Revision Walk" tutorial.
+ */
+
+#include <stdio.h>
+#include "builtin.h"
Quoted 7 lines

Git source files must always include cache.h or git-compat-util.h (or, for builtins, builtin.h) as the very first header since those headers take care of differences which might crop up as problems with system headers on various platforms. System headers are included after Git headers. So, stdio.h should be included after builtin.h. In this case, however, stdio.h will get pulled in by git-compat-util.h anyhow, so you need not include it here.

Done.

Quoted 11 lines

Documentation/MyFirstRevWalk.txt line 55

Quoted 8 lines
Documentation/MyFirstRevWalk.txt +7 -0
+Add usage text and `-h` handling, in order to pass the test suite:
+
+----
+static const char * const walken_usage[] = {
+       N_("git walken"),
+       NULL,
+}

Unless you plan on referencing this from functions other than cmd_walken(), it need not be global.

Done; bad C++ habits sneaking in. :)

Quoted 14 lines

Documentation/MyFirstRevWalk.txt line 65

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +9 -0
+int cmd_walken(int argc, const char **argv, const char *prefix)
+{
+       struct option options[] = {
+               OPT_END()
+       };
+
+       argc = parse_options(argc, argv, prefix, options, walken_usage, 0);
+
+       ...

Perhaps comment out the "..." or remove it altogether to avoid having the compiler barf when the below instructions tell the reader to build the command.

Hmm. That part I'm not so sure about. I like to use the "..." to indicate where the code in the snippet should be added around the other code already in the file - which I suppose it does just as clearly if it's commented - but I also hope folks are not simply copy-pasting blindly from the tutorial.

It seems like including uncommented "..." in code tutorials is pretty common.

I don't think I have a good reason to push back on this except that I think "/* ... */" is ugly :)

I'll go through and replace "..." with some actual hints about what's supposed to go there; for example, here I'll replace with "/* print and return */".

Quoted 6 lines

Documentation/MyFirstRevWalk.txt line 69

Quoted 4 lines
Documentation/MyFirstRevWalk.txt +3 -0
+}
+
+Also add the relevant line in builtin.h near `cmd_whatchanged()`:

s/builtin.h/&/

Done.

Quoted 9 lines

Documentation/MyFirstRevWalk.txt line 91

Quoted 6 lines
Documentation/MyFirstRevWalk.txt +5 -0
+Build and test out your command, without forgetting to ensure the `DEVELOPER`
+flag is set:
+
+----
+echo DEVELOPER=1 >config.mak

This will blast existing content of 'config.mak' which could be dangerous. It might be better to suggest >> instead.

Done.

Quoted 11 lines

Documentation/MyFirstRevWalk.txt line 122

Quoted 5 lines
Documentation/MyFirstRevWalk.txt +4 -0
+`name` is the SHA-1 of the object - a 40-digit hex string you may be familiar
+with from using Git to organize your source in the past. Check the tutorial
+mentioned above towards the top for a discussion of where the SHA-1 can come
+from.

With all the recent work to move away from SHA-1 and to support other hash functions, perhaps just call this "object ID" rather than SHA-1, and drop mention of it being exactly 40 digits. Instead, perhaps say something like "...is the hexadecimal representation of the object ID...".

Good point. Will do.

Quoted 16 lines

Documentation/MyFirstRevWalk.txt line 148

Quoted 9 lines
Documentation/MyFirstRevWalk.txt +8 -0
+== Basic Commit Walk
+
+First, let's see if we can replicate the output of `git log --oneline`. We'll
+refer back to the implementation frequently to discover norms when performing
+a revision walk of our own.
+
+We'll need all the commits, in order, which preceded our current commit. We will
+also need to know the name and subject.

This paragraph confused me. I read it as these being prerequisites I would somehow have to provide in order to write the code. Perhaps it can be rephrased to state that this is what the code will be doing.
Maybe: "To do this, we will find all the commits, in order, which precede the current commit, and extract from them the name and subject [of the commit message]" or something.

Yeah, good point. Thanks - this is the kind of thing that sounds logical when you write it but not when you read it later :)

Quoted 12 lines

Documentation/MyFirstRevWalk.txt line 161

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +9 -0
+=== Setting Up
+
+Preparing for your revision walk has some distinct stages.
+
+1. Perform default setup for this mode, and others which may be invoked.
+2. Check configuration files for relevant settings.
+3. Set up the rev_info struct.
+4. Tweak the initialized rev_info to suit the current walk.
+5. Prepare the rev_info for the walk.

s/rev_info/&/ in the above three lines.

Done.

Quoted 13 lines

Documentation/MyFirstRevWalk.txt line 172

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +9 -0
+==== Default Setups
+
+Before you begin to examine user configuration for your revision walk, it's
+common practice for you to initialize to default any switches that your command
+may have, as well as ask any other components you may invoke to initialize as
+well. `git log` does this in `init_log_defaults()`; in that case, one global
+`decoration_style` is initialized, as well as the grep and diff-UI components.
+
+For our purposes, within `git walken`, for the first example we do we don't

"we do we don't"?

Quoted 6 lines

Documentation/MyFirstRevWalk.txt line 173

Quoted 1 line
Documentation/MyFirstRevWalk.txt +1 -0
+intend to invoke anything, and we don't have any configuration to do. However,

"invoke anything" is pretty nebulous, as is the earlier "components you may invoke". A newcomer is unlikely to know what this means, so perhaps it needs an example (even if just a short parenthetical comment).

I have tried to reword this; I hope this is a little clearer.

Before you begin to examine user configuration for your revision walk, it's common practice for you to initialize to default any switches that your command may have, as well as ask any other components you may invoke to initialize as well (for example, how git log also uses the grep and diff components). git log does this in init_log_defaults(); in that case, one global decoration_style is initialized, as well as the grep and diff-UI components.

For our purposes, within git walken, for the first example we don't intend to use any other components within Git, and we don't have any configuration to do. However, we may want to add some later, so for now, we can add an empty placeholder. Create a new function in builtin/walken.c:

Quoted 16 lines

Documentation/MyFirstRevWalk.txt line 183

Quoted 11 lines
Documentation/MyFirstRevWalk.txt +10 -0
+we may want to add some later, so for now, we can add an empty placeholder.
+Create a new function in `builtin/walken.c`:
+
+----
+static void init_walken_defaults(void)
+{
+       /* We don't actually need the same components `git log` does; leave this
+        * empty for now.
+        */
+}

/*
* Git multi-line comments
* are formatted like this.
*/

Done; I'll look through the rest of the samples for it too.

Quoted 13 lines

Documentation/MyFirstRevWalk.txt line 217

Quoted 9 lines
Documentation/MyFirstRevWalk.txt +8 -0
+Add a new function to `builtin/walken.c`:
+
+----
+static int git_walken_config(const char *var, const char *value, void *cb)
+{
+       /* For now, let's not bother with anything. */
+       return git_default_config(var, value, cb);
+}

Comment is somewhat confusing. Perhaps say instead "We don't currently have custom configuration, so fall back to git_default_config()" or something.

Done.

Quoted 9 lines

Documentation/MyFirstRevWalk.txt line 238

Quoted 7 lines
Documentation/MyFirstRevWalk.txt +6 -0
+==== Setting Up `rev_info`
+
+Now that we've gathered external configuration and options, it's time to
+initialize the `rev_info` object which we will use to perform the walk. This is
+typically done by calling `repo_init_revisions()` with the repository you intend
+to target, as well as the prefix and your `rev_info` struct.

Maybe: s/the prefix/the & argument of cmd_walken/

Done.

Quoted 11 lines

Documentation/MyFirstRevWalk.txt line 246

Quoted 8 lines
Documentation/MyFirstRevWalk.txt +7 -0
+Add the `struct rev_info` and the `repo_init_revisions()` call:
+----
+int cmd_walken(int argc, const char **argv, const char *prefix)
+{
+       /* This can go wherever you like in your declarations.*/
+       struct rev_info rev;
+       ...

A less verbose way to indicate the same without using a /* comment */:

Quoted 3 lines
    ...
    struct rev_info rev;
    ...

Per the earlier comment about losing "..." I'm not going to take this comment; I'll also be replacing the "..." after.

Quoted 12 lines

Documentation/MyFirstRevWalk.txt line 263

Quoted 9 lines
Documentation/MyFirstRevWalk.txt +8 -0
+       /* This should go after the git_config() call. */
+       repo_init_revisions(the_repository, &rev, prefix);
+}
+----
+static void final_rev_info_setup(struct rev_info *rev)
+{
+       /* We want to mimick the appearance of `git log --oneline`, so let's
+        * force oneline format. */

s/mimick/mimic/

Quoted 4 lines

/*
* Multi-line
* comment.
*/

Done.

Quoted 17 lines

Documentation/MyFirstRevWalk.txt line 313

Quoted 13 lines
Documentation/MyFirstRevWalk.txt +12 -0
+==== Preparing `rev_info` For the Walk
+
+Now that `rev` is all initialized and configured, we've got one more setup step
+before we get rolling. We can do this in a helper, which will both prepare the
+`rev_info` for the walk, and perform the walk itself. Let's start the helper
+with the call to `prepare_revision_walk()`.
+
+----
+static int walken_commit_walk(struct rev_info *rev)
+{
+       /* prepare_revision_walk() gets the final steps ready for a revision
+        * walk. We check the return value for errors. */

Not at all sure what this comment is trying to say. Also, the second sentence adds no value to what the code itself already says clearly by actually checking the return value.

Attempted to rephrase. I ended up with:

/*
* prepare_revision_walk() does the final setup needed by revision.h
* before a walk. It may return an error if there is a problem. */

Maybe the second sentence still doesn't serve a purpose, but I was trying to express that prepare_revision_walk() won't die() on its own.

Quoted 21 lines
Quoted 8 lines
Documentation/MyFirstRevWalk.txt +7 -0
+       if (prepare_revision_walk(rev))
+               die(_("revision walk setup failed"));
+}
+==== Performing the Walk!
+
+Finally! We are ready to begin the walk itself. Now we can see that `rev_info`
+can also be used as an iterator; we move to the next item in the walk by using

Documentation/MyFirstRevWalk.txt line 332

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +10 -0
+`get_revision()` repeatedly. Add the listed variable declarations at the top and
+the walk loop below the `prepare_revision_walk()` call within your
+`walken_commit_walk()`:
+
+----
+static int walken_commit_walk(struct rev_info *rev)
+{
+       struct commit *commit;
+       struct strbuf prettybuf;
+       strbuf_init(&prettybuf, 0);

More idiomatic:

Quoted 1 line
    struct strbuf prettybuf = STRBUF_INIT;

Ok, I'll change it. I wasn't sure which one was preferred, so this is super helpful. Thanks.

Quoted 10 lines

Documentation/MyFirstRevWalk.txt line 338

Quoted 4 lines
Documentation/MyFirstRevWalk.txt +3 -0
+       while ((commit = get_revision(rev)) != NULL) {
+               if (commit == NULL)
+                       continue;

Idiomatic Git code doesn't mention NULL explicitly in conditionals, so:

    while ((commit = get_revision(rev))) {
        if (!commit)
            continue;

Done, thanks.

Quoted 8 lines

Documentation/MyFirstRevWalk.txt line 341

Quoted 3 lines
Documentation/MyFirstRevWalk.txt +2 -0
+               strbuf_reset(&prettybuf);
+               pp_commit_easy(CMIT_FMT_ONELINE, commit, &prettybuf);

Earlier, you talked about calling get_commit_format("oneline",...) to get "oneline" output, so what is the purpose of CMIT_FMT_ONELINE here? The text should explain more clearly what these two different "online"-related bits mean.

Thanks. I've got to research a little on this one. I'll clarify it before the next reroll.

Quoted 10 lines

Documentation/MyFirstRevWalk.txt line 342

Quoted 2 lines
Documentation/MyFirstRevWalk.txt +1 -0
+               printf(_("%s\n"), prettybuf.buf);

There is nothing here to localize, so drop _(...):

    printf("%s\n", prettybuf.buf);

or perhaps just:

    puts(prettybuf.buf);

Sure, I'll use this one.

Quoted 7 lines

Documentation/MyFirstRevWalk.txt line 346

Quoted 5 lines
Documentation/MyFirstRevWalk.txt +4 -0
+       }
+
+       return 0;
+}

What does the return value signify?

Will double check that I don't use it for anything; I can probalby drop it and make this a void function instead.

Quoted 8 lines

Documentation/MyFirstRevWalk.txt line 389

Quoted 6 lines
Documentation/MyFirstRevWalk.txt +5 -0
+=== Adding a Filter
+
+Next, we can modify the `grep_filter`. This is done with convenience functions
+found in `grep.h`. For fun, we're filtering to only commits from folks using a
+gmail.com email address - a not-very-precise guess at who may be working on Git

Perhaps? s/gmail.com/&/

Done.

Quoted 10 lines
Quoted 10 lines
Documentation/MyFirstRevWalk.txt +9 -0
+=== Changing the Order
+
+Let's see what happens when we run with `REV_SORT_BY_COMMIT_DATE` as opposed to
+`REV_SORT_BY_AUTHOR_DATE`. Add the following:
+
+static void final_rev_info_setup(int argc, const char **argv,
+                const char *prefix, struct rev_info *rev)
+{
+       ...
Quoted 8 lines

Documentation/MyFirstRevWalk.txt line 438

Quoted 3 lines
Documentation/MyFirstRevWalk.txt +3 -0
+
+       rev->topo_order = 1;
+       rev->sort_order = REV_SORT_BY_COMMIT_DATE;

The assignment to rev->sort_order is obvious enough, but the rev->topo_order assignment is quite mysterious to someone coming to this tutorial to learn about revision walking, thus some commentary explaining 'topo_order' would be a good idea.

Will do.

Quoted 13 lines

Documentation/MyFirstRevWalk.txt line 480

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +9 -0
+Finally, compare the two. This is a little less helpful without object names or
+dates, but hopefully we get the idea.
+
+----
+$ diff -u commit-date.txt author-date.txt
+----
+
+This display is an indicator for the latency between publishing a commit for
+review the first time, and getting it actually merged into master.

Perhaps: s/master/&/

Quoted 6 lines

Even as a long-time contributor to the project, I had to pause over this statement for several seconds before figuring out what it was talking about. Without a long-winded explanation of how topics progress from submission through 'pu' through 'next' through 'master' and finally into a release, the above statement is likely to be mystifying to a newcomer. Perhaps it should be dropped.

Such an explanation exists in MyFirstContribution.txt. I will include a shameless plug to that document here. :)

Quoted 6 lines

Documentation/MyFirstRevWalk.txt line 483

Quoted 3 lines
Documentation/MyFirstRevWalk.txt +2 -0
+Let's try one more reordering of commits. `rev_info` exposes a `reverse` flag.
+However, it needs to be applied after `add_head_to_pending()` is called. Find

This leaves the reader hanging, wondering why 'reverse' needs to be assigned after add_head_to_pending().

Will address.

Quoted 29 lines

Documentation/MyFirstRevWalk.txt line 559

Quoted 12 lines
Documentation/MyFirstRevWalk.txt +11 -0
+== Basic Object Walk
+
+static void walken_show_commit(struct commit *cmt, void *buf)
+{
+        commit_count++;
+}
+----
+
+Since we have the `struct commit` object, we can look at all the same parts that
+we looked at in our earlier commit-only walk. For the sake of this tutorial,
+though, we'll just increment the commit counter and move on.

This leaves the reader wondering what 'buf' is and what it's used for. Presumably this is the 'show_data' context mentioned earlier? If so, perhaps name this 'ctxt' or 'context' or something and, because this is a tutorial trying to teach revision walking, say a quick word about how it might be used.

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +10 -0
+static void walken_show_object(struct object *obj, const char *str, void *buf)
+{
+        switch (obj->type) {
+        [...]
+        case OBJ_COMMIT:
+                printf(_("Unexpectedly encountered a commit in "
+                         "walken_show_object!\n"));
+                commit_count++;
+                break;
+        default:
Quoted 8 lines

Documentation/MyFirstRevWalk.txt line 587

Quoted 5 lines
Documentation/MyFirstRevWalk.txt +5 -0
+                printf(_("Unexpected object type %s!\n"),
+                       type_name(obj->type));
+                break;
+        }
+}

Modern practice in this project is to start error messages with lowercase and to not punctuate the end (no need for "!").

Done.

Quoted 2 lines

Also, same complaint about the mysterious 'str' argument to the callback as for 'buf' mentioned above.

Will do.

Quoted 9 lines

Documentation/MyFirstRevWalk.txt line 592

Quoted 4 lines
Documentation/MyFirstRevWalk.txt +3 -0
+To help assure us that we aren't double-counting commits, we'll include some
+complaining if a commit object is routed through our non-commit callback; we'll
+also complain if we see an invalid object type.

Are these two error cases "impossible" conditions or can they
actually arise in practice? If the former, use die() instead and drop use of _(...) so as to avoid confusing the reader into thinking that the behavior is indeterminate.

Ah, these should be impossible. I'll turn them into die().

Quoted 14 lines

Documentation/MyFirstRevWalk.txt line 603

Quoted 11 lines
Documentation/MyFirstRevWalk.txt +10 -0
+Our main object walk implementation is substantially different from our commit
+walk implementation, so let's make a new function to perform the object walk. We
+can perform setup which is applicable to all objects here, too, to keep separate
+from setup which is applicable to commit-only walks.
+
+----
+static int walken_object_walk(struct rev_info *rev)
+{
+}
+----

This skeleton function definition is populated immediately below, so it's not clear why it needs to be shown here.

Yeah, you're right. Removed the skeleton snippet.

Quoted 21 lines
Quoted 21 lines
Documentation/MyFirstRevWalk.txt +20 -0
+We'll start by enabling all types of objects in the `struct rev_info`, and
+asking to have our trees and blobs shown in commit order. We'll also exclude
+promisors as the walk becomes more complicated with those types of objects. When
+our settings are ready, we'll perform the normal revision walk setup and
+initialize our tracking variables.
+
+----
+static int walken_object_walk(struct rev_info *rev)
+{
+        rev->tree_objects = 1;
+        rev->blob_objects = 1;
+        rev->tag_objects = 1;
+        rev->tree_blobs_in_commit_order = 1;
+        rev->exclude_promisor_objects = 1;
+        [...]
+----
+
+Unless you cloned or fetched your repository earlier with a filter,
+`exclude_promisor_objects` is unlikely to make a difference, but we'll turn it
+on just to make sure our lives are simple.  We'll also turn on
Quoted 8 lines

Documentation/MyFirstRevWalk.txt line 635

Quoted 4 lines
Documentation/MyFirstRevWalk.txt +4 -0
+`tree_blobs_in_commit_order`, which means that we will walk a commit's tree and
+everything it points to immediately after we find each commit, as opposed to
+waiting for the end and walking through all trees after the commit history has
+been discovered.

This paragraph is repeating much of the information in the paragraph just above the code snippet. One or the other should be dropped or thinned to avoid the duplication.

We'll start by enabling all types of objects in the struct rev_info. Unless you cloned or fetched your repository earlier with a filter, exclude_promisor_objects is unlikely to make a difference, but we'll turn it on just to make sure our lives are simple. We'll also turn on tree_blobs_in_commit_order, which means that we will walk a commit's tree and everything it points to immediately after we find each commit, as opposed to waiting for the end and walking through all trees after the commit history has been discovered. With the appropriate settings configured, we are ready to call prepare_revision_walk().

Quoted 14 lines

Documentation/MyFirstRevWalk.txt line 645

Quoted 10 lines
Documentation/MyFirstRevWalk.txt +9 -0
+Let's start by calling just the unfiltered walk and reporting our counts.
+Complete your implementation of `walken_object_walk()`:
+
+----
+       traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL);
+
+       printf(_("Object walk completed. Found %d commits, %d blobs, %d tags, "
+                "and %d trees.\n"), commit_count, blob_count, tag_count,
+              tree_count);

Or make the output more useful by having it be machine-parseable (and not localized):

Quoted 2 lines

printf("commits %d\nblobs %d\ntags %d\ntrees %d\n",
commit_count, blob_count, tag_cont, tree_count);

I'm not sure whether I agree, since it's a useless toy command only for human parsing.

Quoted 5 lines

Documentation/MyFirstRevWalk.txt line 255

Quoted 3 lines
Documentation/MyFirstRevWalk.txt +2 -0
+       return 0;
+}

What does the return value signify?

Yeah, again I think I can get rid of this; I'll take a look at the final sample code and make sure it can go.

Quoted 11 lines
Quoted 11 lines
Documentation/MyFirstRevWalk.txt +10 -0
+Now we can try to run our command! It should take noticeably longer than the
+commit walk, but an examination of the output will give you an idea why - for
+example:
+
+----
+Object walk completed. Found 55733 commits, 100274 blobs, 0 tags, and 104210 trees.
+----
+
+This makes sense. We have more trees than commits because the Git project has
+lots of subdirectories which can change, plus at least one tree per commit. We
Quoted 8 lines

Documentation/MyFirstRevWalk.txt line 686

Quoted 5 lines
Documentation/MyFirstRevWalk.txt +5 -0
+have no tags because we started on a commit (`HEAD`) and while tags can point to
+commits, commits can't point to tags.
+
+NOTE: You will have different counts when you run this yourself! The number of
+objects grows along with the Git project.

Not sure if this NOTE is useful; after all, you introduced the output by saying "for example".

I think you're probably right, but I'll try to fix this by slightly fleshing out the "for example" phrasing.

Quoted 13 lines

Documentation/MyFirstRevWalk.txt line 697

Quoted 11 lines
Documentation/MyFirstRevWalk.txt +10 -0
+=== Adding a Filter
+
+There are a handful of filters that we can apply to the object walk laid out in
+`Documentation/rev-list-options.txt`. These filters are typically useful for
+operations such as creating packfiles or performing a partial or shallow clone.
+They are defined in `list-objects-filter-options.h`. For the purposes of this
+tutorial we will use the "tree:1" filter, which causes the walk to omit all
+trees and blobs which are not directly referenced by commits reachable from the
+commit in `pending` when the walk begins. (In our case, that means we omit trees
+and blobs not directly referenced by HEAD or HEAD's history.)

Need some explanation of what 'pending' is, as it's just mysterious as written.

Done. I've tried to explain it by drawing a parallel to BFS tree traversal, although that might be even more confusing as the DAG isn't quite the same.

Quoted 27 lines

Documentation/MyFirstRevWalk.txt line 709

Quoted 12 lines
Documentation/MyFirstRevWalk.txt +11 -0
+First, we'll need to `#include "list-objects-filter-options.h`". Then, we can
+set up the `struct list_objects_filter_options` and `struct oidset` at the top
+of `walken_object_walk()`:
+
+----
+static int walken_object_walk(struct rev_info *rev)
+{
+        struct list_objects_filter_options filter_options = {};
+        struct oidset omitted;
+        oidset_init(&omitted, 0);
+       ...

This 'omitted' is so far removed from the description of the 'omitted' argument to traverse_commit_list_filtered() way earlier in the tutorial that a reader is likely to have forgotten what it's about (indeed, I did). Some explanation, even if superficial, is likely warranted here or at least mention that it is explained in more detail below (as I discovered).

Documentation/MyFirstRevWalk.txt line 743

Quoted 4 lines
Documentation/MyFirstRevWalk.txt +4 -0
+After we run `traverse_commit_list_filtered()` we would also be able to examine
+`omitted`, which is a linked-list of all objects we did not include in our walk.
+Since all omitted objects are included, the performance of
+`traverse_commit_list_filtered()` with a non-null `omitted` arument is equitable

s/arument/argument/

Quoted 5 lines

Documentation/MyFirstRevWalk.txt line 746

Quoted 3 lines
Documentation/MyFirstRevWalk.txt +3 -0
+with the performance of `traverse_commit_list()`; so for our purposes, we leave
+it null. It's easy to provide one and iterate over it, though - check `oidset.h`
+for the declaration of the accessor methods for `oidset`.

I'm confused. What are we leaving NULL here?

Yeah, this isn't very well written. I'll try to rephrase it; I think I meant to leave omitted out of the arglist to traverse_comit_list_filtered() but looks like I didn't manage to do so in the actual impl. I think I'll break out an additional section to show how --filter-print-omitted works, instead of just leaving this with an RTFM at the end. (This will also end up with a reroll of the example patchset, too.)

Quoted 8 lines

Documentation/MyFirstRevWalk.txt line 757

Quoted 6 lines
Documentation/MyFirstRevWalk.txt +5 -0
+=== Changing the Order
+
+Finally, let's demonstrate that you can also reorder walks of all objects, not
+just walks of commits. First, we'll make our handlers chattier - modify
+`walken_show_commit()` and `walken_show_object` to print the object as they go:

s/walken_show_object/&()/

Done.

Quoted 9 lines

Documentation/MyFirstRevWalk.txt line 764

Quoted 6 lines
Documentation/MyFirstRevWalk.txt +5 -0
+static void walken_show_commit(struct commit *cmt, void *buf)
+{
+        printf(_("commit: %s\n"), oid_to_hex(&cmt->object.oid));
+        commit_count++;
+}

Is there a bunch of trailing whitespace on these lines of the code sample (and in some lines below)?

Oh no, there might be. Bad on me for my copy/paste between vim windows workflow; I thought I had trimmed from all of them but guess not. I'll check over the whole doc and fix it up.

Quoted 8 lines

Documentation/MyFirstRevWalk.txt line 768

Quoted 4 lines
Documentation/MyFirstRevWalk.txt +3 -0
+static void walken_show_object(struct object *obj, const char *str, void *buf)
+{
+        printf(_("%s: %s\n"), type_name(obj->type), oid_to_hex(&obj->oid));

Localizing "%s: %s\n" via _(...) probably doesn't add value, which implies that you might not want to be localizing "commit" above either.

This is closer to machine-readable, so I'll remove the locale.

Quoted 16 lines

Documentation/MyFirstRevWalk.txt line 782

Quoted 11 lines
Documentation/MyFirstRevWalk.txt +10 -0
+(Try to leave the counter increment logic in place in `walken_show_object()`.)
+
+With only that change, run again (but save yourself some scrollback):
+
+----
+$ ./bin-wrappers/git walken | head -n 10
+----
+
+Take a look at the top commit with `git show` and the OID you printed; it should
+be the same as the output of `git show HEAD`.

I think this is the first use of "OID", which might be mysterious and confusing to a newcomer. Earlier, you used SHA-1 and I suggested "object ID" instead. Perhaps use the same here, or define OID earlier in the document in place of SHA-1.

Yeah, I ended up replacing it above with "object ID (OID)" but this is far enough along that I think I'll replace it with "object ID" here too.

Quoted 8 lines

Documentation/MyFirstRevWalk.txt line 787

Quoted 5 lines
Documentation/MyFirstRevWalk.txt +4 -0
+Next, let's change a setting on our `struct rev_info` within
+`walken_object_walk()`. Find where you're changing the other settings on `rev`,
+such as `rev->tree_objects` and `rev->tree_blobs_in_commit_order`, and add
+another setting at the bottom:

Instead of nebulous "another setting", mentioning 'reverse' explicitly would make this clearer.

Done.

Quoted 7 lines

Documentation/MyFirstRevWalk.txt line 797

Quoted 7 lines
Documentation/MyFirstRevWalk.txt +6 -0
+        rev->tree_objects = 1;
+        rev->blob_objects = 1;
+        rev->tag_objects = 1;
+        rev->tree_blobs_in_commit_order = 1;
+        rev->exclude_promisor_objects = 1;
+        rev->reverse = 1;

Thank you so much for taking the time to do a detailed review of this. This is great feedback.

- Emily

#21 lore raw
Quoted 16 lines · Emily Shaffer
Quoted 14 lines · Eric Sunshine

Documentation/MyFirstRevWalk.txt line 65

Quoted 9 lines · Emily Shaffer
Documentation/MyFirstRevWalk.txt new file +9 -0
+int cmd_walken(int argc, const char **argv, const char *prefix)
+{
+       struct option options[] = {
+               OPT_END()
+       };
+
+       argc = parse_options(argc, argv, prefix, options, walken_usage, 0);
+
+       ...

Perhaps comment out the "..." or remove it altogether to avoid having the compiler barf when the below instructions tell the reader to build the command.

Quoted 8 lines

Hmm. That part I'm not so sure about. I like to use the "..." to indicate where the code in the snippet should be added around the other code already in the file - which I suppose it does just as clearly if it's commented - but I also hope folks are not simply copy-pasting blindly from the tutorial.

It seems like including uncommented "..." in code tutorials is pretty common.

You're right, and that's not what I was "complaining" about. Looking back at your original email, I see that I somehow got confused and didn't realize or (quickly) forgot that you had already presented a _complete_ cmd_walken() snippet just above that spot, and that the cmd_walken() snippet upon which I was commenting was _incomplete_, thus the "..." was perfectly justified. Not realizing that the incomplete cmd_walken() example was just that (incomplete), I "complained" that the following "compile the project" instructions would barf on "...".

Maybe I got confused because the tiny cmd_walken() snippets followed one another so closely (or because I got interrupted several times during the review), but one way to avoid that would be to present a single _complete_ snippet from the start, followed by a bit of explanation. That is, something like this:

    Open up a new file `builtin/walken.c` and set up the command handler:

    ----
    /* "git walken" -- Part of the "My First Revision Walk" tutorial. */
    #include "builtin.h"

    int cmd_walken(int argc, const char **argv, const char *prefix)
    {
        const char * const usage[] = {
            N_("git walken"),
            NULL,
        }
        struct option options[] = {
            OPT_END()
        };

        argc = parse_options(argc, argv, prefix, options, usage, 0);

        printf(_("cmd_walken incoming...\n"));
        return 0;
    }
    ----

    `usage` is the usage message presented by `git -h walken`, and
    `options` will eventually specify command-line options.
Quoted 6 lines

I don't think I have a good reason to push back on this except that I think "/* ... */" is ugly :)

I'll go through and replace "..." with some actual hints about what's supposed to go there; for example, here I'll replace with "/* print and return */".

Seeing as my initial review comment was in error, I'm not sure that you ought to replace "..." with anything else.

Quoted 5 lines
Quoted 4 lines

"invoke anything" is pretty nebulous, as is the earlier "components you may invoke". A newcomer is unlikely to know what this means, so perhaps it needs an example (even if just a short parenthetical comment).

Quoted 8 lines

I have tried to reword this; I hope this is a little clearer.

Before you begin to examine user configuration for your revision walk, it's common practice for you to initialize to default any switches that your command may have, as well as ask any other components you may invoke to initialize as well (for example, how git log also uses the grep and diff components). git log does this in init_log_defaults(); in that case, one global decoration_style is initialized, as well as the grep and diff-UI components.

By trying to express too many things at once, it's still difficult to follow. Perhaps use shorter, more easily digestible sentences, like this:

Before examining configuration files which may modify command behavior, set up default state for switches or options your command may have. If your command utilizes other Git components, ask them to set up their default states, as well. For instance, git log takes advantage of grep and diff functionality; its init_log_defaults() sets its own state (decoration_style) and asks grep and diff to initialize themselves by calling their initialization functions.

Quoted 11 lines
Quoted 8 lines

Documentation/MyFirstRevWalk.txt line 313

Quoted 4 lines
Documentation/MyFirstRevWalk.txt new file +4 -0
+static int walken_commit_walk(struct rev_info *rev)
+{
+       /* prepare_revision_walk() gets the final steps ready for a revision
+        * walk. We check the return value for errors. */

Not at all sure what this comment is trying to say. Also, the second sentence adds no value to what the code itself already says clearly by actually checking the return value.

Attempted to rephrase. I ended up with:

Quoted 11 lines

/*
* prepare_revision_walk() does the final setup needed by revision.h
* before a walk. It may return an error if there is a problem. */

Maybe the second sentence still doesn't serve a purpose, but I was trying to express that prepare_revision_walk() won't die() on its own.

Quoted 3 lines
Quoted 3 lines
(quoted diff) +2 -0
+       if (prepare_revision_walk(rev))
+               die(_("revision walk setup failed"));

As this is just a toy example, I don't care too strongly about the unnecessary second sentence. On the other hand, the tutorial is trying to teach people how to contribute to this project, and on this project, that sort of pointless comment is likely to be called out in review. In fact, given that view, the entire comment block is unnecessary (it doesn't add any value for anyone reviewing or reading the code), so it might make more sense to drop the comment from the code entirely, and just do a better job explaining in prose above the snippet why you are calling that function. For instance:

... Let's start the helper with the call to prepare_revision_walk(), which does the final setup of the rev_info structure before it can be used.

The above observation may be more widely applicable than to just this one instance. Don't use in-code comments for what should be explained in prose if the in-code comment adds no value to the code itself (to wit, if a reviewer would say "don't repeat in a comment what the code already says clearly" or "don't use a comment to state the obvious").

Quoted 12 lines
Quoted 11 lines

Documentation/MyFirstRevWalk.txt line 480

Quoted 2 lines
Documentation/MyFirstRevWalk.txt new file +2 -0
+This display is an indicator for the latency between publishing a commit for
+review the first time, and getting it actually merged into master.

Perhaps: s/master/&/

Even as a long-time contributor to the project, I had to pause over this statement for several seconds before figuring out what it was talking about. Without a long-winded explanation of how topics progress from submission through 'pu' through 'next' through 'master' and finally into a release, the above statement is likely to be mystifying to a newcomer. Perhaps it should be dropped.

Quoted 2 lines

Such an explanation exists in MyFirstContribution.txt. I will include a shameless plug to that document here. :)

I found that this sort of tangential reference disturbed the flow of the tutorial, leading the mind astray from the otherwise natural progression of the presentation. So, I'm not convinced that talking about the migration of a topic in the Git project itself adds value to this tutorial. The same effect could be seen when commits have been re-ordered via git-rebase, too, right? Perhaps mention that instead?

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Documentation/MyFirstRevWalk.txt new file +3 -0
+       printf(_("Object walk completed. Found %d commits, %d blobs, %d tags, "
+                "and %d trees.\n"), commit_count, blob_count, tag_count,
+              tree_count);
Quoted 8 lines
Quoted 5 lines

Or make the output more useful by having it be machine-parseable (and not localized):

printf("commits %d\nblobs %d\ntags %d\ntrees %d\n",
commit_count, blob_count, tag_cont, tree_count);

I'm not sure whether I agree, since it's a useless toy command only for human parsing.

True, it's not a big deal, and I don't insist upon it. But, if you mention in prose that this output is easily machine-parseable, then perhaps that nudges the reader a bit in the direction of thinking about porcelain vs. plumbing, which is something a contributor to this project eventually has to be concerned with (the sooner, the better).

#22 lore raw
Quoted 60 lines · Eric Sunshine
Quoted 16 lines · Emily Shaffer
Quoted 14 lines · Eric Sunshine

Documentation/MyFirstRevWalk.txt line 65

Quoted 9 lines · Emily Shaffer
Documentation/MyFirstRevWalk.txt new file +9 -0
+int cmd_walken(int argc, const char **argv, const char *prefix)
+{
+       struct option options[] = {
+               OPT_END()
+       };
+
+       argc = parse_options(argc, argv, prefix, options, walken_usage, 0);
+
+       ...

Perhaps comment out the "..." or remove it altogether to avoid having the compiler barf when the below instructions tell the reader to build the command.

Quoted 8 lines

Hmm. That part I'm not so sure about. I like to use the "..." to indicate where the code in the snippet should be added around the other code already in the file - which I suppose it does just as clearly if it's commented - but I also hope folks are not simply copy-pasting blindly from the tutorial.

It seems like including uncommented "..." in code tutorials is pretty common.

You're right, and that's not what I was "complaining" about. Looking back at your original email, I see that I somehow got confused and didn't realize or (quickly) forgot that you had already presented a _complete_ cmd_walken() snippet just above that spot, and that the cmd_walken() snippet upon which I was commenting was _incomplete_, thus the "..." was perfectly justified. Not realizing that the incomplete cmd_walken() example was just that (incomplete), I "complained" that the following "compile the project" instructions would barf on "...".

Maybe I got confused because the tiny cmd_walken() snippets followed one another so closely (or because I got interrupted several times during the review), but one way to avoid that would be to present a single _complete_ snippet from the start, followed by a bit of explanation. That is, something like this:

    Open up a new file `builtin/walken.c` and set up the command handler:

    ----
    /* "git walken" -- Part of the "My First Revision Walk" tutorial. */
    #include "builtin.h"

    int cmd_walken(int argc, const char **argv, const char *prefix)
    {
        const char * const usage[] = {
            N_("git walken"),
            NULL,
        }
        struct option options[] = {
            OPT_END()
        };

        argc = parse_options(argc, argv, prefix, options, usage, 0);
Quoted 7 lines
        printf(_("cmd_walken incoming...\n"));
        return 0;
    }
    ----

    `usage` is the usage message presented by `git -h walken`, and
    `options` will eventually specify command-line options.

Hmm. I can say that I personally would find that much more difficult to follow interactively, and I'd be tempted to copy-and-paste and skim through the wall of text if I was presented with such a snippet. However, I could also imagine the reverse - someone becoming tired of having their hand held through a fairly straightforward implementation, when they're perfectly capable of reading a long description and would just like to get on with it.

I'm really curious about what others think in this scenario, since I imagine it boils down to individual learning styles.

(Maybe we can split the difference and present a complete patch or new function, followed by a breakdown? That would end up even more verbose than the current approach, though.)

... Now that I'm thinking more about this, and reading some of your later comments on this mail, I think it might be valuable to lean on the sample patchset for complete code samples, especially if we figure a good way to distribute the patchset near the tutorial (as Junio and I are discussing in another branch of this thread). Then we can keep the tutorial concise, but have the complete code available for those who prefer to look there.

Quoted 29 lines
Quoted 7 lines

I don't think I have a good reason to push back on this except that I think "/* ... */" is ugly :)

I'll go through and replace "..." with some actual hints about what's supposed to go there; for example, here I'll replace with "/* print and return */".

Seeing as my initial review comment was in error, I'm not sure that you ought to replace "..." with anything else.

Quoted 5 lines
Quoted 4 lines

"invoke anything" is pretty nebulous, as is the earlier "components you may invoke". A newcomer is unlikely to know what this means, so perhaps it needs an example (even if just a short parenthetical comment).

Quoted 8 lines

I have tried to reword this; I hope this is a little clearer.

Before you begin to examine user configuration for your revision walk, it's common practice for you to initialize to default any switches that your command may have, as well as ask any other components you may invoke to initialize as well (for example, how git log also uses the grep and diff components). git log does this in init_log_defaults(); in that case, one global decoration_style is initialized, as well as the grep and diff-UI components.

By trying to express too many things at once, it's still difficult to follow. Perhaps use shorter, more easily digestible sentences, like this:

Quoted 8 lines

Before examining configuration files which may modify command behavior, set up default state for switches or options your command may have. If your command utilizes other Git components, ask them to set up their default states, as well. For instance, git log takes advantage of grep and diff functionality; its init_log_defaults() sets its own state (decoration_style) and asks grep and diff to initialize themselves by calling their initialization functions.

Yeah, I like this a lot. Thanks! I took it word for word; will be adding you to the Helped-by line of the commit.

Quoted 14 lines

As this is just a toy example, I don't care too strongly about the unnecessary second sentence. On the other hand, the tutorial is trying to teach people how to contribute to this project, and on this project, that sort of pointless comment is likely to be called out in review. In fact, given that view, the entire comment block is unnecessary (it doesn't add any value for anyone reviewing or reading the code), so it might make more sense to drop the comment from the code entirely, and just do a better job explaining in prose above the snippet why you are calling that function. For instance:

... Let's start the helper with the call to prepare_revision_walk(), which does the final setup of the rev_info structure before it can be used.

Quoted 5 lines

The above observation may be more widely applicable than to just this one instance. Don't use in-code comments for what should be explained in prose if the in-code comment adds no value to the code itself (to wit, if a reviewer would say "don't repeat in a comment what the code already says clearly" or "don't use a comment to state the obvious").

I'm of two minds about this. On the one hand, I'm somewhat in favor of leaving contextual, informational comments in the sample code, so the sample code can teach on its own without the tutorial (specifically, I mean the patchset that was sent alongside this one as RFC). On the other hand, you're right that adding these informational comments doesn't model best practices for real commits.

I don't have a strong opposition to removing those comments from the in-place samples in the tutorial itself. But I do think it's useful to include them in the sample patchset, which is intended as an additional learning tool, rather than as a pristine code example - especially if we make it clear in the commit messages there.

Quoted 16 lines
Quoted 13 lines
Quoted 6 lines

Documentation/MyFirstRevWalk.txt line 480

Quoted 3 lines
Documentation/MyFirstRevWalk.txt new file +2 -0
+This display is an indicator for the latency between publishing a commit for
+review the first time, and getting it actually merged into master.

Perhaps: s/master/&/

Quoted 6 lines

Even as a long-time contributor to the project, I had to pause over this statement for several seconds before figuring out what it was talking about. Without a long-winded explanation of how topics progress from submission through 'pu' through 'next' through 'master' and finally into a release, the above statement is likely to be mystifying to a newcomer. Perhaps it should be dropped.

Quoted 2 lines

Such an explanation exists in MyFirstContribution.txt. I will include a shameless plug to that document here. :)

Quoted 6 lines

I found that this sort of tangential reference disturbed the flow of the tutorial, leading the mind astray from the otherwise natural progression of the presentation. So, I'm not convinced that talking about the migration of a topic in the Git project itself adds value to this tutorial. The same effect could be seen when commits have been re-ordered via git-rebase, too, right? Perhaps mention that instead?

Yeah, that's a good point. I'll try to mention it in a more universally-applicable way, like you suggested.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

Documentation/MyFirstRevWalk.txt line 645

Quoted 4 lines
Documentation/MyFirstRevWalk.txt new file +3 -0
+       printf(_("Object walk completed. Found %d commits, %d blobs, %d tags, "
+                "and %d trees.\n"), commit_count, blob_count, tag_count,
+              tree_count);

Or make the output more useful by having it be machine-parseable (and not localized):

printf("commits %d\nblobs %d\ntags %d\ntrees %d\n",
commit_count, blob_count, tag_cont, tree_count);

Quoted 8 lines
Quoted 2 lines

I'm not sure whether I agree, since it's a useless toy command only for human parsing.

True, it's not a big deal, and I don't insist upon it. But, if you mention in prose that this output is easily machine-parseable, then perhaps that nudges the reader a bit in the direction of thinking about porcelain vs. plumbing, which is something a contributor to this project eventually has to be concerned with (the sooner, the better).

Oh, that's a very good point. I'll frame it that way - that's a handy place to slip in some bonus context about Git. Thanks.

NOTE: We aren't localizing the printf here because we have purposefully formatted it in a machine-parseable way. Commands in Git are divided into "plumbing" and "porcelain"; the "plumbing" commands are machine-parseable and intended for use in scripts, while the "porcelain" commands are intended for human interaction. Output intended for script usage doesn't need to be localized; output intended for humans does.

Thanks again for the review effort.

- Emily

#23 lore raw
Quoted 15 lines · Emily Shaffer
Quoted 5 lines · Eric Sunshine

Maybe I got confused because the tiny cmd_walken() snippets followed one another so closely (or because I got interrupted several times during the review), but one way to avoid that would be to present a single _complete_ snippet from the start, followed by a bit of explanation. [...]

Hmm. I can say that I personally would find that much more difficult to follow interactively, and I'd be tempted to copy-and-paste and skim through the wall of text if I was presented with such a snippet. However, I could also imagine the reverse - someone becoming tired of having their hand held through a fairly straightforward implementation, when they're perfectly capable of reading a long description and would just like to get on with it.

Quoted 3 lines

(Maybe we can split the difference and present a complete patch or new function, followed by a breakdown? That would end up even more verbose than the current approach, though.)

It might not be that important and may not need fixing considering that I read it correctly the second time, and don't know how I managed to get confused on the first read.

Quoted 27 lines
Quoted 14 lines

As this is just a toy example, I don't care too strongly about the unnecessary second sentence. On the other hand, the tutorial is trying to teach people how to contribute to this project, and on this project, that sort of pointless comment is likely to be called out in review. In fact, given that view, the entire comment block is unnecessary (it doesn't add any value for anyone reviewing or reading the code), so it might make more sense to drop the comment from the code entirely, and just do a better job explaining in prose above the snippet why you are calling that function. For instance:

... Let's start the helper with the call to prepare_revision_walk(), which does the final setup of the rev_info structure before it can be used.

Quoted 5 lines

The above observation may be more widely applicable than to just this one instance. Don't use in-code comments for what should be explained in prose if the in-code comment adds no value to the code itself (to wit, if a reviewer would say "don't repeat in a comment what the code already says clearly" or "don't use a comment to state the obvious").

I'm of two minds about this. On the one hand, I'm somewhat in favor of leaving contextual, informational comments in the sample code, so the sample code can teach on its own without the tutorial (specifically, I mean the patchset that was sent alongside this one as RFC). On the other hand, you're right that adding these informational comments doesn't model best practices for real commits.

Quoted 5 lines

I don't have a strong opposition to removing those comments from the in-place samples in the tutorial itself. But I do think it's useful to include them in the sample patchset, which is intended as an additional learning tool, rather than as a pristine code example - especially if we make it clear in the commit messages there.

Indeed, having the comments in the sample patch-set makes sense for people who learn better that way (by seeing a complete piece of code).

Quoted 18 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Or make the output more useful by having it be machine-parseable (and not localized):

printf("commits %d\nblobs %d\ntags %d\ntrees %d\n",
commit_count, blob_count, tag_cont, tree_count);

Quoted 8 lines
Quoted 2 lines

I'm not sure whether I agree, since it's a useless toy command only for human parsing.

True, it's not a big deal, and I don't insist upon it. But, if you mention in prose that this output is easily machine-parseable, then perhaps that nudges the reader a bit in the direction of thinking about porcelain vs. plumbing, which is something a contributor to this project eventually has to be concerned with (the sooner, the better).

Oh, that's a very good point. I'll frame it that way - that's a handy place to slip in some bonus context about Git. Thanks.

Quoted 6 lines

NOTE: We aren't localizing the printf here because we have purposefully formatted it in a machine-parseable way. Commands in Git are divided into "plumbing" and "porcelain"; the "plumbing" commands are machine-parseable and intended for use in scripts, while the "porcelain" commands are intended for human interaction. Output intended for script usage doesn't need to be localized; output intended for humans does.

I'd go with stronger language than "doesn't need to be localized" and say instead that plumbing output "must not be localized" since scripts depend upon stable output (and stable API).

#24 lore raw
In reply to Emily Shaffer
Quoted 8 lines · Emily Shaffer

I'll also be mailing an RFC patchset In-Reply-To this message; the RFC patchset should not be merged to Git, as I intend to host it in my own mirror as an example. I hosted a similar example for the MyFirstContribution tutorial; it's visible at
https://github.com/nasamuffin/git/tree/psuh. There might be a better place to host these so I don't "own" them but I'm not sure what it is; keeping them as a live branch somewhere struck me as an okay way to keep them from getting stale.

Yes, writing the initial version is one thing, but keeping it alive is more work and more important. As the underlying API changes over time, it will become necessary to update the sample implementation, but for a newbie who wants to learn by building "walken" on top of the then-current codebase and API, it would not be so helpful to show "these 7 patches were for older codebase, and the tip 2 are incremental updates to adjust to the newer API", so the maintenance of these sample patches may need different paradigm than the norm for our main codebase that values incremental polishing.

#25 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Emily Shaffer

I'll also be mailing an RFC patchset In-Reply-To this message; the RFC patchset should not be merged to Git, as I intend to host it in my own mirror as an example. I hosted a similar example for the MyFirstContribution tutorial; it's visible at
https://github.com/nasamuffin/git/tree/psuh. There might be a better place to host these so I don't "own" them but I'm not sure what it is; keeping them as a live branch somewhere struck me as an okay way to keep them from getting stale.

Quoted 10 lines

Yes, writing the initial version is one thing, but keeping it alive is more work and more important. As the underlying API changes over time, it will become necessary to update the sample implementation, but for a newbie who wants to learn by building "walken" on top of the then-current codebase and API, it would not be so helpful to show "these 7 patches were for older codebase, and the tip 2 are incremental updates to adjust to the newer API", so the maintenance of these sample patches may need different paradigm than the norm for our main codebase that values incremental polishing.

I'm trying to think of how it would end up working if I tried to use a Github workflow. I think it wouldn't - someone would open a PR, and then I'd have to rewrite that change into the appropriate commit in the live branch and push the entire branch anew. Considering that workflow leaves me doubly convinced that leaving it in my personal fork indefinitely might not be wise (what if I become unable to continue maintaining it)?

I wonder if this is something that might fit well in
one of the more closely-associated mirrors, like gitster/git or gitgitgadget/git - although I wonder if those count as "owned" by Junio and Johannes, respectively. Hmmmm.

Maybe there's a case for storing them as a set of patch files that are revision-controlled somewhere within Documentation/? There was some discussion on the IRC a few weeks ago about trying to organize these tutorials into their own directory to form a sort of "Git Contribution 101" course, maybe it makes sense to store there?

Documentation/contributing/myfirstcontrib/MyFirstContrib.txt Documentation/contributing/myfirstcontrib/sample/*.patch Documentation/contributing/myfirstrevwalk/MyFirstRevWalk.txt Documentation/contributing/myfirstrevwalk/sample/*.patch

I don't love the idea of maintaining text patches with the expectation that they should cleanly apply always, but it might make the idea that they shouldn't contain 2 patches on the tip for API adjustment more clear. And it would be probably pretty easy to inflate and build them with a build target or something. Hmmmmmmmmm.

- Emily

#26 lore raw
Quoted 6 lines · Emily Shaffer

Maybe there's a case for storing them as a set of patch files that are revision-controlled somewhere within Documentation/? There was some discussion on the IRC a few weeks ago about trying to organize these tutorials into their own directory to form a sort of "Git Contribution 101" course, maybe it makes sense to store there?

Quoted 7 lines

Documentation/contributing/myfirstcontrib/MyFirstContrib.txt Documentation/contributing/myfirstcontrib/sample/*.patch Documentation/contributing/myfirstrevwalk/MyFirstRevWalk.txt Documentation/contributing/myfirstrevwalk/sample/*.patch

I don't love the idea of maintaining text patches with the expectation that they should cleanly apply always,...

Well, I actually think the above organization does match the intent of the "My first contribution codelab" perfectly. When the codebase, the workflow used by the project, and/or the coding or documentation guideline gets updated, the text that documents how to contribute to the project as well as the sample patches must be updated to match the updated reality.

I agree with you that maintaining the *.patch files to always cleanly apply is less than ideal. A topic to update the sample patches and tutorial text may be competing with another topic that updates the very API the tutorials are teaching, and the sample patches may not apply cleanly when two topics are merged together, even if the "update sample patches and tutorial text" topic does update them to match the API at the tip of the topic branch itself. One thing we _could_ do is to pin the target version of the codebase for the sake of tutorial. IOW, the sample/*.patch may not apply cleanly to the version of the tree these patches were taken from, but would always apply cleanly to the most recent released version before the last update to the tutorial, or something like that.

Also having to review the patch to sample/*.patch files will be unpleasant.

#27 lore raw
Quoted 36 lines · Junio C Hamano
Quoted 6 lines · Emily Shaffer

Maybe there's a case for storing them as a set of patch files that are revision-controlled somewhere within Documentation/? There was some discussion on the IRC a few weeks ago about trying to organize these tutorials into their own directory to form a sort of "Git Contribution 101" course, maybe it makes sense to store there?

Quoted 7 lines

Documentation/contributing/myfirstcontrib/MyFirstContrib.txt Documentation/contributing/myfirstcontrib/sample/*.patch Documentation/contributing/myfirstrevwalk/MyFirstRevWalk.txt Documentation/contributing/myfirstrevwalk/sample/*.patch

I don't love the idea of maintaining text patches with the expectation that they should cleanly apply always,...

Well, I actually think the above organization does match the intent of the "My first contribution codelab" perfectly. When the codebase, the workflow used by the project, and/or the coding or documentation guideline gets updated, the text that documents how to contribute to the project as well as the sample patches must be updated to match the updated reality.

I agree with you that maintaining the *.patch files to always cleanly apply is less than ideal. A topic to update the sample patches and tutorial text may be competing with another topic that updates the very API the tutorials are teaching, and the sample patches may not apply cleanly when two topics are merged together, even if the "update sample patches and tutorial text" topic does update them to match the API at the tip of the topic branch itself. One thing we _could_ do is to pin the target version of the codebase for the sake of tutorial. IOW, the sample/*.patch may not apply cleanly to the version of the tree these patches were taken from, but would always apply cleanly to the most recent released version before the last update to the tutorial, or something like that.

Quoted 2 lines

Also having to review the patch to sample/*.patch files will be unpleasant.

I wonder if we can ease some pain for both of the above issues by including some scripts to "inflate" the patch files into a topic branch, or figure out some more easily-reviewed (but more complicated, I suppose) method for sending updates to the sample/*.patch files.

Imagining workflows like this:

Doing the tutorial:
- In worktree a/.
- Run a magic script which creates a worktree with the sample code, b/.
- Read through a/Documentation/MyFirstContribution.txt and generate a/builtins/psuh.c, referring to b/builtins/psuh.c if confused.

Rebasing the tutorial patches:
- In worktree a/.
- Run a magic script which checks out a new branch at the last known good base for the patchset, then applies all the patches.
- Now faced with, likely, a topic branch based on v<n-1> (where n is latest release).
- git rebase v<n> -x (make && ./bin-wrappers/git psuh)
- Interactively fix conflicts
- Run a script to generate a magic interdiff from the old version of patches
- Mail out magic interdiff to list and get approval
- (Maybe maintainer does this when interdiff is happy? Maybe updater does this when review looks good?) Run a magic script to regenerate patches from rebased branch, and note somewhere they are based on v<n>
- Mail sample/*.patch (based on v<n>) to list (if maintainer rolled the patches after interdiff approval, this step can be skipped)

(This seems to still be a lot of steps, even with the magic script..)

Alternatively, for the same process:
Updater: Run a magic script to create topic branch based on v<n-1>
(like before)
U: git rebase v<n> -x (make && ./bin-wrappers/git psuh)
U: Interactively fix conflicts
U: Run a script to turn topic branch back into sample/*.patch
U: Send email with changes to sample/*.patch (this will be ugly and
unreadable) - message ID <M1>
Reviewer: Run a magic script, providing <M1> argument, which grabs the
diff-of-.patch and generates an interdiff, or a topic branch based on v<n>
R: Send comments explaining where issue is (tricky to find where to
inline in the diff-of-.patch)
U: Reroll diff-of-.patch email
R: Accepts
Maintainer: Applies diff-of-.patch email normally

I suppose for the first suggestion, there ends up being quite a lot of onus on the maintainer, and a lot of trust that there is no difference between the RFC easy-to-read interdiff patchset. For the second suggestion, there ends up being onus on the reviewers to run some magical script. Maybe we can split the difference by expecting Updater to provide the interdiff below the --- line? Maybe in practice the diff-of-.patch isn't so unreadable, if it's only minor changes needed to bring the tutorial up to latest?

I'm not sure there's a way to make this totally painless using email tools.

- Emily

#28 lore raw
Quoted 99 lines · Emily Shaffer
Quoted 36 lines · Junio C Hamano
Quoted 6 lines · Emily Shaffer

Maybe there's a case for storing them as a set of patch files that are revision-controlled somewhere within Documentation/? There was some discussion on the IRC a few weeks ago about trying to organize these tutorials into their own directory to form a sort of "Git Contribution 101" course, maybe it makes sense to store there?

Quoted 7 lines

Documentation/contributing/myfirstcontrib/MyFirstContrib.txt Documentation/contributing/myfirstcontrib/sample/*.patch Documentation/contributing/myfirstrevwalk/MyFirstRevWalk.txt Documentation/contributing/myfirstrevwalk/sample/*.patch

I don't love the idea of maintaining text patches with the expectation that they should cleanly apply always,...

Well, I actually think the above organization does match the intent of the "My first contribution codelab" perfectly. When the codebase, the workflow used by the project, and/or the coding or documentation guideline gets updated, the text that documents how to contribute to the project as well as the sample patches must be updated to match the updated reality.

I agree with you that maintaining the *.patch files to always cleanly apply is less than ideal. A topic to update the sample patches and tutorial text may be competing with another topic that updates the very API the tutorials are teaching, and the sample patches may not apply cleanly when two topics are merged together, even if the "update sample patches and tutorial text" topic does update them to match the API at the tip of the topic branch itself. One thing we _could_ do is to pin the target version of the codebase for the sake of tutorial. IOW, the sample/*.patch may not apply cleanly to the version of the tree these patches were taken from, but would always apply cleanly to the most recent released version before the last update to the tutorial, or something like that.

Quoted 2 lines

Also having to review the patch to sample/*.patch files will be unpleasant.

I wonder if we can ease some pain for both of the above issues by including some scripts to "inflate" the patch files into a topic branch, or figure out some more easily-reviewed (but more complicated, I suppose) method for sending updates to the sample/*.patch files.

Imagining workflows like this:

Doing the tutorial:
- In worktree a/.
- Run a magic script which creates a worktree with the sample code, b/.
- Read through a/Documentation/MyFirstContribution.txt and generate a/builtins/psuh.c, referring to b/builtins/psuh.c if confused.

Rebasing the tutorial patches:
- In worktree a/.
- Run a magic script which checks out a new branch at the last known good base for the patchset, then applies all the patches.
- Now faced with, likely, a topic branch based on v<n-1> (where n is latest release).
- git rebase v<n> -x (make && ./bin-wrappers/git psuh)
- Interactively fix conflicts
- Run a script to generate a magic interdiff from the old version of patches
- Mail out magic interdiff to list and get approval
- (Maybe maintainer does this when interdiff is happy? Maybe updater does this when review looks good?) Run a magic script to regenerate patches from rebased branch, and note somewhere they are based on v<n>
- Mail sample/*.patch (based on v<n>) to list (if maintainer rolled the patches after interdiff approval, this step can be skipped)

(This seems to still be a lot of steps, even with the magic script..)

Alternatively, for the same process:
Updater: Run a magic script to create topic branch based on v<n-1>
(like before)
U: git rebase v<n> -x (make && ./bin-wrappers/git psuh)
U: Interactively fix conflicts
U: Run a script to turn topic branch back into sample/*.patch
U: Send email with changes to sample/*.patch (this will be ugly and
unreadable) - message ID <M1>
Reviewer: Run a magic script, providing <M1> argument, which grabs the
diff-of-.patch and generates an interdiff, or a topic branch based on v<n>
R: Send comments explaining where issue is (tricky to find where to
inline in the diff-of-.patch)
U: Reroll diff-of-.patch email
R: Accepts
Maintainer: Applies diff-of-.patch email normally

I suppose for the first suggestion, there ends up being quite a lot of onus on the maintainer, and a lot of trust that there is no difference between the RFC easy-to-read interdiff patchset. For the second suggestion, there ends up being onus on the reviewers to run some magical script. Maybe we can split the difference by expecting Updater to provide the interdiff below the --- line? Maybe in practice the diff-of-.patch isn't so unreadable, if it's only minor changes needed to bring the tutorial up to latest?

Quoted 2 lines

I'm not sure there's a way to make this totally painless using email tools.

Random thought about the "magic scripts": if we keep an mbox instead of a directory of *.patch files, then it seems like git-format-patch and git-am would solve the bulk of this. I don't think dealing with diffs-of-patches-in-mbox is much worse than dealing with diffs-of-patches-in-multiple-files. And for the "Doing the tutorial" workflow, it nudges the new contributor to learn git-am.

But I guess the hard part here is the reviewing diffs-of-diffs part. I'm leaning towards the second option here; I personally would not feel too troubled as a reviewer by having to run an extra script. And as you say, diff-of-diffs may not be so bad in practice. Reviewers already see these whenever someone includes a range-diff in their v>=2 emails.

#29 lore raw
Quoted 110 lines · Josh Steadmon
Quoted 99 lines · Emily Shaffer
Quoted 36 lines · Junio C Hamano
Quoted 6 lines · Emily Shaffer

Maybe there's a case for storing them as a set of patch files that are revision-controlled somewhere within Documentation/? There was some discussion on the IRC a few weeks ago about trying to organize these tutorials into their own directory to form a sort of "Git Contribution 101" course, maybe it makes sense to store there?

Quoted 7 lines

Documentation/contributing/myfirstcontrib/MyFirstContrib.txt Documentation/contributing/myfirstcontrib/sample/*.patch Documentation/contributing/myfirstrevwalk/MyFirstRevWalk.txt Documentation/contributing/myfirstrevwalk/sample/*.patch

I don't love the idea of maintaining text patches with the expectation that they should cleanly apply always,...

Well, I actually think the above organization does match the intent of the "My first contribution codelab" perfectly. When the codebase, the workflow used by the project, and/or the coding or documentation guideline gets updated, the text that documents how to contribute to the project as well as the sample patches must be updated to match the updated reality.

I agree with you that maintaining the *.patch files to always cleanly apply is less than ideal. A topic to update the sample patches and tutorial text may be competing with another topic that updates the very API the tutorials are teaching, and the sample patches may not apply cleanly when two topics are merged together, even if the "update sample patches and tutorial text" topic does update them to match the API at the tip of the topic branch itself. One thing we _could_ do is to pin the target version of the codebase for the sake of tutorial. IOW, the sample/*.patch may not apply cleanly to the version of the tree these patches were taken from, but would always apply cleanly to the most recent released version before the last update to the tutorial, or something like that.

Quoted 2 lines

Also having to review the patch to sample/*.patch files will be unpleasant.

I wonder if we can ease some pain for both of the above issues by including some scripts to "inflate" the patch files into a topic branch, or figure out some more easily-reviewed (but more complicated, I suppose) method for sending updates to the sample/*.patch files.

Imagining workflows like this:

Doing the tutorial:
- In worktree a/.
- Run a magic script which creates a worktree with the sample code, b/.
- Read through a/Documentation/MyFirstContribution.txt and generate a/builtins/psuh.c, referring to b/builtins/psuh.c if confused.

Rebasing the tutorial patches:
- In worktree a/.
- Run a magic script which checks out a new branch at the last known good base for the patchset, then applies all the patches.
- Now faced with, likely, a topic branch based on v<n-1> (where n is latest release).
- git rebase v<n> -x (make && ./bin-wrappers/git psuh)
- Interactively fix conflicts
- Run a script to generate a magic interdiff from the old version of patches
- Mail out magic interdiff to list and get approval
- (Maybe maintainer does this when interdiff is happy? Maybe updater does this when review looks good?) Run a magic script to regenerate patches from rebased branch, and note somewhere they are based on v<n>
- Mail sample/*.patch (based on v<n>) to list (if maintainer rolled the patches after interdiff approval, this step can be skipped)

(This seems to still be a lot of steps, even with the magic script..)

Alternatively, for the same process:
Updater: Run a magic script to create topic branch based on v<n-1>
(like before)
U: git rebase v<n> -x (make && ./bin-wrappers/git psuh)
U: Interactively fix conflicts
U: Run a script to turn topic branch back into sample/*.patch
U: Send email with changes to sample/*.patch (this will be ugly and
unreadable) - message ID <M1>
Reviewer: Run a magic script, providing <M1> argument, which grabs the
diff-of-.patch and generates an interdiff, or a topic branch based on v<n>
R: Send comments explaining where issue is (tricky to find where to
inline in the diff-of-.patch)
U: Reroll diff-of-.patch email
R: Accepts
Maintainer: Applies diff-of-.patch email normally

I suppose for the first suggestion, there ends up being quite a lot of onus on the maintainer, and a lot of trust that there is no difference between the RFC easy-to-read interdiff patchset. For the second suggestion, there ends up being onus on the reviewers to run some magical script. Maybe we can split the difference by expecting Updater to provide the interdiff below the --- line? Maybe in practice the diff-of-.patch isn't so unreadable, if it's only minor changes needed to bring the tutorial up to latest?

Quoted 2 lines

I'm not sure there's a way to make this totally painless using email tools.

Random thought about the "magic scripts": if we keep an mbox instead of a directory of *.patch files, then it seems like git-format-patch and git-am would solve the bulk of this. I don't think dealing with diffs-of-patches-in-mbox is much worse than dealing with diffs-of-patches-in-multiple-files. And for the "Doing the tutorial" workflow, it nudges the new contributor to learn git-am.

Quoted 5 lines

But I guess the hard part here is the reviewing diffs-of-diffs part. I'm leaning towards the second option here; I personally would not feel too troubled as a reviewer by having to run an extra script. And as you say, diff-of-diffs may not be so bad in practice. Reviewers already see these whenever someone includes a range-diff in their v>=2 emails.

There was also some suggestion of instead checking in ed scripts or similar to populate the changes. On one hand, it might be nicer, as there aren't diff markers on the front of all the code... but on the other hand, I'm not sure how many folks are familiar with ed (I know I'm not) and it might be complex to indicate where to insert changes.

I have been in a position of reviewing diff-of-.patch in a past life, albeit via Gerrit, and it's not the worst when the code is simple (as we should always hope this example tutorial code would be).

- Emily

#30 lore raw
Quoted 3 lines · Emily Shaffer

I have been in a position of reviewing diff-of-.patch in a past life, albeit via Gerrit, and it's not the worst when the code is simple (as we should always hope this example tutorial code would be).

I personally think a directory full of patch files is OK. I am not sure if they (together with this rev walk tutorial) belong to the main part of the project, though.

#31 lore raw
In reply to Emily Shaffer

Documentation/MyFirstRevWalk.txt line 10

Quoted 10 lines · Emily Shaffer
Documentation/MyFirstRevWalk.txt new file +10 -0
+My First Revision Walk
+======================
+
+== What's a Revision Walk?
+
+The revision walk is a key concept in Git - this is the process that underpins
+operations like `git log`, `git blame`, and `git reflog`. Beginning at HEAD, the
+list of objects is found by walking parent relationships between objects. The
+revision walk can also be usedto determine whether or not a given object is
+reachable from the current HEAD pointer.

s/usedto/used to/;

Documentation/MyFirstRevWalk.txt line 39

Quoted 11 lines
Documentation/MyFirstRevWalk.txt new file +11 -0
+We'll put our fiddling into a new command. For fun, let's name it `git walken`.
+Open up a new file `builtin/walken.c` and set up the command handler:
+
+----
+/*
+ * "git walken"
+ *
+ * Part of the "My First Revision Walk" tutorial.
+ */
+
+#include <stdio.h>

Bad idea. In the generic part of the codebase, system headers are supposed to be supplied by including git-compat-util.h (or cache.h or builtin.h, that are common header files that begin by including it and are allowed by CodingGuidelines to be used as such).

Documentation/MyFirstRevWalk.txt line 47

Quoted 8 lines
Documentation/MyFirstRevWalk.txt new file +8 -0
+#include "builtin.h"
+
+int cmd_walken(int argc, const char **argv, const char *prefix)
+{
+        printf(_("cmd_walken incoming...\n"));
+        return 0;
+}
+----

I wonder if it makes sense to use trace instead of printf, as our reader has already seen the psuh example for doing the above.

Quoted 1 line

+Add usage text and -h handling, in order to pass the test suite:

It is not wrong per-se, and it indeed is a very good practice to make sure that our subcommands consistently gives usage text and short usage. Encouraging them early is a good idea.

But "in order to pass the test suite" invites "eh, the test suite does not pass without usage and -h? why?".

Either drop the mention of "the test suite", or perhaps say something like

Add usage text and -h handling, like all the subcommands should consistently do (our test suite will notice and complain if you fail to do so).

i.e. the real purpose is consistency and usability; test suite is merely an enforcement mechanism.

Documentation/MyFirstRevWalk.txt line 81

Quoted 5 lines

+----

Documentation/MyFirstRevWalk.txt new file +4 -0
+{ "walken", cmd_walken, RUN_SETUP },
+----
+
+Add it to the `Makefile` near the line for `builtin\worktree.o`:

Backslash intended?

#32 lore raw
Quoted 14 lines · Junio C Hamano

Documentation/MyFirstRevWalk.txt line 10

Quoted 10 lines · Emily Shaffer
Documentation/MyFirstRevWalk.txt new file +10 -0
+My First Revision Walk
+======================
+
+== What's a Revision Walk?
+
+The revision walk is a key concept in Git - this is the process that underpins
+operations like `git log`, `git blame`, and `git reflog`. Beginning at HEAD, the
+list of objects is found by walking parent relationships between objects. The
+revision walk can also be usedto determine whether or not a given object is
+reachable from the current HEAD pointer.

s/usedto/used to/;

Done.

Quoted 17 lines

Documentation/MyFirstRevWalk.txt line 39

Quoted 12 lines
Documentation/MyFirstRevWalk.txt new file +11 -0
+We'll put our fiddling into a new command. For fun, let's name it `git walken`.
+Open up a new file `builtin/walken.c` and set up the command handler:
+
+----
+/*
+ * "git walken"
+ *
+ * Part of the "My First Revision Walk" tutorial.
+ */
+
+#include <stdio.h>

Bad idea. In the generic part of the codebase, system headers are supposed to be supplied by including git-compat-util.h (or cache.h or builtin.h, that are common header files that begin by including it and are allowed by CodingGuidelines to be used as such).

Done.

Quoted 12 lines

Documentation/MyFirstRevWalk.txt line 47

Quoted 9 lines
Documentation/MyFirstRevWalk.txt new file +8 -0
+#include "builtin.h"
+
+int cmd_walken(int argc, const char **argv, const char *prefix)
+{
+        printf(_("cmd_walken incoming...\n"));
+        return 0;
+}
+----

I wonder if it makes sense to use trace instead of printf, as our reader has already seen the psuh example for doing the above.

Hmmm. I will think about it and look into the intended use of each. I hadn't considered using a different logging method.

Quoted 13 lines
Quoted 2 lines

+Add usage text and -h handling, in order to pass the test suite:

It is not wrong per-se, and it indeed is a very good practice to make sure that our subcommands consistently gives usage text and short usage. Encouraging them early is a good idea.

But "in order to pass the test suite" invites "eh, the test suite does not pass without usage and -h? why?".

Either drop the mention of "the test suite", or perhaps say something like

Quoted 6 lines

Add usage text and -h handling, like all the subcommands should consistently do (our test suite will notice and complain if you fail to do so).

i.e. the real purpose is consistency and usability; test suite is merely an enforcement mechanism.

Yeah, you're right. I'll reword this.

Quoted 8 lines

Documentation/MyFirstRevWalk.txt line 81

Quoted 6 lines

+----

Documentation/MyFirstRevWalk.txt new file +4 -0
+{ "walken", cmd_walken, RUN_SETUP },
+----
+
+Add it to the `Makefile` near the line for `builtin\worktree.o`:

Backslash intended?

Nope, typo.

Thanks for the comments, Junio.

- Emily

#33 lore raw

PATCH v2 1/1 documentation: add tutorial for revision walking

In reply to Emily Shaffer

Existing documentation on revision walks seems to be primarily intended as a reference for those already familiar with the procedure. This tutorial attempts to give an entry-level guide to a couple of bare-bones revision walks so that new Git contributors can learn the concepts without having to wade through options parsing or special casing.

The target audience is a Git contributor who is just getting started with the concept of revision walking. The goal is to prepare this contributor to be able to understand and modify existing commands which perform revision walks more easily, although it will also prepare contributors to create new commands which perform walks.

The tutorial covers a basic overview of the structs involved during revision walk, setting up a basic commit walk, setting up a basic all-object walk, and adding some configuration changes to both walk types. It intentionally does not cover how to create new commands or search for options from the command line or gitconfigs.

There is an associated patchset at
https://github.com/nasamuffin/git/tree/revwalk that contains a reference implementation of the code generated by this tutorial.

---
Significant changes since r1 related to Eric and Junio's comments:
- Formatting fixes (multiline comments, whitespaces, etc.)
- Clarifications:
- oneline options
- buf arg in object walk callback
- topo_order
- placement of reverse setting
- '-h' handling
- Converted patchset to plumbing tool, using trace where appropriate
- Removed unnecessary return values in walken_commit_walk and walken_object_walk
- Added an entire section devoted to the omitted list
- Tried to remove unnecessary explanatory comments in tutorial (and added more explanatory comments in sample code)

There's still the question of how the samples should be source-controlled and kept fresh. I think we left it at "Maybe checking in a stack of *.patch files would be tolerable", but it didn't sound like anybody was quite happy with that solution.

- Emily

 Documentation/Makefile           |   1 +
 Documentation/MyFirstRevWalk.txt | 910 +++++++++++++++++++++++++++++++
 2 files changed, 911 insertions(+)
 create mode 100644 Documentation/MyFirstRevWalk.txt
Documentation/Makefile +1 -0
index 76f2ecfc1b..91e5da67c4 100644
@@ -78,6 +78,7 @@ SP_ARTICLES += $(API_DOCS)
 
 TECH_DOCS += MyFirstContribution
 TECH_DOCS += SubmittingPatches
+TECH_DOCS += MyFirstRevWalk
 TECH_DOCS += technical/hash-function-transition
 TECH_DOCS += technical/http-protocol
 TECH_DOCS += technical/index-format
Documentation/MyFirstRevWalk.txt new file +910 -0

910 lines not on this page · raw message

Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#34 lore raw

v2 cover example implementation of revwalk tutorial

Since r1, made some significant changes.

- Added a commit for counting the 'omitted' list, to match the new section added to the tutorial.
- Added significant comments to allow the sample to better stand on its own.
- Fixed style issues (die() formatting, etc)
- Distinguished between human- and machine-readable output with trace_printf() and printf(), to turn the command into plumbing.
- More changes as mentioned in the tutorial patch.

Thanks.
- Emily

Emily Shaffer (13):
walken: add infrastructure for revwalk demo
walken: add usage to enable -h
walken: add placeholder to initialize defaults
walken: add handler to git_config
walken: configure rev_info and prepare for walk
walken: perform our basic revision walk
walken: filter for authors from gmail address
walken: demonstrate various topographical sorts
walken: demonstrate reversing a revision walk list
walken: add unfiltered object walk from HEAD
walken: add filtered object walk
walken: count omitted objects
walken: reverse the object walk order

 Makefile         |   1 +
 builtin.h        |   1 +
 builtin/walken.c | 290 +++++++++++++++++++++++++++++++++++++++++++++++
 git.c            |   1 +
 4 files changed, 293 insertions(+)
 create mode 100644 builtin/walken.c
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#35 lore raw

RFC PATCH v2 1/13 walken: add infrastructure for revwalk demo

Begin to add scaffolding for git walken, a toy command which we will teach to perform a number of revision walks, in order to demonstrate the mechanics of revision walking for developers new to the Git project.

This commit is the beginning of an educational series which correspond to the tutorial in Documentation/MyFirstRevWalk.txt.

Change-Id I64297621919412f54701e111366e99c4ef0feae3
---
 Makefile         |  1 +
 builtin.h        |  1 +
 builtin/walken.c | 13 +++++++++++++
 3 files changed, 15 insertions(+)
 create mode 100644 builtin/walken.c
Makefile +1 -0
index f58bf14c7b..5bac1dbf8d 100644
@@ -1137,6 +1137,7 @@ BUILTIN_OBJS += builtin/var.o
 BUILTIN_OBJS += builtin/verify-commit.o
 BUILTIN_OBJS += builtin/verify-pack.o
 BUILTIN_OBJS += builtin/verify-tag.o
+BUILTIN_OBJS += builtin/walken.o
 BUILTIN_OBJS += builtin/worktree.o
 BUILTIN_OBJS += builtin/write-tree.o
 
builtin.h +1 -0
index ec7e0954c4..c919736c36 100644
@@ -242,6 +242,7 @@ int cmd_var(int argc, const char **argv, const char *prefix);
 int cmd_verify_commit(int argc, const char **argv, const char *prefix);
 int cmd_verify_tag(int argc, const char **argv, const char *prefix);
 int cmd_version(int argc, const char **argv, const char *prefix);
+int cmd_walken(int argc, const char **argv, const char *prefix);
 int cmd_whatchanged(int argc, const char **argv, const char *prefix);
 int cmd_worktree(int argc, const char **argv, const char *prefix);
 int cmd_write_tree(int argc, const char **argv, const char *prefix);
builtin/walken.c new file +13 -0
new file mode 100644
index 0000000000..d2772a0e8f
@@ -0,0 +1,13 @@
+/*
+ * "git walken"
+ *
+ * Part of the "My First Revision Walk" tutorial.
+ */
+
+#include "builtin.h"
+
+int cmd_walken(int argc, const char **argv, const char *prefix)
+{
+	trace_printf(_("cmd_walken incoming...\n"));
+	return 0;
+}
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#36 lore raw

RFC PATCH v2 2/13 walken: add usage to enable -h

In reply to Emily Shaffer

It's expected that Git commands support '-h' in order to provide a consistent user experience (and this expectation is enforced by the test suite). '-h' is captured by parse_options() by default; in order to support this flag, we add a short usage text to walken.c and invoke parse_options().

With this change, we can now add cmd_walken to the builtins set and expect tests to pass, so we'll do so - cmd_walken is now open for business.

Change-Id I2919dc1efadb82acb335617ea24371c84b03bbce
---
 builtin/walken.c | 25 +++++++++++++++++++++++++
 git.c            |  1 +
 2 files changed, 26 insertions(+)
builtin/walken.c +25 -0
index d2772a0e8f..9eea51ff70 100644
@@ -5,9 +5,34 @@
  */
 
 #include "builtin.h"
+#include "parse-options.h"
+
+/*
+ * All builtins are expected to provide a usage to provide a consistent user
+ * experience.
+ */
+const char * const walken_usage[] = {
+	N_("git walken"),
+	NULL,
+};
 
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
+	struct option options[] = {
+		OPT_END()
+	};
+
+	/*
+	 * parse_options() handles showing usage if incorrect options are
+	 * provided, or if '-h' is passed.
+	 */
+	argc = parse_options(argc, argv, prefix, options, walken_usage, 0);
+
+	/*
+	 * This line is "human-readable" and we are writing a plumbing command,
+	 * so we localize it and use the trace library to print only when
+	 * the GIT_TRACE environment variable is set.
+	 */
 	trace_printf(_("cmd_walken incoming...\n"));
 	return 0;
 }
git.c +1 -0
index c2eec470c9..2a7fb9714f 100644
@@ -601,6 +601,7 @@ static struct cmd_struct commands[] = {
 	{ "verify-pack", cmd_verify_pack },
 	{ "verify-tag", cmd_verify_tag, RUN_SETUP },
 	{ "version", cmd_version },
+	{ "walken", cmd_walken, RUN_SETUP },
 	{ "whatchanged", cmd_whatchanged, RUN_SETUP },
 	{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT },
 	{ "write-tree", cmd_write_tree, RUN_SETUP },
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#37 lore raw

Re: [RFC PATCH v2 02/13] walken: add usage to enable -h

Quoted 10 lines · Emily Shaffer

It's expected that Git commands support '-h' in order to provide a consistent user experience (and this expectation is enforced by the test suite). '-h' is captured by parse_options() by default; in order to support this flag, we add a short usage text to walken.c and invoke parse_options().

---

builtin/walken.c line 8

Quoted 4 lines
builtin/walken.c +4 -0
@@ -5,9 +5,34 @@
+const char * const walken_usage[] = {
+       N_("git walken"),
+       NULL,
+};

Unless you expect to reference this from multiple functions, there is no need for it to reside here; instead, it can live inside cmd_walken(). (And, if you do leave it in the global scope for some reason, it should be 'static'.)

Quoted 5 lines
builtin/walken.c +3 -0
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
+       struct option options[] = {
+               OPT_END()
+       };
#38 lore raw

Re: [RFC PATCH v2 02/13] walken: add usage to enable -h

Quoted 12 lines · Eric Sunshine
Quoted 11 lines · Emily Shaffer

It's expected that Git commands support '-h' in order to provide a consistent user experience (and this expectation is enforced by the test suite). '-h' is captured by parse_options() by default; in order to support this flag, we add a short usage text to walken.c and invoke parse_options().

---

builtin/walken.c +1 -0
@@ -5,9 +5,34 @@
+const char * const walken_usage[] = {
Quoted 8 lines

builtin/walken.c line 17

Quoted 3 lines
builtin/walken.c +3 -0
+       N_("git walken"),
+       NULL,
+};

Unless you expect to reference this from multiple functions, there is no need for it to reside here; instead, it can live inside cmd_walken(). (And, if you do leave it in the global scope for some reason, it should be 'static'.)

Thanks, done.

Quoted 6 lines

builtin/walken.c line 23

Quoted 6 lines
builtin/walken.c +3 -0
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
+       struct option options[] = {
+               OPT_END()
+       };

Fixed the comment from your other mail too.

Thanks!

#39 lore raw

Re: [RFC PATCH v2 02/13] walken: add usage to enable -h

In reply to Emily Shaffer
Quoted 10 lines · Emily Shaffer

It's expected that Git commands support '-h' in order to provide a consistent user experience (and this expectation is enforced by the test suite). '-h' is captured by parse_options() by default; in order to support this flag, we add a short usage text to walken.c and invoke parse_options().

---

builtin/walken.c line 13

Quoted 9 lines
builtin/walken.c +6 -0
@@ -5,9 +5,34 @@
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
+       [...]
+       /*
+        * This line is "human-readable" and we are writing a plumbing command,
+        * so we localize it and use the trace library to print only when
+        * the GIT_TRACE environment variable is set.
+        */
        trace_printf(_("cmd_walken incoming...\n"));

Also, this in-code comment should have been introduced in patch 1/13, not here in 2/13.

#40 lore raw

RFC PATCH v2 3/13 walken: add placeholder to initialize defaults

In reply to Emily Shaffer

Eventually, we will want a good place to initialize default variables for use during our revision walk(s) in git walken. For now, there's nothing to do here, but let's add the scaffolding so that it's easy to tell where to put the setup later on.

---
 builtin/walken.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
builtin/walken.c +15 -0
index 9eea51ff70..daae4f811a 100644
@@ -16,6 +16,19 @@ const char * const walken_usage[] = {
 	NULL,
 };
 
+/*
+ * Within init_walken_defaults() we can call into other useful defaults to set
+ * in the global scope or on the_repository. It's okay to borrow from other
+ * functions which are doing something relatively similar to yours.
+ */
+static void init_walken_defaults(void)
+{
+	/*
+	 * We don't actually need the same components `git log` does; leave this
+	 * empty for now.
+	 */
+}
+
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
 	struct option options[] = {
@@ -28,6 +41,8 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 	 */
 	argc = parse_options(argc, argv, prefix, options, walken_usage, 0);
 
+	init_walken_defaults();
+
 	/*
 	 * This line is "human-readable" and we are writing a plumbing command,
 	 * so we localize it and use the trace library to print only when
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#41 lore raw

RFC PATCH v2 4/13 walken: add handler to git_config

In reply to Emily Shaffer

For now, we have no configuration options we want to set up for ourselves, but in the future we may need to. At the very least, we should invoke git_default_config() for each config option; we will do so inside of a skeleton config callback so that we know where to add configuration handling later on when we need it.

---
 builtin/walken.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
builtin/walken.c +30 -2
index daae4f811a..2474a0d7b2 100644
@@ -5,6 +5,7 @@
  */
 
 #include "builtin.h"
+#include "config.h"
 #include "parse-options.h"
 
 /*
@@ -24,11 +25,36 @@ const char * const walken_usage[] = {
 static void init_walken_defaults(void)
 {
 	/*
-	 * We don't actually need the same components `git log` does; leave this
-	 * empty for now.
+	 * We don't use any other components or have settings to initialize, so
+	 * leave this empty.
 	 */
 }
 
+/*
+ * This method will be called back by git_config(). It is used to gather values
+ * from the configuration files available to Git.
+ *
+ * Each time git_config() finds a configuration file entry, it calls this
+ * callback. Then, this function should compare it to entries which concern us,
+ * and make settings changes as necessary.
+ *
+ * If we are called with a config setting we care about, we should use one of
+ * the helpers which exist in config.h to pull out the value for ourselves, i.e.
+ * git_config_string(...) or git_config_bool(...).
+ *
+ * If we don't match anything, we should pass it along to another stakeholder
+ * who may otherwise care - in log's case, grep, gpg, and diff-ui. For our case,
+ * we'll ignore everybody else.
+ */
+static int git_walken_config(const char *var, const char *value, void *cb)
+{
+	/*
+	 * For now, we don't have any custom configuration, so fall back on the
+	 * default config.
+	 */
+	return git_default_config(var, value, cb);
+}
+
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
 	struct option options[] = {
@@ -43,6 +69,8 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 
 	init_walken_defaults();
 
+	git_config(git_walken_config, NULL);
+
 	/*
 	 * This line is "human-readable" and we are writing a plumbing command,
 	 * so we localize it and use the trace library to print only when
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#42 lore raw

Re: [RFC PATCH v2 04/13] walken: add handler to git_config

Quoted 10 lines · Emily Shaffer

For now, we have no configuration options we want to set up for ourselves, but in the future we may need to. At the very least, we should invoke git_default_config() for each config option; we will do so inside of a skeleton config callback so that we know where to add configuration handling later on when we need it.

---

builtin/walken.c const char * const walken_usage[] = { · line 31

Quoted 9 lines
builtin/walken.c +2 -2
@@ -24,11 +25,36 @@ const char * const walken_usage[] = {
 static void init_walken_defaults(void)
 {
        /*
-        * We don't actually need the same components `git log` does; leave this
-        * empty for now.
+        * We don't use any other components or have settings to initialize, so
+        * leave this empty.
         */
 }

Meh, I don't think this change has anything to do with this patch. If the rewritten text is the one you prefer, then just introduce it like that in patch 3/13 where the function itself was introduced.

#43 lore raw

Re: [RFC PATCH v2 04/13] walken: add handler to git_config

Quoted 16 lines · Eric Sunshine
Quoted 15 lines · Emily Shaffer

For now, we have no configuration options we want to set up for ourselves, but in the future we may need to. At the very least, we should invoke git_default_config() for each config option; we will do so inside of a skeleton config callback so that we know where to add configuration handling later on when we need it.

---

builtin/walken.c +0 -2
@@ -24,11 +25,36 @@ const char * const walken_usage[] = {
 static void init_walken_defaults(void)
 {
        /*
-        * We don't actually need the same components `git log` does; leave this
-        * empty for now.
Quoted 8 lines

builtin/walken.c const char * const walken_usage[] = { · line 31

Quoted 4 lines
builtin/walken.c +2 -0
+        * We don't use any other components or have settings to initialize, so
+        * leave this empty.
         */
 }

Meh, I don't think this change has anything to do with this patch. If the rewritten text is the one you prefer, then just introduce it like that in patch 3/13 where the function itself was introduced.

Whoops, yeah. I removed this change, I don't think it's significant.

#44 lore raw

RFC PATCH v2 5/13 walken: configure rev_info and prepare for walk

In reply to Emily Shaffer

struct rev_info is what's used by the struct itself. repo_init_revisions() initializes the struct; then we need to set it up for the walk we want to perform, which is done in final_rev_info_setup().

The most important step here is adding the first object we want to walk to the pending array. Here, we take the easy road and use add_head_to_pending(); there is also a way to do it with setup_revision_opt() and setup_revisions() which we demonstrate but do not use. If we were to forget this step, the walk would do nothing - the pending queue would be checked, determined to be empty, and the walk would terminate immediately.

Change-Id I76754b740227cf17a449f3f536dbbe37031e6f9a
---
 builtin/walken.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
builtin/walken.c +50 -0
index 2474a0d7b2..c463eca843 100644
@@ -5,6 +5,7 @@
  */
 
 #include "builtin.h"
+#include "revision.h"
 #include "config.h"
 #include "parse-options.h"
 
@@ -30,6 +31,40 @@ static void init_walken_defaults(void)
 	 */
 }
 
+/*
+ * cmd_log calls a second set of init after the repo_init_revisions call. We'll
+ * mirror those settings in post_repo_init_init.
+ */
+static void final_rev_info_setup(int argc, const char **argv, const char *prefix,
+		struct rev_info *rev)
+{
+	/*
+	 * Optional:
+	 * setup_revision_opt is used to pass options to the setup_revisions()
+	 * call. It's got some special items for submodules and other types of
+	 * optimizations, but for now, we'll just point it to HEAD and call it
+	 * good. First we should make sure to reset it. This is useful for more
+	 * complicated stuff but a decent shortcut for the first pass is
+	 * add_head_to_pending().
+	 */
+
+	/*
+	 * struct setup_revision_opt opt;
+
+	 * memset(&opt, 0, sizeof(opt));
+	 * opt.def = "HEAD";
+	 * opt.revarg_opt = REVARG_COMMITTISH;
+	 * setup_revisions(argc, argv, rev, &opt);
+	 */
+
+	/* Let's force oneline format. */
+	get_commit_format("oneline", rev);
+	rev->verbose_header = 1;
+
+	/* add the HEAD to pending so we can start */
+	add_head_to_pending(rev);
+}
+
 /*
  * This method will be called back by git_config(). It is used to gather values
  * from the configuration files available to Git.
@@ -61,6 +96,8 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	struct rev_info rev;
+
 	/*
 	 * parse_options() handles showing usage if incorrect options are
 	 * provided, or if '-h' is passed.
@@ -71,6 +108,19 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 
 	git_config(git_walken_config, NULL);
 
+	/*
+	 * Time to set up the walk. repo_init_revisions sets up rev_info with
+	 * the defaults, but then you need to make some configuration settings
+	 * to make it do what's special about your walk.
+	 */
+	repo_init_revisions(the_repository, &rev, prefix);
+
+	/*
+	 * Before we do the walk, we need to set a starting point by giving it
+	 * something to go in `pending` - that happens in here
+	 */
+	final_rev_info_setup(argc, argv, prefix, &rev);
+
 	/*
 	 * This line is "human-readable" and we are writing a plumbing command,
 	 * so we localize it and use the trace library to print only when
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#45 lore raw

Re: [RFC PATCH v2 05/13] walken: configure rev_info and prepare for walk

Quoted 1 line · Emily Shaffer

struct rev_info is what's used by the struct itself.

What "struct itself"? Do you mean 'struct rev_info' is used by the _walk_ itself? Or something?

builtin/walken.c static void init_walken_defaults(void) · line 34

Quoted 12 lines

repo_init_revisions() initializes the struct; then we need to set it up for the walk we want to perform, which is done in final_rev_info_setup().

---

builtin/walken.c +4 -0
@@ -30,6 +31,40 @@ static void init_walken_defaults(void)
+/*
+ * cmd_log calls a second set of init after the repo_init_revisions call. We'll
+ * mirror those settings in post_repo_init_init.
+ */

What is 'post_repo_init_init'?

I found the reference to cmd_log() confusing because I was looking for it in this patch (as if it was being introduced here). Newcomers might be even more confused. Perhaps if you state explicitly that you're referring to existing code in an existing file, it might be clearer. Maybe:

builtin/log.c:cmd_log() calls a second ...

Overall, I find this entire function comment mystifying.

builtin/walken.c static void init_walken_defaults(void) · line 49

Quoted 12 lines
builtin/walken.c +12 -0
+static void final_rev_info_setup(int argc, const char **argv, const char *prefix,
+               struct rev_info *rev)
+{
+       /*
+        * Optional:
+        * setup_revision_opt is used to pass options to the setup_revisions()
+        * call. It's got some special items for submodules and other types of
+        * optimizations, but for now, we'll just point it to HEAD and call it
+        * good. First we should make sure to reset it. This is useful for more
+        * complicated stuff but a decent shortcut for the first pass is
+        * add_head_to_pending().
+        */

I had to pause over "call it good" for several seconds (since I couldn't understand why someone would want to write "bad" code) until I figured out you meant "do nothing else". It would be clearer simply to drop that, ending the sentence at "HEAD":

..., but for now, we'll just point it at HEAD.

Quoted 6 lines
builtin/walken.c +6 -0
+       /*
+        * struct setup_revision_opt opt;
+
+        * memset(&opt, 0, sizeof(opt));
+        * opt.def = "HEAD";
+        * opt.revarg_opt = REVARG_COMMITTISH;

builtin/walken.c static void init_walken_defaults(void) · line 66

Quoted 10 lines
builtin/walken.c +10 -0
+        * setup_revisions(argc, argv, rev, &opt);
+        */
+
+       /* Let's force oneline format. */
+       get_commit_format("oneline", rev);
+       rev->verbose_header = 1;
+
+       /* add the HEAD to pending so we can start */
+       add_head_to_pending(rev);
+}

It would be easier for the reader to associate the add_head_to_pending() invocation with the commented-out setting of "HEAD" via 'setup_revision_opt' if the two bits abutted one another without being separated by the "oneline" gunk.

#46 lore raw

Re: [RFC PATCH v2 05/13] walken: configure rev_info and prepare for walk

Quoted 5 lines · Eric Sunshine
Quoted 1 line · Emily Shaffer

struct rev_info is what's used by the struct itself.

What "struct itself"? Do you mean 'struct rev_info' is used by the _walk_ itself? Or something?

Yep, that's the one. Thanks for the fresh eyes.

Quoted 22 lines

builtin/walken.c static void init_walken_defaults(void) · line 34

Quoted 13 lines

repo_init_revisions() initializes the struct; then we need to set it up for the walk we want to perform, which is done in final_rev_info_setup().

---

builtin/walken.c +4 -0
@@ -30,6 +31,40 @@ static void init_walken_defaults(void)
+/*
+ * cmd_log calls a second set of init after the repo_init_revisions call. We'll
+ * mirror those settings in post_repo_init_init.
+ */

What is 'post_repo_init_init'?

I found the reference to cmd_log() confusing because I was looking for it in this patch (as if it was being introduced here). Newcomers might be even more confused. Perhaps if you state explicitly that you're referring to existing code in an existing file, it might be clearer. Maybe:

Quoted 3 lines

builtin/log.c:cmd_log() calls a second ...

Overall, I find this entire function comment mystifying.

Yeah, this is very stale and never got updated when I realized cmd_log() was calling two init functions for apparently legacy reasons, and I didn't need to mirror it here. Again a case where fresh eyes caught something that became invisible after I stared at it for weeks. I really appreciate you doing the deep review, Eric.

I've replaced it:

/*
* Perform configuration for commit walk here. Within this function we set a
* starting point, and can customize our walk in various ways. */

Quoted 19 lines

builtin/walken.c static void init_walken_defaults(void) · line 49

Quoted 13 lines
builtin/walken.c +12 -0
+static void final_rev_info_setup(int argc, const char **argv, const char *prefix,
+               struct rev_info *rev)
+{
+       /*
+        * Optional:
+        * setup_revision_opt is used to pass options to the setup_revisions()
+        * call. It's got some special items for submodules and other types of
+        * optimizations, but for now, we'll just point it to HEAD and call it
+        * good. First we should make sure to reset it. This is useful for more
+        * complicated stuff but a decent shortcut for the first pass is
+        * add_head_to_pending().
+        */

I had to pause over "call it good" for several seconds (since I couldn't understand why someone would want to write "bad" code) until I figured out you meant "do nothing else". It would be clearer simply to drop that, ending the sentence at "HEAD":

Quoted 1 line

..., but for now, we'll just point it at HEAD.

Definitely. Done.

Quoted 14 lines
Quoted 14 lines
builtin/walken.c +13 -0
+       /*
+        * struct setup_revision_opt opt;
+
+        * memset(&opt, 0, sizeof(opt));
+        * opt.def = "HEAD";
+        * opt.revarg_opt = REVARG_COMMITTISH;
+        * setup_revisions(argc, argv, rev, &opt);
+        */
+
+       /* Let's force oneline format. */
+       get_commit_format("oneline", rev);
+       rev->verbose_header = 1;
+
Quoted 8 lines

builtin/walken.c static void init_walken_defaults(void) · line 66

Quoted 3 lines
builtin/walken.c +3 -0
+       /* add the HEAD to pending so we can start */
+       add_head_to_pending(rev);
+}

It would be easier for the reader to associate the add_head_to_pending() invocation with the commented-out setting of "HEAD" via 'setup_revision_opt' if the two bits abutted one another without being separated by the "oneline" gunk.

Good point, done.

#47 lore raw

RFC PATCH v2 6/13 walken: perform our basic revision walk

In reply to Emily Shaffer

Add the final steps needed and implement the walk loop itself. We add a method walken_commit_walk() which performs the final setup to revision.c and then iterates over commits from get_revision().

This basic walk only prints the subject line of each commit in the history. It is nearly equivalent to git log --oneline.

Change-Id If6dc5f3c9d14df077b99e42806cf790c96191582
---
 builtin/walken.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
builtin/walken.c +43 -0
index c463eca843..335dcb6b21 100644
@@ -6,8 +6,11 @@
 
 #include "builtin.h"
 #include "revision.h"
+#include "commit.h"
 #include "config.h"
 #include "parse-options.h"
+#include "pretty.h"
+#include "line-log.h"
 
 /*
  * All builtins are expected to provide a usage to provide a consistent user
@@ -90,6 +93,41 @@ static int git_walken_config(const char *var, const char *value, void *cb)
 	return git_default_config(var, value, cb);
 }
 
+/*
+ * walken_commit_walk() is invoked by cmd_walken() after initialization. It
+ * does the commit walk only.
+ */
+static void walken_commit_walk(struct rev_info *rev)
+{
+	struct commit *commit;
+	struct strbuf prettybuf = STRBUF_INIT;
+
+	/*
+         * prepare_revision_walk() gets the final steps ready for a revision
+	 * walk. We check the return value for errors.
+         */
+	if (prepare_revision_walk(rev)) {
+		die(_("revision walk setup failed"));
+	}
+
+	/*
+         * Now we can start the real commit walk. get_revision grabs the next
+	 * revision based on the contents of rev.
+	 */
+	rev->diffopt.close_file = 0;
+	while ((commit = get_revision(rev))) {
+		if (!commit)
+			continue;
+		strbuf_reset(&prettybuf);
+		pp_commit_easy(CMIT_FMT_ONELINE, commit, &prettybuf);
+		/*
+		 * We expect this part of the output to be machine-parseable -
+		 * one commit message per line - so we must not localize it.
+		 */
+		puts(prettybuf.buf);
+	}
+}
+
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
 	struct option options[] = {
@@ -115,12 +153,17 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 	 */
 	repo_init_revisions(the_repository, &rev, prefix);
 
+	/* We can set our traversal flags here. */
+	rev.always_show_header = 1;
+
 	/*
 	 * Before we do the walk, we need to set a starting point by giving it
 	 * something to go in `pending` - that happens in here
 	 */
 	final_rev_info_setup(argc, argv, prefix, &rev);
 
+	walken_commit_walk(&rev);
+
 	/*
 	 * This line is "human-readable" and we are writing a plumbing command,
 	 * so we localize it and use the trace library to print only when
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#48 lore raw

Re: [RFC PATCH v2 06/13] walken: perform our basic revision walk

builtin/walken.c static int git_walken_config(const char *var, const char *value, void *cb) · line 99

Quoted 11 lines · Emily Shaffer

Add the final steps needed and implement the walk loop itself. We add a method walken_commit_walk() which performs the final setup to revision.c and then iterates over commits from get_revision().

---

builtin/walken.c +4 -0
+/*
+ * walken_commit_walk() is invoked by cmd_walken() after initialization. It
+ * does the commit walk only.
+ */

"only" as opposed to what? Maybe just say:

... after initialization. It performs the actual commit walk.

builtin/walken.c static int git_walken_config(const char *var, const char *value, void *cb) · line 108

Quoted 9 lines
builtin/walken.c +9 -0
+static void walken_commit_walk(struct rev_info *rev)
+{
+       struct commit *commit;
+       struct strbuf prettybuf = STRBUF_INIT;
+
+       /*
+         * prepare_revision_walk() gets the final steps ready for a revision
+        * walk. We check the return value for errors.
+         */

You have some funky mix of spaces and tabs indenting the comment lines. Same for the next comment block.

builtin/walken.c static int git_walken_config(const char *var, const char *value, void *cb) · line 116

Quoted 8 lines
builtin/walken.c +8 -0
+       if (prepare_revision_walk(rev)) {
+               die(_("revision walk setup failed"));
+       }
+
+       /*
+         * Now we can start the real commit walk. get_revision grabs the next
+        * revision based on the contents of rev.
+        */

s/get_revision/&()/

Quoted 1 line

+ rev->diffopt.close_file = 0;

Why this? And, why isn't it set up where other 'rev' options are initialized?

builtin/walken.c static int git_walken_config(const char *var, const char *value, void *cb) · line 120

Quoted 3 lines
builtin/walken.c +3 -0
+       while ((commit = get_revision(rev))) {
+               if (!commit)
+                       continue;

If get_revision() returns NULL, then the while-loop exits, which means that the "if (!commit)" condition will never be satisfied, thus is unnecessary code.

builtin/walken.c static int git_walken_config(const char *var, const char *value, void *cb) · line 127

Quoted 7 lines
builtin/walken.c +7 -0
+               strbuf_reset(&prettybuf);
+               pp_commit_easy(CMIT_FMT_ONELINE, commit, &prettybuf);
+               /*
+                * We expect this part of the output to be machine-parseable -
+                * one commit message per line - so we must not localize it.
+                */
+               puts(prettybuf.buf);

Meh, but there isn't any literal text here to localize anyway, so the comment talking about not localizing it is just confusing.

Quoted 1 line

+ }

Leaking 'prettybuf'. Add here:

    strbuf_release(&prettybuf);
Quoted 1 line

+}

#49 lore raw

Re: [RFC PATCH v2 06/13] walken: perform our basic revision walk

Quoted 15 lines · Eric Sunshine

builtin/walken.c static int git_walken_config(const char *var, const char *value, void *cb) · line 99

Quoted 11 lines · Emily Shaffer

Add the final steps needed and implement the walk loop itself. We add a method walken_commit_walk() which performs the final setup to revision.c and then iterates over commits from get_revision().

---

builtin/walken.c +4 -0
+/*
+ * walken_commit_walk() is invoked by cmd_walken() after initialization. It
+ * does the commit walk only.
+ */

"only" as opposed to what? Maybe just say:

Quoted 1 line

... after initialization. It performs the actual commit walk.

Done.

Quoted 13 lines

builtin/walken.c static int git_walken_config(const char *var, const char *value, void *cb) · line 108

Quoted 10 lines
builtin/walken.c +9 -0
+static void walken_commit_walk(struct rev_info *rev)
+{
+       struct commit *commit;
+       struct strbuf prettybuf = STRBUF_INIT;
+
+       /*
+         * prepare_revision_walk() gets the final steps ready for a revision
+        * walk. We check the return value for errors.
+         */

You have some funky mix of spaces and tabs indenting the comment lines. Same for the next comment block.

Done.

Quoted 11 lines

builtin/walken.c static int git_walken_config(const char *var, const char *value, void *cb) · line 116

Quoted 9 lines
builtin/walken.c +8 -0
+       if (prepare_revision_walk(rev)) {
+               die(_("revision walk setup failed"));
+       }
+
+       /*
+         * Now we can start the real commit walk. get_revision grabs the next
+        * revision based on the contents of rev.
+        */

s/get_revision/&()/

Done.

Quoted 4 lines
Quoted 2 lines

+ rev->diffopt.close_file = 0;

Why this? And, why isn't it set up where other 'rev' options are initialized?

Removed. Artifact of closely mirroring log.

Quoted 8 lines

builtin/walken.c static int git_walken_config(const char *var, const char *value, void *cb) · line 120

Quoted 4 lines
builtin/walken.c +3 -0
+       while ((commit = get_revision(rev))) {
+               if (!commit)
+                       continue;

If get_revision() returns NULL, then the while-loop exits, which means that the "if (!commit)" condition will never be satisfied, thus is unnecessary code.

Yep, removed.

Quoted 11 lines

builtin/walken.c static int git_walken_config(const char *var, const char *value, void *cb) · line 127

Quoted 8 lines
builtin/walken.c +7 -0
+               strbuf_reset(&prettybuf);
+               pp_commit_easy(CMIT_FMT_ONELINE, commit, &prettybuf);
+               /*
+                * We expect this part of the output to be machine-parseable -
+                * one commit message per line - so we must not localize it.
+                */
+               puts(prettybuf.buf);

Meh, but there isn't any literal text here to localize anyway, so the comment talking about not localizing it is just confusing.

Yeah, you're right. I'll change to "so we send it to stdout", which is less obvious from puts().

Quoted 6 lines
Quoted 2 lines

+ }

Leaking 'prettybuf'. Add here:

    strbuf_release(&prettybuf);

Thanks, done.

#50 lore raw

RFC PATCH v2 7/13 walken: filter for authors from gmail address

In reply to Emily Shaffer

In order to demonstrate how to create grep filters for revision walks, filter the walk performed by cmd_walken() to print only commits which are authored by someone with a gmail address.

This commit demonstrates how to append a grep pattern to a rev_info.grep_filter, to teach new contributors how to create their own more generalized grep filters during revision walks.

---
 builtin/walken.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
builtin/walken.c +8 -8
index 335dcb6b21..da2d197914 100644
@@ -11,6 +11,7 @@
 #include "parse-options.h"
 #include "pretty.h"
 #include "line-log.h"
+#include "grep.h"
 
 /*
  * All builtins are expected to provide a usage to provide a consistent user
@@ -28,10 +29,8 @@ const char * const walken_usage[] = {
  */
 static void init_walken_defaults(void)
 {
-	/*
-	 * We don't use any other components or have settings to initialize, so
-	 * leave this empty.
-	 */
+	/* Needed by our grep filter. */
+	init_grep_defaults(the_repository);
 }
 
 /*
@@ -60,6 +59,10 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
 	 * setup_revisions(argc, argv, rev, &opt);
 	 */
 
+	/* Add a grep pattern to the author line in the header. */
+	append_header_grep_pattern(&rev->grep_filter, GREP_HEADER_AUTHOR, "gmail");
+	compile_grep_patterns(&rev->grep_filter);
+
 	/* Let's force oneline format. */
 	get_commit_format("oneline", rev);
 	rev->verbose_header = 1;
@@ -86,10 +89,7 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
  */
 static int git_walken_config(const char *var, const char *value, void *cb)
 {
-	/*
-	 * For now, we don't have any custom configuration, so fall back on the
-	 * default config.
-	 */
+	grep_config(var, value, cb);
 	return git_default_config(var, value, cb);
 }
 
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#51 lore raw

Re: [RFC PATCH v2 07/13] walken: filter for authors from gmail address

builtin/walken.c static void final_rev_info_setup(int argc, const char **argv, const char *prefix · line 59

Quoted 9 lines · Emily Shaffer

In order to demonstrate how to create grep filters for revision walks, filter the walk performed by cmd_walken() to print only commits which are authored by someone with a gmail address.

---

builtin/walken.c +1 -0
@@ -60,6 +59,10 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
+       /* Add a grep pattern to the author line in the header. */

This sounds as if we are adding something to the author line, which is confusing. Maybe say instead:

    /* Apply a 'grep' pattern to the author header. */
Quoted 2 lines
builtin/walken.c +2 -0
+       append_header_grep_pattern(&rev->grep_filter, GREP_HEADER_AUTHOR, "gmail");
+       compile_grep_patterns(&rev->grep_filter);
#52 lore raw

Re: [RFC PATCH v2 07/13] walken: filter for authors from gmail address

Quoted 14 lines · Eric Sunshine

builtin/walken.c static void final_rev_info_setup(int argc, const char **argv, const char *prefix · line 59

Quoted 9 lines · Emily Shaffer

In order to demonstrate how to create grep filters for revision walks, filter the walk performed by cmd_walken() to print only commits which are authored by someone with a gmail address.

---

builtin/walken.c +1 -0
@@ -60,6 +59,10 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
+       /* Add a grep pattern to the author line in the header. */

This sounds as if we are adding something to the author line, which is confusing. Maybe say instead:

Quoted 2 lines
    /* Apply a 'grep' pattern to the author header. */

I also s/author/'&'/; thanks.

Quoted 2 lines
Quoted 2 lines
builtin/walken.c +2 -0
+       append_header_grep_pattern(&rev->grep_filter, GREP_HEADER_AUTHOR, "gmail");
+       compile_grep_patterns(&rev->grep_filter);
#53 lore raw

RFC PATCH v2 8/13 walken: demonstrate various topographical sorts

In reply to Emily Shaffer

Order the revision walk by author or commit dates, to demonstrate how to apply topo_sort to a revision walk.

While following the tutorial, new contributors are guided to run a walk with each sort and compare the results.

Change-Id I7ce2f3e8a77c42001293637ae209087afec4ce2c
---
 builtin/walken.c | 7 +++++++
 1 file changed, 7 insertions(+)
builtin/walken.c +7 -0
index da2d197914..6cc451324a 100644
@@ -69,6 +69,13 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
 
 	/* add the HEAD to pending so we can start */
 	add_head_to_pending(rev);
+	
+	/* Let's play with the sort order. */
+	rev->topo_order = 1;
+
+	/* Toggle between these and observe the difference. */
+	rev->sort_order = REV_SORT_BY_COMMIT_DATE;
+	/* rev->sort_order = REV_SORT_BY_AUTHOR_DATE; */
 }
 
 /*
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#54 lore raw

Re: [RFC PATCH v2 08/13] walken: demonstrate various topographical sorts

Quoted 1 line · Emily Shaffer

Order the revision walk by author or commit dates, to demonstrate how to

s/,//

Quoted 6 lines

apply topo_sort to a revision walk.

While following the tutorial, new contributors are guided to run a walk with each sort and compare the results.

#55 lore raw

Re: [RFC PATCH v2 08/13] walken: demonstrate various topographical sorts

Quoted 4 lines · Eric Sunshine
Quoted 1 line · Emily Shaffer

Order the revision walk by author or commit dates, to demonstrate how to

s/,//

Done.

#56 lore raw

RFC PATCH v2 9/13 walken: demonstrate reversing a revision walk list

In reply to Emily Shaffer

The final installment in the tutorial about sorting revision walk outputs. This commit reverses the commit list, so that we see newer commits last (handy since we aren't using a pager).

It's important to note that rev->reverse needs to be set after add_head_to_pending() or before setup_revisions(). (This is mentioned in the accompanying tutorial.)

---
 builtin/walken.c | 3 +++
 1 file changed, 3 insertions(+)
builtin/walken.c +3 -0
index 6cc451324a..958923c172 100644
@@ -69,6 +69,9 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
 
 	/* add the HEAD to pending so we can start */
 	add_head_to_pending(rev);
+
+	/* Reverse the order */
+	rev->reverse = 1;
 	
 	/* Let's play with the sort order. */
 	rev->topo_order = 1;
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#57 lore raw

Re: [RFC PATCH v2 09/13] walken: demonstrate reversing a revision walk list

Quoted 7 lines · Emily Shaffer

The final installment in the tutorial about sorting revision walk outputs. This commit reverses the commit list, so that we see newer commits last (handy since we aren't using a pager).

It's important to note that rev->reverse needs to be set after add_head_to_pending() or before setup_revisions(). (This is mentioned in the accompanying tutorial.)

This leaves the reader wondering "why that requirement?". Is it because those functions may change the value or otherwise depend upon the value?

Also, something this important probably deserves an in-code comment (and need not be mentioned in the commit message if the in-code comment explains it well.)

Quoted 9 lines

---

builtin/walken.c +3 -0
@@ -69,6 +69,9 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
        /* add the HEAD to pending so we can start */
        add_head_to_pending(rev);
+
+       /* Reverse the order */
+       rev->reverse = 1;
#58 lore raw

Re: [RFC PATCH v2 09/13] walken: demonstrate reversing a revision walk list

Quoted 9 lines · Eric Sunshine
Quoted 7 lines · Emily Shaffer

The final installment in the tutorial about sorting revision walk outputs. This commit reverses the commit list, so that we see newer commits last (handy since we aren't using a pager).

It's important to note that rev->reverse needs to be set after add_head_to_pending() or before setup_revisions(). (This is mentioned in the accompanying tutorial.)

Quoted 7 lines

This leaves the reader wondering "why that requirement?". Is it because those functions may change the value or otherwise depend upon the value?

Also, something this important probably deserves an in-code comment (and need not be mentioned in the commit message if the in-code comment explains it well.)

This I will remove. I removed from the tutorial as it turned out I was incorrect. Thanks.

Quoted 10 lines
Quoted 10 lines

---

builtin/walken.c +3 -0
@@ -69,6 +69,9 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
        /* add the HEAD to pending so we can start */
        add_head_to_pending(rev);
+
+       /* Reverse the order */
+       rev->reverse = 1;
#59 lore raw

RFC PATCH v2 10/13 walken: add unfiltered object walk from HEAD

In reply to Emily Shaffer

Provide a demonstration of a revision walk which traverses all types of object, not just commits. This type of revision walk is used for operations such as creating packfiles and performing fetches or clones, so it's useful to teach new developers how it works. For starters, only demonstrate the unfiltered version, as this will make the tutorial easier to follow.

This commit is part of a tutorial on revision walking.

Change-Id If3b11652ba011b28d29b1c3984dac4a3f80a5f53
---
 builtin/walken.c | 88 +++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 79 insertions(+), 9 deletions(-)
builtin/walken.c +79 -9
index 958923c172..42b23ba1ec 100644
@@ -11,6 +11,7 @@
 #include "parse-options.h"
 #include "pretty.h"
 #include "line-log.h"
+#include "list-objects.h"
 #include "grep.h"
 
 /*
@@ -22,6 +23,11 @@ const char * const walken_usage[] = {
 	NULL,
 };
 
+static int commit_count;
+static int tag_count;
+static int blob_count;
+static int tree_count;
+
 /*
  * Within init_walken_defaults() we can call into other useful defaults to set
  * in the global scope or on the_repository. It's okay to borrow from other
@@ -103,6 +109,65 @@ static int git_walken_config(const char *var, const char *value, void *cb)
 	return git_default_config(var, value, cb);
 }
 
+static void walken_show_commit(struct commit *cmt, void *buf)
+{
+	commit_count++;
+}
+
+static void walken_show_object(struct object *obj, const char *str, void *buf)
+{
+	switch (obj->type) {
+	case OBJ_TREE:
+		tree_count++;
+		break;
+	case OBJ_BLOB:
+		blob_count++;
+		break;
+	case OBJ_TAG:
+		tag_count++;
+		break;
+	case OBJ_COMMIT:
+		die(_("unexpectedly encountered a commit in "
+		      "walken_show_object\n"));
+		commit_count++;
+		break;
+	default:
+		die(_("unexpected object type %s\n"), type_name(obj->type));
+		break;
+	}
+}
+
+/*
+ * walken_object_walk() is invoked by cmd_walken() after initialization. It does
+ * a walk of all object types.
+ */
+static void walken_object_walk(struct rev_info *rev)
+{
+	rev->tree_objects = 1;
+	rev->blob_objects = 1;
+	rev->tag_objects = 1;
+	rev->tree_blobs_in_commit_order = 1;
+	rev->exclude_promisor_objects = 1;
+
+	if (prepare_revision_walk(rev))
+		die(_("revision walk setup failed"));
+
+	commit_count = 0;
+	tag_count = 0;
+	blob_count = 0;
+	tree_count = 0;
+
+	traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL);
+
+	/*
+	 * This print statement is designed to be script-parseable. Script
+	 * authors will rely on the output not to change, so we will not
+	 * localize this string. It will go to stdout directly.
+	 */
+	printf("commits %d\n blobs %d\n tags %d\n trees %d\n", commit_count,
+	       blob_count, tag_count, tree_count);
+}
+
 /*
  * walken_commit_walk() is invoked by cmd_walken() after initialization. It
  * does the commit walk only.
@@ -113,15 +178,15 @@ static void walken_commit_walk(struct rev_info *rev)
 	struct strbuf prettybuf = STRBUF_INIT;
 
 	/*
-         * prepare_revision_walk() gets the final steps ready for a revision
+	 * prepare_revision_walk() gets the final steps ready for a revision
 	 * walk. We check the return value for errors.
-         */
+	 */
 	if (prepare_revision_walk(rev)) {
 		die(_("revision walk setup failed"));
 	}
 
 	/*
-         * Now we can start the real commit walk. get_revision grabs the next
+	 * Now we can start the real commit walk. get_revision grabs the next
 	 * revision based on the contents of rev.
 	 */
 	rev->diffopt.close_file = 0;
@@ -166,13 +231,18 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 	/* We can set our traversal flags here. */
 	rev.always_show_header = 1;
 
-	/*
-	 * Before we do the walk, we need to set a starting point by giving it
-	 * something to go in `pending` - that happens in here
-	 */
-	final_rev_info_setup(argc, argv, prefix, &rev);
 
-	walken_commit_walk(&rev);
+	if (1) {
+		add_head_to_pending(&rev);
+		walken_object_walk(&rev);
+	} else {
+		/*
+		 * Before we do the walk, we need to set a starting point by giving it
+		 * something to go in `pending` - that happens in here
+		 */
+		final_rev_info_setup(argc, argv, prefix, &rev);
+		walken_commit_walk(&rev);
+	}
 
 	/*
 	 * This line is "human-readable" and we are writing a plumbing command,
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#60 lore raw

Re: [RFC PATCH v2 10/13] walken: add unfiltered object walk from HEAD

Quoted 17 lines · Emily Shaffer

Provide a demonstration of a revision walk which traverses all types of object, not just commits. This type of revision walk is used for operations such as creating packfiles and performing fetches or clones, so it's useful to teach new developers how it works. For starters, only demonstrate the unfiltered version, as this will make the tutorial easier to follow.

---

builtin/walken.c +6 -0
@@ -103,6 +109,65 @@ static int git_walken_config(const char *var, const char *value, void *cb)
+static void walken_show_commit(struct commit *cmt, void *buf)
+{
+       commit_count++;
+}
+
+static void walken_show_object(struct object *obj, const char *str, void *buf)

builtin/walken.c static int git_walken_config(const char *var, const char *value, void *cb) · line 124

Quoted 10 lines
builtin/walken.c +10 -0
+{
+       switch (obj->type) {
+       [...]
+       case OBJ_TAG:
+               tag_count++;
+               break;
+       case OBJ_COMMIT:
+               die(_("unexpectedly encountered a commit in "
+                     "walken_show_object\n"));
+               commit_count++;

The "commit_count++" line is not only dead code, but it also confuses the reader (or makes the reader think that the author of this code doesn't understand C programming). You should drop this line.

builtin/walken.c static int git_walken_config(const char *var, const char *value, void *cb) · line 136

Quoted 4 lines
builtin/walken.c +4 -0
+               break;
+       default:
+               die(_("unexpected object type %s\n"), type_name(obj->type));
+               break;

Likewise, this "break" (and the one in the OBJ_COMMIT case) are dead code which should be dropped to avoid confusing the reader.

Don't localize the die() message via _() here or in the preceding OBJ_COMMIT case.

The two die() messages are unnecessarily dissimilar. Try to unify them so that they read in the same way.

builtin/walken.c static void walken_commit_walk(struct rev_info *rev) · line 191

Quoted 13 lines
builtin/walken.c +5 -3
+       }
+}> @@ -113,15 +178,15 @@ static void walken_commit_walk(struct rev_info *rev)
        /*
-         * prepare_revision_walk() gets the final steps ready for a revision
+        * prepare_revision_walk() gets the final steps ready for a revision
         * walk. We check the return value for errors.
-         */
+        */
        /*
-         * Now we can start the real commit walk. get_revision grabs the next
+        * Now we can start the real commit walk. get_revision grabs the next
         * revision based on the contents of rev.
         */

I think these are just correcting whitespace/indentation errors I pointed out in an earlier patch (so they are unnecessary noise in this patch).

#61 lore raw

Re: [RFC PATCH v2 10/13] walken: add unfiltered object walk from HEAD

Quoted 24 lines · Eric Sunshine
Quoted 23 lines · Emily Shaffer

Provide a demonstration of a revision walk which traverses all types of object, not just commits. This type of revision walk is used for operations such as creating packfiles and performing fetches or clones, so it's useful to teach new developers how it works. For starters, only demonstrate the unfiltered version, as this will make the tutorial easier to follow.

---

builtin/walken.c +12 -0
@@ -103,6 +109,65 @@ static int git_walken_config(const char *var, const char *value, void *cb)
+static void walken_show_commit(struct commit *cmt, void *buf)
+{
+       commit_count++;
+}
+
+static void walken_show_object(struct object *obj, const char *str, void *buf)
+{
+       switch (obj->type) {
+       [...]
+       case OBJ_TAG:
+               tag_count++;
+               break;
Quoted 8 lines

builtin/walken.c static int git_walken_config(const char *var, const char *value, void *cb) · line 132

Quoted 4 lines
builtin/walken.c +4 -0
+       case OBJ_COMMIT:
+               die(_("unexpectedly encountered a commit in "
+                     "walken_show_object\n"));
+               commit_count++;

The "commit_count++" line is not only dead code, but it also confuses the reader (or makes the reader think that the author of this code doesn't understand C programming). You should drop this line.

Ow, yes. Removed. This is stale (pre-die()).

Quoted 8 lines

builtin/walken.c static int git_walken_config(const char *var, const char *value, void *cb) · line 136

Quoted 5 lines
builtin/walken.c +4 -0
+               break;
+       default:
+               die(_("unexpected object type %s\n"), type_name(obj->type));
+               break;

Likewise, this "break" (and the one in the OBJ_COMMIT case) are dead code which should be dropped to avoid confusing the reader.

Done.

Quoted 3 lines

Don't localize the die() message via _() here or in the preceding OBJ_COMMIT case.

I'm a little surprised by that. Is it because die() is expected to only be seen by the developer? It seems like a poor user experience if someone in non-English locale encounters a bug that Git team didn't find, and needed to try to translate the English die() string and figure out if a workaround is possible.

Quoted 3 lines

The two die() messages are unnecessarily dissimilar. Try to unify them so that they read in the same way.

I'm a little surprised by this too; it seems to me the root cause of each would be different. In the former case, I'd guess that traverse_commit_list()'s behavior changed, and in the latter case I'd guess that a new object type was recently added to the model. Can you help me understand the motivation for making the messages similar?

(I don't think, though, that I did a good job of indicating either root cause in the die() messages as they are now.)

Quoted 15 lines
Quoted 4 lines
builtin/walken.c +2 -0
+       }
+}> @@ -113,15 +178,15 @@ static void walken_commit_walk(struct rev_info *rev)
        /*

builtin/walken.c static void walken_commit_walk(struct rev_info *rev) · line 191

Quoted 10 lines
builtin/walken.c +3 -3
-         * prepare_revision_walk() gets the final steps ready for a revision
+        * prepare_revision_walk() gets the final steps ready for a revision
         * walk. We check the return value for errors.
-         */
+        */
        /*
-         * Now we can start the real commit walk. get_revision grabs the next
+        * Now we can start the real commit walk. get_revision grabs the next
         * revision based on the contents of rev.
         */
Quoted 3 lines

I think these are just correcting whitespace/indentation errors I pointed out in an earlier patch (so they are unnecessary noise in this patch).

ACK

#62 lore raw

Re: [RFC PATCH v2 10/13] walken: add unfiltered object walk from HEAD

Quoted 6 lines · Emily Shaffer
Quoted 2 lines · Eric Sunshine

Don't localize the die() message via _() here or in the preceding OBJ_COMMIT case.

I'm a little surprised by that. Is it because die() is expected to only be seen by the developer?

Sorry, I was reading those as BUG(), not die(), and we don't localize BUG() text. But, why aren't those BUG()? Can those cases arise in practice? (Genuine question; I haven't familiarized myself with that code yet.)

If they legitimately should be die(), then ignore my comment about not localizing them.

Quoted 8 lines
Quoted 2 lines

The two die() messages are unnecessarily dissimilar. Try to unify them so that they read in the same way.

I'm a little surprised by this too; it seems to me the root cause of each would be different. In the former case, I'd guess that traverse_commit_list()'s behavior changed, and in the latter case I'd guess that a new object type was recently added to the model. Can you help me understand the motivation for making the messages similar?

Both causes you describe here sound like BUG() cases, not die(). If I'm understanding correctly, they could only trigger if someone made some breaking or behavior changing modifications within Git and failed to update all the code in the project impacted by the change. In other words, these can't be triggered by user input, hence they would be BUG()s indicating that a Git developer needs to fix the code.

As for the messages themselves, I was referring to the grammatical dissimilarity of "unexpectedly" and "unexpected", and I also don't understand why one messages mentions walken_show_object() explicitly, whereas the other does not.

#63 lore raw

Re: [RFC PATCH v2 10/13] walken: add unfiltered object walk from HEAD

Quoted 8 lines · Eric Sunshine
Quoted 6 lines · Emily Shaffer
Quoted 2 lines · Eric Sunshine

Don't localize the die() message via _() here or in the preceding OBJ_COMMIT case.

I'm a little surprised by that. Is it because die() is expected to only be seen by the developer?

Quoted 7 lines

Sorry, I was reading those as BUG(), not die(), and we don't localize BUG() text. But, why aren't those BUG()? Can those cases arise in practice? (Genuine question; I haven't familiarized myself with that code yet.)

If they legitimately should be die(), then ignore my comment about not localizing them.

Hmmm. Yeah, I'll switch them to BUG() - I think there are other instances of die() in the example and it'd be good to describe yet another way of reporting behavior.

Quoted 17 lines
Quoted 9 lines
Quoted 3 lines

The two die() messages are unnecessarily dissimilar. Try to unify them so that they read in the same way.

I'm a little surprised by this too; it seems to me the root cause of each would be different. In the former case, I'd guess that traverse_commit_list()'s behavior changed, and in the latter case I'd guess that a new object type was recently added to the model. Can you help me understand the motivation for making the messages similar?

Both causes you describe here sound like BUG() cases, not die(). If I'm understanding correctly, they could only trigger if someone made some breaking or behavior changing modifications within Git and failed to update all the code in the project impacted by the change. In other words, these can't be triggered by user input, hence they would be BUG()s indicating that a Git developer needs to fix the code.

Quoted 4 lines

As for the messages themselves, I was referring to the grammatical dissimilarity of "unexpectedly" and "unexpected", and I also don't understand why one messages mentions walken_show_object() explicitly, whereas the other does not.

I see - ok, I have reworded.

Thanks!
- Emily

#64 lore raw

RFC PATCH v2 11/13 walken: add filtered object walk

In reply to Emily Shaffer

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.

Change-Id I6d22ba153c1afbc780c261c47f1fa03ea478b5ed
---
 builtin/walken.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
builtin/walken.c +23 -1
index 42b23ba1ec..a744d042d8 100644
@@ -12,6 +12,7 @@
 #include "pretty.h"
 #include "line-log.h"
 #include "list-objects.h"
+#include "list-objects-filter-options.h"
 #include "grep.h"
 
 /*
@@ -143,6 +144,10 @@ static void walken_show_object(struct object *obj, const char *str, void *buf)
  */
 static void walken_object_walk(struct rev_info *rev)
 {
+	struct list_objects_filter_options filter_options = {};
+
+	printf("walken_object_walk beginning...\n");
+
 	rev->tree_objects = 1;
 	rev->blob_objects = 1;
 	rev->tag_objects = 1;
@@ -157,7 +162,24 @@ static void 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: */
+		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"));
+		/*
+		 * We can parse a tree depth of 1 to demonstrate the kind of
+		 * filtering that could occur during various operations (see
+		 * `git help rev-list` and read the entry on `--filter`).
+		 */
+		parse_list_objects_filter(&filter_options, "tree:1");
+
+		traverse_commit_list_filtered(&filter_options, rev,
+			walken_show_commit, walken_show_object, NULL, NULL);
+	}
 
 	/*
 	 * This print statement is designed to be script-parseable. Script
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#65 lore raw

Re: [RFC PATCH v2 11/13] walken: add filtered object walk

Quoted 10 lines · Emily Shaffer

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.

---

builtin/walken.c static void walken_show_object(struct object *obj, const char *str, void *buf) · line 148

Quoted 5 lines
builtin/walken.c +3 -0
@@ -143,6 +144,10 @@ static void walken_show_object(struct object *obj, const char *str, void *buf)
 static void walken_object_walk(struct rev_info *rev)
 {
+       struct list_objects_filter_options filter_options = {};
+
+       printf("walken_object_walk beginning...\n");

Is this debugging code which you accidentally left in? Or is it meant to use trace_printf()? Or something else? If it is a genuine message, should it be localizable?

builtin/walken.c static void walken_object_walk(struct rev_info *rev) · line 166

Quoted 7 lines
builtin/walken.c +2 -1
@@ -157,7 +162,24 @@ static void 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: */

The subject talks about adding a _filtered_ object walk (which is in the 'else' arm), so should this be "if (0)" instead?

Quoted 16 lines
builtin/walken.c +16 -0
+               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"));
+               /*
+                * We can parse a tree depth of 1 to demonstrate the kind of
+                * filtering that could occur during various operations (see
+                * `git help rev-list` and read the entry on `--filter`).
+                */
+               parse_list_objects_filter(&filter_options, "tree:1");
+
+               traverse_commit_list_filtered(&filter_options, rev,
+                       walken_show_commit, walken_show_object, NULL, NULL);
+       }
#66 lore raw

Re: [RFC PATCH v2 11/13] walken: add filtered object walk

Quoted 7 lines · Eric Sunshine
Quoted 6 lines · Emily Shaffer

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.

Quoted 13 lines

builtin/walken.c static void walken_show_object(struct object *obj, const char *str, void *buf) · line 148

Quoted 9 lines

---

builtin/walken.c +3 -0
@@ -143,6 +144,10 @@ static void walken_show_object(struct object *obj, const char *str, void *buf)
 static void walken_object_walk(struct rev_info *rev)
 {
+       struct list_objects_filter_options filter_options = {};
+
+       printf("walken_object_walk beginning...\n");

Is this debugging code which you accidentally left in? Or is it meant to use trace_printf()? Or something else? If it is a genuine message, should it be localizable?

The former. Removed.

Quoted 11 lines

builtin/walken.c static void walken_object_walk(struct rev_info *rev) · line 166

Quoted 8 lines
builtin/walken.c +2 -1
@@ -157,7 +162,24 @@ static void 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: */

The subject talks about adding a _filtered_ object walk (which is in the 'else' arm), so should this be "if (0)" instead?

Done.

#67 lore raw

RFC PATCH v2 12/13 walken: count omitted objects

In reply to Emily Shaffer

It may be illuminating to see which objects were not included within a given filter. This also demonstrates, since filter-spec "tree:1" is used, that the 'omitted' list contains all objects which are omitted, not just the first objects which were omitted - that is, it continues to dereference omitted trees and commits.

This is part of a tutorial on performing revision walks.

---
 builtin/walken.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
builtin/walken.c +14 -3
index a744d042d8..dc59ff5009 100644
@@ -45,7 +45,7 @@ static void init_walken_defaults(void)
  * mirror those settings in post_repo_init_init.
  */
 static void final_rev_info_setup(int argc, const char **argv, const char *prefix,
-		struct rev_info *rev)
+				 struct rev_info *rev)
 {
 	/*
 	 * Optional:
@@ -145,6 +145,11 @@ static void walken_show_object(struct object *obj, const char *str, void *buf)
 static void walken_object_walk(struct rev_info *rev)
 {
 	struct list_objects_filter_options filter_options = {};
+	struct oidset omitted;
+	struct oidset_iter oit;
+	struct object_id *oid = NULL;
+	int omitted_count = 0;
+	oidset_init(&omitted, 0);
 
 	printf("walken_object_walk beginning...\n");
 
@@ -181,13 +186,19 @@ static void walken_object_walk(struct rev_info *rev)
 			walken_show_commit, walken_show_object, NULL, NULL);
 	}
 
+	/* Count the omitted objects. */
+	oidset_iter_init(&omitted, &oit);
+
+	while ((oid = oidset_iter_next(&oit)))
+		omitted_count++;
+
 	/*
 	 * This print statement is designed to be script-parseable. Script
 	 * authors will rely on the output not to change, so we will not
 	 * localize this string. It will go to stdout directly.
 	 */
-	printf("commits %d\n blobs %d\n tags %d\n trees %d\n", commit_count,
-	       blob_count, tag_count, tree_count);
+	printf("commits %d\n blobs %d\n tags %d\n trees %d omitted %d\n",
+	       commit_count, blob_count, tag_count, tree_count, omitted_count);
 }
 
 /*
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#68 lore raw

Re: [RFC PATCH v2 12/13] walken: count omitted objects

builtin/walken.c static void init_walken_defaults(void) · line 46

Quoted 13 lines · Emily Shaffer

It may be illuminating to see which objects were not included within a given filter. This also demonstrates, since filter-spec "tree:1" is used, that the 'omitted' list contains all objects which are omitted, not just the first objects which were omitted - that is, it continues to dereference omitted trees and commits.

---

builtin/walken.c +1 -1
@@ -45,7 +45,7 @@ static void init_walken_defaults(void)
 static void final_rev_info_setup(int argc, const char **argv, const char *prefix,
-               struct rev_info *rev)
+                                struct rev_info *rev)

Use the correct indentation in the patch which introduces this code rather than adjusting it in this patch.

#69 lore raw

RFC PATCH v2 13/13 walken: reverse the object walk order

In reply to Emily Shaffer

Demonstrate that just like commit walks, object walks can have their order reversed. Additionally, add verbose logging of objects encountered in order to let contributors prove to themselves that the walk has actually been reversed. With this commit, git walken becomes extremely chatty - it's recommended to pipe the output through head or tail or to redirect it into a file.

Change-Id I91883b209a61ae4d87855878291e487fe36220c4
---
 builtin/walken.c | 3 +++
 1 file changed, 3 insertions(+)
builtin/walken.c +3 -0
index dc59ff5009..37b02887a5 100644
@@ -112,11 +112,13 @@ static int git_walken_config(const char *var, const char *value, void *cb)
 
 static void walken_show_commit(struct commit *cmt, void *buf)
 {
+	printf("commit: %s\n", oid_to_hex(&cmt->object.oid));
 	commit_count++;
 }
 
 static void walken_show_object(struct object *obj, const char *str, void *buf)
 {
+	printf("%s: %s\n", type_name(obj->type), oid_to_hex(&obj->oid));
 	switch (obj->type) {
 	case OBJ_TREE:
 		tree_count++;
@@ -158,6 +160,7 @@ static void walken_object_walk(struct rev_info *rev)
 	rev->tag_objects = 1;
 	rev->tree_blobs_in_commit_order = 1;
 	rev->exclude_promisor_objects = 1;
+	rev->reverse = 1;
 
 	if (prepare_revision_walk(rev))
 		die(_("revision walk setup failed"));
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#70 lore raw

Re: [RFC PATCH v2 00/13] example implementation of revwalk tutorial

In reply to Emily Shaffer
Quoted 11 lines · Emily Shaffer

Since r1, made some significant changes.

- Added a commit for counting the 'omitted' list, to match the new section added to the tutorial.
- Added significant comments to allow the sample to better stand on its own.
- Fixed style issues (die() formatting, etc)
- Distinguished between human- and machine-readable output with trace_printf() and printf(), to turn the command into plumbing.
- More changes as mentioned in the tutorial patch.

Quoted 2 lines

Thanks.
- Emily

I have a v3 ready with changes based on Eric's suggestions. However, since they're almost all verbatim changes, I'm going to hold off on sending it for a couple days to see if anybody else wants to peek though. I'll likely be sending v3 on Monday.

- Emily

#71 lore raw

PATCH v3 1/1 documentation: add tutorial for revision walking

In reply to Emily Shaffer

Existing documentation on revision walks seems to be primarily intended as a reference for those already familiar with the procedure. This tutorial attempts to give an entry-level guide to a couple of bare-bones revision walks so that new Git contributors can learn the concepts without having to wade through options parsing or special casing.

The target audience is a Git contributor who is just getting started with the concept of revision walking. The goal is to prepare this contributor to be able to understand and modify existing commands which perform revision walks more easily, although it will also prepare contributors to create new commands which perform walks.

The tutorial covers a basic overview of the structs involved during revision walk, setting up a basic commit walk, setting up a basic all-object walk, and adding some configuration changes to both walk types. It intentionally does not cover how to create new commands or search for options from the command line or gitconfigs.

There is an associated patchset at
https://github.com/nasamuffin/git/tree/revwalk that contains a reference implementation of the code generated by this tutorial.

---
Since v2, responded to Eric's substantiative review of the sample codebase. In most cases that review pointed to comments in the sample code, but in a couple cases the code itself changed, and that's reflected here.

- Move usage and options struct to local scope of cmd_walken().
- Use BUG() to complain when an unexpected object is found in show_object() during object walk.
- Fix a hardcoded switch between commit and object walks pointing the wrong way for its place in the tutorial.
- Fix a memory leak during commit walk.

 Documentation/Makefile           |   1 +
 Documentation/MyFirstRevWalk.txt | 908 +++++++++++++++++++++++++++++++
 2 files changed, 909 insertions(+)
 create mode 100644 Documentation/MyFirstRevWalk.txt
Documentation/Makefile +1 -0
index 76f2ecfc1b..91e5da67c4 100644
@@ -78,6 +78,7 @@ SP_ARTICLES += $(API_DOCS)
 
 TECH_DOCS += MyFirstContribution
 TECH_DOCS += SubmittingPatches
+TECH_DOCS += MyFirstRevWalk
 TECH_DOCS += technical/hash-function-transition
 TECH_DOCS += technical/http-protocol
 TECH_DOCS += technical/index-format
Documentation/MyFirstRevWalk.txt new file +908 -0

908 lines not on this page · raw message

Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#72 lore raw

v3 cover example implementation of revwalk tutorial

Since v2, mostly reworded comments, plus fixed the issues mentioned in the tutorial itself. Thanks Eric for the review.

Emily Shaffer (13):
walken: add infrastructure for revwalk demo
walken: add usage to enable -h
walken: add placeholder to initialize defaults
walken: add handler to git_config
walken: configure rev_info and prepare for walk
walken: perform our basic revision walk
walken: filter for authors from gmail address
walken: demonstrate various topographical sorts
walken: demonstrate reversing a revision walk list
walken: add unfiltered object walk from HEAD
walken: add filtered object walk
walken: count omitted objects
walken: reverse the object walk order

 Makefile         |   1 +
 builtin.h        |   1 +
 builtin/walken.c | 297 +++++++++++++++++++++++++++++++++++++++++++++++
 git.c            |   1 +
 4 files changed, 300 insertions(+)
 create mode 100644 builtin/walken.c
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#73 lore raw

RFC PATCH v3 1/13 walken: add infrastructure for revwalk demo

Begin to add scaffolding for git walken, a toy command which we will teach to perform a number of revision walks, in order to demonstrate the mechanics of revision walking for developers new to the Git project.

This commit is the beginning of an educational series which correspond to the tutorial in Documentation/MyFirstRevWalk.txt.

Change-Id I64297621919412f54701e111366e99c4ef0feae3
---
 Makefile         |  1 +
 builtin.h        |  1 +
 builtin/walken.c | 18 ++++++++++++++++++
 3 files changed, 20 insertions(+)
 create mode 100644 builtin/walken.c
Makefile +1 -0
index f58bf14c7b..5bac1dbf8d 100644
@@ -1137,6 +1137,7 @@ BUILTIN_OBJS += builtin/var.o
 BUILTIN_OBJS += builtin/verify-commit.o
 BUILTIN_OBJS += builtin/verify-pack.o
 BUILTIN_OBJS += builtin/verify-tag.o
+BUILTIN_OBJS += builtin/walken.o
 BUILTIN_OBJS += builtin/worktree.o
 BUILTIN_OBJS += builtin/write-tree.o
 
builtin.h +1 -0
index ec7e0954c4..c919736c36 100644
@@ -242,6 +242,7 @@ int cmd_var(int argc, const char **argv, const char *prefix);
 int cmd_verify_commit(int argc, const char **argv, const char *prefix);
 int cmd_verify_tag(int argc, const char **argv, const char *prefix);
 int cmd_version(int argc, const char **argv, const char *prefix);
+int cmd_walken(int argc, const char **argv, const char *prefix);
 int cmd_whatchanged(int argc, const char **argv, const char *prefix);
 int cmd_worktree(int argc, const char **argv, const char *prefix);
 int cmd_write_tree(int argc, const char **argv, const char *prefix);
builtin/walken.c new file +18 -0
new file mode 100644
index 0000000000..db3ca50b04
@@ -0,0 +1,18 @@
+/*
+ * "git walken"
+ *
+ * Part of the "My First Revision Walk" tutorial.
+ */
+
+#include "builtin.h"
+
+int cmd_walken(int argc, const char **argv, const char *prefix)
+{
+	/*
+	 * This line is "human-readable" and we are writing a plumbing command,
+	 * so we localize it and use the trace library to print only when
+	 * the GIT_TRACE environment variable is set.
+	 */
+	trace_printf(_("cmd_walken incoming...\n"));
+	return 0;
+}
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#74 lore raw

RFC PATCH v3 2/13 walken: add usage to enable -h

In reply to Emily Shaffer

It's expected that Git commands support '-h' in order to provide a consistent user experience (and this expectation is enforced by the test suite). '-h' is captured by parse_options() by default; in order to support this flag, we add a short usage text to walken.c and invoke parse_options().

With this change, we can now add cmd_walken to the builtins set and expect tests to pass, so we'll do so - cmd_walken is now open for business.

Change-Id I2919dc1efadb82acb335617ea24371c84b03bbce
---
 builtin/walken.c | 21 +++++++++++++++++++++
 git.c            |  1 +
 2 files changed, 22 insertions(+)
builtin/walken.c +21 -0
index db3ca50b04..dd55f3b350 100644
@@ -5,9 +5,30 @@
  */
 
 #include "builtin.h"
+#include "parse-options.h"
+
 
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
+	/*
+	 * All builtins are expected to provide a usage to provide a consistent user
+	 * experience.
+	 */
+	const char * const walken_usage[] = {
+		N_("git walken"),
+		NULL,
+	};
+
+	struct option options[] = {
+		OPT_END()
+	};
+
+	/*
+	 * parse_options() handles showing usage if incorrect options are
+	 * provided, or if '-h' is passed.
+	 */
+	argc = parse_options(argc, argv, prefix, options, walken_usage, 0);
+
 	/*
 	 * This line is "human-readable" and we are writing a plumbing command,
 	 * so we localize it and use the trace library to print only when
git.c +1 -0
index c2eec470c9..2a7fb9714f 100644
@@ -601,6 +601,7 @@ static struct cmd_struct commands[] = {
 	{ "verify-pack", cmd_verify_pack },
 	{ "verify-tag", cmd_verify_tag, RUN_SETUP },
 	{ "version", cmd_version },
+	{ "walken", cmd_walken, RUN_SETUP },
 	{ "whatchanged", cmd_whatchanged, RUN_SETUP },
 	{ "worktree", cmd_worktree, RUN_SETUP | NO_PARSEOPT },
 	{ "write-tree", cmd_write_tree, RUN_SETUP },
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#75 lore raw

RFC PATCH v3 3/13 walken: add placeholder to initialize defaults

In reply to Emily Shaffer

Eventually, we will want a good place to initialize default variables for use during our revision walk(s) in git walken. For now, there's nothing to do here, but let's add the scaffolding so that it's easy to tell where to put the setup later on.

---
 builtin/walken.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
builtin/walken.c +15 -0
index dd55f3b350..19657b5e31 100644
@@ -8,6 +8,19 @@
 #include "parse-options.h"
 
 
+/*
+ * Within init_walken_defaults() we can call into other useful defaults to set
+ * in the global scope or on the_repository. It's okay to borrow from other
+ * functions which are doing something relatively similar to yours.
+ */
+static void init_walken_defaults(void)
+{
+	/*
+	 * We don't actually need the same components `git log` does; leave this
+	 * empty for now.
+	 */
+}
+
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
 	/*
@@ -29,6 +42,8 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 	 */
 	argc = parse_options(argc, argv, prefix, options, walken_usage, 0);
 
+	init_walken_defaults();
+
 	/*
 	 * This line is "human-readable" and we are writing a plumbing command,
 	 * so we localize it and use the trace library to print only when
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#76 lore raw

RFC PATCH v3 4/13 walken: add handler to git_config

In reply to Emily Shaffer

For now, we have no configuration options we want to set up for ourselves, but in the future we may need to. At the very least, we should invoke git_default_config() for each config option; we will do so inside of a skeleton config callback so that we know where to add configuration handling later on when we need it.

---
 builtin/walken.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
builtin/walken.c +30 -2
index 19657b5e31..e53c42ea18 100644
@@ -5,6 +5,7 @@
  */
 
 #include "builtin.h"
+#include "config.h"
 #include "parse-options.h"
 
 
@@ -16,11 +17,36 @@
 static void init_walken_defaults(void)
 {
 	/*
-	 * We don't actually need the same components `git log` does; leave this
-	 * empty for now.
+	 * We don't use any other components or have settings to initialize, so
+	 * leave this empty.
 	 */
 }
 
+/*
+ * This method will be called back by git_config(). It is used to gather values
+ * from the configuration files available to Git.
+ *
+ * Each time git_config() finds a configuration file entry, it calls this
+ * callback. Then, this function should compare it to entries which concern us,
+ * and make settings changes as necessary.
+ *
+ * If we are called with a config setting we care about, we should use one of
+ * the helpers which exist in config.h to pull out the value for ourselves, i.e.
+ * git_config_string(...) or git_config_bool(...).
+ *
+ * If we don't match anything, we should pass it along to another stakeholder
+ * who may otherwise care - in log's case, grep, gpg, and diff-ui. For our case,
+ * we'll ignore everybody else.
+ */
+static int git_walken_config(const char *var, const char *value, void *cb)
+{
+	/*
+	 * For now, we don't have any custom configuration, so fall back on the
+	 * default config.
+	 */
+	return git_default_config(var, value, cb);
+}
+
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
 	/*
@@ -44,6 +70,8 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 
 	init_walken_defaults();
 
+	git_config(git_walken_config, NULL);
+
 	/*
 	 * This line is "human-readable" and we are writing a plumbing command,
 	 * so we localize it and use the trace library to print only when
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#77 lore raw

RFC PATCH v3 5/13 walken: configure rev_info and prepare for walk

In reply to Emily Shaffer

struct rev_info is what's used by the walk itself. repo_init_revisions() initializes the struct; then we need to set it up for the walk we want to perform, which is done in final_rev_info_setup().

The most important step here is adding the first object we want to walk to the pending array. Here, we take the easy road and use add_head_to_pending(); there is also a way to do it with setup_revision_opt() and setup_revisions() which we demonstrate but do not use. If we were to forget this step, the walk would do nothing - the pending queue would be checked, determined to be empty, and the walk would terminate immediately.

Change-Id I76754b740227cf17a449f3f536dbbe37031e6f9a
---
 builtin/walken.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
builtin/walken.c +50 -0
index e53c42ea18..333d9ecc5e 100644
@@ -5,6 +5,7 @@
  */
 
 #include "builtin.h"
+#include "revision.h"
 #include "config.h"
 #include "parse-options.h"
 
@@ -22,6 +23,40 @@ static void init_walken_defaults(void)
 	 */
 }
 
+/*
+ * Perform configuration for commit walk here. Within this function we set a
+ * starting point, and can customize our walk in various ways.
+ */
+static void final_rev_info_setup(int argc, const char **argv, const char *prefix,
+		struct rev_info *rev)
+{
+	/*
+	 * Optional:
+	 * setup_revision_opt is used to pass options to the setup_revisions()
+	 * call. It's got some special items for submodules and other types of
+	 * optimizations, but for now, we'll just point it to HEAD. First we
+	 * should make sure to reset it. This is useful for more complicated
+	 * stuff but a decent shortcut for the first pass is
+	 * add_head_to_pending().
+	 */
+
+	/*
+	 * struct setup_revision_opt opt;
+
+	 * memset(&opt, 0, sizeof(opt));
+	 * opt.def = "HEAD";
+	 * opt.revarg_opt = REVARG_COMMITTISH;
+	 * setup_revisions(argc, argv, rev, &opt);
+	 */
+
+	/* add the HEAD to pending so we can start */
+	add_head_to_pending(rev);
+
+	/* Let's force oneline format. */
+	get_commit_format("oneline", rev);
+	rev->verbose_header = 1;
+}
+
 /*
  * This method will be called back by git_config(). It is used to gather values
  * from the configuration files available to Git.
@@ -62,6 +97,8 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 		OPT_END()
 	};
 
+	struct rev_info rev;
+
 	/*
 	 * parse_options() handles showing usage if incorrect options are
 	 * provided, or if '-h' is passed.
@@ -72,6 +109,19 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 
 	git_config(git_walken_config, NULL);
 
+	/*
+	 * Time to set up the walk. repo_init_revisions sets up rev_info with
+	 * the defaults, but then you need to make some configuration settings
+	 * to make it do what's special about your walk.
+	 */
+	repo_init_revisions(the_repository, &rev, prefix);
+
+	/*
+	 * Before we do the walk, we need to set a starting point by giving it
+	 * something to go in `pending` - that happens in here
+	 */
+	final_rev_info_setup(argc, argv, prefix, &rev);
+
 	/*
 	 * This line is "human-readable" and we are writing a plumbing command,
 	 * so we localize it and use the trace library to print only when
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#78 lore raw

RFC PATCH v3 6/13 walken: perform our basic revision walk

In reply to Emily Shaffer

Add the final steps needed and implement the walk loop itself. We add a method walken_commit_walk() which performs the final setup to revision.c and then iterates over commits from get_revision().

This basic walk only prints the subject line of each commit in the history. It is nearly equivalent to git log --oneline.

Change-Id If6dc5f3c9d14df077b99e42806cf790c96191582
---
 builtin/walken.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
builtin/walken.c +42 -0
index 333d9ecc5e..f116bb6fca 100644
@@ -6,8 +6,11 @@
 
 #include "builtin.h"
 #include "revision.h"
+#include "commit.h"
 #include "config.h"
 #include "parse-options.h"
+#include "pretty.h"
+#include "line-log.h"
 
 
 /*
@@ -82,6 +85,40 @@ static int git_walken_config(const char *var, const char *value, void *cb)
 	return git_default_config(var, value, cb);
 }
 
+/*
+ * walken_commit_walk() is invoked by cmd_walken() after initialization. It
+ * performs the actual commit walk.
+ */
+static void walken_commit_walk(struct rev_info *rev)
+{
+	struct commit *commit;
+	struct strbuf prettybuf = STRBUF_INIT;
+
+	/*
+	 * prepare_revision_walk() gets the final steps ready for a revision
+	 * walk. We check the return value for errors.
+	 */
+	if (prepare_revision_walk(rev)) {
+		die(_("revision walk setup failed"));
+	}
+
+	/*
+	 * Now we can start the real commit walk. get_revision() grabs the next
+	 * revision based on the contents of rev.
+	 */
+	while ((commit = get_revision(rev))) {
+		strbuf_reset(&prettybuf);
+		pp_commit_easy(CMIT_FMT_ONELINE, commit, &prettybuf);
+		/*
+		 * We expect this part of the output to be machine-parseable -
+		 * one commit message per line - so we send it to stdout.
+		 */
+		puts(prettybuf.buf);
+	}
+
+	strbuf_release(&prettybuf);
+}
+
 int cmd_walken(int argc, const char **argv, const char *prefix)
 {
 	/*
@@ -116,12 +153,17 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 	 */
 	repo_init_revisions(the_repository, &rev, prefix);
 
+	/* We can set our traversal flags here. */
+	rev.always_show_header = 1;
+
 	/*
 	 * Before we do the walk, we need to set a starting point by giving it
 	 * something to go in `pending` - that happens in here
 	 */
 	final_rev_info_setup(argc, argv, prefix, &rev);
 
+	walken_commit_walk(&rev);
+
 	/*
 	 * This line is "human-readable" and we are writing a plumbing command,
 	 * so we localize it and use the trace library to print only when
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#79 lore raw

RFC PATCH v3 7/13 walken: filter for authors from gmail address

In reply to Emily Shaffer

In order to demonstrate how to create grep filters for revision walks, filter the walk performed by cmd_walken() to print only commits which are authored by someone with a gmail address.

This commit demonstrates how to append a grep pattern to a rev_info.grep_filter, to teach new contributors how to create their own more generalized grep filters during revision walks.

---
 builtin/walken.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
builtin/walken.c +8 -8
index f116bb6fca..a600f88cf6 100644
@@ -11,6 +11,7 @@
 #include "parse-options.h"
 #include "pretty.h"
 #include "line-log.h"
+#include "grep.h"
 
 
 /*
@@ -20,10 +21,8 @@
  */
 static void init_walken_defaults(void)
 {
-	/*
-	 * We don't use any other components or have settings to initialize, so
-	 * leave this empty.
-	 */
+	/* Needed by our grep filter. */
+	init_grep_defaults(the_repository);
 }
 
 /*
@@ -55,6 +54,10 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
 	/* add the HEAD to pending so we can start */
 	add_head_to_pending(rev);
 
+	/* Apply a 'grep' pattern to the 'author' header. */
+	append_header_grep_pattern(&rev->grep_filter, GREP_HEADER_AUTHOR, "gmail");
+	compile_grep_patterns(&rev->grep_filter);
+
 	/* Let's force oneline format. */
 	get_commit_format("oneline", rev);
 	rev->verbose_header = 1;
@@ -78,10 +81,7 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
  */
 static int git_walken_config(const char *var, const char *value, void *cb)
 {
-	/*
-	 * For now, we don't have any custom configuration, so fall back on the
-	 * default config.
-	 */
+	grep_config(var, value, cb);
 	return git_default_config(var, value, cb);
 }
 
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#80 lore raw

RFC PATCH v3 8/13 walken: demonstrate various topographical sorts

In reply to Emily Shaffer

Order the revision walk by author or commit dates to demonstrate how to apply topo_sort to a revision walk.

While following the tutorial, new contributors are guided to run a walk with each sort and compare the results.

Change-Id I7ce2f3e8a77c42001293637ae209087afec4ce2c
---
 builtin/walken.c | 7 +++++++
 1 file changed, 7 insertions(+)
builtin/walken.c +7 -0
index a600f88cf6..b334f61e69 100644
@@ -61,6 +61,13 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
 	/* Let's force oneline format. */
 	get_commit_format("oneline", rev);
 	rev->verbose_header = 1;
+	
+	/* Let's play with the sort order. */
+	rev->topo_order = 1;
+
+	/* Toggle between these and observe the difference. */
+	rev->sort_order = REV_SORT_BY_COMMIT_DATE;
+	/* rev->sort_order = REV_SORT_BY_AUTHOR_DATE; */
 }
 
 /*
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#81 lore raw

RFC PATCH v3 9/13 walken: demonstrate reversing a revision walk list

In reply to Emily Shaffer

The final installment in the tutorial about sorting revision walk outputs. This commit reverses the commit list, so that we see newer commits last (handy since we aren't using a pager).

---
 builtin/walken.c | 3 +++
 1 file changed, 3 insertions(+)
builtin/walken.c +3 -0
index b334f61e69..03a50158fb 100644
@@ -61,6 +61,9 @@ static void final_rev_info_setup(int argc, const char **argv, const char *prefix
 	/* Let's force oneline format. */
 	get_commit_format("oneline", rev);
 	rev->verbose_header = 1;
+
+	/* Reverse the order */
+	rev->reverse = 1;
 	
 	/* Let's play with the sort order. */
 	rev->topo_order = 1;
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#82 lore raw

RFC PATCH v3 10/13 walken: add unfiltered object walk from HEAD

In reply to Emily Shaffer

Provide a demonstration of a revision walk which traverses all types of object, not just commits. This type of revision walk is used for operations such as creating packfiles and performing fetches or clones, so it's useful to teach new developers how it works. For starters, only demonstrate the unfiltered version, as this will make the tutorial easier to follow.

This commit is part of a tutorial on revision walking.

Change-Id If3b11652ba011b28d29b1c3984dac4a3f80a5f53
---
 builtin/walken.c | 91 ++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 85 insertions(+), 6 deletions(-)
builtin/walken.c +85 -6
index 03a50158fb..b613102cfb 100644
@@ -11,9 +11,15 @@
 #include "parse-options.h"
 #include "pretty.h"
 #include "line-log.h"
+#include "list-objects.h"
 #include "grep.h"
 
 
+static int commit_count;
+static int tag_count;
+static int blob_count;
+static int tree_count;
+
 /*
  * Within init_walken_defaults() we can call into other useful defaults to set
  * in the global scope or on the_repository. It's okay to borrow from other
@@ -95,6 +101,74 @@ static int git_walken_config(const char *var, const char *value, void *cb)
 	return git_default_config(var, value, cb);
 }
 
+static void walken_show_commit(struct commit *cmt, void *buf)
+{
+	commit_count++;
+}
+
+static void walken_show_object(struct object *obj, const char *str, void *buf)
+{
+	switch (obj->type) {
+	case OBJ_TREE:
+		tree_count++;
+		break;
+	case OBJ_BLOB:
+		blob_count++;
+		break;
+	case OBJ_TAG:
+		tag_count++;
+		break;
+	case OBJ_COMMIT:
+		/*
+		 * BUG() is used to warn developers when they've made a change
+		 * which breaks some relied-upon behavior of Git. In this case,
+		 * we're telling developers that we don't expect commits to be
+		 * routed as objects during an object walk. BUG() messages
+		 * should not be localized.
+		 */
+		BUG("unexpected commit object in walken_show_object\n");
+	default:
+		/*
+		 * This statement will only be hit if a new object type is added
+		 * to Git; we BUG() to tell developers that the new object type
+		 * needs to be handled and counted here.
+		 */
+		BUG("unexpected object type %s in walken_show_object\n"),
+				type_name(obj->type);
+	}
+}
+
+/*
+ * walken_object_walk() is invoked by cmd_walken() after initialization. It does
+ * a walk of all object types.
+ */
+static void walken_object_walk(struct rev_info *rev)
+{
+	rev->tree_objects = 1;
+	rev->blob_objects = 1;
+	rev->tag_objects = 1;
+	rev->tree_blobs_in_commit_order = 1;
+	rev->exclude_promisor_objects = 1;
+
+	if (prepare_revision_walk(rev))
+		die(_("revision walk setup failed"));
+
+	commit_count = 0;
+	tag_count = 0;
+	blob_count = 0;
+	tree_count = 0;
+
+	traverse_commit_list(rev, walken_show_commit, walken_show_object, NULL);
+
+	/*
+	 * This print statement is designed to be script-parseable. Script
+	 * authors will rely on the output not to change, so we will not
+	 * localize this string. It will go to stdout directly.
+	 */
+	printf("commits %d\n blobs %d\n tags %d\n trees %d\n", commit_count,
+	       blob_count, tag_count, tree_count);
+}
+
 /*
  * walken_commit_walk() is invoked by cmd_walken() after initialization. It
  * performs the actual commit walk.
@@ -166,13 +240,18 @@ int cmd_walken(int argc, const char **argv, const char *prefix)
 	/* We can set our traversal flags here. */
 	rev.always_show_header = 1;
 
-	/*
-	 * Before we do the walk, we need to set a starting point by giving it
-	 * something to go in `pending` - that happens in here
-	 */
-	final_rev_info_setup(argc, argv, prefix, &rev);
 
-	walken_commit_walk(&rev);
+	if (1) {
+		add_head_to_pending(&rev);
+		walken_object_walk(&rev);
+	} else {
+		/*
+		 * Before we do the walk, we need to set a starting point by giving it
+		 * something to go in `pending` - that happens in here
+		 */
+		final_rev_info_setup(argc, argv, prefix, &rev);
+		walken_commit_walk(&rev);
+	}
 
 	/*
 	 * This line is "human-readable" and we are writing a plumbing command,
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#83 lore raw

RFC PATCH v3 11/13 walken: add filtered object walk

In reply to Emily Shaffer

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.

Change-Id I6d22ba153c1afbc780c261c47f1fa03ea478b5ed
---
 builtin/walken.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
builtin/walken.c +21 -1
index b613102cfb..7b46377a2e 100644
@@ -12,6 +12,7 @@
 #include "pretty.h"
 #include "line-log.h"
 #include "list-objects.h"
+#include "list-objects-filter-options.h"
 #include "grep.h"
 
 
@@ -144,6 +145,8 @@ static void walken_show_object(struct object *obj, const char *str, void *buf)
  */
 static void walken_object_walk(struct rev_info *rev)
 {
+	struct list_objects_filter_options filter_options = {};
+
 	rev->tree_objects = 1;
 	rev->blob_objects = 1;
 	rev->tag_objects = 1;
@@ -158,7 +161,24 @@ static void 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 (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"));
+		/*
+		 * We can parse a tree depth of 1 to demonstrate the kind of
+		 * filtering that could occur during various operations (see
+		 * `git help rev-list` and read the entry on `--filter`).
+		 */
+		parse_list_objects_filter(&filter_options, "tree:1");
+
+		traverse_commit_list_filtered(&filter_options, rev,
+			walken_show_commit, walken_show_object, NULL, NULL);
+	}
 
 	/*
 	 * This print statement is designed to be script-parseable. Script
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#84 lore raw

RFC PATCH v3 12/13 walken: count omitted objects

In reply to Emily Shaffer

It may be illuminating to see which objects were not included within a given filter. This also demonstrates, since filter-spec "tree:1" is used, that the 'omitted' list contains all objects which are omitted, not just the first objects which were omitted - that is, it continues to dereference omitted trees and commits.

This is part of a tutorial on performing revision walks.

---
 builtin/walken.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
builtin/walken.c +13 -2
index 7b46377a2e..1638f679f2 100644
@@ -146,6 +146,11 @@ static void walken_show_object(struct object *obj, const char *str, void *buf)
 static void walken_object_walk(struct rev_info *rev)
 {
 	struct list_objects_filter_options filter_options = {};
+	struct oidset omitted;
+	struct oidset_iter oit;
+	struct object_id *oid = NULL;
+	int omitted_count = 0;
+	oidset_init(&omitted, 0);
 
 	rev->tree_objects = 1;
 	rev->blob_objects = 1;
@@ -180,13 +185,19 @@ static void walken_object_walk(struct rev_info *rev)
 			walken_show_commit, walken_show_object, NULL, NULL);
 	}
 
+	/* Count the omitted objects. */
+	oidset_iter_init(&omitted, &oit);
+
+	while ((oid = oidset_iter_next(&oit)))
+		omitted_count++;
+
 	/*
 	 * This print statement is designed to be script-parseable. Script
 	 * authors will rely on the output not to change, so we will not
 	 * localize this string. It will go to stdout directly.
 	 */
-	printf("commits %d\n blobs %d\n tags %d\n trees %d\n", commit_count,
-	       blob_count, tag_count, tree_count);
+	printf("commits %d\n blobs %d\n tags %d\n trees %d omitted %d\n",
+	       commit_count, blob_count, tag_count, tree_count, omitted_count);
 }
 
 /*
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#85 lore raw

RFC PATCH v3 13/13 walken: reverse the object walk order

In reply to Emily Shaffer

Demonstrate that just like commit walks, object walks can have their order reversed. Additionally, add verbose logging of objects encountered in order to let contributors prove to themselves that the walk has actually been reversed. With this commit, git walken becomes extremely chatty - it's recommended to pipe the output through head or tail or to redirect it into a file.

Change-Id I91883b209a61ae4d87855878291e487fe36220c4
---
 builtin/walken.c | 3 +++
 1 file changed, 3 insertions(+)
builtin/walken.c +3 -0
index 1638f679f2..2eb12f92ed 100644
@@ -104,11 +104,13 @@ static int git_walken_config(const char *var, const char *value, void *cb)
 
 static void walken_show_commit(struct commit *cmt, void *buf)
 {
+	printf("commit: %s\n", oid_to_hex(&cmt->object.oid));
 	commit_count++;
 }
 
 static void walken_show_object(struct object *obj, const char *str, void *buf)
 {
+	printf("%s: %s\n", type_name(obj->type), oid_to_hex(&obj->oid));
 	switch (obj->type) {
 	case OBJ_TREE:
 		tree_count++;
@@ -157,6 +159,7 @@ static void walken_object_walk(struct rev_info *rev)
 	rev->tag_objects = 1;
 	rev->tree_blobs_in_commit_order = 1;
 	rev->exclude_promisor_objects = 1;
+	rev->reverse = 1;
 
 	if (prepare_revision_walk(rev))
 		die(_("revision walk setup failed"));
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
#86 lore raw

Re: [RFC PATCH v3 00/13] example implementation of revwalk tutorial

In reply to Emily Shaffer

Hi Emily,

Quoted 18 lines · Emily Shaffer

Since v2, mostly reworded comments, plus fixed the issues mentioned in the tutorial itself. Thanks Eric for the review.

Emily Shaffer (13):
walken: add infrastructure for revwalk demo
walken: add usage to enable -h
walken: add placeholder to initialize defaults
walken: add handler to git_config
walken: configure rev_info and prepare for walk
walken: perform our basic revision walk
walken: filter for authors from gmail address
walken: demonstrate various topographical sorts
walken: demonstrate reversing a revision walk list
walken: add unfiltered object walk from HEAD
walken: add filtered object walk
walken: count omitted objects
walken: reverse the object walk order

Quoted 3 lines
 Makefile         |   1 +
 builtin.h        |   1 +
 builtin/walken.c | 297 +++++++++++++++++++++++++++++++++++++++++++++++

Since this is not really intended to be an end user-facing command, I think it should not become a built-in, to be carried into every Git user's setup.

Instead, I would recommend to implement this as a test helper.

This would have the following advantages:

- it won't clutter the end user installations,

- it will still be compile-tested with every build (guaranteeing that the tutorial won't become stale over time as so many other tutorials),

- it really opens the door very wide to follow up with another tutorial to guide new contributors to write stellar regression tests.

Thanks,
Dscho

Quoted 9 lines
 git.c            |   1 +
 4 files changed, 300 insertions(+)
 create mode 100644 builtin/walken.c

--
2.22.0.410.gd8fdbe21b5-goog

#87 lore raw

Re: [RFC PATCH v3 00/13] example implementation of revwalk tutorial

Quoted 22 lines · Johannes Schindelin

Hi Emily,

Quoted 18 lines · Emily Shaffer

Since v2, mostly reworded comments, plus fixed the issues mentioned in the tutorial itself. Thanks Eric for the review.

Emily Shaffer (13):
walken: add infrastructure for revwalk demo
walken: add usage to enable -h
walken: add placeholder to initialize defaults
walken: add handler to git_config
walken: configure rev_info and prepare for walk
walken: perform our basic revision walk
walken: filter for authors from gmail address
walken: demonstrate various topographical sorts
walken: demonstrate reversing a revision walk list
walken: add unfiltered object walk from HEAD
walken: add filtered object walk
walken: count omitted objects
walken: reverse the object walk order

Quoted 7 lines
Quoted 3 lines
 Makefile         |   1 +
 builtin.h        |   1 +
 builtin/walken.c | 297 +++++++++++++++++++++++++++++++++++++++++++++++

Since this is not really intended to be an end user-facing command, I think it should not become a built-in, to be carried into every Git user's setup.

It's not intended to be checked into Git source as-is.

Quoted 2 lines

Instead, I would recommend to implement this as a test helper.

I'm not sure I follow how you imagine this looking, but the drawback I see of implementing this in a different way than you would typically do when writing a real feature for the project is that it becomes less useful as a reference for new contributors.

Quoted 7 lines

This would have the following advantages:

- it won't clutter the end user installations,

- it will still be compile-tested with every build (guaranteeing that the tutorial won't become stale over time as so many other tutorials),

This part of your suggestion appeals to me; so I'm really curious how you would do it. Do you have something else written in the way you're suggesting in mind?

Quoted 16 lines

- it really opens the door very wide to follow up with another tutorial to guide new contributors to write stellar regression tests.

Thanks,
Dscho

Quoted 9 lines
 git.c            |   1 +
 4 files changed, 300 insertions(+)
 create mode 100644 builtin/walken.c

--
2.22.0.410.gd8fdbe21b5-goog

#88 lore raw

Re: [RFC PATCH v3 00/13] example implementation of revwalk tutorial

Hi Emily,

Quoted 26 lines · Emily Shaffer
Quoted 25 lines · Johannes Schindelin
Quoted 21 lines · Emily Shaffer

Since v2, mostly reworded comments, plus fixed the issues mentioned in the tutorial itself. Thanks Eric for the review.

Emily Shaffer (13):
walken: add infrastructure for revwalk demo
walken: add usage to enable -h
walken: add placeholder to initialize defaults
walken: add handler to git_config
walken: configure rev_info and prepare for walk
walken: perform our basic revision walk
walken: filter for authors from gmail address
walken: demonstrate various topographical sorts
walken: demonstrate reversing a revision walk list
walken: add unfiltered object walk from HEAD
walken: add filtered object walk
walken: count omitted objects
walken: reverse the object walk order

 Makefile         |   1 +
 builtin.h        |   1 +
 builtin/walken.c | 297 +++++++++++++++++++++++++++++++++++++++++++++++
Quoted 5 lines
Quoted 3 lines

Since this is not really intended to be an end user-facing command, I think it should not become a built-in, to be carried into every Git user's setup.

It's not intended to be checked into Git source as-is.

Then it runs the very real danger of becoming stale: we do _not_ guarantee a stable API, not even an internal one.

Quoted 6 lines
Quoted 1 line

Instead, I would recommend to implement this as a test helper.

I'm not sure I follow how you imagine this looking, but the drawback I see of implementing this in a different way than you would typically do when writing a real feature for the project is that it becomes less useful as a reference for new contributors.

To the contrary. Some code in t/helper/ is intended to test functionality in a way that is copy-editable.

Your use case strikes me a perfect example for such a test helper:

- It guarantees that the example is valid,
- It demonstrates how to use the API,
- In case the API changes, the changes to the helper will inform contributors how to change their copy-edited versions

Quoted 10 lines
Quoted 6 lines

This would have the following advantages:

- it won't clutter the end user installations,

- it will still be compile-tested with every build (guaranteeing that the tutorial won't become stale over time as so many other tutorials),

This part of your suggestion appeals to me; so I'm really curious how you would do it. Do you have something else written in the way you're suggesting in mind?

I looked at t/helper/test-hashmap.c and it looks _almost_ like a perfect example for what I have in mind: it uses a given API, demonstrates how to use it properly, and is copy-editable.

Ciao,
Dscho

#89 lore raw
In reply to Emily Shaffer
Quoted 18 lines · Emily Shaffer

Existing documentation on revision walks seems to be primarily intended as a reference for those already familiar with the procedure. This tutorial attempts to give an entry-level guide to a couple of bare-bones revision walks so that new Git contributors can learn the concepts without having to wade through options parsing or special casing.

The target audience is a Git contributor who is just getting started with the concept of revision walking. The goal is to prepare this contributor to be able to understand and modify existing commands which perform revision walks more easily, although it will also prepare contributors to create new commands which perform walks.

The tutorial covers a basic overview of the structs involved during revision walk, setting up a basic commit walk, setting up a basic all-object walk, and adding some configuration changes to both walk types. It intentionally does not cover how to create new commands or search for options from the command line or gitconfigs.

Quoted 6 lines

There is an associated patchset at
https://github.com/nasamuffin/git/tree/revwalk that contains a reference implementation of the code generated by this tutorial.

This looks good to me; as a new Git developer I found it informative and wish it had been present before I took my first look at the rev-walk code.

#90 lore raw
In reply to Emily Shaffer

Thanks - I think this is a useful guide to what can be a complicated topic. It looks good overall; I just have some minor comments below.

Documentation/Makefile SP_ARTICLES += $(API_DOCS) · line 81

Quoted 9 lines
Documentation/Makefile +1 -0
index 76f2ecfc1b..91e5da67c4 100644
@@ -78,6 +78,7 @@ SP_ARTICLES += $(API_DOCS)
 
 TECH_DOCS += MyFirstContribution
 TECH_DOCS += SubmittingPatches
+TECH_DOCS += MyFirstRevWalk

Any reason why this is not in alphabetical order?

Documentation/Makefile SP_ARTICLES += $(API_DOCS)

Quoted 5 lines
Documentation/Makefile +5 -0
+Also add the relevant line in `builtin.h` near `cmd_whatchanged()`:
+
+----
+extern int cmd_walken(int argc, const char **argv, const char *prefix);
+----

builtin.h no longer has "extern", so we can delete it.

Documentation/Makefile

Quoted 5 lines
Documentation/Makefile +5 -0
+Add it to the `Makefile` near the line for `builtin\worktree.o`:
+
+----
+BUILTIN_OBJS += builtin/walken.o
+----

In the first line, change the backslash to a slash. (The line in Makefile for "builtin/worktree.o" uses a forward slash as expected.)

Documentation/Makefile

Quoted 4 lines
Documentation/Makefile +4 -0
+NOTE: For a more exhaustive overview of the new command process, take a look at
+`Documentation/MyFirstContribution.txt`.
+
+NOTE: A reference implementation can be found at TODO LINK.

I think you have a reference implementation at
https://github.com/nasamuffin/git/tree/revwalk?

Quoted 8 lines
Documentation/Makefile +8 -0
+We'll start by enabling all types of objects in the `struct rev_info`. Unless
+you cloned or fetched your repository earlier with a filter,
+`exclude_promisor_objects` is unlikely to make a difference, but we'll turn it
+on just to make sure our lives are simple. We'll also turn on
+`tree_blobs_in_commit_order`, which means that we will walk a commit's tree and
+everything it points to immediately after we find each commit, as opposed to
+waiting for the end and walking through all trees after the commit history has
+been discovered. With the appropriate settings configured, we are ready to call

Documentation/Makefile

Quoted 10 lines
Documentation/Makefile +10 -0
+`prepare_revision_walk()`.
+
+----
+static void walken_object_walk(struct rev_info *rev)
+{
+	rev->tree_objects = 1;
+	rev->blob_objects = 1;
+	rev->tag_objects = 1;
+	rev->tree_blobs_in_commit_order = 1;
+	rev->exclude_promisor_objects = 1;

Optional: I think we should not bother with exclude_promisor_objects. If the user really cloned with a filter, then every object would be a promisor object and the revision walk should output nothing, which is very confusing.

#91 lore raw
Quoted 9 lines · Jonathan Tan

Thanks - I think this is a useful guide to what can be a complicated topic. It looks good overall; I just have some minor comments below.

Quoted 6 lines
Documentation/Makefile +0 -0
index 76f2ecfc1b..91e5da67c4 100644
@@ -78,6 +78,7 @@ SP_ARTICLES += $(API_DOCS)
 
Quoted 5 lines

Documentation/Makefile SP_ARTICLES += $(API_DOCS) · line 81

Quoted 3 lines
Documentation/Makefile +1 -0
 TECH_DOCS += MyFirstContribution
 TECH_DOCS += SubmittingPatches
+TECH_DOCS += MyFirstRevWalk

Any reason why this is not in alphabetical order?

No reason, will fix.

Quoted 8 lines

Documentation/Makefile SP_ARTICLES += $(API_DOCS)

Quoted 6 lines
Documentation/Makefile +5 -0
+Also add the relevant line in `builtin.h` near `cmd_whatchanged()`:
+
+----
+extern int cmd_walken(int argc, const char **argv, const char *prefix);
+----

builtin.h no longer has "extern", so we can delete it.

Done.

Quoted 9 lines

Documentation/Makefile

Quoted 6 lines
Documentation/Makefile +5 -0
+Add it to the `Makefile` near the line for `builtin\worktree.o`:
+
+----
+BUILTIN_OBJS += builtin/walken.o
+----

In the first line, change the backslash to a slash. (The line in Makefile for "builtin/worktree.o" uses a forward slash as expected.)

Done, not sure how this got in there. Thanks!

Quoted 8 lines

Documentation/Makefile

Quoted 5 lines
Documentation/Makefile +4 -0
+NOTE: For a more exhaustive overview of the new command process, take a look at
+`Documentation/MyFirstContribution.txt`.
+
+NOTE: A reference implementation can be found at TODO LINK.

I think you have a reference implementation at
https://github.com/nasamuffin/git/tree/revwalk?

Yep, although it's not very fresh. I was hoping to wait for a way for us to check in the reference implementation to Git source, although that can wait and the off-project branch is maybe OK for now.

Quoted 16 lines
Quoted 16 lines
Documentation/Makefile +15 -0
+We'll start by enabling all types of objects in the `struct rev_info`. Unless
+you cloned or fetched your repository earlier with a filter,
+`exclude_promisor_objects` is unlikely to make a difference, but we'll turn it
+on just to make sure our lives are simple. We'll also turn on
+`tree_blobs_in_commit_order`, which means that we will walk a commit's tree and
+everything it points to immediately after we find each commit, as opposed to
+waiting for the end and walking through all trees after the commit history has
+been discovered. With the appropriate settings configured, we are ready to call
+`prepare_revision_walk()`.
+
+----
+static void walken_object_walk(struct rev_info *rev)
+{
+	rev->tree_objects = 1;
+	rev->blob_objects = 1;
Quoted 8 lines

Documentation/Makefile

Quoted 3 lines
Documentation/Makefile +3 -0
+	rev->tag_objects = 1;
+	rev->tree_blobs_in_commit_order = 1;
+	rev->exclude_promisor_objects = 1;

Optional: I think we should not bother with exclude_promisor_objects. If the user really cloned with a filter, then every object would be a promisor object and the revision walk should output nothing, which is very confusing.

Sure, that makes sense. Ok, I removed it.

Thanks for looking - and for the patience with the latency on the reply.

#92 lore raw

PATCH v4 1/1 documentation: add tutorial for revision walking

In reply to Emily Shaffer

Existing documentation on revision walks seems to be primarily intended as a reference for those already familiar with the procedure. This tutorial attempts to give an entry-level guide to a couple of bare-bones revision walks so that new Git contributors can learn the concepts without having to wade through options parsing or special casing.

The target audience is a Git contributor who is just getting started with the concept of revision walking. The goal is to prepare this contributor to be able to understand and modify existing commands which perform revision walks more easily, although it will also prepare contributors to create new commands which perform walks.

The tutorial covers a basic overview of the structs involved during revision walk, setting up a basic commit walk, setting up a basic all-object walk, and adding some configuration changes to both walk types. It intentionally does not cover how to create new commands or search for options from the command line or gitconfigs.

There is an associated patchset at
https://github.com/nasamuffin/git/tree/revwalk that contains a reference implementation of the code generated by this tutorial.

---

Since v3, only a couple of minor changes from Jonathan Tan - thanks.

I'm dropping the updates for the RFC set, since they're incremental from now. Next time you all see them they will be in a form which we would hope to maintain over a long period of time, checked into source - likely in the form of an mbox or dir of .patch file.

I think the tutorial itself is pretty much ready; the example source is more like "supporting material" - so I'd like to try to get this back on people's minds and hopefully checked in.

Thanks!
- Emily

 Documentation/Makefile           |   1 +
 Documentation/MyFirstRevWalk.txt | 904 +++++++++++++++++++++++++++++++
 2 files changed, 905 insertions(+)
 create mode 100644 Documentation/MyFirstRevWalk.txt
Documentation/Makefile +1 -0
index 76f2ecfc1b..7d136b480c 100644
@@ -77,6 +77,7 @@ API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technica
 SP_ARTICLES += $(API_DOCS)
 
 TECH_DOCS += MyFirstContribution
+TECH_DOCS += MyFirstRevWalk
 TECH_DOCS += SubmittingPatches
 TECH_DOCS += technical/hash-function-transition
 TECH_DOCS += technical/http-protocol
Documentation/MyFirstRevWalk.txt new file +904 -0

904 lines not on this page · raw message

Signature · 1 line
2.22.0.770.g0f2c4a37fd-goog
#93 lore raw
Quoted 6 lines · Emily Shaffer

Since v3, only a couple of minor changes from Jonathan Tan - thanks.

I'm dropping the updates for the RFC set, since they're incremental from now. Next time you all see them they will be in a form which we would hope to maintain over a long period of time, checked into source - likely in the form of an mbox or dir of .patch file.

Sure.

Quoted 1 line

I think the tutorial itself is pretty much ready...

A few comments after skimming this round; none of them may be a show stopper, but others may have different opinions.

- There is still a leftover "TODO: checking CLI options"; is that something we postpone teaching?

- This is an offtopic tangent, but "my first contribution" being an addition of an entire command probably mistakenly raised the bar to contributors a bit too much. A typical first contribution is a typofix, fix to a small (e.g. off-by-one) bug, etc.

- For a revision walk tutorial, not seeing any mention of pathspec filtering and associated history simplification is somewhat unsatisfying. On the other hand, I expect that enumeration of objects contained within commits is (hence various --filter options are) totally uninteresting for end users who run the command interactively and view the output of the command on screen.

- Enumeration of objects is useful at least in three places in Git:
(1) enumerate objects to be packed, with some filtering based on various criteria; (2) enumerate objects that are reachable from anchor points like refs, index, reflog, etc., to discover what are not reachable and can be discarded; (3) enumerate objects that still matter (i.e. the opposite of (2)) so that they can be fed to validation mechanisms (e.g. "cat-file --batch-check"). If this were titled "My first object enumeration", the reaction led to the latter half of the previous point may not have occurred (pathspec filtering would still be relevant, but not as much---for packing to create a narrow clone, you do not want to use pathspec with history simplification, but you would want to use something more like "root and intermediate trees that are necessary to cover these paths" filter in the list--objects-filter layer).

And from the point of view of the last item, I would think the new document is covering a need that is different from what we traditionally would call "revision walk", which is more about "git log", not the upstream of "git pack-objects", which this new document is more geared towards.

Unless "git walken" is an exercise of how to write code that does random thing, use of --grep filter however may be out of place, though. I do not offhand think of a use case where --grep would be useful in the revision walk/object enumeration that is placed upstream of "pack-objects".

Thanks.

#94 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 6 lines · Emily Shaffer

Since v3, only a couple of minor changes from Jonathan Tan - thanks.

I'm dropping the updates for the RFC set, since they're incremental from now. Next time you all see them they will be in a form which we would hope to maintain over a long period of time, checked into source - likely in the form of an mbox or dir of .patch file.

Sure.

Quoted 7 lines
Quoted 1 line

I think the tutorial itself is pretty much ready...

A few comments after skimming this round; none of them may be a show stopper, but others may have different opinions.

- There is still a leftover "TODO: checking CLI options"; is that something we postpone teaching?

Yeah, I think it would make more sense to include it into the other one (my first contribution) instead.

Quoted 5 lines

- This is an offtopic tangent, but "my first contribution" being an addition of an entire command probably mistakenly raised the bar to contributors a bit too much. A typical first contribution is a typofix, fix to a small (e.g. off-by-one) bug, etc.

Sure, I agree with that; but I think the larger (though less common) project of new command allowed me to explain more about the architecture of the project overall than a typo fix would. Maybe there's a clearer name to use?

Quoted 25 lines

- For a revision walk tutorial, not seeing any mention of pathspec filtering and associated history simplification is somewhat unsatisfying. On the other hand, I expect that enumeration of objects contained within commits is (hence various --filter options are) totally uninteresting for end users who run the command interactively and view the output of the command on screen.

- Enumeration of objects is useful at least in three places in Git:
(1) enumerate objects to be packed, with some filtering based on various criteria; (2) enumerate objects that are reachable from anchor points like refs, index, reflog, etc., to discover what are not reachable and can be discarded; (3) enumerate objects that still matter (i.e. the opposite of (2)) so that they can be fed to validation mechanisms (e.g. "cat-file --batch-check"). If this were titled "My first object enumeration", the reaction led to the latter half of the previous point may not have occurred (pathspec filtering would still be relevant, but not as much---for packing to create a narrow clone, you do not want to use pathspec with history simplification, but you would want to use something more like "root and intermediate trees that are necessary to cover these paths" filter in the list--objects-filter layer).

Quoted 5 lines

And from the point of view of the last item, I would think the new document is covering a need that is different from what we traditionally would call "revision walk", which is more about "git log", not the upstream of "git pack-objects", which this new document is more geared towards.

Hmmm. It sounds like you're saying:

- This object covers walking objects, which is surprising since it's titled about "revision walks". Revision walks are more about commits ("git log").
- Using grep on objects doesn't make any sense.
- Other filters (like pathspecs) which do make sense for object walks aren't covered.

Quoted 6 lines

Unless "git walken" is an exercise of how to write code that does random thing, use of --grep filter however may be out of place, though. I do not offhand think of a use case where --grep would be useful in the revision walk/object enumeration that is placed upstream of "pack-objects".

In this case, it might make sense to do one of these things:

- Apply the grep filter to the commit walk, and apply a more interesting object filter to the object walk.

Or,

- Choose a different kind of filter which is interesting when applied to commits alone _and_ all objects.

In the interest of covering more ground with this kind of tutorial, I'd lean more towards the former.

It's possible that the added scope will make the document large enough that we'd rather split it into two (one for "git log"-ish, one for "git pack-objects"-ish). I think that's fine if we end up there.

Thanks. I hope to get back to this soon...

- Emily

#95 lore raw
Quoted 10 lines · Emily Shaffer
Quoted 5 lines
Quoted 1 line

I think the tutorial itself is pretty much ready...

A few comments after skimming this round; none of them may be a show stopper, but others may have different opinions.
...

Hmmm. It sounds like you're saying:

- This object covers walking objects, which is surprising since it's titled about "revision walks". Revision walks are more about commits ("git log").

Yes, the document does not duplicate what existing docs on "revision walk" API would cover, which is a very good thing, as it is (or at least "feels to be") primarly about walking objects.

Quoted 1 line

- Using grep on objects doesn't make any sense.

The grep filter works on commit's log messages, and does not even look at other types of objects, so while that point is true, what I was driving at was that skipping commits using grep filter would mean showing trees and blobs related only to the chosen commits, and while it can be explained as such (i.e. "trees and blobs contained only in commits without these strings are excluded"), the practical usefulness of such a "feature" is dubious (here I am imagining the primary practical use of "object walk" is to feed pack-objects).

Quoted 2 lines

- Other filters (like pathspecs) which do make sense for object walks aren't covered.

Yup. For example, "trees and blobs that appear only outside of this directory hierarchy are excluded" would be useful to enumerate objects necessary for a narrow commits (again, to feed pack-objects).

Quoted 10 lines

- Apply the grep filter to the commit walk, and apply a more interesting object filter to the object walk.

Or,

- Choose a different kind of filter which is interesting when applied to commits alone _and_ all objects.

In the interest of covering more ground with this kind of tutorial, I'd lean more towards the former.

Sorry, I do not have enough imagination to cheer for either of these two options---these may be "interesting" in the same way as "trees and blobs contained only in commits without these strings are excluded" enumeration, but I fail to see practical usefulness (i.e. the reason why a user may be tempted to learn how to achieve it).

In any case, that was my personal take and not a strong request to change anything, as I said upfront. The document just gave me an impression that it was teaching coding exercise that may be interesting but of dubious utility.

#96 lore raw

PATCH v5 1/1 documentation: add tutorial for object walking

In reply to Emily Shaffer

The target audience is a Git contributor who is just getting started with the concept of object walking. The goal is to prepare this contributor to be able to understand and modify existing commands which perform revision walks more easily, although it will also prepare contributors to create new commands which perform walks.

The tutorial covers a basic overview of the structs involved during object walk, setting up a basic commit walk, setting up a basic all-object walk, and adding some configuration changes to both walk types. It intentionally does not cover how to create new commands or search for options from the command line or gitconfigs.

There is an associated patchset at
https://github.com/nasamuffin/git/tree/revwalk that contains a reference implementation of the code generated by this tutorial.

---
Primarily since v5 this is a reword to try to frame the tutorial as "object walk tutorial which also covers commit-only walk", rather than "revision walk tutorial which also covers all-object walk" - per Junio's suggestion.

Since I had spent some time away from the patch, I also made some small changes to the wording.

Here's the rangediff from gitster/es/walken-tutorial:

1: 1ed29a34d1 ! 1: 554d940af7 documentation: add tutorial for revision walking

     a => b | 0
     1 file changed, 0 insertions(+), 0 deletions(-)

@@ Metadata
Author: Emily Shaffer <[email protected]>

## Commit message ##
- documentation: add tutorial for revision walking
+ documentation: add tutorial for object walking

- Existing documentation on revision walks seems to be primarily intended
+ Existing documentation on object walks seems to be primarily intended
as a reference for those already familiar with the procedure. This tutorial attempts to give an entry-level guide to a couple of bare-bones
- revision walks so that new Git contributors can learn the concepts
+ object walks so that new Git contributors can learn the concepts
without having to wade through options parsing or special casing.

The target audience is a Git contributor who is just getting started
- with the concept of revision walking. The goal is to prepare this
+ with the concept of object walking. The goal is to prepare this
contributor to be able to understand and modify existing commands which perform revision walks more easily, although it will also prepare contributors to create new commands which perform walks.

The tutorial covers a basic overview of the structs involved during
- revision walk, setting up a basic commit walk, setting up a basic
+ object walk, setting up a basic commit walk, setting up a basic
all-object walk, and adding some configuration changes to both walk types. It intentionally does not cover how to create new commands or search for options from the command line or gitconfigs.
@@ Commit message

- Signed-off-by: Junio C Hamano <[email protected]>

## Documentation/Makefile ##
@@ Documentation/Makefile: API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technica
@@ Documentation/Makefile: API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api
TECH_DOCS += technical/hash-function-transition
TECH_DOCS += technical/http-protocol

- ## Documentation/MyFirstRevWalk.txt (new) ##
+ ## Documentation/MyFirstObjectWalk.txt (new) ##
@@
-+My First Revision Walk
++My First Object Walk
+======================
+
-+== What's a Revision Walk?
++== What's an Object Walk?
+
-+The revision walk is a key concept in Git - this is the process that underpins ++The object walk is a key concept in Git - this is the process that underpins
+operations like git log, git blame, and git reflog. Beginning at HEAD, the +list of objects is found by walking parent relationships between objects. The
-+revision walk can also be used to determine whether or not a given object is ++object walk can also be used to determine whether or not a given object is
+reachable from the current HEAD pointer.
+
++A related concept is the revision walk, which is focused on commit objects and ++their relationships.
++
+=== Related Reading
+
+- Documentation/user-manual.txt under "Hacking Git" contains some coverage of
+ the revision walker in its various incarnations.
+- Documentation/technical/api-revision-walking.txt
+- https://eagain.net/articles/git-for-computer-scientists/[Git for Computer Scientists]
-+ gives a good overview of the types of objects in Git and what your revision ++ gives a good overview of the types of objects in Git and what your object
+ walk is really describing.
+
+== Setting Up
@@ Documentation/MyFirstRevWalk.txt (new)
+/*
+ * "git walken"
+ *
-+ * Part of the "My First Revision Walk" tutorial.
++ * Part of the "My First Object Walk" tutorial.
+ */
+
+#include "builtin.h"
@@ Documentation/MyFirstRevWalk.txt (new)
+
+Per entry, we find:
+
-+item is the object provided upon which to base the revision walk. Items in Git ++item is the object provided upon which to base the object walk. Items in Git
+can be blobs, trees, commits, or tags. (See Documentation/gittutorial-2.txt.) +
+name is the object ID (OID) of the object - a hex string you may be familiar
@@ Documentation/MyFirstRevWalk.txt (new)
+
+First, let's see if we can replicate the output of git log --oneline. We'll +refer back to the implementation frequently to discover norms when performing
-+a revision walk of our own.
++an object walk of our own.
+
+To do so, we'll first find all the commits, in order, which preceded the current +commit. We'll extract the name and subject of the commit from each.
@@ Documentation/MyFirstRevWalk.txt (new)
+
+=== Setting Up
+
-+Preparing for your revision walk has some distinct stages.
++Preparing for your object walk has some distinct stages.
+
+1. Perform default setup for this mode, and others which may be invoked. +2. Check configuration files for relevant settings.
@@ Documentation/MyFirstRevWalk.txt (new)
+grep and diff to initialize themselves by calling each of their +initialization functions.
+
-+For our purposes, within git walken, for the first example we don't intend to -+use any other components within Git, and we don't have any configuration to do. -+However, we may want to add some later, so for now, we can add an empty -+placeholder. Create a new function in builtin/walken.c:
++For our first example within git walken, we don't intend to use any other ++components within Git, and we don't have any configuration to do. However, we ++may want to add some later, so for now, we can add an empty placeholder. Create ++a new function in builtin/walken.c:
+
+----
+static void init_walken_defaults(void)
@@ Documentation/MyFirstRevWalk.txt (new)
+}
+----
+
-+// TODO: Checking CLI options
-+
+==== Setting Up rev_info
+
+Now that we've gathered external configuration and options, it's time to
@@ Documentation/MyFirstRevWalk.txt (new)
+ */
+ get_commit_format("oneline", rev);
+
-+ /* Start our revision walk at HEAD. */
++ /* Start our object walk at HEAD. */
+ add_head_to_pending(rev);
+}
+----
@@ Documentation/MyFirstRevWalk.txt (new)
+
+There are a few ways that we can change the order of the commits during a +revision walk. Firstly, we can use the enum rev_sort_order to choose from some
-+sane orderings.
++typical orderings.
+
+topo_order is the same as git log --topo-order: we avoid showing a parent +before all of its children have been shown, and we avoid mixing commits which
@@ Documentation/MyFirstRevWalk.txt (new)
+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
-+revision walk does not perform any better than an unfiltered revision walk; all ++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:

<end rangediff>

 Documentation/Makefile              |   1 +
 Documentation/MyFirstObjectWalk.txt | 905 ++++++++++++++++++++++++++++
 2 files changed, 906 insertions(+)
 create mode 100644 Documentation/MyFirstObjectWalk.txt
Documentation/Makefile +1 -0
index 06d85ad958..fc35cb29b1 100644
@@ -77,6 +77,7 @@ API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technica
 SP_ARTICLES += $(API_DOCS)
 
 TECH_DOCS += MyFirstContribution
+TECH_DOCS += MyFirstRevWalk
 TECH_DOCS += SubmittingPatches
 TECH_DOCS += technical/hash-function-transition
 TECH_DOCS += technical/http-protocol
Documentation/MyFirstObjectWalk.txt new file +905 -0

905 lines not on this page · raw message

Signature · 1 line
2.23.0.700.g56cf767bdb-goog
#97 lore raw

Re: [PATCH v5] documentation: add tutorial for object walking

Documentation/Makefile API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technica · line 80

Quoted 5 lines · Emily Shaffer
Documentation/Makefile +1 -0
@@ -77,6 +77,7 @@ API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technica
 SP_ARTICLES += $(API_DOCS)
 
 TECH_DOCS += MyFirstContribution
+TECH_DOCS += MyFirstRevWalk

s/Rev/Object/ probably (if so I can locally amend).

Quoted 6 lines
Documentation/MyFirstObjectWalk.txt new file +0 -0
new file mode 100644
index 0000000000..7085f17072

Documentation/MyFirstObjectWalk.txt line 8

Quoted 8 lines
Documentation/MyFirstObjectWalk.txt new file +8 -0
@@ -0,0 +1,905 @@
+My First Object Walk
+======================
+
+== What's an Object Walk?
+
+The object walk is a key concept in Git - this is the process that underpins
+operations like `git log`, `git blame`, and `git reflog`. Beginning at HEAD, the
+list of objects is found by walking parent relationships between objects.

The above is more about revision walk, for which we have plenty of docs already, isn't it? Walking objects, while walking the commit DAG, is a lessor concept than the key "revision walk" concept and underpins different set of operations like object transfer and fsck.

Also, the object walk, unlike the revision walk, follows containment relationships between objects.

Documentation/MyFirstObjectWalk.txt line 13

Quoted 2 lines
Documentation/MyFirstObjectWalk.txt new file +2 -0
+A related concept is the revision walk, which is focused on commit objects and
+their relationships.

Yes, s/their/& parent/ perhaps, to contrast the two a bit better. git log and friends, if they need to be listed, should come on this side, I think.

#98 lore raw

Re: [PATCH v5] documentation: add tutorial for object walking

Quoted 9 lines · Junio C Hamano

Documentation/Makefile API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technica · line 80

Quoted 5 lines · Emily Shaffer
Documentation/Makefile +1 -0
@@ -77,6 +77,7 @@ API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technica
 SP_ARTICLES += $(API_DOCS)
 
 TECH_DOCS += MyFirstContribution
+TECH_DOCS += MyFirstRevWalk

s/Rev/Object/ probably (if so I can locally amend).

Yes, that's the case, although I'll send a reroll shortly if you don't want to amend locally - there's other stuff to fix according to you and SZEDER.

Quoted 21 lines
Quoted 7 lines
Documentation/MyFirstObjectWalk.txt new file +0 -0
new file mode 100644
index 0000000000..7085f17072

Documentation/MyFirstObjectWalk.txt line 8

Quoted 8 lines
Documentation/MyFirstObjectWalk.txt new file +8 -0
@@ -0,0 +1,905 @@
+My First Object Walk
+======================
+
+== What's an Object Walk?
+
+The object walk is a key concept in Git - this is the process that underpins
+operations like `git log`, `git blame`, and `git reflog`. Beginning at HEAD, the
+list of objects is found by walking parent relationships between objects.

The above is more about revision walk, for which we have plenty of docs already, isn't it? Walking objects, while walking the commit DAG, is a lessor concept than the key "revision walk" concept and underpins different set of operations like object transfer and fsck.

Quoted 2 lines

Also, the object walk, unlike the revision walk, follows containment relationships between objects.

Good point; I'll rewrite this paragraph rather than trying to just edit it a little for the next reroll.

Quoted 8 lines

Documentation/MyFirstObjectWalk.txt line 13

Quoted 3 lines
Documentation/MyFirstObjectWalk.txt new file +2 -0
+A related concept is the revision walk, which is focused on commit objects and
+their relationships.

Yes, s/their/& parent/ perhaps, to contrast the two a bit better. git log and friends, if they need to be listed, should come on this side, I think.

OK.

#99 lore raw

Re: [PATCH v5] documentation: add tutorial for object walking

In reply to Emily Shaffer

Documentation/MyFirstObjectWalk.txt line 2

Quoted 8 lines · Emily Shaffer
Documentation/MyFirstObjectWalk.txt new file +2 -0
new file mode 100644
index 0000000000..7085f17072
@@ -0,0 +1,905 @@
+My First Object Walk
+======================

In our CI builds [1] Asciidoctor complains about the above line like this:

asciidoctor: WARNING: MyFirstObjectWalk.txt: line 2: unterminated example block

I have no idea what it is trying to say, but I suspect that it complains about the length of that '=====' line not matching the length of the previous title line. I kicked off a build with the '====' line shortened, and it did silence that warning, and the build succeeded.

Note, however, that we recently had a patch [2] that argued that a different header notation is better, at least for the Git User Manual. I'm not sure whether that applies for this tutorial as well; just mentioning it for consideration.

[1] https://travis-ci.org/git/git/jobs/596474664#L1192
[2] fd5b820d9c (user-manual.txt: change header notation, 2019-09-22)

#100 lore raw

Re: [PATCH v5] documentation: add tutorial for object walking

Quoted 13 lines · SZEDER Gábor

Documentation/MyFirstObjectWalk.txt line 2

Quoted 8 lines · Emily Shaffer
Documentation/MyFirstObjectWalk.txt new file +2 -0
new file mode 100644
index 0000000000..7085f17072
@@ -0,0 +1,905 @@
+My First Object Walk
+======================

In our CI builds [1] Asciidoctor complains about the above line like this:

Quoted 7 lines

asciidoctor: WARNING: MyFirstObjectWalk.txt: line 2: unterminated example block

I have no idea what it is trying to say, but I suspect that it complains about the length of that '=====' line not matching the length of the previous title line. I kicked off a build with the '====' line shortened, and it did silence that warning, and the build succeeded.

Oh, I'm sure it's a consequence of changing it from "Revision" to "Object" in the title.

Quoted 5 lines

Note, however, that we recently had a patch [2] that argued that a different header notation is better, at least for the Git User Manual. I'm not sure whether that applies for this tutorial as well; just mentioning it for consideration.

Interesting read! It looks like we actually do use the format that that patch suggests is better, except for the title. I'll change the title to come into line with everything else, since I'm sending a reroll anyways.

Thanks!
- Emily

#101 lore raw

PATCH v6 1/1 documentation: add tutorial for object walking

In reply to Emily Shaffer

Existing documentation on object walks seems to be primarily intended as a reference for those already familiar with the procedure. This tutorial attempts to give an entry-level guide to a couple of bare-bones object walks so that new Git contributors can learn the concepts without having to wade through options parsing or special casing.

The target audience is a Git contributor who is just getting started with the concept of object walking. The goal is to prepare this contributor to be able to understand and modify existing commands which perform revision walks more easily, although it will also prepare contributors to create new commands which perform walks.

The tutorial covers a basic overview of the structs involved during object walk, setting up a basic commit walk, setting up a basic all-object walk, and adding some configuration changes to both walk types. It intentionally does not cover how to create new commands or search for options from the command line or gitconfigs.

There is an associated patchset at
https://github.com/nasamuffin/git/tree/revwalk that contains a reference implementation of the code generated by this tutorial.

---
Since v5 only a couple small changes:

The opening paragraph was reworked per Junio's comments to hopefully make more sense for this document's new life as an object walking tutorial (instead of a revision walking one).

The title formatting line was changed from "underlining" with === to being prepended with a single "=", to both silence a warning and match the headers through the rest of the document.

Thanks!
- Emily

 Documentation/Makefile              |   1 +
 Documentation/MyFirstObjectWalk.txt | 906 ++++++++++++++++++++++++++++
 2 files changed, 907 insertions(+)
 create mode 100644 Documentation/MyFirstObjectWalk.txt
Documentation/Makefile +1 -0
index 06d85ad958..8fe829cc1b 100644
@@ -77,6 +77,7 @@ API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technica
 SP_ARTICLES += $(API_DOCS)
 
 TECH_DOCS += MyFirstContribution
+TECH_DOCS += MyFirstObjectWalk
 TECH_DOCS += SubmittingPatches
 TECH_DOCS += technical/hash-function-transition
 TECH_DOCS += technical/http-protocol
Documentation/MyFirstObjectWalk.txt new file +906 -0

906 lines not on this page · raw message

Signature · 1 line
2.23.0.700.g56cf767bdb-goog