Git fork

builtins: send usage_with_options() help text to standard output

Using the show_usage_with_options_if_asked() helper we introduced
earlier, fix callers of usage_with_options() that want to show the
help text when explicitly asked by the end-user. The help text now
goes to the standard output stream for them.

The test in t7600 for "git merge -h" may want to be retired, as the
same is covered by t0012 already, but it is specifically testing that
the "-h" option gets a response even with a corrupt index file, so
for now let's leave it there.

Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

+31 -32
+1 -2
builtin/am.c
··· 2427 2427 OPT_END() 2428 2428 }; 2429 2429 2430 - if (argc == 2 && !strcmp(argv[1], "-h")) 2431 - usage_with_options(usage, options); 2430 + show_usage_with_options_if_asked(argc, argv, usage, options); 2432 2431 2433 2432 git_config(git_default_config, NULL); 2434 2433
+2 -2
builtin/branch.c
··· 784 784 filter.kind = FILTER_REFS_BRANCHES; 785 785 filter.abbrev = -1; 786 786 787 - if (argc == 2 && !strcmp(argv[1], "-h")) 788 - usage_with_options(builtin_branch_usage, options); 787 + show_usage_with_options_if_asked(argc, argv, 788 + builtin_branch_usage, options); 789 789 790 790 /* 791 791 * Try to set sort keys from config. If config does not set any,
+3 -3
builtin/checkout--worker.c
··· 128 128 OPT_END() 129 129 }; 130 130 131 - if (argc == 2 && !strcmp(argv[1], "-h")) 132 - usage_with_options(checkout_worker_usage, 133 - checkout_worker_options); 131 + show_usage_with_options_if_asked(argc, argv, 132 + checkout_worker_usage, 133 + checkout_worker_options); 134 134 135 135 git_config(git_default_config, NULL); 136 136 argc = parse_options(argc, argv, prefix, checkout_worker_options,
+3 -3
builtin/checkout-index.c
··· 250 250 OPT_END() 251 251 }; 252 252 253 - if (argc == 2 && !strcmp(argv[1], "-h")) 254 - usage_with_options(builtin_checkout_index_usage, 255 - builtin_checkout_index_options); 253 + show_usage_with_options_if_asked(argc, argv, 254 + builtin_checkout_index_usage, 255 + builtin_checkout_index_options); 256 256 git_config(git_default_config, NULL); 257 257 prefix_length = prefix ? strlen(prefix) : 0; 258 258
+2 -2
builtin/commit-tree.c
··· 119 119 120 120 git_config(git_default_config, NULL); 121 121 122 - if (argc < 2 || !strcmp(argv[1], "-h")) 123 - usage_with_options(commit_tree_usage, options); 122 + show_usage_with_options_if_asked(argc, argv, 123 + commit_tree_usage, options); 124 124 125 125 argc = parse_options(argc, argv, prefix, options, commit_tree_usage, 0); 126 126
+4 -4
builtin/commit.c
··· 1559 1559 OPT_END(), 1560 1560 }; 1561 1561 1562 - if (argc == 2 && !strcmp(argv[1], "-h")) 1563 - usage_with_options(builtin_status_usage, builtin_status_options); 1562 + show_usage_with_options_if_asked(argc, argv, 1563 + builtin_status_usage, builtin_status_options); 1564 1564 1565 1565 prepare_repo_settings(the_repository); 1566 1566 the_repository->settings.command_requires_full_index = 0; ··· 1736 1736 struct strbuf err = STRBUF_INIT; 1737 1737 int ret = 0; 1738 1738 1739 - if (argc == 2 && !strcmp(argv[1], "-h")) 1740 - usage_with_options(builtin_commit_usage, builtin_commit_options); 1739 + show_usage_with_options_if_asked(argc, argv, 1740 + builtin_commit_usage, builtin_commit_options); 1741 1741 1742 1742 prepare_repo_settings(the_repository); 1743 1743 the_repository->settings.command_requires_full_index = 0;
+2 -2
builtin/fsmonitor--daemon.c
··· 1598 1598 OPT_END() 1599 1599 }; 1600 1600 1601 - if (argc == 2 && !strcmp(argv[1], "-h")) 1602 - usage_with_options(builtin_fsmonitor__daemon_usage, options); 1601 + show_usage_with_options_if_asked(argc, argv, 1602 + builtin_fsmonitor__daemon_usage, options); 1603 1603 1604 1604 die(_("fsmonitor--daemon not supported on this platform")); 1605 1605 }
+2 -2
builtin/gc.c
··· 710 710 OPT_END() 711 711 }; 712 712 713 - if (argc == 2 && !strcmp(argv[1], "-h")) 714 - usage_with_options(builtin_gc_usage, builtin_gc_options); 713 + show_usage_with_options_if_asked(argc, argv, 714 + builtin_gc_usage, builtin_gc_options); 715 715 716 716 strvec_pushl(&reflog, "reflog", "expire", "--all", NULL); 717 717 strvec_pushl(&repack, "repack", "-d", "-l", NULL);
+2 -2
builtin/ls-files.c
··· 644 644 }; 645 645 int ret = 0; 646 646 647 - if (argc == 2 && !strcmp(argv[1], "-h")) 648 - usage_with_options(ls_files_usage, builtin_ls_files_options); 647 + show_usage_with_options_if_asked(argc, argv, 648 + ls_files_usage, builtin_ls_files_options); 649 649 650 650 prepare_repo_settings(the_repository); 651 651 the_repository->settings.command_requires_full_index = 0;
+2 -2
builtin/merge.c
··· 1300 1300 void *branch_to_free; 1301 1301 int orig_argc = argc; 1302 1302 1303 - if (argc == 2 && !strcmp(argv[1], "-h")) 1304 - usage_with_options(builtin_merge_usage, builtin_merge_options); 1303 + show_usage_with_options_if_asked(argc, argv, 1304 + builtin_merge_usage, builtin_merge_options); 1305 1305 1306 1306 prepare_repo_settings(the_repository); 1307 1307 the_repository->settings.command_requires_full_index = 0;
+3 -3
builtin/rebase.c
··· 1223 1223 }; 1224 1224 int i; 1225 1225 1226 - if (argc == 2 && !strcmp(argv[1], "-h")) 1227 - usage_with_options(builtin_rebase_usage, 1228 - builtin_rebase_options); 1226 + show_usage_with_options_if_asked(argc, argv, 1227 + builtin_rebase_usage, 1228 + builtin_rebase_options); 1229 1229 1230 1230 prepare_repo_settings(the_repository); 1231 1231 the_repository->settings.command_requires_full_index = 0;
+2 -2
builtin/update-index.c
··· 1045 1045 OPT_END() 1046 1046 }; 1047 1047 1048 - if (argc == 2 && !strcmp(argv[1], "-h")) 1049 - usage_with_options(update_index_usage, options); 1048 + show_usage_with_options_if_asked(argc, argv, 1049 + update_index_usage, options); 1050 1050 1051 1051 git_config(git_default_config, NULL); 1052 1052
+2 -2
t/helper/test-simple-ipc.c
··· 612 612 if (argc < 2) 613 613 usage_with_options(simple_ipc_usage, options); 614 614 615 - if (argc == 2 && !strcmp(argv[1], "-h")) 616 - usage_with_options(simple_ipc_usage, options); 615 + show_usage_with_options_if_asked(argc, argv, 616 + simple_ipc_usage, options); 617 617 618 618 if (argc == 2 && !strcmp(argv[1], "SUPPORTS_SIMPLE_IPC")) 619 619 return 0;
+1 -1
t/t7600-merge.sh
··· 173 173 cd broken && 174 174 git init && 175 175 >.git/index && 176 - test_expect_code 129 git merge -h 2>usage 176 + test_expect_code 129 git merge -h >usage 177 177 ) && 178 178 test_grep "[Uu]sage: git merge" broken/usage 179 179 '