Merge branch 'sb/diff-color-move'
"git diff" has been taught to optionally paint new lines that are
the same as deleted lines elsewhere differently from genuinely new
lines.
* sb/diff-color-move: (25 commits)
diff: document the new --color-moved setting
diff.c: add dimming to moved line detection
diff.c: color moved lines differently, plain mode
diff.c: color moved lines differently
diff.c: buffer all output if asked to
diff.c: emit_diff_symbol learns about DIFF_SYMBOL_SUMMARY
diff.c: emit_diff_symbol learns about DIFF_SYMBOL_STAT_SEP
diff.c: convert word diffing to use emit_diff_symbol
diff.c: convert show_stats to use emit_diff_symbol
diff.c: convert emit_binary_diff_body to use emit_diff_symbol
submodule.c: migrate diff output to use emit_diff_symbol
diff.c: emit_diff_symbol learns DIFF_SYMBOL_REWRITE_DIFF
diff.c: emit_diff_symbol learns about DIFF_SYMBOL_BINARY_FILES
diff.c: emit_diff_symbol learns DIFF_SYMBOL_HEADER
diff.c: emit_diff_symbol learns DIFF_SYMBOL_FILEPAIR_{PLUS, MINUS}
diff.c: emit_diff_symbol learns DIFF_SYMBOL_CONTEXT_INCOMPLETE
diff.c: emit_diff_symbol learns DIFF_SYMBOL_WORDS[_PORCELAIN]
diff.c: migrate emit_line_checked to use emit_diff_symbol
diff.c: emit_diff_symbol learns DIFF_SYMBOL_NO_LF_EOF
diff.c: emit_diff_symbol learns DIFF_SYMBOL_CONTEXT_FRAGINFO
...
This commit is contained in:
84
submodule.c
84
submodule.c
@ -478,9 +478,7 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path,
|
||||
return prepare_revision_walk(rev);
|
||||
}
|
||||
|
||||
static void print_submodule_summary(struct rev_info *rev, FILE *f,
|
||||
const char *line_prefix,
|
||||
const char *del, const char *add, const char *reset)
|
||||
static void print_submodule_summary(struct rev_info *rev, struct diff_options *o)
|
||||
{
|
||||
static const char format[] = " %m %s";
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
@ -491,18 +489,12 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
|
||||
ctx.date_mode = rev->date_mode;
|
||||
ctx.output_encoding = get_log_output_encoding();
|
||||
strbuf_setlen(&sb, 0);
|
||||
strbuf_addstr(&sb, line_prefix);
|
||||
if (commit->object.flags & SYMMETRIC_LEFT) {
|
||||
if (del)
|
||||
strbuf_addstr(&sb, del);
|
||||
}
|
||||
else if (add)
|
||||
strbuf_addstr(&sb, add);
|
||||
format_commit_message(commit, format, &sb, &ctx);
|
||||
if (reset)
|
||||
strbuf_addstr(&sb, reset);
|
||||
strbuf_addch(&sb, '\n');
|
||||
fprintf(f, "%s", sb.buf);
|
||||
if (commit->object.flags & SYMMETRIC_LEFT)
|
||||
diff_emit_submodule_del(o, sb.buf);
|
||||
else
|
||||
diff_emit_submodule_add(o, sb.buf);
|
||||
}
|
||||
strbuf_release(&sb);
|
||||
}
|
||||
@ -529,11 +521,9 @@ void prepare_submodule_repo_env(struct argv_array *out)
|
||||
* attempt to lookup both the left and right commits and put them into the
|
||||
* left and right pointers.
|
||||
*/
|
||||
static void show_submodule_header(FILE *f, const char *path,
|
||||
const char *line_prefix,
|
||||
static void show_submodule_header(struct diff_options *o, const char *path,
|
||||
struct object_id *one, struct object_id *two,
|
||||
unsigned dirty_submodule, const char *meta,
|
||||
const char *reset,
|
||||
unsigned dirty_submodule,
|
||||
struct commit **left, struct commit **right,
|
||||
struct commit_list **merge_bases)
|
||||
{
|
||||
@ -542,11 +532,10 @@ static void show_submodule_header(FILE *f, const char *path,
|
||||
int fast_forward = 0, fast_backward = 0;
|
||||
|
||||
if (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
|
||||
fprintf(f, "%sSubmodule %s contains untracked content\n",
|
||||
line_prefix, path);
|
||||
diff_emit_submodule_untracked(o, path);
|
||||
|
||||
if (dirty_submodule & DIRTY_SUBMODULE_MODIFIED)
|
||||
fprintf(f, "%sSubmodule %s contains modified content\n",
|
||||
line_prefix, path);
|
||||
diff_emit_submodule_modified(o, path);
|
||||
|
||||
if (is_null_oid(one))
|
||||
message = "(new submodule)";
|
||||
@ -588,31 +577,29 @@ static void show_submodule_header(FILE *f, const char *path,
|
||||
}
|
||||
|
||||
output_header:
|
||||
strbuf_addf(&sb, "%s%sSubmodule %s ", line_prefix, meta, path);
|
||||
strbuf_addf(&sb, "Submodule %s ", path);
|
||||
strbuf_add_unique_abbrev(&sb, one->hash, DEFAULT_ABBREV);
|
||||
strbuf_addstr(&sb, (fast_backward || fast_forward) ? ".." : "...");
|
||||
strbuf_add_unique_abbrev(&sb, two->hash, DEFAULT_ABBREV);
|
||||
if (message)
|
||||
strbuf_addf(&sb, " %s%s\n", message, reset);
|
||||
strbuf_addf(&sb, " %s\n", message);
|
||||
else
|
||||
strbuf_addf(&sb, "%s:%s\n", fast_backward ? " (rewind)" : "", reset);
|
||||
fwrite(sb.buf, sb.len, 1, f);
|
||||
strbuf_addf(&sb, "%s:\n", fast_backward ? " (rewind)" : "");
|
||||
diff_emit_submodule_header(o, sb.buf);
|
||||
|
||||
strbuf_release(&sb);
|
||||
}
|
||||
|
||||
void show_submodule_summary(FILE *f, const char *path,
|
||||
const char *line_prefix,
|
||||
void show_submodule_summary(struct diff_options *o, const char *path,
|
||||
struct object_id *one, struct object_id *two,
|
||||
unsigned dirty_submodule, const char *meta,
|
||||
const char *del, const char *add, const char *reset)
|
||||
unsigned dirty_submodule)
|
||||
{
|
||||
struct rev_info rev;
|
||||
struct commit *left = NULL, *right = NULL;
|
||||
struct commit_list *merge_bases = NULL;
|
||||
|
||||
show_submodule_header(f, path, line_prefix, one, two, dirty_submodule,
|
||||
meta, reset, &left, &right, &merge_bases);
|
||||
show_submodule_header(o, path, one, two, dirty_submodule,
|
||||
&left, &right, &merge_bases);
|
||||
|
||||
/*
|
||||
* If we don't have both a left and a right pointer, there is no
|
||||
@ -624,11 +611,11 @@ void show_submodule_summary(FILE *f, const char *path,
|
||||
|
||||
/* Treat revision walker failure the same as missing commits */
|
||||
if (prepare_submodule_summary(&rev, path, left, right, merge_bases)) {
|
||||
fprintf(f, "%s(revision walker failed)\n", line_prefix);
|
||||
diff_emit_submodule_error(o, "(revision walker failed)\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
print_submodule_summary(&rev, f, line_prefix, del, add, reset);
|
||||
print_submodule_summary(&rev, o);
|
||||
|
||||
out:
|
||||
if (merge_bases)
|
||||
@ -637,21 +624,18 @@ out:
|
||||
clear_commit_marks(right, ~0);
|
||||
}
|
||||
|
||||
void show_submodule_inline_diff(FILE *f, const char *path,
|
||||
const char *line_prefix,
|
||||
void show_submodule_inline_diff(struct diff_options *o, const char *path,
|
||||
struct object_id *one, struct object_id *two,
|
||||
unsigned dirty_submodule, const char *meta,
|
||||
const char *del, const char *add, const char *reset,
|
||||
const struct diff_options *o)
|
||||
unsigned dirty_submodule)
|
||||
{
|
||||
const struct object_id *old = &empty_tree_oid, *new = &empty_tree_oid;
|
||||
struct commit *left = NULL, *right = NULL;
|
||||
struct commit_list *merge_bases = NULL;
|
||||
struct strbuf submodule_dir = STRBUF_INIT;
|
||||
struct child_process cp = CHILD_PROCESS_INIT;
|
||||
struct strbuf sb = STRBUF_INIT;
|
||||
|
||||
show_submodule_header(f, path, line_prefix, one, two, dirty_submodule,
|
||||
meta, reset, &left, &right, &merge_bases);
|
||||
show_submodule_header(o, path, one, two, dirty_submodule,
|
||||
&left, &right, &merge_bases);
|
||||
|
||||
/* We need a valid left and right commit to display a difference */
|
||||
if (!(left || is_null_oid(one)) ||
|
||||
@ -663,16 +647,16 @@ void show_submodule_inline_diff(FILE *f, const char *path,
|
||||
if (right)
|
||||
new = two;
|
||||
|
||||
fflush(f);
|
||||
cp.git_cmd = 1;
|
||||
cp.dir = path;
|
||||
cp.out = dup(fileno(f));
|
||||
cp.out = -1;
|
||||
cp.no_stdin = 1;
|
||||
|
||||
/* TODO: other options may need to be passed here. */
|
||||
argv_array_pushl(&cp.args, "diff", "--submodule=diff", NULL);
|
||||
argv_array_pushf(&cp.args, "--color=%s", want_color(o->use_color) ?
|
||||
"always" : "never");
|
||||
|
||||
argv_array_pushf(&cp.args, "--line-prefix=%s", line_prefix);
|
||||
if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
|
||||
argv_array_pushf(&cp.args, "--src-prefix=%s%s/",
|
||||
o->b_prefix, path);
|
||||
@ -695,11 +679,17 @@ void show_submodule_inline_diff(FILE *f, const char *path,
|
||||
argv_array_push(&cp.args, oid_to_hex(new));
|
||||
|
||||
prepare_submodule_repo_env(&cp.env_array);
|
||||
if (run_command(&cp))
|
||||
fprintf(f, "(diff failed)\n");
|
||||
if (start_command(&cp))
|
||||
diff_emit_submodule_error(o, "(diff failed)\n");
|
||||
|
||||
while (strbuf_getwholeline_fd(&sb, cp.out, '\n') != EOF)
|
||||
diff_emit_submodule_pipethrough(o, sb.buf, sb.len);
|
||||
|
||||
if (finish_command(&cp))
|
||||
diff_emit_submodule_error(o, "(diff failed)\n");
|
||||
|
||||
done:
|
||||
strbuf_release(&submodule_dir);
|
||||
strbuf_release(&sb);
|
||||
if (merge_bases)
|
||||
free_commit_list(merge_bases);
|
||||
if (left)
|
||||
|
||||
Reference in New Issue
Block a user