]> rtime.felk.cvut.cz Git - git.git/commitdiff
Merge branch 'jn/maint-amend-missing-name'
authorJunio C Hamano <gitster@pobox.com>
Sun, 13 Jun 2010 18:20:52 +0000 (11:20 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 13 Jun 2010 18:20:52 +0000 (11:20 -0700)
* jn/maint-amend-missing-name:
  commit --amend: cope with missing display name

1  2 
builtin/commit.c

diff --combined builtin/commit.c
index ddf77e48e1d9fa1e6db0ac49008857b85a9b5e41,58e477409cf24a30658c606e344675afa73c37fe..a4e4966319651c03a3bb933795c502b24b2324d4
@@@ -66,7 -66,7 +66,7 @@@ static char *edit_message, *use_message
  static char *author_name, *author_email, *author_date;
  static int all, edit_flag, also, interactive, only, amend, signoff;
  static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
 -static int no_post_rewrite;
 +static int no_post_rewrite, allow_empty_message;
  static char *untracked_files_arg, *force_date;
  /*
   * The default commit message cleanup mode will remove the lines
@@@ -83,7 -83,6 +83,7 @@@ static enum 
  static char *cleanup_arg;
  
  static int use_editor = 1, initial_commit, in_merge, include_status = 1;
 +static int show_ignored_in_status;
  static const char *only_include_assumed;
  static struct strbuf message;
  
@@@ -141,15 -140,9 +141,15 @@@ static struct option builtin_commit_opt
        OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
        OPT_BOOLEAN(0, "no-post-rewrite", &no_post_rewrite, "bypass post-rewrite hook"),
        { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
 -      OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
        /* end commit contents options */
  
 +      { OPTION_BOOLEAN, 0, "allow-empty", &allow_empty, NULL,
 +        "ok to record an empty change",
 +        PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
 +      { OPTION_BOOLEAN, 0, "allow-empty-message", &allow_empty_message, NULL,
 +        "ok to record a change with an empty message",
 +        PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
 +
        OPT_END()
  };
  
@@@ -462,15 -455,21 +462,21 @@@ static void determine_author_info(void
                if (!a)
                        die("invalid commit: %s", use_message);
  
-               lb = strstr(a + 8, " <");
-               rb = strstr(a + 8, "> ");
-               eol = strchr(a + 8, '\n');
-               if (!lb || !rb || !eol)
+               lb = strchrnul(a + strlen("\nauthor "), '<');
+               rb = strchrnul(lb, '>');
+               eol = strchrnul(rb, '\n');
+               if (!*lb || !*rb || !*eol)
                        die("invalid commit: %s", use_message);
  
-               name = xstrndup(a + 8, lb - (a + 8));
-               email = xstrndup(lb + 2, rb - (lb + 2));
-               date = xstrndup(rb + 2, eol - (rb + 2));
+               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("<")));
+               date = xmemdupz(rb + strlen("> "), eol - (rb + strlen("> ")));
        }
  
        if (force_author) {
@@@ -1024,7 -1023,6 +1030,7 @@@ static int git_status_config(const cha
  int cmd_status(int argc, const char **argv, const char *prefix)
  {
        struct wt_status s;
 +      int fd;
        unsigned char sha1[20];
        static struct option builtin_status_options[] = {
                OPT__VERBOSE(&verbose),
                  "mode",
                  "show untracked files, optional modes: all, normal, no. (Default: all)",
                  PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
 +              OPT_BOOLEAN(0, "ignored", &show_ignored_in_status,
 +                          "show ignored files"),
                OPT_END(),
        };
  
                             builtin_status_options,
                             builtin_status_usage, 0);
        handle_untracked_files_arg(&s);
 -
 +      if (show_ignored_in_status)
 +              s.show_ignored_files = 1;
        if (*argv)
                s.pathspec = get_pathspec(prefix, argv);
  
        read_cache_preload(s.pathspec);
        refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec, NULL, NULL);
 +
 +      fd = hold_locked_index(&index_lock, 0);
 +      if (0 <= fd) {
 +              if (!write_cache(fd, active_cache, active_nr))
 +                      commit_locked_index(&index_lock);
 +              rollback_lock_file(&index_lock);
 +      }
 +
        s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
        s.in_merge = in_merge;
        wt_status_collect(&s);
@@@ -1312,7 -1299,7 +1318,7 @@@ int cmd_commit(int argc, const char **a
  
        if (cleanup_mode != CLEANUP_NONE)
                stripspace(&sb, cleanup_mode == CLEANUP_ALL);
 -      if (message_is_empty(&sb)) {
 +      if (message_is_empty(&sb) && !allow_empty_message) {
                rollback_index_files();
                fprintf(stderr, "Aborting commit due to empty commit message.\n");
                exit(1);