From: Jonathan Nieder <jrnieder@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Ben Walton <bwalton@artsci.utoronto.ca>,
Johannes Sixt <j.sixt@viscovery.net>,
David Roundy <roundyd@physics.oregonstate.edu>,
GIT List <git@vger.kernel.org>
Subject: [PATCH/RFC 9/8] Teach git var to run the editor
Date: Fri, 30 Oct 2009 05:49:58 -0500 [thread overview]
Message-ID: <20091030104958.GJ1610@progeny.tock> (raw)
In-Reply-To: <20091030101634.GA1610@progeny.tock>
Expose the functionality of launch_editor() for scripts to use.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
As I mentioned in the cover letter, the analogous change for the pager
is a little more tricky. I was wrong to blame Windows for this. The
excellent commit ea27a18 (spawn pager via run_command interface,
2008-07-22) explains all.
The difficulties: the pager receives input from the current process
and the run_pager() function does not take an argument to take input
from somewhere else. Also the pager is not exec()'d directly, so the
current process sticks around uselessly until it quits and it is a
little tricky to find the 'less' exit status for "git var --run" to
use as well.
Documentation/git-var.txt | 10 ++++++++-
var.c | 48 +++++++++++++++++++++++++++++++++++++-------
2 files changed, 49 insertions(+), 9 deletions(-)
diff --git a/Documentation/git-var.txt b/Documentation/git-var.txt
index ef6aa81..1bfdb6c 100644
--- a/Documentation/git-var.txt
+++ b/Documentation/git-var.txt
@@ -8,7 +8,10 @@ git-var - Show a git logical variable
SYNOPSIS
--------
-'git var' [ -l | <variable> ]
+[verse]
+'git var' <variable>
+'git var' -l
+'git var' --run <variable> [ args ]
DESCRIPTION
-----------
@@ -22,6 +25,11 @@ OPTIONS
as well. (However, the configuration variables listing functionality
is deprecated in favor of 'git config -l'.)
+--run variable [args]::
+ If the specified logical variable represents a command, run that
+ command. For example, `git var --run GIT_EDITOR foo.txt` edits
+ foo.txt with the text editor git is configured to use.
+
EXAMPLE
--------
$ git var GIT_AUTHOR_IDENT
diff --git a/var.c b/var.c
index 18dad57..c97b2e6 100644
--- a/var.c
+++ b/var.c
@@ -6,7 +6,8 @@
#include "cache.h"
#include "exec_cmd.h"
-static const char var_usage[] = "git var [-l | <variable>]";
+static const char var_usage[] =
+ "git var { -l | <variable> | --run <variable> [args] }";
static const char *editor(int flag)
{
@@ -26,16 +27,25 @@ static const char *pager(int flag)
return pgm;
}
+static int run_editor(int argc, const char *const *argv)
+{
+ if (argc > 1)
+ return error("cannot launch editor with more than one file");
+
+ return launch_editor(argv[0], NULL, NULL);
+}
+
struct git_var {
const char *name;
const char *(*read)(int);
+ int (*run)(int argc, const char *const *argv);
};
static struct git_var git_vars[] = {
- { "GIT_COMMITTER_IDENT", git_committer_info },
- { "GIT_AUTHOR_IDENT", git_author_info },
- { "GIT_EDITOR", editor },
- { "GIT_PAGER", pager },
- { "", NULL },
+ { "GIT_COMMITTER_IDENT", git_committer_info, NULL },
+ { "GIT_AUTHOR_IDENT", git_author_info, NULL },
+ { "GIT_EDITOR", editor, run_editor },
+ { "GIT_PAGER", pager, NULL },
+ { "", NULL, NULL },
};
static void list_vars(void)
@@ -59,6 +69,17 @@ static const char *read_var(const char *var)
return val;
}
+static int run_var_cmd(const char *var, int argc, char **argv)
+{
+ struct git_var *ptr;
+
+ for (ptr = git_vars; ptr->read; ptr++)
+ if (ptr->run && strcmp(var, ptr->name) == 0)
+ return ptr->run(argc, (const char *const *)argv);
+
+ return error("%s is not a variable command", var);
+}
+
static int show_config(const char *var, const char *value, void *cb)
{
if (value)
@@ -72,12 +93,23 @@ int main(int argc, char **argv)
{
const char *val;
int nongit;
+
+ git_extract_argv0_path(argv[0]);
+
+ if (argv[1] && strcmp(argv[1], "--run") == 0) {
+ if (argc <= 2)
+ usage(var_usage);
+
+ setup_git_directory_gently(&nongit);
+ git_config(git_default_config, NULL);
+
+ return run_var_cmd(argv[2], argc - 3, argv + 3);
+ }
+
if (argc != 2) {
usage(var_usage);
}
- git_extract_argv0_path(argv[0]);
-
setup_git_directory_gently(&nongit);
val = NULL;
--
1.6.5.2
next prev parent reply other threads:[~2009-10-30 10:39 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-28 15:21 packaging vs default pager Ben Walton
2009-10-28 17:55 ` Junio C Hamano
2009-10-29 7:32 ` [PATCH 0/2] " Jonathan Nieder
2009-10-29 7:45 ` [PATCH 1/2] Provide a build time default-pager setting Jonathan Nieder
2009-10-29 7:50 ` [PATCH/RFC 2/2] Provide a build time default-editor setting Jonathan Nieder
2009-10-29 10:36 ` David Roundy
2009-10-29 11:50 ` Johannes Sixt
2009-10-29 20:40 ` Junio C Hamano
2009-10-29 20:57 ` Johannes Sixt
2009-10-29 22:12 ` Junio C Hamano
2009-10-30 2:21 ` David Roundy
2009-10-29 20:43 ` Junio C Hamano
2009-10-30 10:16 ` [PATCH v2 0/8] Default pager and editor Jonathan Nieder
2009-10-30 10:20 ` [PATCH 1/8] launch_editor: Longer error message when TERM=dumb Jonathan Nieder
2009-10-30 10:25 ` [PATCH 2/8] Handle more shell metacharacters in editor names Jonathan Nieder
2009-10-30 10:26 ` [PATCH 3/8] Teach git var about GIT_EDITOR Jonathan Nieder
2009-10-30 20:51 ` Johannes Sixt
2009-10-30 22:47 ` Jonathan Nieder
2009-10-30 22:43 ` Junio C Hamano
2009-10-31 0:01 ` Jonathan Nieder
2009-10-30 10:29 ` [PATCH 4/8] Teach git var about GIT_PAGER Jonathan Nieder
2009-10-30 10:32 ` [PATCH 5/8] add -i, send-email, svn, p4, etc: use "git var GIT_EDITOR" Jonathan Nieder
2009-10-30 10:33 ` [PATCH 6/8] am -i, git-svn: use "git var GIT_PAGER" Jonathan Nieder
2009-10-30 10:35 ` [PATCH 7/8] Provide a build time default-editor setting Jonathan Nieder
2009-10-30 13:17 ` Jonathan Nieder
2009-10-30 10:39 ` [PATCH 8/8] Provide a build time default-pager setting Jonathan Nieder
2009-10-30 22:59 ` Junio C Hamano
2009-10-30 10:49 ` Jonathan Nieder [this message]
2009-10-31 1:20 ` [PATCH v3 0/8] Default pager and editor Jonathan Nieder
2009-10-31 1:24 ` [PATCH 1/8] Handle more shell metacharacters in editor names Jonathan Nieder
2009-10-31 1:30 ` [PATCH 2/8] Do not use VISUAL editor on dumb terminals Jonathan Nieder
2009-10-31 7:46 ` [PATCH v2 " Jonathan Nieder
2009-10-31 1:39 ` [PATCH v2 3/8] Teach git var about GIT_EDITOR Jonathan Nieder
2009-10-31 2:01 ` Junio C Hamano
2009-10-31 2:23 ` Jonathan Nieder
2009-10-31 2:34 ` Junio C Hamano
2009-10-31 4:00 ` Jonathan Nieder
2009-10-31 4:04 ` [PATCH v3] " Jonathan Nieder
2009-10-31 4:53 ` Jonathan Nieder
2009-10-31 7:56 ` [PATCH v4] " Jonathan Nieder
2009-11-01 4:29 ` Junio C Hamano
2009-10-31 19:40 ` [PATCH v2 3/8] " Johannes Sixt
2009-10-31 1:41 ` [PATCH 4/8] Teach git var about GIT_PAGER Jonathan Nieder
2009-10-31 1:42 ` [PATCH 5/8] add -i, send-email, svn, p4, etc: use "git var GIT_EDITOR" Jonathan Nieder
2009-10-31 1:43 ` [PATCH 6/8] am -i, git-svn: use "git var GIT_PAGER" Jonathan Nieder
2009-10-31 1:44 ` [PATCH 7/8] Provide a build time default-editor setting Jonathan Nieder
2009-10-31 2:09 ` Junio C Hamano
2009-10-31 3:26 ` Jonathan Nieder
2009-10-31 19:51 ` Junio C Hamano
2009-10-31 21:21 ` Jonathan Nieder
2009-11-01 4:29 ` Junio C Hamano
2009-10-31 1:45 ` [PATCH 8/8] Provide a build time default-pager setting Jonathan Nieder
2009-11-11 23:51 ` [PATCH v4 0/9] Default pager and editor Jonathan Nieder
2009-11-11 23:52 ` [PATCH 1/9] Handle more shell metacharacters in editor names Jonathan Nieder
2009-11-11 23:56 ` [PATCH 2/9] Do not use VISUAL editor on dumb terminals Jonathan Nieder
2009-11-11 23:57 ` [PATCH 3/9] Suppress warnings from "git var -l" Jonathan Nieder
2009-11-12 0:01 ` [PATCH 4/9] Teach git var about GIT_EDITOR Jonathan Nieder
2009-11-12 0:02 ` [PATCH 5/9] Teach git var about GIT_PAGER Jonathan Nieder
2009-11-12 0:02 ` [PATCH 6/9] add -i, send-email, svn, p4, etc: use "git var GIT_EDITOR" Jonathan Nieder
2009-11-12 0:03 ` [PATCH 7/9] am -i, git-svn: use "git var GIT_PAGER" Jonathan Nieder
2009-11-12 0:03 ` [PATCH 8/9] Provide a build time default-editor setting Jonathan Nieder
2009-11-12 0:04 ` [PATCH 9/9] Provide a build time default-pager setting Jonathan Nieder
2009-11-15 9:04 ` [PATCH v4 0/9] Default pager and editor Junio C Hamano
2009-10-29 16:42 ` [PATCH 0/2] Default Pager and Editor at build-time Ben Walton
2009-10-29 16:42 ` [PATCH 1/2] Provide a build time default-pager setting Ben Walton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20091030104958.GJ1610@progeny.tock \
--to=jrnieder@gmail.com \
--cc=bwalton@artsci.utoronto.ca \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j.sixt@viscovery.net \
--cc=roundyd@physics.oregonstate.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).