From: Junio C Hamano Date: Wed, 11 Feb 2015 21:44:19 +0000 (-0800) Subject: Merge branch 'ah/usage-strings' X-Git-Tag: v2.4.0-rc0~128 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/bb831db6774aaa733199360dc7af6f3ce375fc20?ds=inline;hp=-c Merge branch 'ah/usage-strings' * ah/usage-strings: standardize usage info string format --- bb831db6774aaa733199360dc7af6f3ce375fc20 diff --combined Documentation/CodingGuidelines index 578d07c034,ad3b2adb60..49089de5c0 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@@ -328,14 -328,9 +328,14 @@@ For C programs - When you come up with an API, document it. - - The first #include in C files, except in platform specific - compat/ implementations, should be git-compat-util.h or another - header file that includes it, such as cache.h or builtin.h. + - The first #include in C files, except in platform specific compat/ + implementations, must be either "git-compat-util.h", "cache.h" or + "builtin.h". You do not have to include more than one of these. + + - A C file must directly include the header files that declare the + functions and the types it uses, except for the functions and types + that are made available to it by including one of the header files + it must include by the previous rule. - If you are planning a new command, consider writing it in shell or perl first, so that changes in semantics can be easily @@@ -446,6 -441,10 +446,10 @@@ Writing Documentation --sort= --abbrev[=] + If a placeholder has multiple words, they are separated by dashes: + + --template= + Possibility of multiple occurrences is indicated by three dots: ... (One or more of .) @@@ -462,12 -461,12 +466,12 @@@ (Zero or more of . Note that the dots are inside, not outside the brackets.) - Multiple alternatives are indicated with vertical bar: + Multiple alternatives are indicated with vertical bars: [-q | --quiet] [--utf8 | --no-utf8] Parentheses are used for grouping: - [(|)...] + [( | )...] (Any number of either or . Parens are needed to make it clear that "..." pertains to both and .) diff --combined builtin/apply.c index dfd7a34117,7cd9a3b593..23bda96287 --- a/builtin/apply.c +++ b/builtin/apply.c @@@ -55,7 -55,7 +55,7 @@@ static const char *fake_ancestor static int line_termination = '\n'; static unsigned int p_context = UINT_MAX; static const char * const apply_usage[] = { - N_("git apply [options] [...]"), + N_("git apply [] [...]"), NULL }; @@@ -657,6 -657,11 +657,6 @@@ static size_t diff_timestamp_len(const return line + len - end; } -static char *null_strdup(const char *s) -{ - return s ? xstrdup(s) : NULL; -} - static char *find_name_common(const char *line, const char *def, int p_value, const char *end, int terminate) { @@@ -679,10 -684,10 +679,10 @@@ start = line; } if (!start) - return squash_slash(null_strdup(def)); + return squash_slash(xstrdup_or_null(def)); len = line - start; if (!len) - return squash_slash(null_strdup(def)); + return squash_slash(xstrdup_or_null(def)); /* * Generally we prefer the shorter name, especially @@@ -904,7 -909,7 +904,7 @@@ static void parse_traditional_patch(con patch->old_name = name; } else { patch->old_name = name; - patch->new_name = null_strdup(name); + patch->new_name = xstrdup_or_null(name); } } if (!name) @@@ -993,7 -998,7 +993,7 @@@ static int gitdiff_delete(const char *l { patch->is_delete = 1; free(patch->old_name); - patch->old_name = null_strdup(patch->def_name); + patch->old_name = xstrdup_or_null(patch->def_name); return gitdiff_oldmode(line, patch); } @@@ -1001,7 -1006,7 +1001,7 @@@ static int gitdiff_newfile(const char * { patch->is_new = 1; free(patch->new_name); - patch->new_name = null_strdup(patch->def_name); + patch->new_name = xstrdup_or_null(patch->def_name); return gitdiff_newmode(line, patch); } diff --combined builtin/blame.c index 0374fe8056,f0fac655ed..44b0134ea2 --- a/builtin/blame.c +++ b/builtin/blame.c @@@ -27,12 -27,12 +27,12 @@@ #include "line-range.h" #include "line-log.h" - static char blame_usage[] = N_("git blame [options] [rev-opts] [rev] [--] file"); + static char blame_usage[] = N_("git blame [] [] [] [--] file"); static const char *blame_opt_usage[] = { blame_usage, "", - N_("[rev-opts] are documented in git-rev-list(1)"), + N_(" are documented in git-rev-list(1)"), NULL }; @@@ -2390,7 -2390,7 +2390,7 @@@ static struct commit *fake_working_tree return commit; } -static const char *prepare_final(struct scoreboard *sb) +static char *prepare_final(struct scoreboard *sb) { int i; const char *final_commit_name = NULL; @@@ -2415,10 -2415,10 +2415,10 @@@ sb->final = (struct commit *) obj; final_commit_name = revs->pending.objects[i].name; } - return final_commit_name; + return xstrdup_or_null(final_commit_name); } -static const char *prepare_initial(struct scoreboard *sb) +static char *prepare_initial(struct scoreboard *sb) { int i; const char *final_commit_name = NULL; @@@ -2445,7 -2445,7 +2445,7 @@@ } if (!final_commit_name) die("No commit to dig down to?"); - return final_commit_name; + return xstrdup(final_commit_name); } static int blame_copy_callback(const struct option *option, const char *arg, int unset) @@@ -2489,7 -2489,7 +2489,7 @@@ int cmd_blame(int argc, const char **ar struct origin *o; struct blame_entry *ent = NULL; long dashdash_pos, lno; - const char *final_commit_name = NULL; + char *final_commit_name = NULL; enum object_type type; static struct string_list range_list; @@@ -2786,8 -2786,6 +2786,8 @@@ parse_done assign_blame(&sb, opt); + free(final_commit_name); + if (incremental) return 0; diff --combined builtin/cat-file.c index 31b133b357,c2e4e53ce4..df99df4db1 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@@ -4,8 -4,12 +4,8 @@@ * Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" -#include "exec_cmd.h" -#include "tag.h" -#include "tree.h" #include "builtin.h" #include "parse-options.h" -#include "diff.h" #include "userdiff.h" #include "streaming.h" @@@ -75,6 -79,8 +75,6 @@@ static int cat_one_file(int opt, const if (type_from_string(exp_type) == OBJ_BLOB) { unsigned char blob_sha1[20]; if (sha1_object_info(sha1, NULL) == OBJ_TAG) { - enum object_type type; - unsigned long size; char *buffer = read_sha1_file(sha1, &type, &size); const char *target; if (!skip_prefix(buffer, "object ", &target) || @@@ -323,8 -329,8 +323,8 @@@ static int batch_objects(struct batch_o } static const char * const cat_file_usage[] = { - N_("git cat-file (-t|-s|-e|-p||--textconv) "), - N_("git cat-file (--batch|--batch-check) < "), + N_("git cat-file (-t | -s | -e | -p | | --textconv) "), + N_("git cat-file (--batch | --batch-check) < "), NULL }; diff --combined builtin/commit.c index 5cd1478ebf,6716e11b8d..7f467133b8 --- a/builtin/commit.c +++ b/builtin/commit.c @@@ -34,12 -34,12 +34,12 @@@ #include "mailmap.h" static const char * const builtin_commit_usage[] = { - N_("git commit [options] [--] ..."), + N_("git commit [] [--] ..."), NULL }; static const char * const builtin_status_usage[] = { - N_("git status [options] [--] ..."), + N_("git status [] [--] ..."), NULL }; @@@ -559,14 -559,20 +559,14 @@@ static void set_ident_var(char **buf, c *buf = val; } -static char *envdup(const char *var) -{ - const char *val = getenv(var); - return val ? xstrdup(val) : NULL; -} - static void determine_author_info(struct strbuf *author_ident) { char *name, *email, *date; struct ident_split author; - name = envdup("GIT_AUTHOR_NAME"); - email = envdup("GIT_AUTHOR_EMAIL"); - date = envdup("GIT_AUTHOR_DATE"); + name = xstrdup_or_null(getenv("GIT_AUTHOR_NAME")); + email = xstrdup_or_null(getenv("GIT_AUTHOR_EMAIL")); + date = xstrdup_or_null(getenv("GIT_AUTHOR_DATE")); if (author_message) { struct ident_split ident; diff --combined builtin/for-each-ref.c index a0123f6146,c97368a843..19be78a943 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@@ -717,10 -717,7 +717,10 @@@ static void populate_value(struct refin starts_with(name, "upstream")) { char buf[40]; - stat_tracking_info(branch, &num_ours, &num_theirs); + if (stat_tracking_info(branch, &num_ours, + &num_theirs) != 1) + continue; + if (!num_ours && !num_theirs) v->s = ""; else if (!num_ours) { @@@ -738,11 -735,7 +738,11 @@@ } else if (!strcmp(formatp, "trackshort") && starts_with(name, "upstream")) { assert(branch); - stat_tracking_info(branch, &num_ours, &num_theirs); + + if (stat_tracking_info(branch, &num_ours, + &num_theirs) != 1) + continue; + if (!num_ours && !num_theirs) v->s = "="; else if (!num_ours) @@@ -1061,7 -1054,7 +1061,7 @@@ static int opt_parse_sort(const struct } static char const * const for_each_ref_usage[] = { - N_("git for-each-ref [options] []"), + N_("git for-each-ref [] []"), NULL }; diff --combined builtin/log.c index a131992c52,d65d96a7a3..dd8f3fcfc4 --- a/builtin/log.c +++ b/builtin/log.c @@@ -38,8 -38,8 +38,8 @@@ static const char *fmt_patch_subject_pr static const char *fmt_pretty; static const char * const builtin_log_usage[] = { - N_("git log [] [] [[--] ...]\n") - N_(" or: git show [] ..."), + N_("git log [] [] [[--] ...]"), - N_("git show [options] ..."), ++ N_("git show [] ..."), NULL }; @@@ -705,7 -705,7 +705,7 @@@ static int git_format_config(const cha return 0; } if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff") || - !strcmp(var, "color.ui")) { + !strcmp(var, "color.ui") || !strcmp(var, "diff.submodule")) { return 0; } if (!strcmp(var, "format.numbered")) { @@@ -1023,7 -1023,7 +1023,7 @@@ static const char *set_outdir(const cha } static const char * const builtin_format_patch_usage[] = { - N_("git format-patch [options] [ | ]"), + N_("git format-patch [] [ | ]"), NULL }; diff --combined builtin/remote.c index b4ff468977,33ff7e06e7..5d3ab906bc --- a/builtin/remote.c +++ b/builtin/remote.c @@@ -10,10 -10,10 +10,10 @@@ static const char * const builtin_remote_usage[] = { N_("git remote [-v | --verbose]"), - N_("git remote add [-t ] [-m ] [-f] [--tags|--no-tags] [--mirror=] "), + N_("git remote add [-t ] [-m ] [-f] [--tags | --no-tags] [--mirror=] "), N_("git remote rename "), N_("git remote remove "), - N_("git remote set-head (-a | --auto | -d | --delete |)"), + N_("git remote set-head (-a | --auto | -d | --delete | )"), N_("git remote [-v | --verbose] show [-n] "), N_("git remote prune [-n | --dry-run] "), N_("git remote [-v | --verbose] update [-p | --prune] [( | )...]"), @@@ -180,9 -180,7 +180,9 @@@ static int add(int argc, const char **a url = argv[1]; remote = remote_get(name); - if (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) || + if (remote && (remote->url_nr > 1 || + (strcmp(name, remote->url[0]) && + strcmp(url, remote->url[0])) || remote->fetch_refspec_nr)) die(_("remote %s already exists."), name); diff --combined builtin/show-branch.c index 365228aa8d,e9b37dc479..f3fb5fb2bf --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@@ -6,11 -6,8 +6,11 @@@ #include "parse-options.h" static const char* show_branch_usage[] = { - N_("git show-branch [-a|--all] [-r|--remotes] [--topo-order | --date-order]\n" - N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order] [--current] [--color[=] | --no-color] [--sparse] [--more= | --list | --independent | --merge-base] [--no-name | --sha1-name] [--topics] [( | )...]"), ++ N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n" + " [--current] [--color[=] | --no-color] [--sparse]\n" + " [--more= | --list | --independent | --merge-base]\n" + " [--no-name | --sha1-name] [--topics] [( | )...]"), - N_("git show-branch (-g|--reflog)[=[,]] [--list] []"), + N_("git show-branch (-g | --reflog)[=[,]] [--list] []"), NULL }; diff --combined git.c index 6b5ae6a2ac,0c029ecc4f..8c7ee9c830 --- a/git.c +++ b/git.c @@@ -1,12 -1,15 +1,12 @@@ #include "builtin.h" -#include "cache.h" #include "exec_cmd.h" #include "help.h" -#include "quote.h" #include "run-command.h" -#include "commit.h" const char git_usage_string[] = "git [--version] [--help] [-C ] [-c name=value]\n" " [--exec-path[=]] [--html-path] [--man-path] [--info-path]\n" - " [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]\n" + " [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]\n" " [--git-dir=] [--work-tree=] [--namespace=]\n" " []";