Merge branch 'mm/diff-renames-default'
authorJunio C Hamano <gitster@pobox.com>
Sun, 3 Apr 2016 17:29:22 +0000 (10:29 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 3 Apr 2016 17:29:22 +0000 (10:29 -0700)
The end-user facing Porcelain level commands like "diff" and "log"
now enables the rename detection by default.

* mm/diff-renames-default:
diff: activate diff.renames by default
log: introduce init_log_defaults()
t: add tests for diff.renames (true/false/unset)
t4001-diff-rename: wrap file creations in a test
Documentation/diff-config: fix description of diff.renames

1  2 
builtin/merge.c
diff.c
diff.h
diff --combined builtin/merge.c
index 101ffeff4c942636e0ca688357a4b8ec8aa2a431,4cb4f6aa8682329daf154e5f86a5678aa9236417..c8154aaf6a5afa87ab42d3db632798698a9f2b1d
@@@ -939,7 -939,7 +939,7 @@@ static int setup_with_upstream(const ch
        if (!branch->merge_nr)
                die(_("No default upstream defined for the current branch."));
  
 -      args = xcalloc(branch->merge_nr + 1, sizeof(char *));
 +      args = xcalloc(st_add(branch->merge_nr, 1), sizeof(char *));
        for (i = 0; i < branch->merge_nr; i++) {
                if (!branch->merge[i]->dst)
                        die(_("No remote-tracking branch for %s from %s"),
@@@ -1187,6 -1187,7 +1187,7 @@@ int cmd_merge(int argc, const char **ar
        else
                head_commit = lookup_commit_or_die(head_sha1, "HEAD");
  
+       init_diff_ui_defaults();
        git_config(git_merge_config, NULL);
  
        if (branch_mergeoptions)
diff --combined diff.c
index 059123c5dcef4129763895b0f2ad5a54728b0c07,b4dea07db9f35a563c175bb0b56419378ed2adc4..4dfe6609d059b56c5ab4dd31c8d2139c7fa90abb
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -168,6 -168,11 +168,11 @@@ long parse_algorithm_value(const char *
   * never be affected by the setting of diff.renames
   * the user happens to have in the configuration file.
   */
+ void init_diff_ui_defaults(void)
+ {
+       diff_detect_rename_default = 1;
+ }
  int git_diff_ui_config(const char *var, const char *value, void *cb)
  {
        if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
@@@ -2607,9 -2612,12 +2612,9 @@@ static void builtin_checkdiff(const cha
  
  struct diff_filespec *alloc_filespec(const char *path)
  {
 -      int namelen = strlen(path);
 -      struct diff_filespec *spec = xmalloc(sizeof(*spec) + namelen + 1);
 +      struct diff_filespec *spec;
  
 -      memset(spec, 0, sizeof(*spec));
 -      spec->path = (char *)(spec + 1);
 -      memcpy(spec->path, path, namelen+1);
 +      FLEXPTR_ALLOC_STR(spec, path, path);
        spec->count = 1;
        spec->is_binary = -1;
        return spec;
@@@ -2704,21 -2712,21 +2709,21 @@@ static int reuse_worktree_file(const ch
  
  static int diff_populate_gitlink(struct diff_filespec *s, int size_only)
  {
 -      int len;
 -      char *data = xmalloc(100), *dirty = "";
 +      struct strbuf buf = STRBUF_INIT;
 +      char *dirty = "";
  
        /* Are we looking at the work tree? */
        if (s->dirty_submodule)
                dirty = "-dirty";
  
 -      len = snprintf(data, 100,
 -                     "Subproject commit %s%s\n", sha1_to_hex(s->sha1), dirty);
 -      s->data = data;
 -      s->size = len;
 -      s->should_free = 1;
 +      strbuf_addf(&buf, "Subproject commit %s%s\n", sha1_to_hex(s->sha1), dirty);
 +      s->size = buf.len;
        if (size_only) {
                s->data = NULL;
 -              free(data);
 +              strbuf_release(&buf);
 +      } else {
 +              s->data = strbuf_detach(&buf, NULL);
 +              s->should_free = 1;
        }
        return 0;
  }
@@@ -5082,7 -5090,7 +5087,7 @@@ size_t fill_textconv(struct userdiff_dr
  {
        size_t size;
  
 -      if (!driver || !driver->textconv) {
 +      if (!driver) {
                if (!DIFF_FILE_VALID(df)) {
                        *outbuf = "";
                        return 0;
                return df->size;
        }
  
 +      if (!driver->textconv)
 +              die("BUG: fill_textconv called with non-textconv driver");
 +
        if (driver->textconv_cache && df->sha1_valid) {
                *outbuf = notes_cache_get(driver->textconv_cache, df->sha1,
                                          &size);
diff --combined diff.h
index e7d68edaf9d4744ce3c48356e1835c5506d5322d,0a3ce8658d53452dac286891d34b3447f1dfd88f..125447be09ebf1d79beb7312785c2e89654fbdb0
--- 1/diff.h
--- 2/diff.h
+++ b/diff.h
@@@ -222,8 -222,8 +222,8 @@@ struct combine_diff_path 
        } parent[FLEX_ARRAY];
  };
  #define combine_diff_path_size(n, l) \
 -      (sizeof(struct combine_diff_path) + \
 -       sizeof(struct combine_diff_parent) * (n) + (l) + 1)
 +      st_add4(sizeof(struct combine_diff_path), (l), 1, \
 +              st_mult(sizeof(struct combine_diff_parent), (n)))
  
  extern void show_combined_diff(struct combine_diff_path *elem, int num_parent,
                              int dense, struct rev_info *);
@@@ -266,6 -266,7 +266,7 @@@ extern int parse_long_opt(const char *o
                         const char **optarg);
  
  extern int git_diff_basic_config(const char *var, const char *value, void *cb);
+ extern void init_diff_ui_defaults(void);
  extern int git_diff_ui_config(const char *var, const char *value, void *cb);
  extern void diff_setup(struct diff_options *);
  extern int diff_opt_parse(struct diff_options *, const char **, int, const char *);
@@@ -349,26 -350,10 +350,26 @@@ extern void diff_no_index(struct rev_in
  
  extern int index_differs_from(const char *def, int diff_flags);
  
 +/*
 + * Fill the contents of the filespec "df", respecting any textconv defined by
 + * its userdiff driver.  The "driver" parameter must come from a
 + * previous call to get_textconv(), and therefore should either be NULL or have
 + * textconv enabled.
 + *
 + * Note that the memory ownership of the resulting buffer depends on whether
 + * the driver field is NULL. If it is, then the memory belongs to the filespec
 + * struct. If it is non-NULL, then "outbuf" points to a newly allocated buffer
 + * that should be freed by the caller.
 + */
  extern size_t fill_textconv(struct userdiff_driver *driver,
                            struct diff_filespec *df,
                            char **outbuf);
  
 +/*
 + * Look up the userdiff driver for the given filespec, and return it if
 + * and only if it has textconv enabled (otherwise return NULL). The result
 + * can be passed to fill_textconv().
 + */
  extern struct userdiff_driver *get_textconv(struct diff_filespec *one);
  
  extern int parse_rename_score(const char **cp_p);