diff mbox series

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

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

Commit Message

Emily Shaffer June 26, 2019, 11:50 p.m. UTC
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.

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

Comments

Eric Sunshine June 27, 2019, 5:20 a.m. UTC | #1
On Wed, Jun 26, 2019 at 7:51 PM Emily Shaffer <emilyshaffer@google.com> wrote:
> 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.
> [...]
> Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
> ---
> diff --git a/builtin/walken.c b/builtin/walken.c
> @@ -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. */

> +       append_header_grep_pattern(&rev->grep_filter, GREP_HEADER_AUTHOR, "gmail");
> +       compile_grep_patterns(&rev->grep_filter);
Emily Shaffer June 27, 2019, 8:58 p.m. UTC | #2
On Thu, Jun 27, 2019 at 01:20:25AM -0400, Eric Sunshine wrote:
> On Wed, Jun 26, 2019 at 7:51 PM Emily Shaffer <emilyshaffer@google.com> wrote:
> > 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.
> > [...]
> > Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
> > ---
> > diff --git a/builtin/walken.c b/builtin/walken.c
> > @@ -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. */
> 

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

> > +       append_header_grep_pattern(&rev->grep_filter, GREP_HEADER_AUTHOR, "gmail");
> > +       compile_grep_patterns(&rev->grep_filter);
diff mbox series

Patch

diff --git a/builtin/walken.c b/builtin/walken.c
index 335dcb6b21..da2d197914 100644
--- a/builtin/walken.c
+++ b/builtin/walken.c
@@ -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);
 }