Merge branch 'jk/maint-status-keep-index-timestamp'
authorJunio C Hamano <gitster@pobox.com>
Thu, 15 Jul 2010 19:06:55 +0000 (12:06 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 15 Jul 2010 19:06:55 +0000 (12:06 -0700)
* jk/maint-status-keep-index-timestamp:
do not write out index when status does not have to

1  2 
builtin/commit.c
diff --combined builtin/commit.c
index c101f006f6b5d7d185aa97081fb9717de92b09cd,da18287ca9f9d2ced22f9b210047c1282b0a9dd2..a78dbd83bf04c7080487b8508321d79d848e9b1f
@@@ -62,7 -62,7 +62,7 @@@ static struct lock_file false_lock; /* 
  static enum {
        COMMIT_AS_IS = 1,
        COMMIT_NORMAL,
 -      COMMIT_PARTIAL,
 +      COMMIT_PARTIAL
  } commit_style;
  
  static const char *logfile, *force_author;
@@@ -71,8 -71,8 +71,8 @@@ 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 char *untracked_files_arg, *force_date;
 +static int no_post_rewrite, allow_empty_message;
 +static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
  /*
   * The default commit message cleanup mode will remove the lines
   * beginning with # (shell comments) and leading and trailing
  static enum {
        CLEANUP_SPACE,
        CLEANUP_NONE,
 -      CLEANUP_ALL,
 +      CLEANUP_ALL
  } cleanup_mode;
  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;
  
@@@ -96,9 -95,8 +96,9 @@@ static int null_termination
  static enum {
        STATUS_FORMAT_LONG,
        STATUS_FORMAT_SHORT,
 -      STATUS_FORMAT_PORCELAIN,
 +      STATUS_FORMAT_PORCELAIN
  } status_format = STATUS_FORMAT_LONG;
 +static int status_show_branch;
  
  static int opt_parse_m(const struct option *opt, const char *arg, int unset)
  {
@@@ -140,7 -138,6 +140,7 @@@ static struct option builtin_commit_opt
        OPT_BOOLEAN(0, "dry-run", &dry_run, "show what would be committed"),
        OPT_SET_INT(0, "short", &status_format, "show status concisely",
                    STATUS_FORMAT_SHORT),
 +      OPT_BOOLEAN(0, "branch", &status_show_branch, "show branch information"),
        OPT_SET_INT(0, "porcelain", &status_format,
                    "show porcelain output format", STATUS_FORMAT_PORCELAIN),
        OPT_BOOLEAN('z', "null", &null_termination,
        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()
  };
  
@@@ -219,7 -210,7 +219,7 @@@ static int list_paths(struct string_lis
                        continue;
                if (!match_pathspec(pattern, ce->name, ce_namelen(ce), 0, m))
                        continue;
 -              item = string_list_insert(ce->name, list);
 +              item = string_list_insert(list, ce->name);
                if (ce_skip_worktree(ce))
                        item->util = item; /* better a valid pointer than a fake one */
        }
@@@ -343,9 -334,13 +343,13 @@@ static char *prepare_index(int argc, co
        if (!pathspec || !*pathspec) {
                fd = hold_locked_index(&index_lock, 1);
                refresh_cache_or_die(refresh_flags);
-               if (write_cache(fd, active_cache, active_nr) ||
-                   commit_locked_index(&index_lock))
-                       die("unable to write new_index file");
+               if (active_cache_changed) {
+                       if (write_cache(fd, active_cache, active_nr) ||
+                           commit_locked_index(&index_lock))
+                               die("unable to write new_index file");
+               } else {
+                       rollback_lock_file(&index_lock);
+               }
                commit_style = COMMIT_AS_IS;
                return get_index_file();
        }
@@@ -431,7 -426,7 +435,7 @@@ static int run_status(FILE *fp, const c
  
        switch (status_format) {
        case STATUS_FORMAT_SHORT:
 -              wt_shortstatus_print(s, null_termination);
 +              wt_shortstatus_print(s, null_termination, status_show_branch);
                break;
        case STATUS_FORMAT_PORCELAIN:
                wt_porcelain_print(s, null_termination);
@@@ -739,8 -734,7 +743,8 @@@ static int prepare_to_commit(const cha
  
        if (use_editor) {
                char index[PATH_MAX];
 -              const char *env[2] = { index, NULL };
 +              const char *env[2] = { NULL };
 +              env[0] =  index;
                snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
                if (launch_editor(git_path(commit_editmsg), NULL, env)) {
                        fprintf(stderr,
@@@ -1046,8 -1040,6 +1050,8 @@@ int cmd_status(int argc, const char **a
                OPT__VERBOSE(&verbose),
                OPT_SET_INT('s', "short", &status_format,
                            "show status concisely", STATUS_FORMAT_SHORT),
 +              OPT_BOOLEAN('b', "branch", &status_show_branch,
 +                          "show branch information"),
                OPT_SET_INT(0, "porcelain", &status_format,
                            "show porcelain output format",
                            STATUS_FORMAT_PORCELAIN),
                  "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"),
 +              { OPTION_STRING, 0, "ignore-submodules", &ignore_submodule_arg, "when",
 +                "ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)",
 +                PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
                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);
  
  
        fd = hold_locked_index(&index_lock, 0);
        if (0 <= fd) {
-               if (!write_cache(fd, active_cache, active_nr))
+               if (active_cache_changed &&
+                   !write_cache(fd, active_cache, active_nr))
                        commit_locked_index(&index_lock);
-               rollback_lock_file(&index_lock);
+               else
+                       rollback_lock_file(&index_lock);
        }
  
        s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
        s.in_merge = in_merge;
 +      s.ignore_submodule_arg = ignore_submodule_arg;
        wt_status_collect(&s);
  
        if (s.relative_paths)
  
        switch (status_format) {
        case STATUS_FORMAT_SHORT:
 -              wt_shortstatus_print(&s, null_termination);
 +              wt_shortstatus_print(&s, null_termination, status_show_branch);
                break;
        case STATUS_FORMAT_PORCELAIN:
                wt_porcelain_print(&s, null_termination);
                break;
        case STATUS_FORMAT_LONG:
                s.verbose = verbose;
 +              s.ignore_submodule_arg = ignore_submodule_arg;
                wt_status_print(&s);
                break;
        }
@@@ -1338,7 -1324,7 +1344,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);