git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 21/24] Let 'git <command> -h' show usage without a git dir
Date: Mon,  9 Nov 2009 09:05:01 -0600	[thread overview]
Message-ID: <1257779104-23884-21-git-send-email-jrnieder@gmail.com> (raw)
In-Reply-To: <20091109150235.GA23871@progeny.tock>

There is no need for "git <command> -h" to depend on being inside
a repository.

Reported by Gerfried Fuchs through http://bugs.debian.org/462557

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 builtin-log.c       |    6 ++++++
 builtin-mv.c        |    8 ++++----
 builtin-read-tree.c |    4 ++--
 builtin-reflog.c    |    3 +++
 builtin-rerere.c    |    3 +++
 git.c               |   21 ++++++++++++---------
 index-pack.c        |    3 +++
 pack-redundant.c    |    3 +++
 8 files changed, 36 insertions(+), 15 deletions(-)

diff --git a/builtin-log.c b/builtin-log.c
index 5248507..a0fa30c 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -50,6 +50,12 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
 	if (default_date_mode)
 		rev->date_mode = parse_date_format(default_date_mode);
 
+	/*
+	 * Check for -h before setup_revisions(), or "git log -h" will
+	 * fail when run without a git directory.
+	 */
+	if (argc == 2 && !strcmp(argv[1], "-h"))
+		usage(builtin_log_usage);
 	argc = setup_revisions(argc, argv, rev, "HEAD");
 
 	if (rev->diffopt.pickaxe || rev->diffopt.filter)
diff --git a/builtin-mv.c b/builtin-mv.c
index 1b20028..f633d81 100644
--- a/builtin-mv.c
+++ b/builtin-mv.c
@@ -64,15 +64,15 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 
 	git_config(git_default_config, NULL);
 
-	newfd = hold_locked_index(&lock_file, 1);
-	if (read_cache() < 0)
-		die("index file corrupt");
-
 	argc = parse_options(argc, argv, prefix, builtin_mv_options,
 			     builtin_mv_usage, 0);
 	if (--argc < 1)
 		usage_with_options(builtin_mv_usage, builtin_mv_options);
 
+	newfd = hold_locked_index(&lock_file, 1);
+	if (read_cache() < 0)
+		die("index file corrupt");
+
 	source = copy_pathspec(prefix, argv, argc, 0);
 	modes = xcalloc(argc, sizeof(enum update_mode));
 	dest_path = copy_pathspec(prefix, argv + argc, 1, 0);
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 14c836b..2a3a32c 100644
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
@@ -108,11 +108,11 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 
 	git_config(git_default_config, NULL);
 
-	newfd = hold_locked_index(&lock_file, 1);
-
 	argc = parse_options(argc, argv, unused_prefix, read_tree_options,
 			     read_tree_usage, 0);
 
+	newfd = hold_locked_index(&lock_file, 1);
+
 	prefix_set = opts.prefix ? 1 : 0;
 	if (1 < opts.merge + opts.reset + prefix_set)
 		die("Which one? -m, --reset, or --prefix?");
