Teach git-blame --gui how to start git-gui blame
RFC PATCH 2/2 Teach git-blame --gui how to start git-gui blame
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.
---
From Jakub Narebski <[email protected]>:
Quoted 1 line
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(-)
Documentation/git-blame.txt +8 -0
@@ -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 --------------------
builtin-blame.c +11 -1
@@ -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++;
Signature · 1 line
1.5.2.2.1050.g51a8b
Quoted 11 lines · Shawn O. Pearce
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.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.
Hmm. Now, how does "git-blame" tell if there is usable git-gui installed with it? Will we have "git-gui --list-features"?
In either case, I think this description is far less than optimum:
Documentation/git-blame.txt SYNOPSIS · line 14
Quoted 10 lines
Documentation/git-blame.txt +1
-0@@ -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>
It essentially is two commands with different calling conventions. I would probably do this instead if I were doing this:
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>]
[<rev> | --contents <file>] [--] <file>'git-blame' --gui [<rev>] [--] <file>
Quoted 2 lines · Junio C Hamano
Hmm. Now, how does "git-blame" tell if there is usable git-gui installed with it? Will we have "git-gui --list-features"?
It can run git gui version and check to see that it is >= 0.7.3.
;-)
I'm actually not sure we want to apply this patch, hence the RFC prefix I put on it. Jakub suggested it, this crude implementation was easy enough to hack together, so I posted a patch for someone to play with if they were so inclined.
Maybe we should just put a link in the git-blame manual page to the git-gui manual page:
Documentation/git-blame.txt +5 -1
@@ -36,6 +36,9 @@ $ git log --pretty=oneline -S'blame_usage' ea4c7f9bf69e781dd0cd88d2bccb2bf5cc15c9a7 git-blame: Make the output ----------------------------------------------------------------------------- +A powerful graphical viewer for the output of git-blame can be +accessed through the blame subcommand of gitlink:git-gui[1]. + OPTIONS ------- include::blame-options.txt[]
@@ -184,7 +187,8 @@ commit commentary), a blame viewer won't ever care. SEE ALSO -------- -gitlink:git-annotate[1] +gitlink:git-annotate[1], +gitlink:git-gui[1] AUTHOR ------
Signature · 1 line
Shawn.
Quoted 5 lines · Shawn O. Pearce
Quoted 2 lines · Junio C Hamano
Hmm. Now, how does "git-blame" tell if there is usable git-gui installed with it? Will we have "git-gui --list-features"?
It can run
git gui versionand check to see that it is >= 0.7.3.
This is only minor nuisance, but can we do something about this?
$ git gui --version Application initialization failed: no display name and no $DISPLAY environment variable
I know it is from wish, not you, so I wouldn't insist, though.
Quoted 6 lines · Junio C Hamano
This is only minor nuisance, but can we do something about this?
$ git gui --version Application initialization failed: no display name and no $DISPLAY environment variableI know it is from wish, not you, so I wouldn't insist, though.
Actually that should be fixable.
Should be as simple as using a Bourne shell script up front to check for "z$1" = zversion || "z$1" = z--version, and if so dump back the version, otherwise exec wish. This is actually quite easy and won't change things for existing users. I'll put a patch into maint tonight for it.
Signature · 1 line
Shawn.
Quoted 8 lines · Shawn O. Pearce
Quoted 6 lines · Junio C Hamano
This is only minor nuisance, but can we do something about this?
$ git gui --version Application initialization failed: no display name and no $DISPLAY environment variableI know it is from wish, not you, so I wouldn't insist, though.
Quoted 7 lines
Actually that should be fixable.
Should be as simple as using a Bourne shell script up front to check for "z$1" = zversion || "z$1" = z--version, and if so dump back the version, otherwise exec wish. This is actually quite easy and won't change things for existing users. I'll put a patch into maint tonight for it.
If this makes life any harder to people on Windows, especially minGW, I would suggest against it.
Quoted 11 lines · Junio C Hamano
Quoted 7 lines · Shawn O. Pearce
Quoted 6 lines · Junio C Hamano
This is only minor nuisance, but can we do something about this?
$ git gui --version Application initialization failed: no display name and no $DISPLAY environment variableI know it is from wish, not you, so I wouldn't insist, though.
If this makes life any harder to people on Windows, especially minGW, I would suggest against it.
Its already done. I don't think it will make a difference either way right now.
Currently we still have to have a Bourne shell on both Cygwin and MINGW platforms to perform key actions, like say git-clone. The startup cost of git-gui is also rather high there anyway, so this extra if test in Bourne shell before we exec into Tcl isn't going to kill us.
Besides, you can side-step the entire Bourne shell thing by just starting git-gui in wish yourself. E.g.
CALL /path/to/wish.exe /path/to/git-gui -- ...
I'd like to come back and make git-gui easier to install, perhaps by making "starpacks" of git-gui and Git plumbing available for some popular systems (e.g. MINGW/Windows, Mac OS X). Such starpacks would give users an easy way to get git-gui (and thus basic Git) up and running quickly. At that point I will need to revisit this bootstrap code anyway.
Signature · 1 line
Shawn.
Quoted 13 lines · Junio C Hamano
Quoted 10 lines · Shawn O. Pearce
Quoted 6 lines · Junio C Hamano
This is only minor nuisance, but can we do something about this?
$ git gui --version Application initialization failed: no display name and no $DISPLAY environment variableI know it is from wish, not you, so I wouldn't insist, though.
Actually that should be fixable.
Quoted 8 lines
Quoted 5 lines
Should be as simple as using a Bourne shell script up front to check for "z$1" = zversion || "z$1" = z--version, and if so dump back the version, otherwise exec wish. This is actually quite easy and won't change things for existing users. I'll put a patch into maint tonight for it.
If this makes life any harder to people on Windows, especially minGW, I would suggest against it.
The MinGW port's exec wrapper looks at the shbang line and runs the shell. Hence, invocation as
git gui --version
will work even from CMD.EXE. But
git-gui --version
will only work from MSYS's rxvt.
-- Hannes