Merge branch 'jk/reset-ident-time-per-commit' into maint
authorJunio C Hamano <gitster@pobox.com>
Fri, 12 Aug 2016 16:16:56 +0000 (09:16 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Aug 2016 16:16:56 +0000 (09:16 -0700)
Not-so-recent rewrite of "git am" that started making internal
calls into the commit machinery had an unintended regression, in
that no matter how many seconds it took to apply many patches, the
resulting committer timestamp for the resulting commits were all
the same.

* jk/reset-ident-time-per-commit:
am: reset cached ident date for each patch

1  2 
builtin/am.c
cache.h
ident.c
diff --combined builtin/am.c
index 0d97f2fabb0fe528fcbb82b32146b09a5265f5f6,8058583a20d06a05b0c7829c07a8d487a08dd2ac..00e4a0981443c043d5a5318b53769d29edb8db8f
@@@ -769,15 -769,15 +769,15 @@@ static int split_mail_conv(mail_conv_f
                        in = fopen(*paths, "r");
  
                if (!in)
 -                      return error(_("could not open '%s' for reading: %s"),
 -                                      *paths, strerror(errno));
 +                      return error_errno(_("could not open '%s' for reading"),
 +                                         *paths);
  
                mail = mkpath("%s/%0*d", state->dir, state->prec, i + 1);
  
                out = fopen(mail, "w");
                if (!out)
 -                      return error(_("could not open '%s' for writing: %s"),
 -                                      mail, strerror(errno));
 +                      return error_errno(_("could not open '%s' for writing"),
 +                                         mail);
  
                ret = fn(out, in, keep_cr);
  
@@@ -857,7 -857,8 +857,7 @@@ static int split_mail_stgit_series(stru
  
        fp = fopen(*paths, "r");
        if (!fp)
 -              return error(_("could not open '%s' for reading: %s"), *paths,
 -                              strerror(errno));
 +              return error_errno(_("could not open '%s' for reading"), *paths);
  
        while (!strbuf_getline_lf(&sb, fp)) {
                if (*sb.buf == '#')
@@@ -1578,14 -1579,14 +1578,14 @@@ static int build_fake_ancestor(const st
  }
  
  /**
 - * Do the three-way merge using fake ancestor, his tree constructed
 + * Do the three-way merge using fake ancestor, their tree constructed
   * from the fake ancestor and the postimage of the patch, and our
   * state.
   */
  static int run_fallback_merge_recursive(const struct am_state *state,
                                        unsigned char *orig_tree,
                                        unsigned char *our_tree,
 -                                      unsigned char *his_tree)
 +                                      unsigned char *their_tree)
  {
        struct child_process cp = CHILD_PROCESS_INIT;
        int status;
        cp.git_cmd = 1;
  
        argv_array_pushf(&cp.env_array, "GITHEAD_%s=%.*s",
 -                       sha1_to_hex(his_tree), linelen(state->msg), state->msg);
 +                       sha1_to_hex(their_tree), linelen(state->msg), state->msg);
        if (state->quiet)
                argv_array_push(&cp.env_array, "GIT_MERGE_VERBOSITY=0");
  
        argv_array_push(&cp.args, sha1_to_hex(orig_tree));
        argv_array_push(&cp.args, "--");
        argv_array_push(&cp.args, sha1_to_hex(our_tree));
 -      argv_array_push(&cp.args, sha1_to_hex(his_tree));
 +      argv_array_push(&cp.args, sha1_to_hex(their_tree));
  
        status = run_command(&cp) ? (-1) : 0;
        discard_cache();
   */
  static int fall_back_threeway(const struct am_state *state, const char *index_path)
  {
 -      unsigned char orig_tree[GIT_SHA1_RAWSZ], his_tree[GIT_SHA1_RAWSZ],
 +      unsigned char orig_tree[GIT_SHA1_RAWSZ], their_tree[GIT_SHA1_RAWSZ],
                      our_tree[GIT_SHA1_RAWSZ];
  
        if (get_sha1("HEAD", our_tree) < 0)
                return error(_("Did you hand edit your patch?\n"
                                "It does not apply to blobs recorded in its index."));
  
 -      if (write_index_as_tree(his_tree, &the_index, index_path, 0, NULL))
 +      if (write_index_as_tree(their_tree, &the_index, index_path, 0, NULL))
                return error("could not write tree");
  
        say(state, stdout, _("Falling back to patching base and 3-way merge..."));
  
        /*
         * This is not so wrong. Depending on which base we picked, orig_tree
 -       * may be wildly different from ours, but his_tree has the same set of
 +       * may be wildly different from ours, but their_tree has the same set of
         * wildly different changes in parts the patch did not touch, so
         * recursive ends up canceling them, saying that we reverted all those
         * changes.
         */
  
 -      if (run_fallback_merge_recursive(state, orig_tree, our_tree, his_tree)) {
 +      if (run_fallback_merge_recursive(state, orig_tree, our_tree, their_tree)) {
                rerere(state->allow_rerere_autoupdate);
                return error(_("Failed to merge in the changes."));
        }
@@@ -1839,6 -1840,8 +1839,8 @@@ static void am_run(struct am_state *sta
                const char *mail = am_path(state, msgnum(state));
                int apply_status;
  
+               reset_ident_date();
                if (!file_exists(mail))
                        goto next;
  
diff --combined cache.h
index 7265439584f3567a9674e0d452b035b649b45b97,1876e12b7508afe85f30d2f9e4340a549b2d56f5..c141b3ca0d9c3066632277d933477e0e30881c5f
+++ b/cache.h
@@@ -367,8 -367,8 +367,8 @@@ extern void free_name_hash(struct index
  #define rename_cache_entry_at(pos, new_name) rename_index_entry_at(&the_index, (pos), (new_name))
  #define remove_cache_entry_at(pos) remove_index_entry_at(&the_index, (pos))
  #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))
 -#define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags))
 -#define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags))
 +#define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags), 0)
 +#define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags), 0)
  #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)
  #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
  #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
@@@ -581,8 -581,8 +581,8 @@@ extern int remove_file_from_index(struc
  #define ADD_CACHE_IGNORE_ERRORS       4
  #define ADD_CACHE_IGNORE_REMOVAL 8
  #define ADD_CACHE_INTENT 16
 -extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags);
 -extern int add_file_to_index(struct index_state *, const char *path, int flags);
 +extern int add_to_index(struct index_state *, const char *path, struct stat *, int flags, int force_mode);
 +extern int add_file_to_index(struct index_state *, const char *path, int flags, int force_mode);
  extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, unsigned int refresh_options);
  extern int ce_same_name(const struct cache_entry *a, const struct cache_entry *b);
  extern void set_object_name_for_intent_to_add_entry(struct cache_entry *ce);
@@@ -654,7 -654,6 +654,7 @@@ extern int warn_on_object_refname_ambig
  extern const char *apply_default_whitespace;
  extern const char *apply_default_ignorewhitespace;
  extern const char *git_attributes_file;
 +extern const char *git_hooks_path;
  extern int zlib_compression_level;
  extern int core_compression_level;
  extern int core_compression_seen;
@@@ -808,14 -807,11 +808,14 @@@ extern void check_repository_format(voi
   */
  extern const char *mkpath(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
  extern const char *git_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
 +extern const char *git_common_path(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
  
  extern char *mksnpath(char *buf, size_t n, const char *fmt, ...)
        __attribute__((format (printf, 3, 4)));
  extern void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
        __attribute__((format (printf, 2, 3)));
 +extern void strbuf_git_common_path(struct strbuf *sb, const char *fmt, ...)
 +      __attribute__((format (printf, 2, 3)));
  extern char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
        __attribute__((format (printf, 2, 3)));
  extern void strbuf_git_path_submodule(struct strbuf *sb, const char *path,
@@@ -1166,8 -1162,6 +1166,8 @@@ extern int get_sha1_blob(const char *st
  extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
  extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *orc);
  
 +extern int get_oid(const char *str, struct object_id *oid);
 +
  typedef int each_abbrev_fn(const unsigned char *sha1, void *);
  extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
  
@@@ -1262,6 -1256,7 +1262,7 @@@ extern const char *ident_default_email(
  extern const char *git_editor(void);
  extern const char *git_pager(int stdout_is_tty);
  extern int git_ident_config(const char *, const char *, void *);
+ extern void reset_ident_date(void);
  
  struct ident_split {
        const char *name_begin;
@@@ -1508,7 -1503,7 +1509,7 @@@ struct object_info 
        /* Request */
        enum object_type *typep;
        unsigned long *sizep;
 -      unsigned long *disk_sizep;
 +      off_t *disk_sizep;
        unsigned char *delta_base_sha1;
        struct strbuf *typename;
  
@@@ -1721,6 -1716,7 +1722,6 @@@ extern int copy_file(const char *dst, c
  extern int copy_file_with_time(const char *dst, const char *src, int mode);
  
  extern void write_or_die(int fd, const void *buf, size_t count);
 -extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
  extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg);
  extern void fsync_or_die(int fd, const char *);
  
@@@ -1771,14 -1767,14 +1772,14 @@@ void packet_trace_identity(const char *
   * return 0 if success, 1 - if addition of a file failed and
   * ADD_FILES_IGNORE_ERRORS was specified in flags
   */
 -int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int flags);
 +int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int flags, int force_mode);
  
  /* diff.c */
  extern int diff_auto_refresh_index;
  
  /* match-trees.c */
 -void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int);
 -void shift_tree_by(const unsigned char *, const unsigned char *, unsigned char *, const char *);
 +void shift_tree(const struct object_id *, const struct object_id *, struct object_id *, int);
 +void shift_tree_by(const struct object_id *, const struct object_id *, struct object_id *, const char *);
  
  /*
   * whitespace rules.
diff --combined ident.c
index 139c5289d03b7594af2a07e6e0364bb285ae0348,0c78df7c8f5acb8c2f309cd14139450c21436252..e20a772dde4230b0871ffe85a5204919402aaf94
+++ b/ident.c
@@@ -75,12 -75,14 +75,12 @@@ static int add_mailname_host(struct str
        mailname = fopen("/etc/mailname", "r");
        if (!mailname) {
                if (errno != ENOENT)
 -                      warning("cannot open /etc/mailname: %s",
 -                              strerror(errno));
 +                      warning_errno("cannot open /etc/mailname");
                return -1;
        }
        if (strbuf_getline(&mailnamebuf, mailname) == EOF) {
                if (ferror(mailname))
 -                      warning("cannot read /etc/mailname: %s",
 -                              strerror(errno));
 +                      warning_errno("cannot read /etc/mailname");
                strbuf_release(&mailnamebuf);
                fclose(mailname);
                return -1;
@@@ -123,7 -125,7 +123,7 @@@ static void add_domainname(struct strbu
        char buf[1024];
  
        if (gethostname(buf, sizeof(buf))) {
 -              warning("cannot get host name: %s", strerror(errno));
 +              warning_errno("cannot get host name");
                strbuf_addstr(out, "(none)");
                *is_bogus = 1;
                return;
@@@ -184,6 -186,11 +184,11 @@@ static const char *ident_default_date(v
        return git_default_date.buf;
  }
  
+ void reset_ident_date(void)
+ {
+       strbuf_reset(&git_default_date);
+ }
  static int crud(unsigned char c)
  {
        return  c <= 32  ||