diff --git a/builtin-reflog.c b/builtin-reflog.c
index e23b5ef..7498210 100644
--- a/builtin-reflog.c
+++ b/builtin-reflog.c
@@ -698,6 +698,9 @@ static const char reflog_usage[] =
 
 int cmd_reflog(int argc, const char **argv, const char *prefix)
 {
+	if (argc > 1 && !strcmp(argv[1], "-h"))
+		usage(reflog_usage);
+
 	/* With no command, we default to showing it. */
 	if (argc < 2 || *argv[1] == '-')
 		return cmd_log_reflog(argc, argv, prefix);
diff --git a/builtin-rerere.c b/builtin-rerere.c
index adfb7b5..343d6cd 100644
--- a/builtin-rerere.c
+++ b/builtin-rerere.c
@@ -106,6 +106,9 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
 	if (argc < 2)
 		return rerere();
 
+	if (!strcmp(argv[1], "-h"))
+		usage(git_rerere_usage);
+
 	fd = setup_rerere(&merge_rr);
 	if (fd < 0)
 		return 0;
diff --git a/git.c b/git.c
index f295561..743ee57 100644
--- a/git.c
+++ b/git.c
@@ -229,21 +229,24 @@ struct cmd_struct {
 
 static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 {
-	int status;
+	int status, help;
 	struct stat st;
 	const char *prefix;
 
 	prefix = NULL;
-	if (p->option & RUN_SETUP)
-		prefix = setup_git_directory();
-
-	if (use_pager == -1 && p->option & RUN_SETUP)
-		use_pager = check_pager_config(p->cmd);
-	if (use_pager == -1 && p->option & USE_PAGER)
-		use_pager = 1;
+	help = argc == 2 && !strcmp(argv[1], "-h");
+	if (!help) {
+		if (p->option & RUN_SETUP)
+			prefix = setup_git_directory();
+
+		if (use_pager == -1 && p->option & RUN_SETUP)
+			use_pager = check_pager_config(p->cmd);
+		if (use_pager == -1 && p->option & USE_PAGER)
+			use_pager = 1;
+	}
 	commit_pager_choice();
 
-	if (p->option & NEED_WORK_TREE)
+	if (!help && p->option & NEED_WORK_TREE)
 		setup_work_tree();
 
 	trace_argv_printf(argv, "trace: built-in: git");
diff --git a/index-pack.c b/index-pack.c
index b4f8278..190f372 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -882,6 +882,9 @@ int main(int argc, char **argv)
 
 	git_extract_argv0_path(argv[0]);
 
+	if (argc == 2 && !strcmp(argv[1], "-h"))
+		usage(index_pack_usage);
+
 	/*
 	 * We wish to read the repository's config file if any, and
 	 * for that it is necessary to call setup_git_directory_gently().
diff --git a/pack-redundant.c b/pack-redundant.c
index 69a7ab2..21c61db 100644
--- a/pack-redundant.c
+++ b/pack-redundant.c
@@ -603,6 +603,9 @@ int main(int argc, char **argv)
 
 	git_extract_argv0_path(argv[0]);
 
+	if (argc == 2 && !strcmp(argv[1], "-h"))
+		usage(pack_redundant_usage);
+
 	setup_git_directory();
 
 	for (i = 1; i < argc; i++) {
-- 
1.6.5.2

  parent reply	other threads:[~2009-11-09 14:56 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20080125173149.GA10287@edna.gwendoline.at>
2009-11-08  7:11 ` [PATCH] Let 'git <command> -h' show usage without a git dir Jonathan Nieder
2009-11-08  7:26   ` [PATCH] Show usage string for 'git http-push -h' Jonathan Nieder
2009-11-09  8:52     ` Tay Ray Chuan
2009-11-09 10:47       ` [PATCH v2] " Jonathan Nieder
2009-11-09 13:56         ` Tay Ray Chuan
2009-11-08  9:21   ` [PATCH] Let 'git <command> -h' show usage without a git dir Junio C Hamano
2009-11-08 11:03     ` Jonathan Nieder
2009-11-09 15:02       ` [PATCH 00/24] " Jonathan Nieder
2009-11-09 15:04         ` [PATCH 01/24] Retire fetch--tool helper to contrib/examples Jonathan Nieder
2009-11-09 15:04         ` [PATCH 02/24] Show usage string for 'git grep -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH 03/24] Show usage string for 'git cherry -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH 04/24] Show usage string for 'git commit-tree -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH 05/24] Show usage string for 'git merge-ours -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH/RFC 06/24] Show usage string for 'git show-ref -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH 07/24] check-ref-format: update usage string Jonathan Nieder
2009-11-10 20:11           ` Junio C Hamano
2009-11-09 15:04         ` [PATCH 08/24] Show usage string for 'git check-ref-format -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH 09/24] Show usage string for 'git fast-import -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH 10/24] Show usage string for 'git get-tar-commit-id -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH 11/24] Show usage string for 'git imap-send -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH 12/24] Show usage string for 'git mailsplit -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH 13/24] Show usage string for 'git merge-one-file -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH 14/24] Show usage string for 'git rev-parse -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH 15/24] Show usage string for 'git show-index -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH 16/24] Show usage string for 'git unpack-file -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH 17/24] Show usage string for 'git stripspace -h' Jonathan Nieder
2009-11-09 15:04         ` [PATCH 18/24] merge: do not setup worktree twice Jonathan Nieder
2009-11-10 20:11           ` Junio C Hamano
2009-11-11  1:58             ` Jonathan Nieder
2009-11-09 15:04         ` [PATCH 19/24] Let 'git http-fetch -h' show usage outside any git repository Jonathan Nieder
2009-11-09 15:05         ` [PATCH 20/24] http-fetch: add missing initialization of argv0_path Jonathan Nieder
2009-11-10 20:12           ` Junio C Hamano
2009-11-10 21:56             ` Johannes Sixt
2009-11-11  1:52             ` Jonathan Nieder
2009-11-09 15:05         ` Jonathan Nieder [this message]
2009-11-09 15:05         ` [PATCH 22/24] Let usage() take a printf-style format Jonathan Nieder
2009-11-10 20:16           ` Junio C Hamano
2009-11-09 15:05         ` [PATCH 23/24] merge-{recursive,subtree}: use usage() to print usage Jonathan Nieder
2009-11-09 15:05         ` [PATCH 24/24] diff --no-index: make the usage string less scary Jonathan Nieder

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=1257779104-23884-21-git-send-email-jrnieder@gmail.com \
    --to=jrnieder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).