From: Junio C Hamano Date: Sun, 3 Apr 2016 17:29:22 +0000 (-0700) Subject: Merge branch 'mm/diff-renames-default' X-Git-Tag: v2.9.0-rc0~177 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/5d2a30d7d8777319c745804f040fa405d02169ce?hp=-c Merge branch 'mm/diff-renames-default' 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 --- 5d2a30d7d8777319c745804f040fa405d02169ce diff --combined builtin/merge.c index 101ffeff4c,4cb4f6aa86..c8154aaf6a --- a/builtin/merge.c +++ b/builtin/merge.c @@@ -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 059123c5dc,b4dea07db9..4dfe6609d0 --- a/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; @@@ -5093,9 -5101,6 +5098,9 @@@ 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 e7d68edaf9,0a3ce8658d..125447be09 --- a/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);