Merge branch 'lt/diff-tree'
* lt/diff-tree: combine-diff: Record diff status a bit more faithfully find_unique_abbrev() simplification. combine-diff: move formatting logic to show_combined_diff() combined-diff: use diffcore before intersecting paths. diff-tree -c raw outputmaint
commit
3f6726e1f1
142
combine-diff.c
142
combine-diff.c
|
@ -39,6 +39,7 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
|
||||||
p->mode = q->queue[i]->two->mode;
|
p->mode = q->queue[i]->two->mode;
|
||||||
memcpy(p->parent[n].sha1, q->queue[i]->one->sha1, 20);
|
memcpy(p->parent[n].sha1, q->queue[i]->one->sha1, 20);
|
||||||
p->parent[n].mode = q->queue[i]->one->mode;
|
p->parent[n].mode = q->queue[i]->one->mode;
|
||||||
|
p->parent[n].status = q->queue[i]->status;
|
||||||
*tail = p;
|
*tail = p;
|
||||||
tail = &p->next;
|
tail = &p->next;
|
||||||
}
|
}
|
||||||
|
@ -62,6 +63,7 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
|
||||||
memcpy(p->parent[n].sha1,
|
memcpy(p->parent[n].sha1,
|
||||||
q->queue[i]->one->sha1, 20);
|
q->queue[i]->one->sha1, 20);
|
||||||
p->parent[n].mode = q->queue[i]->one->mode;
|
p->parent[n].mode = q->queue[i]->one->mode;
|
||||||
|
p->parent[n].status = q->queue[i]->status;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -618,8 +620,8 @@ static void reuse_combine_diff(struct sline *sline, unsigned long cnt,
|
||||||
sline->p_lno[i] = sline->p_lno[j];
|
sline->p_lno[i] = sline->p_lno[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
int show_combined_diff(struct combine_diff_path *elem, int num_parent,
|
static int show_patch_diff(struct combine_diff_path *elem, int num_parent,
|
||||||
int dense, const char *header)
|
int dense, const char *header)
|
||||||
{
|
{
|
||||||
unsigned long size, cnt, lno;
|
unsigned long size, cnt, lno;
|
||||||
char *result, *cp, *ep;
|
char *result, *cp, *ep;
|
||||||
|
@ -716,10 +718,7 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
|
||||||
|
|
||||||
if (show_hunks || mode_differs) {
|
if (show_hunks || mode_differs) {
|
||||||
const char *abb;
|
const char *abb;
|
||||||
char null_abb[DEFAULT_ABBREV + 1];
|
|
||||||
|
|
||||||
memset(null_abb, '0', DEFAULT_ABBREV);
|
|
||||||
null_abb[DEFAULT_ABBREV] = 0;
|
|
||||||
if (header) {
|
if (header) {
|
||||||
shown_header++;
|
shown_header++;
|
||||||
puts(header);
|
puts(header);
|
||||||
|
@ -734,26 +733,33 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
|
||||||
for (i = 0; i < num_parent; i++) {
|
for (i = 0; i < num_parent; i++) {
|
||||||
if (elem->parent[i].mode != elem->mode)
|
if (elem->parent[i].mode != elem->mode)
|
||||||
mode_differs = 1;
|
mode_differs = 1;
|
||||||
if (memcmp(elem->parent[i].sha1, null_sha1, 20))
|
abb = find_unique_abbrev(elem->parent[i].sha1,
|
||||||
abb = find_unique_abbrev(elem->parent[i].sha1,
|
DEFAULT_ABBREV);
|
||||||
DEFAULT_ABBREV);
|
|
||||||
else
|
|
||||||
abb = null_abb;
|
|
||||||
printf("%s%s", i ? "," : "", abb);
|
printf("%s%s", i ? "," : "", abb);
|
||||||
}
|
}
|
||||||
if (memcmp(elem->sha1, null_sha1, 20))
|
abb = find_unique_abbrev(elem->sha1, DEFAULT_ABBREV);
|
||||||
abb = find_unique_abbrev(elem->sha1, DEFAULT_ABBREV);
|
|
||||||
else
|
|
||||||
abb = null_abb;
|
|
||||||
printf("..%s\n", abb);
|
printf("..%s\n", abb);
|
||||||
|
|
||||||
if (mode_differs) {
|
if (mode_differs) {
|
||||||
printf("mode ");
|
int added = !!elem->mode;
|
||||||
for (i = 0; i < num_parent; i++) {
|
for (i = 0; added && i < num_parent; i++)
|
||||||
printf("%s%06o", i ? "," : "",
|
if (elem->parent[i].status !=
|
||||||
elem->parent[i].mode);
|
DIFF_STATUS_ADDED)
|
||||||
|
added = 0;
|
||||||
|
if (added)
|
||||||
|
printf("new file mode %06o", elem->mode);
|
||||||
|
else {
|
||||||
|
if (!elem->mode)
|
||||||
|
printf("deleted file ");
|
||||||
|
printf("mode ");
|
||||||
|
for (i = 0; i < num_parent; i++) {
|
||||||
|
printf("%s%06o", i ? "," : "",
|
||||||
|
elem->parent[i].mode);
|
||||||
|
}
|
||||||
|
if (elem->mode)
|
||||||
|
printf("..%06o", elem->mode);
|
||||||
}
|
}
|
||||||
printf("..%06o\n", elem->mode);
|
putchar('\n');
|
||||||
}
|
}
|
||||||
dump_sline(sline, cnt, num_parent);
|
dump_sline(sline, cnt, num_parent);
|
||||||
}
|
}
|
||||||
|
@ -776,8 +782,92 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
|
||||||
return shown_header;
|
return shown_header;
|
||||||
}
|
}
|
||||||
|
|
||||||
int diff_tree_combined_merge(const unsigned char *sha1,
|
#define COLONS "::::::::::::::::::::::::::::::::"
|
||||||
const char *header, int dense)
|
|
||||||
|
static void show_raw_diff(struct combine_diff_path *p, int num_parent, const char *header, struct diff_options *opt)
|
||||||
|
{
|
||||||
|
int i, offset, mod_type = 'A';
|
||||||
|
const char *prefix;
|
||||||
|
int line_termination, inter_name_termination;
|
||||||
|
|
||||||
|
line_termination = opt->line_termination;
|
||||||
|
inter_name_termination = '\t';
|
||||||
|
if (!line_termination)
|
||||||
|
inter_name_termination = 0;
|
||||||
|
|
||||||
|
if (header)
|
||||||
|
puts(header);
|
||||||
|
|
||||||
|
for (i = 0; i < num_parent; i++) {
|
||||||
|
if (p->parent[i].mode)
|
||||||
|
mod_type = 'M';
|
||||||
|
}
|
||||||
|
if (!p->mode)
|
||||||
|
mod_type = 'D';
|
||||||
|
|
||||||
|
if (opt->output_format == DIFF_FORMAT_RAW) {
|
||||||
|
offset = strlen(COLONS) - num_parent;
|
||||||
|
if (offset < 0)
|
||||||
|
offset = 0;
|
||||||
|
prefix = COLONS + offset;
|
||||||
|
|
||||||
|
/* Show the modes */
|
||||||
|
for (i = 0; i < num_parent; i++) {
|
||||||
|
printf("%s%06o", prefix, p->parent[i].mode);
|
||||||
|
prefix = " ";
|
||||||
|
}
|
||||||
|
printf("%s%06o", prefix, p->mode);
|
||||||
|
|
||||||
|
/* Show sha1's */
|
||||||
|
for (i = 0; i < num_parent; i++)
|
||||||
|
printf(" %s", diff_unique_abbrev(p->parent[i].sha1,
|
||||||
|
opt->abbrev));
|
||||||
|
printf(" %s ", diff_unique_abbrev(p->sha1, opt->abbrev));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opt->output_format == DIFF_FORMAT_RAW ||
|
||||||
|
opt->output_format == DIFF_FORMAT_NAME_STATUS) {
|
||||||
|
for (i = 0; i < num_parent; i++)
|
||||||
|
putchar(p->parent[i].status);
|
||||||
|
putchar(inter_name_termination);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line_termination) {
|
||||||
|
if (quote_c_style(p->path, NULL, NULL, 0))
|
||||||
|
quote_c_style(p->path, NULL, stdout, 0);
|
||||||
|
else
|
||||||
|
printf("%s", p->path);
|
||||||
|
putchar(line_termination);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("%s%c", p->path, line_termination);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int show_combined_diff(struct combine_diff_path *p,
|
||||||
|
int num_parent,
|
||||||
|
int dense,
|
||||||
|
const char *header,
|
||||||
|
struct diff_options *opt)
|
||||||
|
{
|
||||||
|
if (!p->len)
|
||||||
|
return 0;
|
||||||
|
switch (opt->output_format) {
|
||||||
|
case DIFF_FORMAT_RAW:
|
||||||
|
case DIFF_FORMAT_NAME_STATUS:
|
||||||
|
case DIFF_FORMAT_NAME:
|
||||||
|
show_raw_diff(p, num_parent, header, opt);
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
default:
|
||||||
|
case DIFF_FORMAT_PATCH:
|
||||||
|
return show_patch_diff(p, num_parent, dense, header);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *diff_tree_combined_merge(const unsigned char *sha1,
|
||||||
|
const char *header, int dense,
|
||||||
|
struct diff_options *opt)
|
||||||
{
|
{
|
||||||
struct commit *commit = lookup_commit(sha1);
|
struct commit *commit = lookup_commit(sha1);
|
||||||
struct diff_options diffopts;
|
struct diff_options diffopts;
|
||||||
|
@ -785,7 +875,7 @@ int diff_tree_combined_merge(const unsigned char *sha1,
|
||||||
struct combine_diff_path *p, *paths = NULL;
|
struct combine_diff_path *p, *paths = NULL;
|
||||||
int num_parent, i, num_paths;
|
int num_parent, i, num_paths;
|
||||||
|
|
||||||
diff_setup(&diffopts);
|
diffopts = *opt;
|
||||||
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
|
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
|
||||||
diffopts.recursive = 1;
|
diffopts.recursive = 1;
|
||||||
|
|
||||||
|
@ -802,6 +892,7 @@ int diff_tree_combined_merge(const unsigned char *sha1,
|
||||||
struct commit *parent = parents->item;
|
struct commit *parent = parents->item;
|
||||||
diff_tree_sha1(parent->object.sha1, commit->object.sha1, "",
|
diff_tree_sha1(parent->object.sha1, commit->object.sha1, "",
|
||||||
&diffopts);
|
&diffopts);
|
||||||
|
diffcore_std(&diffopts);
|
||||||
paths = intersect_paths(paths, i, num_parent);
|
paths = intersect_paths(paths, i, num_parent);
|
||||||
diff_flush(&diffopts);
|
diff_flush(&diffopts);
|
||||||
}
|
}
|
||||||
|
@ -813,9 +904,8 @@ int diff_tree_combined_merge(const unsigned char *sha1,
|
||||||
}
|
}
|
||||||
if (num_paths) {
|
if (num_paths) {
|
||||||
for (p = paths; p; p = p->next) {
|
for (p = paths; p; p = p->next) {
|
||||||
if (!p->len)
|
if (show_combined_diff(p, num_parent, dense,
|
||||||
continue;
|
header, opt))
|
||||||
if (show_combined_diff(p, num_parent, dense, header))
|
|
||||||
header = NULL;
|
header = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -826,5 +916,5 @@ int diff_tree_combined_merge(const unsigned char *sha1,
|
||||||
paths = paths->next;
|
paths = paths->next;
|
||||||
free(tmp);
|
free(tmp);
|
||||||
}
|
}
|
||||||
return 0;
|
return header;
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,9 +88,8 @@ int main(int argc, const char **argv)
|
||||||
}
|
}
|
||||||
argv++; argc--;
|
argv++; argc--;
|
||||||
}
|
}
|
||||||
if (combine_merges) {
|
if (dense_combined_merges)
|
||||||
diff_options.output_format = DIFF_FORMAT_PATCH;
|
diff_options.output_format = DIFF_FORMAT_PATCH;
|
||||||
}
|
|
||||||
|
|
||||||
/* Find the directory, and set up the pathspec */
|
/* Find the directory, and set up the pathspec */
|
||||||
pathspec = get_pathspec(prefix, argv + 1);
|
pathspec = get_pathspec(prefix, argv + 1);
|
||||||
|
@ -166,7 +165,8 @@ int main(int argc, const char **argv)
|
||||||
if (combine_merges && num_compare_stages == 2) {
|
if (combine_merges && num_compare_stages == 2) {
|
||||||
show_combined_diff(&combine.p, 2,
|
show_combined_diff(&combine.p, 2,
|
||||||
dense_combined_merges,
|
dense_combined_merges,
|
||||||
NULL);
|
NULL,
|
||||||
|
&diff_options);
|
||||||
free(combine.p.path);
|
free(combine.p.path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
20
diff-tree.c
20
diff-tree.c
|
@ -6,7 +6,7 @@ static int show_root_diff = 0;
|
||||||
static int no_commit_id = 0;
|
static int no_commit_id = 0;
|
||||||
static int verbose_header = 0;
|
static int verbose_header = 0;
|
||||||
static int ignore_merges = 1;
|
static int ignore_merges = 1;
|
||||||
static int combine_merges = 0;
|
static int combine_merges = 1;
|
||||||
static int dense_combined_merges = 0;
|
static int dense_combined_merges = 0;
|
||||||
static int read_stdin = 0;
|
static int read_stdin = 0;
|
||||||
static int always_show_header = 0;
|
static int always_show_header = 0;
|
||||||
|
@ -117,8 +117,12 @@ static int diff_tree_commit(struct commit *commit)
|
||||||
return 0;
|
return 0;
|
||||||
else if (combine_merges) {
|
else if (combine_merges) {
|
||||||
header = generate_header(sha1, sha1, commit);
|
header = generate_header(sha1, sha1, commit);
|
||||||
return diff_tree_combined_merge(sha1, header,
|
header = diff_tree_combined_merge(sha1, header,
|
||||||
dense_combined_merges);
|
dense_combined_merges,
|
||||||
|
&diff_options);
|
||||||
|
if (!header && verbose_header)
|
||||||
|
header_prefix = "\ndiff-tree ";
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +248,7 @@ int main(int argc, const char **argv)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp(arg, "-m")) {
|
if (!strcmp(arg, "-m")) {
|
||||||
ignore_merges = 0;
|
combine_merges = ignore_merges = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcmp(arg, "-c")) {
|
if (!strcmp(arg, "-c")) {
|
||||||
|
@ -285,10 +289,12 @@ int main(int argc, const char **argv)
|
||||||
usage(diff_tree_usage);
|
usage(diff_tree_usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (combine_merges) {
|
if (combine_merges)
|
||||||
diff_options.output_format = DIFF_FORMAT_PATCH;
|
|
||||||
ignore_merges = 0;
|
ignore_merges = 0;
|
||||||
}
|
|
||||||
|
/* We can only do dense combined merges with diff output */
|
||||||
|
if (dense_combined_merges)
|
||||||
|
diff_options.output_format = DIFF_FORMAT_PATCH;
|
||||||
|
|
||||||
if (diff_options.output_format == DIFF_FORMAT_PATCH)
|
if (diff_options.output_format == DIFF_FORMAT_PATCH)
|
||||||
diff_options.recursive = 1;
|
diff_options.recursive = 1;
|
||||||
|
|
14
diff.c
14
diff.c
|
@ -963,7 +963,7 @@ void diff_free_filepair(struct diff_filepair *p)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is different from find_unique_abbrev() in that
|
/* This is different from find_unique_abbrev() in that
|
||||||
* it needs to deal with 0{40} SHA1.
|
* it stuffs the result with dots for alignment.
|
||||||
*/
|
*/
|
||||||
const char *diff_unique_abbrev(const unsigned char *sha1, int len)
|
const char *diff_unique_abbrev(const unsigned char *sha1, int len)
|
||||||
{
|
{
|
||||||
|
@ -973,16 +973,8 @@ const char *diff_unique_abbrev(const unsigned char *sha1, int len)
|
||||||
return sha1_to_hex(sha1);
|
return sha1_to_hex(sha1);
|
||||||
|
|
||||||
abbrev = find_unique_abbrev(sha1, len);
|
abbrev = find_unique_abbrev(sha1, len);
|
||||||
if (!abbrev) {
|
if (!abbrev)
|
||||||
if (!memcmp(sha1, null_sha1, 20)) {
|
return sha1_to_hex(sha1);
|
||||||
char *buf = sha1_to_hex(null_sha1);
|
|
||||||
if (len < 37)
|
|
||||||
strcpy(buf + len, "...");
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return sha1_to_hex(sha1);
|
|
||||||
}
|
|
||||||
abblen = strlen(abbrev);
|
abblen = strlen(abbrev);
|
||||||
if (abblen < 37) {
|
if (abblen < 37) {
|
||||||
static char hex[41];
|
static char hex[41];
|
||||||
|
|
8
diff.h
8
diff.h
|
@ -66,6 +66,7 @@ struct combine_diff_path {
|
||||||
unsigned int mode;
|
unsigned int mode;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
struct combine_diff_parent {
|
struct combine_diff_parent {
|
||||||
|
char status;
|
||||||
unsigned int mode;
|
unsigned int mode;
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
} parent[FLEX_ARRAY];
|
} parent[FLEX_ARRAY];
|
||||||
|
@ -74,10 +75,11 @@ struct combine_diff_path {
|
||||||
(sizeof(struct combine_diff_path) + \
|
(sizeof(struct combine_diff_path) + \
|
||||||
sizeof(struct combine_diff_parent) * (n) + (l) + 1)
|
sizeof(struct combine_diff_parent) * (n) + (l) + 1)
|
||||||
|
|
||||||
int show_combined_diff(struct combine_diff_path *elem, int num_parent,
|
extern int show_combined_diff(struct combine_diff_path *elem, int num_parent,
|
||||||
int dense, const char *header);
|
int dense, const char *header,
|
||||||
|
struct diff_options *);
|
||||||
|
|
||||||
extern int diff_tree_combined_merge(const unsigned char *sha1, const char *, int);
|
extern const char *diff_tree_combined_merge(const unsigned char *sha1, const char *, int, struct diff_options *opt);
|
||||||
|
|
||||||
extern void diff_addremove(struct diff_options *,
|
extern void diff_addremove(struct diff_options *,
|
||||||
int addremove,
|
int addremove,
|
||||||
|
|
|
@ -186,16 +186,18 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
|
||||||
|
|
||||||
const char *find_unique_abbrev(const unsigned char *sha1, int len)
|
const char *find_unique_abbrev(const unsigned char *sha1, int len)
|
||||||
{
|
{
|
||||||
int status;
|
int status, is_null;
|
||||||
static char hex[41];
|
static char hex[41];
|
||||||
|
|
||||||
|
is_null = !memcmp(sha1, null_sha1, 20);
|
||||||
memcpy(hex, sha1_to_hex(sha1), 40);
|
memcpy(hex, sha1_to_hex(sha1), 40);
|
||||||
if (len == 40)
|
if (len == 40)
|
||||||
return hex;
|
return hex;
|
||||||
while (len < 40) {
|
while (len < 40) {
|
||||||
unsigned char sha1_ret[20];
|
unsigned char sha1_ret[20];
|
||||||
status = get_short_sha1(hex, len, sha1_ret, 1);
|
status = get_short_sha1(hex, len, sha1_ret, 1);
|
||||||
if (!status) {
|
if (!status ||
|
||||||
|
(is_null && status != SHORT_NAME_AMBIGUOUS)) {
|
||||||
hex[len] = 0;
|
hex[len] = 0;
|
||||||
return hex;
|
return hex;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue