Merge branch 'ah/grammofix'
authorJunio C Hamano <gitster@pobox.com>
Fri, 19 Sep 2014 18:38:35 +0000 (11:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Sep 2014 18:38:35 +0000 (11:38 -0700)
* ah/grammofix:
grammofix in user-facing messages

1  2 
builtin/commit.c
builtin/merge.c
builtin/notes.c
git-stash.sh
git.c
diff --combined builtin/commit.c
index 4a45bedc09d636c58a25099c4ee4b066d7a94284,59c91ea1a48b98845f5f197a5640c8887d29cd8b..b0fe7847d3cbebd2cef28611171924bf7440c467
@@@ -42,20 -42,7 +42,20 @@@ static const char * const builtin_statu
        NULL
  };
  
 -static const char implicit_ident_advice[] =
 +static const char implicit_ident_advice_noconfig[] =
 +N_("Your name and email address were configured automatically based\n"
 +"on your username and hostname. Please check that they are accurate.\n"
 +"You can suppress this message by setting them explicitly. Run the\n"
 +"following command and follow the instructions in your editor to edit\n"
 +"your configuration file:\n"
 +"\n"
 +"    git config --global --edit\n"
 +"\n"
 +"After doing this, you may fix the identity used for this commit with:\n"
 +"\n"
 +"    git commit --amend --reset-author\n");
 +
 +static const char implicit_ident_advice_config[] =
  N_("Your name and email address were configured automatically based\n"
  "on your username and hostname. Please check that they are accurate.\n"
  "You can suppress this message by setting them explicitly:\n"
@@@ -353,13 -340,6 +353,13 @@@ static char *prepare_index(int argc, co
  
                discard_cache();
                read_cache_from(index_lock.filename);
 +              if (update_main_cache_tree(WRITE_TREE_SILENT) == 0) {
 +                      if (reopen_lock_file(&index_lock) < 0)
 +                              die(_("unable to write index file"));
 +                      if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
 +                              die(_("unable to update temporary index"));
 +              } else
 +                      warning(_("Failed to update main cache tree"));
  
                commit_style = COMMIT_NORMAL;
                return index_lock.filename;
        if (!only && !pathspec.nr) {
                hold_locked_index(&index_lock, 1);
                refresh_cache_or_die(refresh_flags);
 -              if (active_cache_changed) {
 +              if (active_cache_changed
 +                  || !cache_tree_fully_valid(active_cache_tree)) {
                        update_main_cache_tree(WRITE_TREE_SILENT);
 +                      active_cache_changed = 1;
 +              }
 +              if (active_cache_changed) {
                        if (write_locked_index(&the_index, &index_lock,
                                               COMMIT_LOCK))
                                die(_("unable to write new_index file"));
        hold_locked_index(&index_lock, 1);
        add_remove_files(&partial);
        refresh_cache(REFRESH_QUIET);
 +      update_main_cache_tree(WRITE_TREE_SILENT);
        if (write_locked_index(&the_index, &index_lock, CLOSE_LOCK))
                die(_("unable to write new_index file"));
  
@@@ -545,80 -520,77 +545,80 @@@ static int sane_ident_split(struct iden
        return 1;
  }
  
 -static int parse_force_date(const char *in, char *out, int len)
 +static int parse_force_date(const char *in, struct strbuf *out)
  {
 -      if (len < 1)
 -              return -1;
 -      *out++ = '@';
 -      len--;
 +      strbuf_addch(out, '@');
  
 -      if (parse_date(in, out, len) < 0) {
 +      if (parse_date(in, out) < 0) {
                int errors = 0;
                unsigned long t = approxidate_careful(in, &errors);
                if (errors)
                        return -1;
 -              snprintf(out, len, "%lu", t);
 +              strbuf_addf(out, "%lu", t);
        }
  
        return 0;
  }
  
 +static void set_ident_var(char **buf, char *val)
 +{
 +      free(*buf);
 +      *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;
 -      char date_buf[64];
  
 -      name = getenv("GIT_AUTHOR_NAME");
 -      email = getenv("GIT_AUTHOR_EMAIL");
 -      date = getenv("GIT_AUTHOR_DATE");
 +      name = envdup("GIT_AUTHOR_NAME");
 +      email = envdup("GIT_AUTHOR_EMAIL");
 +      date = envdup("GIT_AUTHOR_DATE");
  
        if (author_message) {
 -              const char *a, *lb, *rb, *eol;
 +              struct ident_split ident;
                size_t len;
 +              const char *a;
  
 -              a = strstr(author_message_buffer, "\nauthor ");
 +              a = find_commit_header(author_message_buffer, "author", &len);
                if (!a)
 -                      die(_("invalid commit: %s"), author_message);
 -
 -              lb = strchrnul(a + strlen("\nauthor "), '<');
 -              rb = strchrnul(lb, '>');
 -              eol = strchrnul(rb, '\n');
 -              if (!*lb || !*rb || !*eol)
 -                      die(_("invalid commit: %s"), author_message);
 -
 -              if (lb == a + strlen("\nauthor "))
 -                      /* \nauthor <foo@example.com> */
 -                      name = xcalloc(1, 1);
 -              else
 -                      name = xmemdupz(a + strlen("\nauthor "),
 -                                      (lb - strlen(" ") -
 -                                       (a + strlen("\nauthor "))));
 -              email = xmemdupz(lb + strlen("<"), rb - (lb + strlen("<")));
 -              len = eol - (rb + strlen("> "));
 -              date = xmalloc(len + 2);
 -              *date = '@';
 -              memcpy(date + 1, rb + strlen("> "), len);
 -              date[len + 1] = '\0';
 +                      die(_("commit '%s' lacks author header"), author_message);
 +              if (split_ident_line(&ident, a, len) < 0)
 +                      die(_("commit '%s' has malformed author line"), author_message);
 +
 +              set_ident_var(&name, xmemdupz(ident.name_begin, ident.name_end - ident.name_begin));
 +              set_ident_var(&email, xmemdupz(ident.mail_begin, ident.mail_end - ident.mail_begin));
 +
 +              if (ident.date_begin) {
 +                      struct strbuf date_buf = STRBUF_INIT;
 +                      strbuf_addch(&date_buf, '@');
 +                      strbuf_add(&date_buf, ident.date_begin, ident.date_end - ident.date_begin);
 +                      strbuf_addch(&date_buf, ' ');
 +                      strbuf_add(&date_buf, ident.tz_begin, ident.tz_end - ident.tz_begin);
 +                      set_ident_var(&date, strbuf_detach(&date_buf, NULL));
 +              }
        }
  
        if (force_author) {
 -              const char *lb = strstr(force_author, " <");
 -              const char *rb = strchr(force_author, '>');
 +              struct ident_split ident;
  
 -              if (!lb || !rb)
 +              if (split_ident_line(&ident, force_author, strlen(force_author)) < 0)
                        die(_("malformed --author parameter"));
 -              name = xstrndup(force_author, lb - force_author);
 -              email = xstrndup(lb + 2, rb - (lb + 2));
 +              set_ident_var(&name, xmemdupz(ident.name_begin, ident.name_end - ident.name_begin));
 +              set_ident_var(&email, xmemdupz(ident.mail_begin, ident.mail_end - ident.mail_begin));
        }
  
        if (force_date) {
 -              if (parse_force_date(force_date, date_buf, sizeof(date_buf)))
 +              struct strbuf date_buf = STRBUF_INIT;
 +              if (parse_force_date(force_date, &date_buf))
                        die(_("invalid date format: %s"), force_date);
 -              date = date_buf;
 +              set_ident_var(&date, strbuf_detach(&date_buf, NULL));
        }
  
        strbuf_addstr(author_ident, fmt_ident(name, email, date, IDENT_STRICT));
                export_one("GIT_AUTHOR_EMAIL", author.mail_begin, author.mail_end, 0);
                export_one("GIT_AUTHOR_DATE", author.date_begin, author.tz_end, '@');
        }
 +
 +      free(name);
 +      free(email);
 +      free(date);
  }
  
  static void split_ident_or_die(struct ident_split *id, const struct strbuf *buf)
@@@ -1080,8 -1048,7 +1080,8 @@@ static const char *find_author_by_nickn
        revs.mailmap = &mailmap;
        read_mailmap(revs.mailmap, NULL);
  
 -      prepare_revision_walk(&revs);
 +      if (prepare_revision_walk(&revs))
 +              die(_("revision walk setup failed"));
        commit = get_revision(&revs);
        if (commit) {
                struct pretty_print_context ctx = {0};
@@@ -1435,24 -1402,6 +1435,24 @@@ int cmd_status(int argc, const char **a
        return 0;
  }
  
 +static const char *implicit_ident_advice(void)
 +{
 +      char *user_config = NULL;
 +      char *xdg_config = NULL;
 +      int config_exists;
 +
 +      home_config_paths(&user_config, &xdg_config, "config");
 +      config_exists = file_exists(user_config) || file_exists(xdg_config);
 +      free(user_config);
 +      free(xdg_config);
 +
 +      if (config_exists)
 +              return _(implicit_ident_advice_config);
 +      else
 +              return _(implicit_ident_advice_noconfig);
 +
 +}
 +
  static void print_summary(const char *prefix, const unsigned char *sha1,
                          int initial_commit)
  {
                strbuf_addbuf_percentquote(&format, &committer_ident);
                if (advice_implicit_identity) {
                        strbuf_addch(&format, '\n');
 -                      strbuf_addstr(&format, _(implicit_ident_advice));
 +                      strbuf_addstr(&format, implicit_ident_advice());
                }
        }
        strbuf_release(&author_ident);
@@@ -1559,7 -1508,7 +1559,7 @@@ static int run_rewrite_hook(const unsig
  {
        /* oldsha1 SP newsha1 LF NUL */
        static char buf[2*40 + 3];
 -      struct child_process proc;
 +      struct child_process proc = CHILD_PROCESS_INIT;
        const char *argv[3];
        int code;
        size_t n;
        argv[1] = "amend";
        argv[2] = NULL;
  
 -      memset(&proc, 0, sizeof(proc));
        proc.argv = argv;
        proc.in = -1;
        proc.stdout_to_stderr = 1;
@@@ -1670,12 -1620,11 +1670,12 @@@ int cmd_commit(int argc, const char **a
        const char *index_file, *reflog_msg;
        char *nl;
        unsigned char sha1[20];
 -      struct ref_lock *ref_lock;
        struct commit_list *parents = NULL, **pptr = &parents;
        struct stat statbuf;
        struct commit *current_head = NULL;
        struct commit_extra_header *extra = NULL;
 +      struct ref_transaction *transaction;
 +      struct strbuf err = STRBUF_INIT;
  
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage_with_options(builtin_commit_usage, builtin_commit_options);
        strbuf_release(&author_ident);
        free_commit_extra_headers(extra);
  
 -      ref_lock = lock_any_ref_for_update("HEAD",
 -                                         !current_head
 -                                         ? NULL
 -                                         : current_head->object.sha1,
 -                                         0, NULL);
 -      if (!ref_lock) {
 -              rollback_index_files();
 -              die(_("cannot lock HEAD ref"));
 -      }
 -
        nl = strchr(sb.buf, '\n');
        if (nl)
                strbuf_setlen(&sb, nl + 1 - sb.buf);
        strbuf_insert(&sb, 0, reflog_msg, strlen(reflog_msg));
        strbuf_insert(&sb, strlen(reflog_msg), ": ", 2);
  
 -      if (write_ref_sha1(ref_lock, sha1, sb.buf) < 0) {
 +      transaction = ref_transaction_begin(&err);
 +      if (!transaction ||
 +          ref_transaction_update(transaction, "HEAD", sha1,
 +                                 current_head
 +                                 ? current_head->object.sha1 : NULL,
 +                                 0, !!current_head, &err) ||
 +          ref_transaction_commit(transaction, sb.buf, &err)) {
                rollback_index_files();
 -              die(_("cannot update HEAD ref"));
 +              die("%s", err.buf);
        }
 +      ref_transaction_free(transaction);
  
        unlink(git_path("CHERRY_PICK_HEAD"));
        unlink(git_path("REVERT_HEAD"));
  
        if (commit_index_files())
                die (_("Repository has been updated, but unable to write\n"
-                    "new_index file. Check that disk is not full or quota is\n"
+                    "new_index file. Check that disk is not full and quota is\n"
                     "not exceeded, and then \"git reset HEAD\" to recover."));
  
        rerere(0);
        if (!quiet)
                print_summary(prefix, sha1, !current_head);
  
 +      strbuf_release(&err);
        return 0;
  }
diff --combined builtin/merge.c
index 9da9e30d9be46a5ed2de06e8545fe61537ba3676,db47200d81761bdbd5853ae1756481c6d95fe2ac..ec6fa9398faf2e5c61ebce198a5006cfb6dc8192
@@@ -237,10 -237,11 +237,10 @@@ static void drop_save(void
  static int save_state(unsigned char *stash)
  {
        int len;
 -      struct child_process cp;
 +      struct child_process cp = CHILD_PROCESS_INIT;
        struct strbuf buffer = STRBUF_INIT;
        const char *argv[] = {"stash", "create", NULL};
  
 -      memset(&cp, 0, sizeof(cp));
        cp.argv = argv;
        cp.out = -1;
        cp.git_cmd = 1;
@@@ -1143,14 -1144,14 +1143,14 @@@ int cmd_merge(int argc, const char **ar
                 */
                if (advice_resolve_conflict)
                        die(_("You have not concluded your merge (MERGE_HEAD exists).\n"
-                                 "Please, commit your changes before you can merge."));
+                                 "Please, commit your changes before you merge."));
                else
                        die(_("You have not concluded your merge (MERGE_HEAD exists)."));
        }
        if (file_exists(git_path("CHERRY_PICK_HEAD"))) {
                if (advice_resolve_conflict)
                        die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
-                           "Please, commit your changes before you can merge."));
+                           "Please, commit your changes before you merge."));
                else
                        die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists)."));
        }
diff --combined builtin/notes.c
index c25a4125103b5bb1c8571864a974105decc1a181,0606964ce483f472d03a8b35a239bdf5fd465f3e..67d0bb14f8f18003d6a073b0c264f5b46ca12685
@@@ -122,11 -122,12 +122,11 @@@ static void write_commented_object(int 
  {
        const char *show_args[5] =
                {"show", "--stat", "--no-notes", sha1_to_hex(object), NULL};
 -      struct child_process show;
 +      struct child_process show = CHILD_PROCESS_INIT;
        struct strbuf buf = STRBUF_INIT;
        struct strbuf cbuf = STRBUF_INIT;
  
        /* Invoke "git show --stat --no-notes $object" */
 -      memset(&show, 0, sizeof(show));
        show.argv = show_args;
        show.no_stdin = 1;
        show.out = -1;
@@@ -210,7 -211,7 +210,7 @@@ static void create_note(const unsigned 
                if (write_sha1_file(msg->buf.buf, msg->buf.len, blob_type, result)) {
                        error(_("unable to write note object"));
                        if (path)
-                               error(_("The note contents has been left in %s"),
+                               error(_("The note contents have been left in %s"),
                                      path);
                        exit(128);
                }
diff --combined git-stash.sh
index 9c1ba8e4b81a1f118af1967c2c72795ba12d6df0,a640a36513d18aa878d8d2ed4a44683576f20ee5..0158c7338685c8ccbc31766927f905b455a444c2
@@@ -297,7 -297,7 +297,7 @@@ have_stash () 
  
  list_stash () {
        have_stash || return 0
 -      git log --format="%gd: %gs" -g "$@" $ref_stash --
 +      git log --format="%gd: %gs" -g --first-parent -m "$@" $ref_stash --
  }
  
  show_stash () {
@@@ -394,7 -394,7 +394,7 @@@ parse_flags_and_rev(
  
        REV=$(git rev-parse --quiet --symbolic --verify "$1" 2>/dev/null) || {
                reference="$1"
-               die "$(eval_gettext "\$reference is not valid reference")"
+               die "$(eval_gettext "\$reference is not valid reference")"
        }
  
        i_commit=$(git rev-parse --quiet --verify "$REV^2" 2>/dev/null) &&
diff --combined git.c
index 210f1ae9d04dda4d16f9f072ef710bf630f6d52e,465d33a83599bf6abaf1d73e7464d8ab13b8ff84..523768da616c5884d2279acebc43cf57c98dd3e2
--- 1/git.c
--- 2/git.c
+++ b/git.c
@@@ -14,13 -14,13 +14,13 @@@ const char git_usage_string[] 
        "           <command> [<args>]";
  
  const char git_more_info_string[] =
-       N_("'git help -a' and 'git help -g' lists available subcommands and some\n"
+       N_("'git help -a' and 'git help -g' list available subcommands and some\n"
           "concept guides. See 'git help <command>' or 'git help <concept>'\n"
           "to read about a specific subcommand or concept.");
  
  static struct startup_info git_startup_info;
  static int use_pager = -1;
 -static char orig_cwd[PATH_MAX];
 +static char *orig_cwd;
  static const char *env_names[] = {
        GIT_DIR_ENVIRONMENT,
        GIT_WORK_TREE_ENVIRONMENT,
@@@ -36,7 -36,8 +36,7 @@@ static void save_env(void
        if (saved_environment)
                return;
        saved_environment = 1;
 -      if (!getcwd(orig_cwd, sizeof(orig_cwd)))
 -              die_errno("cannot getcwd");
 +      orig_cwd = xgetcwd();
        for (i = 0; i < ARRAY_SIZE(env_names); i++) {
                orig_env[i] = getenv(env_names[i]);
                if (orig_env[i])
@@@ -47,9 -48,8 +47,9 @@@
  static void restore_env(void)
  {
        int i;
 -      if (*orig_cwd && chdir(orig_cwd))
 +      if (orig_cwd && chdir(orig_cwd))
                die_errno("could not move to %s", orig_cwd);
 +      free(orig_cwd);
        for (i = 0; i < ARRAY_SIZE(env_names); i++) {
                if (orig_env[i])
                        setenv(env_names[i], orig_env[i], 1);
@@@ -161,10 -161,9 +161,10 @@@ static int handle_options(const char **
                        if (envchanged)
                                *envchanged = 1;
                } else if (!strcmp(cmd, "--bare")) {
 -                      static char git_dir[PATH_MAX+1];
 +                      char *cwd = xgetcwd();
                        is_bare_repository_cfg = 1;
 -                      setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 0);
 +                      setenv(GIT_DIR_ENVIRONMENT, cwd, 0);
 +                      free(cwd);
                        setenv(GIT_IMPLICIT_WORK_TREE_ENVIRONMENT, "0", 1);
                        if (envchanged)
                                *envchanged = 1;