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

[PATCH v2 15/19] builtins: utilize startup_info->help where possible

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 21, 2010, 10:30 UTC
Message-ID
<1269167446-7799-16-git-send-email-pclouds@gmail.com>
In-Reply-To
<1269167446-7799-1-git-send-email-pclouds@gmail.com>

It helps reduce false alarms while I'm looking for "git foo -h" code path that accesses repository. Anyway it looks like a good thing to do.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/check-ref-format.c |    2 +-
 builtin/grep.c             |    2 +-
 builtin/index-pack.c       |    2 +-
 builtin/log.c              |    7 ++-----
 builtin/merge-ours.c       |    2 +-
 builtin/pack-redundant.c   |    2 +-
 builtin/show-ref.c         |    2 +-
 7 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/builtin/check-ref-format.c b/builtin/check-ref-format.c
index b106c65..c13f90a 100644
--- a/builtin/check-ref-format.c
+++ b/builtin/check-ref-format.c
@@ -35,7 +35,7 @@ static void collapse_slashes(char *dst, const char *src)
 
 int cmd_check_ref_format(int argc, const char **argv, const char *prefix)
 {
-	if (argc == 2 && !strcmp(argv[1], "-h"))
+	if (startup_info->help)
 		usage(builtin_check_ref_format_usage);
 
 	if (argc == 3 && !strcmp(argv[1], "--branch")) {
diff --git a/builtin/grep.c b/builtin/grep.c
index fb82ff8..a7bdd7b 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -857,7 +857,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 	 * 'git grep -h', unlike 'git grep -h <pattern>', is a request
 	 * to show usage information and exit.
 	 */
-	if (argc == 2 && !strcmp(argv[1], "-h"))
+	if (startup_info->help)
 		usage_with_options(grep_usage, options);
 
 	memset(&opt, 0, sizeof(opt));
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 9aa6a13..44375a2 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -880,7 +880,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 	struct pack_idx_entry **idx_objects;
 	unsigned char pack_sha1[20];
 
-	if (argc == 2 && !strcmp(argv[1], "-h"))
+	if (startup_info->help)
 		usage(index_pack_usage);
 
 	/*
diff --git a/builtin/log.c b/builtin/log.c
index e0d5caa..382d4a3 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -50,12 +50,9 @@ 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"))
+	if (startup_info->help)
 		usage(builtin_log_usage);
+
 	argc = setup_revisions(argc, argv, rev, "HEAD");
 
 	if (!rev->show_notes_given && !rev->pretty_given)
diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c
index 6844116..8e0777b 100644
--- a/builtin/merge-ours.c
+++ b/builtin/merge-ours.c
@@ -20,7 +20,7 @@ static const char *diff_index_args[] = {
 
 int cmd_merge_ours(int argc, const char **argv, const char *prefix)
 {
-	if (argc == 2 && !strcmp(argv[1], "-h"))
+	if (startup_info->help)
 		usage(builtin_merge_ours_usage);
 
 	/*
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 41e1615..3f090b2 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -601,7 +601,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix)
 	unsigned char *sha1;
 	char buf[42]; /* 40 byte sha1 + \n + \0 */
 
-	if (argc == 2 && !strcmp(argv[1], "-h"))
+	if (startup_info->help)
 		usage(pack_redundant_usage);
 
 	for (i = 1; i < argc; i++) {
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 17ada88..59f90df 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -204,7 +204,7 @@ static const struct option show_ref_options[] = {
 
 int cmd_show_ref(int argc, const char **argv, const char *prefix)
 {
-	if (argc == 2 && !strcmp(argv[1], "-h"))
+	if (startup_info->help)
 		usage_with_options(show_ref_usage, show_ref_options);
 
 	argc = parse_options(argc, argv, prefix, show_ref_options,
-- 
1.7.0.2.425.gb99f1
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 16 of 20 in “nd/setup part two, second round”
  1. 00/19 nd/setup part two, second roundNguyễn Thái Ngọc Duy, Mar 21, 2010
  2. 01/19 Move enter_repo() to setup.cNguyễn Thái Ngọc Duy, Mar 21, 2010
  3. 02/19 enter_repo(): initialize other variables as setup_git_directory_gently() doesNguyễn Thái Ngọc Duy, Mar 21, 2010
  4. 03/19 rev-parse --git-dir: print relative gitdir correctlyNguyễn Thái Ngọc Duy, Mar 21, 2010
  5. 04/19 worktree setup: call set_git_dir explicitlyNguyễn Thái Ngọc Duy, Mar 21, 2010
  6. 05/19 Add git_config_early()Nguyễn Thái Ngọc Duy, Mar 21, 2010
  7. 06/19 Use git_config_early() instead of git_config() during repo setupNguyễn Thái Ngọc Duy, Mar 21, 2010
  8. 07/19 worktree setup: restore original state when things go wrongNguyễn Thái Ngọc Duy, Mar 21, 2010
  9. 08/19 init/clone: turn on startup->have_repository properlyNguyễn Thái Ngọc Duy, Mar 21, 2010
  10. 09/19 git_config(): do not read .git/config if there is no repositoryNguyễn Thái Ngọc Duy, Mar 21, 2010
  11. 10/19 Do not read .git/info/exclude if there is no repositoryNguyễn Thái Ngọc Duy, Mar 21, 2010
  12. 11/19 Do not read .git/info/attributes if there is no repositoryNguyễn Thái Ngọc Duy, Mar 21, 2010
  13. 12/19 apply: do not check sha1 when repository has not been foundNguyễn Thái Ngọc Duy, Mar 21, 2010
  14. 13/19 config: do not read .git/config if there is no repositoryNguyễn Thái Ngọc Duy, Mar 21, 2010
  15. 14/19 run_builtin(): save "-h" detection result for later useNguyễn Thái Ngọc Duy, Mar 21, 2010
  16. 15/19 builtins: utilize startup_info->help where possibleNguyễn Thái Ngọc Duy, Mar 21, 2010
  17. 16/19 builtins: check for startup_info->help, print and exit earlyNguyễn Thái Ngọc Duy, Mar 21, 2010
  18. 17/19 Allow to undo setup_git_directory_gently() gracefully (and fix alias code)Nguyễn Thái Ngọc Duy, Mar 21, 2010
  19. 18/19 alias: keep repository found while collecting aliases as long as possibleNguyễn Thái Ngọc Duy, Mar 21, 2010
  20. 19/19 Guard unallowed access to repository when it's not set upNguyễn Thái Ngọc Duy, Mar 21, 2010

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.