Retire fetch--tool helper to contrib/examples
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 Let 'git <command> -h' show usage without a git dir
Hi,
Quoted 11 lines · Gerfried Fuchs
I really wonder why "git <command> -h" depends on being inside a
repository. I noticed it with "git diff -h" (add, branch does that, too):#v+
~/git> git tag -h
usage: git-tag [-n [<num>]] -l [<pattern>] | [-a | -s | -u <key-id>] [-f | -d | -v] [-m <msg> | -F <file>] <tagname> [<head>] ~/git> cd
~> git tag -h
fatal: Not a git repository
~>
#v-
This is a nuisance, I agree.
So how about something like this patch? This just avoids looking for a .git directory if the only option to a subcommand is '-h'.
-- %< --
Subject: [PATCH] Let 'git <command> -h' show usage without a git dir
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
---
Tested with all builtins and non-builtins written in C. Some commands do not show usage with '-h' and have been left unchanged.
git.c | 48 ++++++++++++++++++++++++++++++------------------ http-fetch.c | 13 ++++++++++++- index-pack.c | 5 +++++ pack-redundant.c | 5 +++++ 4 files changed, 52 insertions(+), 19 deletions(-)
git.c +30 -18
@@ -220,6 +220,11 @@ const char git_version_string[] = GIT_VERSION;* RUN_SETUP for reading from the configuration file. */ #define NEED_WORK_TREE (1<<2) +/* +* Let RUN_SETUP, USE_PAGER, and NEED_WORK_TREE take effect even if +* passed the -h option. +*/ +#define H_IS_NOT_HELP (1<<3)struct cmd_struct {const char *cmd;
@@ -229,21 +234,25 @@ 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 && !(p->option &H_IS_NOT_HELP ) && + !strcmp (argv[1 ],"-h" ); +if (!help) { +if (p->option &RUN_SETUP && !help) + 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" );
@@ -278,7 +287,8 @@ static void handle_internal_command(int argc, const char **argv) { "annotate", cmd_annotate, RUN_SETUP }, { "apply", cmd_apply }, { "archive", cmd_archive }, - { "bisect--helper", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE }, + { "bisect--helper", cmd_bisect__helper, + RUN_SETUP | NEED_WORK_TREE }, { "blame", cmd_blame, RUN_SETUP }, { "branch", cmd_branch, RUN_SETUP }, { "bundle", cmd_bundle },
@@ -288,12 +298,12 @@ static void handle_internal_command(int argc, const char **argv) RUN_SETUP | NEED_WORK_TREE}, { "check-ref-format", cmd_check_ref_format }, { "check-attr", cmd_check_attr, RUN_SETUP }, - { "cherry", cmd_cherry, RUN_SETUP }, + { "cherry", cmd_cherry, RUN_SETUP | H_IS_NOT_HELP }, { "cherry-pick", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE }, { "clone", cmd_clone }, { "clean", cmd_clean, RUN_SETUP | NEED_WORK_TREE }, { "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE }, - { "commit-tree", cmd_commit_tree, RUN_SETUP }, + { "commit-tree", cmd_commit_tree, RUN_SETUP | H_IS_NOT_HELP }, { "config", cmd_config }, { "count-objects", cmd_count_objects, RUN_SETUP }, { "describe", cmd_describe, RUN_SETUP },
@@ -304,7 +314,7 @@ static void handle_internal_command(int argc, const char **argv) { "fast-export", cmd_fast_export, RUN_SETUP }, { "fetch", cmd_fetch, RUN_SETUP }, { "fetch-pack", cmd_fetch_pack, RUN_SETUP }, - { "fetch--tool", cmd_fetch__tool, RUN_SETUP }, + { "fetch--tool", cmd_fetch__tool, RUN_SETUP | H_IS_NOT_HELP }, { "fmt-merge-msg", cmd_fmt_merge_msg, RUN_SETUP }, { "for-each-ref", cmd_for_each_ref, RUN_SETUP }, { "format-patch", cmd_format_patch, RUN_SETUP },
@@ -312,7 +322,7 @@ static void handle_internal_command(int argc, const char **argv) { "fsck-objects", cmd_fsck, RUN_SETUP }, { "gc", cmd_gc, RUN_SETUP }, { "get-tar-commit-id", cmd_get_tar_commit_id }, - { "grep", cmd_grep, RUN_SETUP | USE_PAGER }, + { "grep", cmd_grep, RUN_SETUP | USE_PAGER | H_IS_NOT_HELP }, { "help", cmd_help }, { "init", cmd_init_db }, { "init-db", cmd_init_db },
@@ -325,9 +335,11 @@ static void handle_internal_command(int argc, const char **argv) { "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE }, { "merge-base", cmd_merge_base, RUN_SETUP }, { "merge-file", cmd_merge_file }, - { "merge-ours", cmd_merge_ours, RUN_SETUP }, - { "merge-recursive", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE }, - { "merge-subtree", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE }, + { "merge-ours", cmd_merge_ours, RUN_SETUP | H_IS_NOT_HELP }, + { "merge-recursive", cmd_merge_recursive, + RUN_SETUP | NEED_WORK_TREE | H_IS_NOT_HELP }, + { "merge-subtree", cmd_merge_recursive, + RUN_SETUP | NEED_WORK_TREE | H_IS_NOT_HELP }, { "mktree", cmd_mktree, RUN_SETUP }, { "mv", cmd_mv, RUN_SETUP | NEED_WORK_TREE }, { "name-rev", cmd_name_rev, RUN_SETUP },
@@ -368,7 +380,7 @@ static void handle_internal_command(int argc, const char **argv) { "whatchanged", cmd_whatchanged, RUN_SETUP | USE_PAGER }, { "write-tree", cmd_write_tree, RUN_SETUP }, { "verify-pack", cmd_verify_pack }, - { "show-ref", cmd_show_ref, RUN_SETUP }, + { "show-ref", cmd_show_ref, RUN_SETUP | H_IS_NOT_HELP }, { "pack-refs", cmd_pack_refs, RUN_SETUP }, };int i;
http-fetch.c +12 -1
@@ -1,6 +1,10 @@#include "cache.h" +#include "exec_cmd.h" #include "walker.h" +static const char http_fetch_usage[] ="git http-fetch " +"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url" ; +int main (int argc,const char **argv) {const char *prefix;
@@ -19,6 +23,13 @@ int main(int argc, const char **argv)int get_verbosely =0 ;int get_recover =0 ; +git_extract_argv0_path (argv[0 ]); + +if (argc ==2 && !strcmp (argv[1 ],"-h" )) { +fprintf (stderr,"%s\n" , http_fetch_usage); +return 0 ; + } + prefix =setup_git_directory ();git_config (git_default_config,NULL );
@@ -45,7 +56,7 @@ int main(int argc, const char **argv) arg++; }if (argc < arg +2 - commits_on_stdin) { -usage ("git http-fetch [-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url" ); +usage (http_fetch_usage);return 1 ; }if (commits_on_stdin) {
index-pack.c +5 -0
@@ -882,6 +882,11 @@ int main(int argc, char **argv)git_extract_argv0_path (argv[0 ]); +if (argc ==2 && !strcmp (argv[1 ],"-h" )) { +fprintf (stderr,"usage: %s\n" , index_pack_usage); +return 0 ; + } +/* * We wish to read the repository's config file if any, and * for that it is necessary to call setup_git_directory_gently().
pack-redundant.c +5 -0
@@ -603,6 +603,11 @@ int main(int argc, char **argv)git_extract_argv0_path (argv[0 ]); +if (argc ==2 && !strcmp (argv[1 ],"-h" )) { +fprintf (stderr,"usage: %s\n" , pack_redundant_usage); +return 0 ; + } +setup_git_directory ();for (i =1 ; i < argc; i++) {
Signature · 1 line
1.6.5.2
PATCH 1/1 Show usage string for 'git http-push -h'
git http-push already knows how to dump usage if it is given no options, but it interprets '-h' as the URL to a remote repository:
$ git http-push -h error: Cannot access URL -h/, return code 6
Dump usage on -h, instead. Humans wanting to pass the URL -h/ to curl for some reason can use 'git http-push -h/' explicitly. Scripts expecting to access an HTTP repository at URL '-h' will break, though.
---
Quoted 2 lines · Jonathan Nieder
Some commands
do not show usage with '-h' and have been left unchanged.
Like this one. Full list of non-builtin commands in C like this:
http-push, fast-import, imap-send, remote-curl, show-index.
http-push.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
http-push.c +7 -2
@@ -13,8 +13,8 @@#include <expat.h> -static const char http_push_usage[] = -"git http-push [--all] [--dry-run] [--force] [--verbose] <remote> [<head>...]\n" ; +static const char http_push_usage[] ="git http-push " +"[-h] [--all] [--dry-run] [--force] [--verbose] <remote> [<head>...]\n" ;#ifndef XML_STATUS_OK enum XML_Status {
@@ -1792,6 +1792,11 @@ int main(int argc, char **argv)git_extract_argv0_path (argv[0 ]); +if (argc ==2 && !strcmp (argv[1 ],"-h" )) { +fprintf (stderr,"usage: %s\n" , http_push_usage); +return 0 ; + } +setup_git_directory (); repo =xcalloc (sizeof (*repo),1 );
Signature · 1 line
1.6.5.2
Re: [PATCH] Show usage string for 'git http-push -h'
Hi,
http-push.c int main(int argc, char **argv) · line 1802
Quoted 12 lines · Jonathan Nieder
http-push.c +5
-0@@ -1792,6 +1792,11 @@ int main(int argc, char **argv) git_extract_argv0_path(argv[0]); + if (argc == 2 && !strcmp(argv[1], "-h")) { + fprintf(stderr, "usage: %s\n", http_push_usage); + return 0; + } + setup_git_directory(); repo = xcalloc(sizeof(*repo), 1);
just curious, I'm wondering why isn't the check for "-h" done in the argv loop later on? I see this being done already in the builtins diff, log, ls-remote and update-index.
Also, unlike grep, -h <arg> is not an option we're looking out for, so I'm not sure if we should allow the user to mix -h with a valid set of arguments (which is what Johnathan's patch would allow).
Signature · 2 lines
Cheers, Ray Chuan
PATCH v2 1/1 Show usage string for 'git http-push -h'
http-push already knows how to dump usage if it is given no options, but it interprets '-h' as the URL to a remote repository:
$ git http-push -h error: Cannot access URL -h/, return code 6
Dump usage instead. Humans wanting to pass the URL -h/ to curl for some reason can use 'git http-push -h/' explicitly. Scripts expecting to access an HTTP repository at URL '-h' will break, though.
Also delay finding a git directory until after option parsing, so "http-push -h" can be used outside any git repository.
---
Quoted 3 lines · Tay Ray Chuan
just curious, I'm wondering why isn't the check for "-h" done in the argv loop later on? I see this being done already in the builtins diff, log, ls-remote and update-index.
Good question. :)
(I was making sure "git http-push -h" would work without a git directory by putting the check for -h before setup_git_directory(). But nothing in the argv loop requires a git repository, so it is better and simpler to move the setup_git_directory() call to after the loop. Thanks for the catch.)
Quoted 3 lines
Also, unlike grep, -h <arg> is not an option we're looking out for, so I'm not sure if we should allow the user to mix -h with a valid set of arguments (which is what Johnathan's patch would allow).
Makes sense.
http-push.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
http-push.c +4 -2
@@ -1792,8 +1792,6 @@ int main(int argc, char **argv)git_extract_argv0_path (argv[0 ]); -setup_git_directory (); - repo =xcalloc (sizeof (*repo),1 ); argv++;
@@ -1827,6 +1825,8 @@ int main(int argc, char **argv) force_delete =1 ;continue ; } +if (!strcmp (arg,"-h" )) +usage (http_push_usage); }if (!repo->url) {char *path =strstr (arg,"//" );
@@ -1854,6 +1854,8 @@ int main(int argc, char **argv)if (delete_branch && nr_refspec !=1 )die ("You must specify only one branch name when deleting a remote branch" ); +setup_git_directory (); +memset (remote_dir_exists,-1 ,256 );/*
Signature · 1 line
1.6.5.2
Re: [PATCH v2] Show usage string for 'git http-push -h'
Hi,
Quoted 5 lines · Jonathan Nieder
(I was making sure "git http-push -h" would work without a git directory by putting the check for -h before
setup_git_directory(). But nothing in the argv loop requires a git repository, so it is better and simpler to move thesetup_git_directory()call to after the loop. Thanks for the catch.)
Actually, I didn't notice the removal of the "is in a git directory for -h" requirement; I was only looking at the argument mix.
Thanks.
Signature · 2 lines
Cheers, Ray Chuan
Re: [PATCH] Let 'git <command> -h' show usage without a git dir
In reply to Jonathan Niedergit.c const char git_version_string[] = GIT_VERSION; · line 227
Quoted 13 lines · Jonathan Nieder
git.c +5
-0@@ -220,6 +220,11 @@ const char git_version_string[] = GIT_VERSION;* RUN_SETUP for reading from the configuration file. */ #define NEED_WORK_TREE (1<<2) +/* +* Let RUN_SETUP, USE_PAGER, and NEED_WORK_TREE take effect even if +* passed the -h option. +*/ +#define H_IS_NOT_HELP (1<<3)
Yuck. Let's think of a way to avoid this ugliness.
git.c static void handle_internal_command(int argc, const char **argv) · line 291
Quoted 7 lines
git.c +2
-1@@ -278,7 +287,8 @@ static void handle_internal_command(int argc, const char **argv) { "annotate", cmd_annotate, RUN_SETUP }, { "apply", cmd_apply }, { "archive", cmd_archive }, - { "bisect--helper", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE }, + { "bisect--helper", cmd_bisect__helper, + RUN_SETUP | NEED_WORK_TREE },
Besides, this hunk is totally unwarranted.
Here are the relevant parts (some of your H_IS_NOT_HELP are not visible because you needlessly wrapped the lines):
git.c static void handle_internal_command(int argc, const char **argv)
Quoted 8 lines
git.c +8
-0+ { "cherry", cmd_cherry, RUN_SETUP | H_IS_NOT_HELP }, + { "commit-tree", cmd_commit_tree, RUN_SETUP | H_IS_NOT_HELP }, + { "fetch--tool", cmd_fetch__tool, RUN_SETUP | H_IS_NOT_HELP }, + { "grep", cmd_grep, RUN_SETUP | USE_PAGER | H_IS_NOT_HELP }, + { "merge-ours", cmd_merge_ours, RUN_SETUP | H_IS_NOT_HELP }, + { "merge-recursive", cmd_merge_recursive, + { "merge-subtree", cmd_merge_recursive, + { "show-ref", cmd_show_ref, RUN_SETUP | H_IS_NOT_HELP },
Except for "grep" and "show-ref", none of these have a valid -h option that means something else.
Considering that this niggle is strictly about "git cmd -h", and not about "git cmd --otheropt -h somearg", we can even say that "git grep -h" is asking for help, and not "do not show filenames from match", as there is no pattern specified.
So I think the right approach is something like how you handled http-push; namely, check if the sole argument is "-h", and if so show help and exit.
Clarification. the following description only talks about "cmd -h" without any other options and arguments.
Such a change cannot be breaking backward compatibility for...
* "cherry -h" could be asking to compare histories that leads to our HEAD and a commit that can be named as "-h". Strictly speaking, that may be a valid refname, but the user would have to say something like "tags/-h" to name such a pathological ref already, so I do not think it is such a big deal.
* "commit-tree -h" is to make a root commit that records a tree-ish pointed by a tag whose name is "-h". Same as above.
* The first word to "fetch--tool" is a subcommand name, so "fetch--tool -h" is an error and there cannot be any existing callers. Besides, is it still being used?
* "grep -h" cannot be asking for suppressing filenames as there is no match pattern specified.
* "merge-*" strategy backends take the merge base (or "--") as the first parameter; it cannot sanely be "-h". The callers are supposed to run rev-parse to make it 40-hexdigit and the command won't see a refname anyway.
That leaves "show-ref -h". It shows all the refs/* and HEAD, as opposed to "show-ref" that shows all the refs/* and not HEAD.
Does anybody use "show-ref -h"? It was in Linus's original, and I suspect it was done only because he thought "it might be handy", not because "the command should not show the HEAD by default for such and such reasons". So I think it actually is Ok if "show-ref -h" (but not "show-ref --head") gave help and exit.
Re: [PATCH] Let 'git <command> -h' show usage without a git dir
Quoted 9 lines · Junio C Hamano
Review
Quoted 5 lines · Jonathan Nieder
(quoted diff) +5
-0+/* + * Let RUN_SETUP, USE_PAGER, and NEED_WORK_TREE take effect even if + * passed the -h option. + */ +#define H_IS_NOT_HELP (1<<3)Yuck. Let's think of a way to avoid this ugliness.
Thank you. :)
Quoted 7 lines
So I think the right approach is something like how you handled http-push; namely, check if the sole argument is "-h", and if so show help and exit.
Clarification. the following description only talks about "cmd -h" without any other options and arguments.
Such a change cannot be breaking backward compatibility for...
[...]
Quoted 2 lines
* "grep -h" cannot be asking for suppressing filenames as there is no match pattern specified.
Okay, here’s a start.
-- %< --
Subject: Show usage string for 'git grep -h'
Clarification: the following description only talks about "git grep -h" without any other options and arguments.
Such a change cannot be breaking backward compatibility. "grep -h" cannot be asking for suppressing filenames, as there is no match pattern specified.
---
Is the long usage information really what is wanted here? (I would think yes, since there is no other way to get that, but sometimes all I want is a reminder of the non-optional arguments.)
Without something like the previous patch, the usage information is captured by a pager. I know this is an accidental thing (not all commands send their -h output through a pager), but it is very convenient and mitigates the first effect somewhat. Should whatever -h always use with a pager?
The -h output is very long, and since it goes to standard error, "git grep -h | head" does not succeed in capturing the best of it.
Usage errors caught in the same function die() currently. I was going to switch them to usage_msg_opt(), but because of the long usage message, that would cause the error message to scroll off the screen...
So I am not totally happy with this. But it is certainly an improvement over the output from before:
$ git grep -h fatal: no pattern given.
I’ll sleep on it. Thank you for the advice.
Good night,
Jonathan
builtin-grep.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
builtin-grep.c +7 -0
@@ -788,6 +788,13 @@ int cmd_grep(int argc, const char **argv, const char *prefix) OPT_END() }; +/* +* 'git grep -h', unlike 'git grep -h <pattern>', is a request +* to show usage information and exit. +*/ +if (argc ==2 && !strcmp (argv[1 ],"-h" )) +usage_with_options (grep_usage, options); +memset (&opt,0 ,sizeof (opt)); opt.prefix = prefix; opt.prefix_length = (prefix && *prefix) ?strlen (prefix) :0 ;
Signature · 1 line
1.6.5.2
cover Let 'git <command> -h' show usage without a git dir
Quoted 2 lines · Junio C Hamano
So I think the right approach is something like how you handled http-push; namely, check if the sole argument is "-h", and if so show help and exit.
I took a more aggressive approach with some commands. As long as it was obviously safe and not too complicated to implement, I let -h work wherever other options work.
Tested with
git_home=$(pwd)
while read a b
do
cmd=${a#git-}
test "$cmd" = "$a" && continue
echo "$cmd"
( cd /tmp && "$git_home/git" "$cmd" -h 2>&1 | head -1 )done |
less
and the test suite.
Thoughts?
Jonathan Nieder (24):
Retire fetch--tool helper to contrib/examples
Show usage string for 'git grep -h'
Show usage string for 'git cherry -h'
Show usage string for 'git commit-tree -h'
Show usage string for 'git merge-ours -h'
Show usage string for 'git show-ref -h'
check-ref-format: update usage string
Show usage string for 'git check-ref-format -h' Show usage string for 'git fast-import -h'
Show usage string for 'git get-tar-commit-id -h' Show usage string for 'git imap-send -h'
Show usage string for 'git mailsplit -h'
Show usage string for 'git merge-one-file -h'
Show usage string for 'git rev-parse -h'
Show usage string for 'git show-index -h'
Show usage string for 'git unpack-file -h'
Show usage string for 'git stripspace -h'
merge: do not setup worktree twice
Let 'git http-fetch -h' show usage outside any git repository
http-fetch: add missing initialization of argv0_path Let 'git <command> -h' show usage without a git dir Let usage() take a printf-style format merge-{recursive,subtree}: use usage() to print usage diff --no-index: make the usage string less scary
Documentation/git-show-ref.txt | 3 +- Makefile | 1 - builtin-check-ref-format.c | 9 +++++++- builtin-commit-tree.c | 2 +- builtin-grep.c | 7 ++++++ builtin-log.c | 9 ++++++++ builtin-mailsplit.c | 2 + builtin-merge-ours.c | 6 +++++ builtin-merge-recursive.c | 2 +- builtin-merge.c | 1 - builtin-mv.c | 8 +++--- builtin-read-tree.c | 4 +- builtin-reflog.c | 3 ++ builtin-rerere.c | 3 ++ builtin-rev-parse.c | 10 +++++++++ builtin-show-ref.c | 10 +++++++- builtin-stripspace.c | 4 ++- builtin-tar-tree.c | 6 +++++ builtin.h | 1 - .../examples/builtin-fetch--tool.c | 0 diff-no-index.c | 2 +- fast-import.c | 3 ++ git-compat-util.h | 2 +- git-merge-one-file.sh | 12 ++++++++++ git.c | 22 ++++++++++--------- http-fetch.c | 21 ++++++++++++------ imap-send.c | 5 ++++ index-pack.c | 3 ++ pack-redundant.c | 3 ++ show-index.c | 5 ++++ unpack-file.c | 2 +- usage.c | 14 ++++++++---- 32 files changed, 143 insertions(+), 42 deletions(-) rename builtin-fetch--tool.c => contrib/examples/builtin-fetch--tool.c (100%)
PATCH 1/24 Retire fetch--tool helper to contrib/examples
When git-fetch was builtin-ized, the previous script was moved to contrib/examples. Now, it is the sole remaining user for 'git fetch--tool'.
The fetch--tool code is still worth keeping around so people can try out the old git-fetch.sh, for example when investigating regressions from the builtinifaction.
---
See also <http://thread.gmane.org/gmane.comp.version-control.git/65122/focus=65191>.
Makefile | 1 - builtin.h | 1 - .../examples/builtin-fetch--tool.c | 0 git.c | 1 - 4 files changed, 0 insertions(+), 3 deletions(-) rename builtin-fetch--tool.c => contrib/examples/builtin-fetch--tool.c (100%)
Makefile +0 -1
@@ -601,7 +601,6 @@ BUILTIN_OBJS += builtin-diff-index.o BUILTIN_OBJS += builtin-diff-tree.o BUILTIN_OBJS += builtin-diff.o BUILTIN_OBJS += builtin-fast-export.o -BUILTIN_OBJS += builtin-fetch--tool.o BUILTIN_OBJS += builtin-fetch-pack.o BUILTIN_OBJS += builtin-fetch.o BUILTIN_OBJS += builtin-fmt-merge-msg.o
builtin.h +0 -1
@@ -48,7 +48,6 @@ extern int cmd_diff_tree(int argc, const char **argv, const char *prefix);extern int cmd_fast_export (int argc,const char **argv,const char *prefix);extern int cmd_fetch (int argc,const char **argv,const char *prefix);extern int cmd_fetch_pack (int argc,const char **argv,const char *prefix); -extern int cmd_fetch__tool (int argc,const char **argv,const char *prefix);extern int cmd_fmt_merge_msg (int argc,const char **argv,const char *prefix);extern int cmd_for_each_ref (int argc,const char **argv,const char *prefix);extern int cmd_format_patch (int argc,const char **argv,const char *prefix);
contrib/examples/builtin-fetch--tool.c renamed from builtin-fetch--tool.c +0 -0
git.c +0 -1
@@ -304,7 +304,6 @@ static void handle_internal_command(int argc, const char **argv) { "fast-export", cmd_fast_export, RUN_SETUP }, { "fetch", cmd_fetch, RUN_SETUP }, { "fetch-pack", cmd_fetch_pack, RUN_SETUP }, - { "fetch--tool", cmd_fetch__tool, RUN_SETUP }, { "fmt-merge-msg", cmd_fmt_merge_msg, RUN_SETUP }, { "for-each-ref", cmd_for_each_ref, RUN_SETUP }, { "format-patch", cmd_format_patch, RUN_SETUP },
Signature · 1 line
1.6.5.2
PATCH 2/24 Show usage string for 'git grep -h'
In reply to Jonathan NiederClarification: the following description only talks about "git grep -h" without any other options and arguments.
Such a change cannot be breaking backward compatibility. "grep -h" cannot be asking for suppressing filenames, as there is no match pattern specified.
--- builtin-grep.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
builtin-grep.c +7 -0
@@ -788,6 +788,13 @@ int cmd_grep(int argc, const char **argv, const char *prefix) OPT_END() }; +/* +* 'git grep -h', unlike 'git grep -h <pattern>', is a request +* to show usage information and exit. +*/ +if (argc ==2 && !strcmp (argv[1 ],"-h" )) +usage_with_options (grep_usage, options); +memset (&opt,0 ,sizeof (opt)); opt.prefix = prefix; opt.prefix_length = (prefix && *prefix) ?strlen (prefix) :0 ;
Signature · 1 line
1.6.5.2
PATCH 3/24 Show usage string for 'git cherry -h'
In reply to Jonathan NiederTreat an "-h" option as a request for help, rather than an "Unknown commit -h" error.
"cherry -h" could be asking to compare histories that leads to our HEAD and a commit that can be named as "-h". Strictly speaking, that may be a valid refname, but the user would have to say something like "tags/-h" to name such a pathological ref already, so it is not such a big deal.
The "-h" option keeps its meaning even if preceded by other options or followed by other arguments. This keeps the command-line syntax closer to what parse_options would give and supports shell aliases like 'alias cherry="git cherry -v"' a little better.
--- builtin-log.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
builtin-log.c +3 -0
@@ -1237,6 +1237,9 @@ int cmd_cherry(int argc, const char **argv, const char *prefix) argv++; } +if (argc >1 && !strcmp (argv[1 ],"-h" )) +usage (cherry_usage); +switch (argc) {case 4 : limit = argv[3 ];
Signature · 1 line
1.6.5.2
PATCH 4/24 Show usage string for 'git commit-tree -h'
In reply to Jonathan NiederTreat an "-h" option as a request for help, rather than a "Not a valid object name" error.
"commit-tree -h" could be asking to create a new commit from a treeish named "-h". Strictly speaking, such a pathological ref name is possible, but the user would have to had said something like "tags/-h" to name such a pathological already. commit-tree is usually used in scripts with raw object ids, anyway.
For consistency, the "-h" option uses its new meaning even if followed by other arguments.
--- builtin-commit-tree.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
builtin-commit-tree.c +1 -1
@@ -105,7 +105,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)git_config (git_default_config,NULL ); -if (argc <2 ) +if (argc <2 || !strcmp (argv[1 ],"-h" ))usage (commit_tree_usage);if (get_sha1 (argv[1 ], tree_sha1))die ("Not a valid object name %s" , argv[1 ]);
Signature · 1 line
1.6.5.2
PATCH 5/24 Show usage string for 'git merge-ours -h'
In reply to Jonathan NiederThis change is strictly about 'git merge-ours -h' without any other options and arguments.
This change cannot break compatibility since merge drivers are always passed '--', among other arguments.
Any usage string for this command is a lie, since it ignored its arguments until now. Still, it makes sense to let the user know the expected usage when asked.
--- builtin-merge-ours.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
builtin-merge-ours.c +6 -0
@@ -10,6 +10,9 @@#include "git-compat-util.h" #include "builtin.h" +static const char builtin_merge_ours_usage[] = +"git merge-ours <base>... -- HEAD <remote>..." ; +static const char *diff_index_args[] = {"diff-index" ,"--quiet" ,"--cached" ,"HEAD" ,"--" ,NULL };
@@ -17,6 +20,9 @@ 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" )) +usage (builtin_merge_ours_usage); +/* * We need to exit with 2 if the index does not match our HEAD tree, * because the current index is what we will be committing as the
Signature · 1 line
1.6.5.2
PATCH 6/24 Show usage string for 'git show-ref -h'
In reply to Jonathan NiederThis only changes the behavior of "git show-ref -h" without any other options and arguments.
"show-ref -h" currently is short for "show-ref --head", which shows all the refs/* and HEAD, as opposed to "show-ref" that shows all the refs/* and not HEAD.
Does anybody use "show-ref -h"? It was in Linus's original, most likely only because "it might be handy", not because "the command should not show the HEAD by default for such and such reasons". So I think it is okay if "show-ref -h" (but not "show-ref --head") gives help and exits.
If a current script uses "git show-ref -h" without any other arguments, it would have to be adapted by changing "-h" to "--head".
--- Documentation/git-show-ref.txt | 3 +-- builtin-show-ref.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-)
Documentation/git-show-ref.txt +1 -2
@@ -8,7 +8,7 @@ git-show-ref - List references in a local repository SYNOPSIS -------- [verse] -'git show-ref' [-q|--quiet] [--verify] [-h|--head] [-d|--dereference] +'git show-ref' [-q|--quiet] [--verify] [--head] [-d|--dereference] [-s|--hash[=<n>]] [--abbrev[=<n>]] [--tags] [--heads] [--] <pattern>... 'git show-ref' --exclude-existing[=<pattern>] < ref-list
@@ -30,7 +30,6 @@ the `.git` directory. OPTIONS ------- --h:: --head:: Show the HEAD reference.
builtin-show-ref.c +8 -2
@@ -7,7 +7,7 @@#include "parse-options.h" static const char *const show_ref_usage[] = { -"git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--dereference] [-s|--hash[=<n>]] [--abbrev[=<n>]] [--tags] [--heads] [--] [pattern*] " , +"git show-ref [-q|--quiet] [--verify] [--head] [-d|--dereference] [-s|--hash[=<n>]] [--abbrev[=<n>]] [--tags] [--heads] [--] [pattern*] " ,"git show-ref --exclude-existing[=pattern] < ref-list" ,NULL };
@@ -183,7 +183,10 @@ static const struct option show_ref_options[] = {OPT_BOOLEAN (0 ,"heads" , &heads_only,"only show heads (can be combined with tags)" ),OPT_BOOLEAN (0 ,"verify" , &verify,"stricter reference checking, " "requires exact ref path" ), -OPT_BOOLEAN ('h' ,"head" , &show_head,"show the HEAD reference" ), + { OPTION_BOOLEAN, 'h', NULL, &show_head, NULL, +"show the HEAD reference" , + PARSE_OPT_NOARG | PARSE_OPT_HIDDEN }, +OPT_BOOLEAN (0 ,"head" , &show_head,"show the HEAD reference" ),OPT_BOOLEAN ('d' ,"dereference" , &deref_tags,"dereference tags into object IDs" ), { OPTION_CALLBACK, 's', "hash", &abbrev, "n",
@@ -201,6 +204,9 @@ 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" )) +usage_with_options (show_ref_usage, show_ref_options); + argc =parse_options (argc, argv, prefix, show_ref_options, show_ref_usage,PARSE_OPT_NO_INTERNAL_HELP );
Signature · 1 line
1.6.5.2
PATCH 7/24 check-ref-format: update usage string
In reply to Jonathan Nieder'git check-ref-format' has learned --branch and --print options since the usage string was last updated.
--- builtin-check-ref-format.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
builtin-check-ref-format.c +5 -1
@@ -7,6 +7,10 @@#include "builtin.h" #include "strbuf.h" +static const char builtin_check_ref_format_usage[] = +"git check-ref-format [--print] <refname>\n" +" or: git check-ref-format --branch <branchname-shorthand>" ; +/* * Replace each run of adjacent slashes in src with a single slash, * and write the result to dst.
@@ -49,6 +53,6 @@ int cmd_check_ref_format(int argc, const char **argv, const char *prefix)exit (0 ); }if (argc !=2 ) -usage ("git check-ref-format refname" ); +usage (builtin_check_ref_format_usage);return !!check_ref_format (argv[1 ]); }
Signature · 1 line
1.6.5.2
Re: [PATCH 07/24] check-ref-format: update usage string
This deserves to go to maint, so I ejected it out of the series.
Thanks.
PATCH 8/24 Show usage string for 'git check-ref-format -h'
In reply to Jonathan NiederThis only changes the behavior of "git check-ref-format -h" without any other options and arguments.
This change cannot be breaking backward compatibility, since any
valid refname must contain a /. Most existing scripts use
arguments such as "heads/$foo". If some script checks the refname "-h" alone, git check-ref-format will still exit with nonzero status, and the only detrimental side-effect will be a usage string sent to stderr.
--- builtin-check-ref-format.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
builtin-check-ref-format.c +3 -0
@@ -35,6 +35,9 @@ 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" )) +usage (builtin_check_ref_format_usage); +if (argc ==3 && !strcmp (argv[1 ],"--branch" )) {struct strbuf sb =STRBUF_INIT ;
Signature · 1 line
1.6.5.2
PATCH 9/24 Show usage string for 'git fast-import -h'
In reply to Jonathan NiederLet "git fast-import -h" (with no other arguments) print usage before exiting, even when run outside any repository.
--- fast-import.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
fast-import.c +3 -0
@@ -2405,6 +2405,9 @@ int main(int argc, const char **argv)git_extract_argv0_path (argv[0 ]); +if (argc ==2 && !strcmp (argv[1 ],"-h" )) +usage (fast_import_usage); +setup_git_directory ();git_config (git_pack_config,NULL );if (!pack_compression_seen && core_compression_seen)
Signature · 1 line
1.6.5.2
PATCH 10/24 Show usage string for 'git get-tar-commit-id -h'
In reply to Jonathan Nieder--- builtin-tar-tree.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
builtin-tar-tree.c +6 -0
@@ -11,6 +11,9 @@ static const char tar_tree_usage[] ="git tar-tree [--remote=<repo>] <tree-ish> [basedir]\n" "*** Note that this command is now deprecated; use \"git archive\" instead." ; +static const char builtin_get_tar_commit_id_usage[] = +"git get-tar-commit-id < <tarfile>" ; +int cmd_tar_tree (int argc,const char **argv,const char *prefix) {/*
@@ -81,6 +84,9 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)char *content = buffer +RECORDSIZE ;ssize_t n; +if (argc !=1 ) +usage (builtin_get_tar_commit_id_usage); + n =read_in_full (0 , buffer,HEADERSIZE );if (n <HEADERSIZE )die ("git get-tar-commit-id: read error" );
Signature · 1 line
1.6.5.2
PATCH 11/24 Show usage string for 'git imap-send -h'
In reply to Jonathan Nieder--- imap-send.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
imap-send.c +5 -0
@@ -93,6 +93,8 @@ struct msg_data { unsigned int crlf:1; }; +static const char imap_send_usage[] ="git imap-send < <mbox>" ; +#define DRV_OK 0#define DRV_MSG_BAD -1#define DRV_BOX_BAD -2
@@ -1491,6 +1493,9 @@ int main(int argc, char **argv)git_extract_argv0_path (argv[0 ]); +if (argc !=1 ) +usage (imap_send_usage); +/* init the random number generator */ arc4_init ();
Signature · 1 line
1.6.5.2
PATCH 12/24 Show usage string for 'git mailsplit -h'
In reply to Jonathan Nieder--- builtin-mailsplit.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
builtin-mailsplit.c +2 -0
@@ -231,6 +231,8 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix)continue ; }else if ( arg[1 ] =='f' ) { nr =strtol (arg+2 ,NULL ,10 ); + }else if ( arg[1 ] =='h' ) { +usage (git_mailsplit_usage); }else if ( arg[1 ] =='b' && !arg[2 ] ) { allow_bare =1 ; }else if (!strcmp (arg,"--keep-cr" )) {
Signature · 1 line
1.6.5.2
PATCH 13/24 Show usage string for 'git merge-one-file -h'
In reply to Jonathan Nieder--- git-merge-one-file.sh | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
git-merge-one-file.sh +12 -0
@@ -16,6 +16,18 @@ # been handled already by git read-tree, but that one doesn't # do any merges that might change the tree layout. +USAGE='<orig blob> <our blob> <their blob> <path>' +USAGE="$USAGE <orig mode> <our mode> <their mode>" +LONG_USAGE="Usage: git merge-one-file $USAGE + +Blob ids and modes should be empty for missing files." + +if ! test "$#" -eq 7 +then + echo "$LONG_USAGE" + exit 1 +fi + case "${1:-.}${2:-.}${3:-.}" in # # Deleted in both or deleted in one and unchanged in the other
Signature · 1 line
1.6.5.2
PATCH 14/24 Show usage string for 'git rev-parse -h'
In reply to Jonathan Nieder--- builtin-rev-parse.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
builtin-rev-parse.c +10 -0
@@ -426,6 +426,13 @@ static void die_no_single_rev(int quiet)die ("Needed a single revision" ); } +static const char builtin_rev_parse_usage[] = +"git rev-parse --parseopt [options] -- [<args>...]\n" +" or: git rev-parse --sq-quote [<arg>...]\n" +" or: git rev-parse [options] [<arg>...]\n" +"\n" +"Run \"git rev-parse --parseopt -h\" for more information on the first usage." ; +int cmd_rev_parse (int argc,const char **argv,const char *prefix) {int i, as_is =0 , verify =0 , quiet =0 , revs_count =0 , type =0 ;
@@ -438,6 +445,9 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)if (argc >1 && !strcmp ("--sq-quote" , argv[1 ]))return cmd_sq_quote (argc -2 , argv +2 ); +if (argc >1 && !strcmp ("-h" , argv[1 ])) +usage (builtin_rev_parse_usage); + prefix =setup_git_directory ();git_config (git_default_config,NULL );for (i =1 ; i < argc; i++) {
Signature · 1 line
1.6.5.2
PATCH 15/24 Show usage string for 'git show-index -h'
In reply to Jonathan Nieder--- show-index.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
show-index.c +5 -0
@@ -1,6 +1,9 @@#include "cache.h" #include "pack.h" +static const char show_index_usage[] = +"git show-index < <packed archive index>" ; +int main (int argc,char **argv) {int i;
@@ -8,6 +11,8 @@ int main(int argc, char **argv)unsigned int version;static unsigned int top_index[256 ]; +if (argc !=1 ) +usage (show_index_usage);if (fread (top_index,2 *4 ,1 , stdin) !=1 )die ("unable to read header" );if (top_index[0 ] ==htonl (PACK_IDX_SIGNATURE )) {
Signature · 1 line
1.6.5.2
PATCH 16/24 Show usage string for 'git unpack-file -h'
In reply to Jonathan Nieder"unpack-file -h" could be asking to save the contents of a blob named "-h". Strictly speaking, such a pathological ref name is possible, but the user would have to had said something like "tags/-h" to name such a pathological ref already. When used in scripts, unpack-file is typically not passed a user-supplied tag name directly.
--- unpack-file.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
unpack-file.c +1 -1
@@ -28,7 +28,7 @@ int main(int argc, char **argv)git_extract_argv0_path (argv[0 ]); -if (argc !=2 ) +if (argc !=2 || !strcmp (argv[1 ],"-h" ))usage ("git unpack-file <sha1>" );if (get_sha1 (argv[1 ], sha1))die ("Not a valid object name %s" , argv[1 ]);
Signature · 1 line
1.6.5.2
PATCH 17/24 Show usage string for 'git stripspace -h'
In reply to Jonathan Nieder--- builtin-stripspace.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
builtin-stripspace.c +3 -1
@@ -73,9 +73,11 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)struct strbuf buf =STRBUF_INIT ;int strip_comments =0 ; -if (argc >1 && (!strcmp (argv[1 ],"-s" ) || +if (argc ==2 && (!strcmp (argv[1 ],"-s" ) || !strcmp (argv[1 ],"--strip-comments" ))) strip_comments =1 ; +else if (argc >1 ) +usage ("git stripspace [-s | --strip-comments] < <stream>" );if (strbuf_read (&buf,0 ,1024 ) <0 )die_errno ("could not read the input" );
Signature · 1 line
1.6.5.2
PATCH 18/24 merge: do not setup worktree twice
In reply to Jonathan NiederBuiltins do not need to run setup_worktree() for themselves, since the builtin machinery runs it for them.
---
This matter since '-h' cannot suppress _this_ setup_work_tree() through the builtin machinery.
builtin-merge.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
builtin-merge.c +0 -1
@@ -843,7 +843,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)const char *best_strategy =NULL , *wt_strategy =NULL ;struct commit_list **remotes = &remoteheads; -setup_work_tree ();if (file_exists (git_path ("MERGE_HEAD" )))die ("You have not concluded your merge. (MERGE_HEAD exists)" );if (read_cache_unmerged ())
Signature · 1 line
1.6.5.2
Re: [PATCH 18/24] merge: do not setup worktree twice
Quoted 7 lines · Jonathan Nieder
Builtins do not need to run
setup_worktree()for themselves, since the builtin machinery runs it for them.Signed-off-by Jonathan Nieder <[email protected]>---
This matter since '-h' cannot suppress _this_setup_work_tree()through the builtin machinery.
I think this should directly go to 'maint'. I ejected it from the series.
Thanks.
Re: [PATCH 18/24] merge: do not setup worktree twice
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Jonathan Nieder
Builtins do not need to run
setup_worktree()for themselves, since the builtin machinery runs it for them.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Jonathan Nieder <[email protected]>---
This matter since '-h' cannot suppress _this_setup_work_tree()through the builtin machinery.I think this should directly go to 'maint'. I ejected it from the series.
Thanks. I think something like this should go on top on maint, then reverted in master.
Sorry for the trouble,
Jonathan
-- %< --
Subject: check-ref-format does not know --print yet
Don’t advertise the --print option of the future in the current usage string.
--- builtin-check-ref-format.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
builtin-check-ref-format.c +1 -1
@@ -8,7 +8,7 @@#include "strbuf.h" static const char builtin_check_ref_format_usage[] = -"git check-ref-format [--print] <refname>\n" +"git check-ref-format <refname>\n" " or: git check-ref-format --branch <branchname-shorthand>" ;int cmd_check_ref_format (int argc,const char **argv,const char *prefix)
Signature · 1 line
1.6.5.2
PATCH 19/24 Let 'git http-fetch -h' show usage outside any git repository
In reply to Jonathan NiederDelay search for a git directory until option parsing has finished. None of the functions used in option parsing look for or read any files other than stdin, so this is safe.
--- http-fetch.c | 21 +++++++++++++-------- 1 files changed, 13 insertions(+), 8 deletions(-)
http-fetch.c +13 -8
@@ -1,6 +1,10 @@#include "cache.h" +#include "exec_cmd.h" #include "walker.h" +static const char http_fetch_usage[] ="git http-fetch " +"[-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url" ; +int main (int argc,const char **argv) {const char *prefix;
@@ -19,10 +23,6 @@ int main(int argc, const char **argv)int get_verbosely =0 ;int get_recover =0 ; - prefix =setup_git_directory (); - -git_config (git_default_config,NULL ); -while (arg < argc && argv[arg][0 ] =='-' ) {if (argv[arg][1 ] =='t' ) { get_tree =1 ;
@@ -37,6 +37,8 @@ int main(int argc, const char **argv) }else if (argv[arg][1 ] =='w' ) { write_ref = &argv[arg +1 ]; arg++; + }else if (argv[arg][1 ] =='h' ) { +usage (http_fetch_usage); }else if (!strcmp (argv[arg],"--recover" )) { get_recover =1 ; }else if (!strcmp (argv[arg],"--stdin" )) {
@@ -44,10 +46,8 @@ int main(int argc, const char **argv) } arg++; } -if (argc < arg +2 - commits_on_stdin) { -usage ("git http-fetch [-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url" ); -return 1 ; - } +if (argc != arg +2 - commits_on_stdin) +usage (http_fetch_usage);if (commits_on_stdin) { commits =walker_targets_stdin (&commit_id, &write_ref); }else {
@@ -55,6 +55,11 @@ int main(int argc, const char **argv) commits =1 ; } url = argv[arg]; + + prefix =setup_git_directory (); + +git_config (git_default_config,NULL ); +if (url && url[strlen (url)-1 ] !='/' ) { rewritten_url =xmalloc (strlen (url)+2 );strcpy (rewritten_url, url);
Signature · 1 line
1.6.5.2
PATCH 20/24 http-fetch: add missing initialization of argv0_path
In reply to Jonathan Nieder--- http-fetch.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
http-fetch.c +2 -0
@@ -23,6 +23,8 @@ int main(int argc, const char **argv)int get_verbosely =0 ;int get_recover =0 ; +git_extract_argv0_path (argv[0 ]); +while (arg < argc && argv[arg][0 ] =='-' ) {if (argv[arg][1 ] =='t' ) { get_tree =1 ;
Signature · 1 line
1.6.5.2
Re: [PATCH 20/24] http-fetch: add missing initialization of argv0_path
Quoted 2 lines · Jonathan Nieder
Signed-off-by Jonathan Nieder <[email protected]>---
Why do you have inclusion of "exec_cmd.h" in [19/24]? As far as I can tell, nothing you do in that patch depends on it.
According to c6dfb39 (remote-curl: add missing initialization of argv0_path, 2009-10-13), this patch is necessary (and you must include "exec_cmd.h") on MinGW, regardless of the "give help upon -h" topic.
I think this should be ejected from your series go directly to 'maint', or am I mistaken?
http-fetch.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
http-fetch.c +2 -1
@@ -1,4 +1,5 @@#include "cache.h" +#include "exec_cmd.h" #include "walker.h" int main (int argc,const char **argv)
@@ -19,8 +20,8 @@ int main(int argc, const char **argv)int get_verbosely =0 ;int get_recover =0 ; +git_extract_argv0_path (argv[0 ]); prefix =setup_git_directory (); -git_config (git_default_config,NULL );while (arg < argc && argv[arg][0 ] =='-' ) {
Re: [PATCH 20/24] http-fetch: add missing initialization of argv0_path
Quoted 7 lines · Junio C Hamano
Quoted 2 lines · Jonathan Nieder
Signed-off-by Jonathan Nieder <[email protected]>---
Why do you have inclusion of "
exec_cmd.h" in [19/24]? As far as I can tell, nothing you do in that patch depends on it.
Quoted 6 lines
According to c6dfb39 (remote-curl: add missing initialization of
argv0_path, 2009-10-13), this patch is necessary (and you must include "exec_cmd.h") on MinGW, regardless of the "give help upon -h" topic.I think this should be ejected from your series go directly to 'maint', or am I mistaken?
You are right.
This command (in bash):
comm <(git grepc -l main\( *.c) <(git grepc -l extract_argv0 *.c)
shows programs in the 1st column that have main(), but do not call git_extract_argv0_path. One remaining candidate is show-index.c, but its only call-out is sha1_to_hex(), which doesn't use any other services.
http-fetch.c is the only file that needs this patch.
-- Hannes
Re: [PATCH 20/24] http-fetch: add missing initialization of argv0_path
In reply to Junio C HamanoQuoted 2 lines · Junio C Hamano
Why do you have inclusion of "
exec_cmd.h" in [19/24]? As far as I can tell, nothing you do in that patch depends on it.
No good reason. Thanks for cleaning up my mess.
Jonathan
PATCH 21/24 Let 'git <command> -h' show usage without a git dir
In reply to Jonathan NiederThere is no need for "git <command> -h" to depend on being inside a repository.
Reported by Gerfried Fuchs through http://bugs.debian.org/462557
--- 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(-)
builtin-log.c +6 -0
@@ -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)
builtin-mv.c +4 -4
@@ -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 );
builtin-read-tree.c +2 -2
@@ -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?" );
builtin-reflog.c +3 -0
@@ -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);
builtin-rerere.c +3 -0
@@ -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 ;
git.c +12 -9
@@ -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" );
index-pack.c +3 -0
@@ -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().
pack-redundant.c +3 -0
@@ -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++) {
Signature · 1 line
1.6.5.2
PATCH 22/24 Let usage() take a printf-style format
In reply to Jonathan Niedermerge-recursive and diff --no-index are not able to use usage() because their usage strings depend on the circumstances in which they are called.
--- git-compat-util.h | 2 +- usage.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-)
git-compat-util.h +1 -1
@@ -188,7 +188,7 @@ extern char *gitbasename(char *);#include "compat/bswap.h" /* General helper functions */ -extern NORETURN void usage(const char *err); +extern NORETURN void usage(const char *err, ...) __attribute__((format (printf, 1, 2))); extern NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2))); extern NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 )));
usage.c +9 -5
@@ -12,9 +12,9 @@ static void report(const char *prefix, const char *err, va_list params)fprintf (stderr,"%s%s\n" , prefix, msg); } -static NORETURN void usage_builtin(const char *err) +static NORETURN void usage_builtin(const char *err, va_list params) { -fprintf (stderr,"usage: %s\n" , err); +report ("usage: " , err, params);exit (129 ); }
@@ -36,7 +36,7 @@ static void warn_builtin(const char *warn, va_list params)/* If we are in a dlopen()ed .so write to a global variable would segfault * (ugh), so keep things static. */ -static NORETURN_PTR void (*usage_routine)(const char *err) = usage_builtin; +static NORETURN_PTR void (*usage_routine)(const char *err, va_list params) = usage_builtin; static NORETURN_PTR void (*die_routine)(const char *err, va_list params) = die_builtin;static void (*error_routine)(const char *err,va_list params) = error_builtin;static void (*warn_routine)(const char *err,va_list params) = warn_builtin;
@@ -46,9 +46,13 @@ void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list param die_routine = routine; } -void usage (const char *err) +void usage (const char *err, ...) { -usage_routine (err); +va_list params; + +va_start (params, err); +usage_routine (err, params); +va_end (params); }void die (const char *err, ...)
Signature · 1 line
1.6.5.2
Re: [PATCH 22/24] Let usage() take a printf-style format
Quoted 3 lines · Jonathan Nieder
merge-recursive and diff --no-index are not able to use
usage()because their usage strings depend on the circumstances in which they are called.
Since die() and warn() are already printf-like, it may be tempting to do this, but this is wrong.
I do not want to vet all the existing call sites to usage() of make sure that all of them _happen_ to pass constant strings that do not have any '%' in them.
Much more importantly, without a patch to future-proof all existing callsites to modify from
usage(blame_usage);
to
usage("%s", blame_usage);everybody needs to remember that some *_usage strings are special and have to double % in it forever, which is a maintenance nightmare.
Besides, the majority of usage strings are _expected_ to be constant. That is an important difference from die/warn whose purpose is to diagnose and give appropriate message to the situation (hence they benefit from formatting).
I've renamed this to usagef() and updated your two callers to use it in the version I queued to 'pu'.
Thanks.
PATCH 23/24 merge-{recursive,subtree}: use usage() to print usage
In reply to Jonathan NiederUsage messages (for example, from "git merge-recursive -h") are friendlier when not preceded by "fatal".
--- builtin-merge-recursive.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
builtin-merge-recursive.c +1 -1
@@ -33,7 +33,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix) }if (argc <4 ) -die ("Usage: %s <base>... -- <head> <remote> ..." , argv[0 ]); +usage ("%s <base>... -- <head> <remote> ..." , argv[0 ]);for (i =1 ; i < argc; ++i) {if (!strcmp (argv[i],"--" ))
Signature · 1 line
1.6.5.2
PATCH 24/24 diff --no-index: make the usage string less scary
In reply to Jonathan NiederStart the diff --no-index usage string with "usage:" instead of "fatal:".
--- diff-no-index.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff-no-index.c +1 -1
@@ -201,7 +201,7 @@ void diff_no_index(struct rev_info *revs,return ; }if (argc != i +2 ) -die ("git diff %s takes two paths" , +usage ("git diff %s <path> <path>" , no_index ?"--no-index" :"[--no-index]" );diff_setup (&revs->diffopt);
Signature · 1 line
1.6.5.2