#endif
static int diff_detect_rename_default;
-static int diff_rename_limit_default = 100;
+static int diff_rename_limit_default = 200;
int diff_use_color_default = -1;
static const char *external_diff_cmd_cfg;
int diff_auto_refresh_index = 1;
* never be affected by the setting of diff.renames
* the user happens to have in the configuration file.
*/
-int git_diff_ui_config(const char *var, const char *value)
+int git_diff_ui_config(const char *var, const char *value, void *cb)
{
- if (!strcmp(var, "diff.renamelimit")) {
- diff_rename_limit_default = git_config_int(var, value);
- return 0;
- }
if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
diff_use_color_default = git_config_colorbool(var, value, -1);
return 0;
diff_auto_refresh_index = git_config_bool(var, value);
return 0;
}
- if (!strcmp(var, "diff.external")) {
- if (!value)
- return config_error_nonbool(var);
- external_diff_cmd_cfg = xstrdup(value);
- return 0;
- }
+ if (!strcmp(var, "diff.external"))
+ return git_config_string(&external_diff_cmd_cfg, var, value);
if (!prefixcmp(var, "diff.")) {
const char *ep = strrchr(var, '.');
return parse_lldiff_command(var, ep, value);
}
- return git_diff_basic_config(var, value);
+ return git_diff_basic_config(var, value, cb);
}
-int git_diff_basic_config(const char *var, const char *value)
+int git_diff_basic_config(const char *var, const char *value, void *cb)
{
+ if (!strcmp(var, "diff.renamelimit")) {
+ diff_rename_limit_default = git_config_int(var, value);
+ return 0;
+ }
+
if (!prefixcmp(var, "diff.color.") || !prefixcmp(var, "color.diff.")) {
int slot = parse_diff_color_slot(var, 11);
if (!value)
}
}
- return git_color_default_config(var, value);
+ return git_color_default_config(var, value, cb);
}
static char *quote_two(const char *one, const char *two)
static void emit_line(FILE *file, const char *set, const char *reset, const char *line, int len)
{
+ int has_trailing_newline = (len > 0 && line[len-1] == '\n');
+ if (has_trailing_newline)
+ len--;
+
fputs(set, file);
fwrite(line, len, 1, file);
fputs(reset, file);
+ if (has_trailing_newline)
+ fputc('\n', file);
}
static void emit_add_line(const char *reset, struct emit_callback *ecbdata, const char *line, int len)
}
}
-struct diffstat_dir {
- struct diffstat_file **files;
- int nr, percent, cumulative;
+struct dirstat_file {
+ const char *name;
+ unsigned long changed;
+};
+
+struct dirstat_dir {
+ struct dirstat_file *files;
+ int alloc, nr, percent, cumulative;
};
-static long gather_dirstat(FILE *file, struct diffstat_dir *dir, unsigned long changed, const char *base, int baselen)
+static long gather_dirstat(FILE *file, struct dirstat_dir *dir, unsigned long changed, const char *base, int baselen)
{
unsigned long this_dir = 0;
unsigned int sources = 0;
while (dir->nr) {
- struct diffstat_file *f = *dir->files;
+ struct dirstat_file *f = dir->files;
int namelen = strlen(f->name);
unsigned long this;
char *slash;
this = gather_dirstat(file, dir, changed, f->name, newbaselen);
sources++;
} else {
- if (f->is_unmerged || f->is_binary)
- this = 0;
- else
- this = f->added + f->deleted;
+ this = f->changed;
dir->files++;
dir->nr--;
sources += 2;
return this_dir;
}
-static void show_dirstat(struct diffstat_t *data, struct diff_options *options)
+static void show_dirstat(struct diff_options *options)
{
int i;
unsigned long changed;
- struct diffstat_dir dir;
+ struct dirstat_dir dir;
+ struct diff_queue_struct *q = &diff_queued_diff;
+
+ dir.files = NULL;
+ dir.alloc = 0;
+ dir.nr = 0;
+ dir.percent = options->dirstat_percent;
+ dir.cumulative = options->output_format & DIFF_FORMAT_CUMULATIVE;
- /* Calculate total changes */
changed = 0;
- for (i = 0; i < data->nr; i++) {
- if (data->files[i]->is_binary || data->files[i]->is_unmerged)
+ for (i = 0; i < q->nr; i++) {
+ struct diff_filepair *p = q->queue[i];
+ const char *name;
+ unsigned long copied, added, damage;
+
+ name = p->one->path ? p->one->path : p->two->path;
+
+ if (DIFF_FILE_VALID(p->one) && DIFF_FILE_VALID(p->two)) {
+ diff_populate_filespec(p->one, 0);
+ diff_populate_filespec(p->two, 0);
+ diffcore_count_changes(p->one, p->two, NULL, NULL, 0,
+ &copied, &added);
+ diff_free_filespec_data(p->one);
+ diff_free_filespec_data(p->two);
+ } else if (DIFF_FILE_VALID(p->one)) {
+ diff_populate_filespec(p->one, 1);
+ copied = added = 0;
+ diff_free_filespec_data(p->one);
+ } else if (DIFF_FILE_VALID(p->two)) {
+ diff_populate_filespec(p->two, 1);
+ copied = 0;
+ added = p->two->size;
+ diff_free_filespec_data(p->two);
+ } else
continue;
- changed += data->files[i]->added;
- changed += data->files[i]->deleted;
+
+ /*
+ * Original minus copied is the removed material,
+ * added is the new material. They are both damages
+ * made to the preimage.
+ */
+ damage = (p->one->size - copied) + added;
+
+ ALLOC_GROW(dir.files, dir.nr + 1, dir.alloc);
+ dir.files[dir.nr].name = name;
+ dir.files[dir.nr].changed = damage;
+ changed += damage;
+ dir.nr++;
}
/* This can happen even with many files, if everything was renames */
return;
/* Show all directories with more than x% of the changes */
- dir.files = data->files;
- dir.nr = data->nr;
- dir.percent = options->dirstat_percent;
- dir.cumulative = options->output_format & DIFF_FORMAT_CUMULATIVE;
gather_dirstat(options->file, &dir, changed, "", 0);
}
char *err;
if (line[0] == '+') {
+ unsigned bad;
data->lineno++;
- data->status = check_and_emit_line(line + 1, len - 1,
+ bad = check_and_emit_line(line + 1, len - 1,
data->ws_rule, NULL, NULL, NULL, NULL);
- if (!data->status)
+ if (!bad)
return;
- err = whitespace_error_string(data->status);
+ data->status |= bad;
+ err = whitespace_error_string(bad);
fprintf(data->file, "%s:%d: %s.\n", data->filename, data->lineno, err);
free(err);
emit_line(data->file, set, reset, line, 1);
options->rename_limit = -1;
options->dirstat_percent = 3;
options->context = 3;
- options->msg_sep = "";
options->change = diff_change;
options->add_remove = diff_addremove;
DIFF_OPT_SET(options, ALLOW_EXTERNAL);
else if (!strcmp(arg, "--no-ext-diff"))
DIFF_OPT_CLR(options, ALLOW_EXTERNAL);
+ else if (!strcmp(arg, "--ignore-submodules"))
+ DIFF_OPT_SET(options, IGNORE_SUBMODULES);
/* misc options */
else if (!strcmp(arg, "-z"))
separator++;
}
- if (output_format & (DIFF_FORMAT_DIFFSTAT|DIFF_FORMAT_SHORTSTAT|DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIRSTAT)) {
+ if (output_format & (DIFF_FORMAT_DIFFSTAT|DIFF_FORMAT_SHORTSTAT|DIFF_FORMAT_NUMSTAT)) {
struct diffstat_t diffstat;
memset(&diffstat, 0, sizeof(struct diffstat_t));
if (check_pair_status(p))
diff_flush_stat(p, options, &diffstat);
}
- if (output_format & DIFF_FORMAT_DIRSTAT)
- show_dirstat(&diffstat, options);
if (output_format & DIFF_FORMAT_NUMSTAT)
show_numstat(&diffstat, options);
if (output_format & DIFF_FORMAT_DIFFSTAT)
free_diffstat_info(&diffstat);
separator++;
}
+ if (output_format & DIFF_FORMAT_DIRSTAT)
+ show_dirstat(options);
if (output_format & DIFF_FORMAT_SUMMARY && !is_summary_empty(q)) {
for (i = 0; i < q->nr; i++)
void diff_addremove(struct diff_options *options,
int addremove, unsigned mode,
const unsigned char *sha1,
- const char *base, const char *path)
+ const char *concatpath)
{
- char concatpath[PATH_MAX];
struct diff_filespec *one, *two;
+ if (DIFF_OPT_TST(options, IGNORE_SUBMODULES) && S_ISGITLINK(mode))
+ return;
+
/* This may look odd, but it is a preparation for
* feeding "there are unchanged files which should
* not produce diffs, but when you are doing copy
addremove = (addremove == '+' ? '-' :
addremove == '-' ? '+' : addremove);
- if (!path) path = "";
- sprintf(concatpath, "%s%s", base, path);
-
if (options->prefix &&
strncmp(concatpath, options->prefix, options->prefix_length))
return;
unsigned old_mode, unsigned new_mode,
const unsigned char *old_sha1,
const unsigned char *new_sha1,
- const char *base, const char *path)
+ const char *concatpath)
{
- char concatpath[PATH_MAX];
struct diff_filespec *one, *two;
+ if (DIFF_OPT_TST(options, IGNORE_SUBMODULES) && S_ISGITLINK(old_mode)
+ && S_ISGITLINK(new_mode))
+ return;
+
if (DIFF_OPT_TST(options, REVERSE_DIFF)) {
unsigned tmp;
const unsigned char *tmp_c;
tmp = old_mode; old_mode = new_mode; new_mode = tmp;
tmp_c = old_sha1; old_sha1 = new_sha1; new_sha1 = tmp_c;
}
- if (!path) path = "";
- sprintf(concatpath, "%s%s", base, path);
if (options->prefix &&
strncmp(concatpath, options->prefix, options->prefix_length))