Merge branch 'ah/usage-strings'
authorJunio C Hamano <gitster@pobox.com>
Wed, 11 Feb 2015 21:44:19 +0000 (13:44 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 11 Feb 2015 21:44:20 +0000 (13:44 -0800)
* ah/usage-strings:
standardize usage info string format

1  2 
Documentation/CodingGuidelines
builtin/apply.c
builtin/blame.c
builtin/cat-file.c
builtin/commit.c
builtin/for-each-ref.c
builtin/log.c
builtin/remote.c
builtin/show-branch.c
git.c
index 578d07c03419bf0d49b38c68feb77ce6dffd8d72,ad3b2adb600dac04edd0c65cdf8bccbe9523a6b6..49089de5c0024202493867e545d3d6b87c98571d
@@@ -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=<key>
     --abbrev[=<n>]
  
+  If a placeholder has multiple words, they are separated by dashes:
+    <new-branch-name>
+    --template=<template-directory>
   Possibility of multiple occurrences is indicated by three dots:
     <file>...
     (One or more of <file>.)
     (Zero or more of <patch>.  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:
-    [(<rev>|<range>)...]
+    [(<rev> | <range>)...]
     (Any number of either <rev> or <range>.  Parens are needed to make
     it clear that "..." pertains to both <rev> and <range>.)
  
diff --combined builtin/apply.c
index dfd7a34117c5d2a9287f59626941a216fc00ff90,7cd9a3b593a7d7308e4607144a37805ed20bb6ff..23bda9628795016353d6feaf2b9699e48837f62c
@@@ -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] [<patch>...]"),
+       N_("git apply [<options>] [<patch>...]"),
        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)
  {
                        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 0374fe8056acfe193d2cbd5c553b3de889b788fe,f0fac655edeed66c196154b73420105d6b301949..44b0134ea295baf0eb8cd8b3de0b8aa8a5dce02e
  #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 [<options>] [<rev-opts>] [<rev>] [--] file");
  
  static const char *blame_opt_usage[] = {
        blame_usage,
        "",
-       N_("[rev-opts] are documented in git-rev-list(1)"),
+       N_("<rev-opts> 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;
                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;
        }
        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 31b133b357f34e9bc0a63dec5ce2dbceba43e765,c2e4e53ce454376f074259e4844ded134b30c8db..df99df4db1ddb058368fe88f07c890d87600e6d9
@@@ -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|<type>|--textconv) <object>"),
-       N_("git cat-file (--batch|--batch-check) < <list_of_objects>"),
+       N_("git cat-file (-t | -s | -e | -p | <type> | --textconv) <object>"),
+       N_("git cat-file (--batch | --batch-check) < <list-of-objects>"),
        NULL
  };
  
diff --combined builtin/commit.c
index 5cd1478ebfdae36a8112c7f93f9017b54954cf44,6716e11b8dbd2a73cd875b528c0471703f0adfb3..7f467133b88c10e2440c878a0218bee981b3acd7
  #include "mailmap.h"
  
  static const char * const builtin_commit_usage[] = {
-       N_("git commit [options] [--] <pathspec>..."),
+       N_("git commit [<options>] [--] <pathspec>..."),
        NULL
  };
  
  static const char * const builtin_status_usage[] = {
-       N_("git status [options] [--] <pathspec>..."),
+       N_("git status [<options>] [--] <pathspec>..."),
        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 a0123f6146b53de295d01b438b72fb3dc7d76a0c,c97368a843fa0c513c93bb7f5e4c9ff6ca10cb8c..19be78a943d303700379f665d64c8843c69848d5
@@@ -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) {
                        } 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] [<pattern>]"),
+       N_("git for-each-ref [<options>] [<pattern>]"),
        NULL
  };
  
diff --combined builtin/log.c
index a131992c52f96daeb7c72b447c5ed6929c01a96a,d65d96a7a349e3902ca080c39a3de48d9a5a55cb..dd8f3fcfc451780b244f6e6fd9e77298f484ad1a
@@@ -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 [<options>] [<revision-range>] [[--] <path>...]\n")
 -      N_("   or: git show [<options>] <object>..."),
 +      N_("git log [<options>] [<revision range>] [[--] <path>...]"),
-       N_("git show [options] <object>..."),
++      N_("git show [<options>] <object>..."),
        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] [<since> | <revision range>]"),
+       N_("git format-patch [<options>] [<since> | <revision-range>]"),
        NULL
  };
  
diff --combined builtin/remote.c
index b4ff4689770e402675faba2ce400150b4803a360,33ff7e06e71945d8cc12b479acd2e61664ebc655..5d3ab906bc7ef6cc8cc9c65a3b86cf4c1ff443fb
  
  static const char * const builtin_remote_usage[] = {
        N_("git remote [-v | --verbose]"),
-       N_("git remote add [-t <branch>] [-m <master>] [-f] [--tags|--no-tags] [--mirror=<fetch|push>] <name> <url>"),
+       N_("git remote add [-t <branch>] [-m <master>] [-f] [--tags | --no-tags] [--mirror=<fetch|push>] <name> <url>"),
        N_("git remote rename <old> <new>"),
        N_("git remote remove <name>"),
-       N_("git remote set-head <name> (-a | --auto | -d | --delete |<branch>)"),
+       N_("git remote set-head <name> (-a | --auto | -d | --delete | <branch>)"),
        N_("git remote [-v | --verbose] show [-n] <name>"),
        N_("git remote prune [-n | --dry-run] <name>"),
        N_("git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]"),
@@@ -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 365228aa8d805bdf86a6eecccdc088068ba000d2,e9b37dc479996323059b4bdfaa2894ef5828b20c..f3fb5fb2bf28019dafcbd2bfbd6b1a024aa6da2f
@@@ -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[=<when>] | --no-color] [--sparse] [--more=<n> | --list | --independent | --merge-base] [--no-name | --sha1-name] [--topics] [(<rev> | <glob>)...]"),
++    N_("git show-branch [-a | --all] [-r | --remotes] [--topo-order | --date-order]\n"
 +       "              [--current] [--color[=<when>] | --no-color] [--sparse]\n"
 +       "              [--more=<n> | --list | --independent | --merge-base]\n"
 +       "              [--no-name | --sha1-name] [--topics] [(<rev> | <glob>)...]"),
-     N_("git show-branch (-g|--reflog)[=<n>[,<base>]] [--list] [<ref>]"),
+     N_("git show-branch (-g | --reflog)[=<n>[,<base>]] [--list] [<ref>]"),
      NULL
  };
  
diff --combined git.c
index 6b5ae6a2ace7fffdd2ec50ce915ad5dc01a9c7da,0c029ecc4f758aa4719488dbc4b7aaf1232581bb..8c7ee9c83000765afa3808f3dd0941aa484ca1ec
--- 1/git.c
--- 2/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 <path>] [-c name=value]\n"
        "           [--exec-path[=<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=<path>] [--work-tree=<path>] [--namespace=<name>]\n"
        "           <command> [<args>]";