Merge branch 'lt/diff-tree'
* lt/diff-tree: combine-diff: Record diff status a bit more faithfully find_unique_abbrev() simplification.
This commit is contained in:
commit
f732d0b857
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -716,10 +718,7 @@ static int show_patch_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 @@ static int show_patch_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) {
|
||||||
|
int added = !!elem->mode;
|
||||||
|
for (i = 0; added && i < num_parent; i++)
|
||||||
|
if (elem->parent[i].status !=
|
||||||
|
DIFF_STATUS_ADDED)
|
||||||
|
added = 0;
|
||||||
|
if (added)
|
||||||
|
printf("new file mode %06o", elem->mode);
|
||||||
|
else {
|
||||||
|
if (!elem->mode)
|
||||||
|
printf("deleted file ");
|
||||||
printf("mode ");
|
printf("mode ");
|
||||||
for (i = 0; i < num_parent; i++) {
|
for (i = 0; i < num_parent; i++) {
|
||||||
printf("%s%06o", i ? "," : "",
|
printf("%s%06o", i ? "," : "",
|
||||||
elem->parent[i].mode);
|
elem->parent[i].mode);
|
||||||
}
|
}
|
||||||
printf("..%06o\n", elem->mode);
|
if (elem->mode)
|
||||||
|
printf("..%06o", elem->mode);
|
||||||
|
}
|
||||||
|
putchar('\n');
|
||||||
}
|
}
|
||||||
dump_sline(sline, cnt, num_parent);
|
dump_sline(sline, cnt, num_parent);
|
||||||
}
|
}
|
||||||
@ -820,8 +826,11 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, const cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (opt->output_format == DIFF_FORMAT_RAW ||
|
if (opt->output_format == DIFF_FORMAT_RAW ||
|
||||||
opt->output_format == DIFF_FORMAT_NAME_STATUS)
|
opt->output_format == DIFF_FORMAT_NAME_STATUS) {
|
||||||
printf("%c%c", mod_type, inter_name_termination);
|
for (i = 0; i < num_parent; i++)
|
||||||
|
putchar(p->parent[i].status);
|
||||||
|
putchar(inter_name_termination);
|
||||||
|
}
|
||||||
|
|
||||||
if (line_termination) {
|
if (line_termination) {
|
||||||
if (quote_c_style(p->path, NULL, NULL, 0))
|
if (quote_c_style(p->path, NULL, NULL, 0))
|
||||||
|
12
diff.c
12
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)) {
|
|
||||||
char *buf = sha1_to_hex(null_sha1);
|
|
||||||
if (len < 37)
|
|
||||||
strcpy(buf + len, "...");
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return sha1_to_hex(sha1);
|
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];
|
||||||
|
1
diff.h
1
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];
|
||||||
|
@ -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
Block a user