git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 2/2] Teach git-blame --gui how to start git-gui blame

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jun 21, 2007, 04:53 UTC
Message-ID
<20070621045333.GB13977@spearce.org>

Jakub Narebski proposed the idea of having a new --gui option for git-blame that would start `git gui blame` with the arguments that were given to git-blame on the command line. This actually makes a lot of sense, as some users may first reach for `git blame` and find the handy `--gui` option, rather than looking for the blame subcommand of `git gui`.

To keep things really simple in git-blame we require that the new --gui option be the first argument on the command line, and cannot be combined with any other option. If it is the first argument then we punt our entire command line as-is into `git gui blame`, where that program's option parser will handle selecting out the revision and path, if present.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 From Jakub Narebski <jnareb@gmail.com>:
 > or have "git blame --gui" invoke "git gui blame"
 Not a bad idea.  Here's an implementation that does that.
 Its simple and not very intrusive, but has the odd behavior that
 no option (like --contents) can be used along with it, because
 git-gui's own blame subcommand doesn't recognize them.  On the
 other hand it is a useful DWIMery for `git gui blame`.
 Documentation/git-blame.txt |    8 ++++++++
 builtin-blame.c             |   12 +++++++++++-
 2 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-blame.txt b/Documentation/git-blame.txt
index 66f1203..96ff02d 100644
--- a/Documentation/git-blame.txt
+++ b/Documentation/git-blame.txt
@@ -10,6 +10,7 @@ SYNOPSIS
 [verse]
 'git-blame' [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-p] [-w] [--incremental] [-L n,m]
             [-S <revs-file>] [-M] [-C] [-C] [--since=<date>]
+            [--gui]
             [<rev> | --contents <file>] [--] <file>
 
 DESCRIPTION
@@ -67,6 +68,13 @@ include::blame-options.txt[]
 	Ignore whitespace when comparing parent's version and
 	child's to find where the lines came from.
 
+--gui::
+	Instead of displaying the blame output on the text console,
+	start git-gui's graphical blame viewer.  This option must
+	be the first option supplied, and cannot be combined with
+	any other option described here, except the optional <rev>
+	and the required <file> arguments.
+
 
 THE PORCELAIN FORMAT
 --------------------
diff --git a/builtin-blame.c b/builtin-blame.c
index f7e2c13..2f50a4a 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -18,9 +18,10 @@
 #include "cache-tree.h"
 #include "path-list.h"
 #include "mailmap.h"
+#include "exec_cmd.h"
 
 static char blame_usage[] =
-"git-blame [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-p] [-w] [-L n,m] [-S <revs-file>] [-M] [-C] [-C] [--contents <filename>] [--incremental] [commit] [--] file\n"
+"git-blame [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-p] [-w] [-L n,m] [-S <revs-file>] [-M] [-C] [-C] [--contents <filename>] [--incremental] [--gui] [commit] [--] file\n"
 "  -c                  Use the same output mode as git-annotate (Default: off)\n"
 "  -b                  Show blank SHA-1 for boundary commits (Default: off)\n"
 "  -l                  Show long commit SHA1 (Default: off)\n"
@@ -34,6 +35,7 @@ static char blame_usage[] =
 "  -L n,m              Process only line range n,m, counting from 1\n"
 "  -M, -C              Find line movements within and across files\n"
 "  --incremental       Show blame entries as we find them, incrementally\n"
+"  --gui               Use git-gui's graphical blame viewer\n"
 "  --contents file     Use <file>'s contents as the final image\n"
 "  -S revs-file        Use revisions from revs-file instead of calling git-rev-list\n";
 
@@ -2137,6 +2139,12 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 	const char *contents_from = NULL;
 
 	cmd_is_annotate = !strcmp(argv[0], "annotate");
+	if (!cmd_is_annotate && argc > 1 && !strcmp(argv[1], "--gui")) {
+		argv[0] = "gui";
+		argv[1] = "blame";
+		execv_git_cmd(argv);
+		die("Cannot execute git-gui blame: %s", strerror(errno));
+	}
 
 	git_config(git_blame_config);
 	save_commit_buffer = 0;
@@ -2214,6 +2222,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 		else if (!strcmp("-p", arg) ||
 			 !strcmp("--porcelain", arg))
 			output_option |= OUTPUT_PORCELAIN;
+		else if (!strcmp("--gui", arg))
+			die("Cannot combine --gui with %s", argv[i - 1]);
 		else if (!strcmp("--", arg)) {
 			seen_dashdash = 1;
 			i++;
-- 
1.5.2.2.1050.g51a8b
Next: Junio C Hamano
Message 1 of 8 in “Teach git-blame --gui how to start git-gui blame”
  1. 2/2 Teach git-blame --gui how to start git-gui blameShawn O. Pearce, Jun 21, 2007
  2. Junio C HamanoJun 21, 2007
  3. Shawn O. PearceJun 22, 2007
  4. Junio C HamanoJun 22, 2007
  5. Shawn O. PearceJun 22, 2007
  6. Junio C HamanoJun 22, 2007
  7. Shawn O. PearceJun 22, 2007
  8. Johannes SixtJun 22, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.