Re: [PATCH v3 2/4] log: add a --no-graph option

2 messages, 2 authors, 2022-02-11 · open the first message on its own page

Re: [PATCH v3 2/4] log: add a --no-graph option

From: Junio C Hamano <hidden>
Date: 2022-02-11 19:02:19

Alex Henrie [off-list ref] writes:
quoted hunk
It's useful to be able to countermand a previous --graph option, for
example if `git log --graph` is run via an alias.

Signed-off-by: Alex Henrie <redacted>
---
v3: don't pass a regular expression with parentheses to grep, so that
the tests pass in all configurations on GitHub
---
 builtin/blame.c    |  1 +
 builtin/shortlog.c |  1 +
 revision.c         | 19 ++++++++++---
 revision.h         |  1 +
 t/t4202-log.sh     | 69 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 87 insertions(+), 4 deletions(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index 7fafeac408..ef831de5ac 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -934,6 +934,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 		parse_revision_opt(&revs, &ctx, options, blame_opt_usage);
 	}
 parse_done:
+	revision_opts_finish(&revs);
This ...
quoted hunk
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index e7f7af5de3..228d782754 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -388,6 +388,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
 		parse_revision_opt(&rev, &ctx, options, shortlog_usage);
 	}
 parse_done:
+	revision_opts_finish(&rev);
 	argc = parse_options_end(&ctx);
 
 	if (nongit && argc > 1) {
... and this.  It is a bit scary that we have to make sure all the
users of parse_revision_opt() users need to call this new helper.
Didn't we recently gain new documentation to help novices write
their first revision-traversal-API-using program?  Does it need to
be updated for this change (I didn't check)?
quoted hunk
diff --git a/revision.c b/revision.c
index 816061f3d9..a39fd1c278 100644
--- a/revision.c
+++ b/revision.c
@@ -2424,10 +2424,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		revs->pretty_given = 1;
 		revs->abbrev_commit = 1;
 	} else if (!strcmp(arg, "--graph")) {
-		revs->topo_order = 1;
-		revs->rewrite_parents = 1;
 		graph_clear(revs->graph);
 		revs->graph = graph_init(revs);
+	} else if (!strcmp(arg, "--no-graph")) {
+		graph_clear(revs->graph);
+		revs->graph = NULL;
 	} else if (!strcmp(arg, "--encode-email-headers")) {
 		revs->encode_email_headers = 1;
 	} else if (!strcmp(arg, "--no-encode-email-headers")) {
@@ -2524,8 +2525,6 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 			unkv[(*unkc)++] = arg;
 		return opts;
 	}
-	if (revs->graph && revs->track_linear)
-		die(_("options '%s' and '%s' cannot be used together"), "--show-linear-break", "--graph");
 
 	return 1;
 }
As a later "--no" can clear an earlier "--graph", we cannot
incrementally check if options are compatible, until the end, at
which time we can be sure that "--graph" is being asked.
+void revision_opts_finish(struct rev_info *revs)
+{
+	if (revs->graph && revs->track_linear)
+		die(_("options '%s' and '%s' cannot be used together"), "--show-linear-break", "--graph");
Inherited from the original, but we may want to wrap this line.
+	if (revs->graph) {
+		revs->topo_order = 1;
+		revs->rewrite_parents = 1;
+	}
+}
+
OK.
quoted hunk
@@ -2786,6 +2796,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 			break;
 		}
 	}
+	revision_opts_finish(revs);
OK.

Will queue.  Thanks.

Re: [PATCH v3 2/4] log: add a --no-graph option

From: Alex Henrie <hidden>
Date: 2022-02-11 19:21:00

On Fri, Feb 11, 2022 at 12:02 PM Junio C Hamano [off-list ref] wrote:
Alex Henrie [off-list ref] writes:
quoted
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -934,6 +934,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
              parse_revision_opt(&revs, &ctx, options, blame_opt_usage);
      }
 parse_done:
+     revision_opts_finish(&revs);
This ...
quoted
diff --git a/builtin/shortlog.c b/builtin/shortlog.c
index e7f7af5de3..228d782754 100644
--- a/builtin/shortlog.c
+++ b/builtin/shortlog.c
@@ -388,6 +388,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
              parse_revision_opt(&rev, &ctx, options, shortlog_usage);
      }
 parse_done:
+     revision_opts_finish(&rev);
      argc = parse_options_end(&ctx);

      if (nongit && argc > 1) {
... and this.  It is a bit scary that we have to make sure all the
users of parse_revision_opt() users need to call this new helper.
Didn't we recently gain new documentation to help novices write
their first revision-traversal-API-using program?  Does it need to
be updated for this change (I didn't check)?
I don't see any documentation on how to use parse_revision_opt
directly; I only see documentation on how to use setup_revisions,
whose interface did not change.

Another approach would be to make a parse_rev_options_step function
that wraps parse_options_step and does the final steps when
parse_options_step returns PARSE_OPT_DONE. Would that be better?
quoted
diff --git a/revision.c b/revision.c
index 816061f3d9..a39fd1c278 100644
--- a/revision.c
+++ b/revision.c
@@ -2424,10 +2424,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
              revs->pretty_given = 1;
              revs->abbrev_commit = 1;
      } else if (!strcmp(arg, "--graph")) {
-             revs->topo_order = 1;
-             revs->rewrite_parents = 1;
              graph_clear(revs->graph);
              revs->graph = graph_init(revs);
+     } else if (!strcmp(arg, "--no-graph")) {
+             graph_clear(revs->graph);
+             revs->graph = NULL;
      } else if (!strcmp(arg, "--encode-email-headers")) {
              revs->encode_email_headers = 1;
      } else if (!strcmp(arg, "--no-encode-email-headers")) {
@@ -2524,8 +2525,6 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                      unkv[(*unkc)++] = arg;
              return opts;
      }
-     if (revs->graph && revs->track_linear)
-             die(_("options '%s' and '%s' cannot be used together"), "--show-linear-break", "--graph");

      return 1;
 }
As a later "--no" can clear an earlier "--graph", we cannot
incrementally check if options are compatible, until the end, at
which time we can be sure that "--graph" is being asked.
Exactly. This is intentional, to avoid erroring out unnecessarily.

-Alex
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help