Skip to content

Commit

Permalink
combine-diff: show mode changes as well.
Browse files Browse the repository at this point in the history
Signed-off-by: Junio C Hamano <junkio@cox.net>
  • Loading branch information
Junio C Hamano committed Feb 6, 2006
1 parent 9843a1f commit 2454c96
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
42 changes: 31 additions & 11 deletions combine-diff.c
Expand Up @@ -28,15 +28,19 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
continue;
path = q->queue[i]->two->path;
len = strlen(path);

p = xmalloc(sizeof(*p) + len + 1 + num_parent * 20);
p->path = (char*) &(p->parent_sha1[num_parent][0]);
p = xmalloc(combine_diff_path_size(num_parent, len));
p->path = (char*) &(p->parent[num_parent]);
memcpy(p->path, path, len);
p->path[len] = 0;
p->len = len;
p->next = NULL;
memset(p->parent, 0,
sizeof(p->parent[0]) * num_parent);

memcpy(p->sha1, q->queue[i]->two->sha1, 20);
memcpy(p->parent_sha1[n], q->queue[i]->one->sha1, 20);
p->mode = q->queue[i]->two->mode;
memcpy(p->parent[n].sha1, q->queue[i]->one->sha1, 20);
p->parent[n].mode = q->queue[i]->one->mode;
*tail = p;
tail = &p->next;
}
Expand All @@ -57,8 +61,9 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
len = strlen(path);
if (len == p->len && !memcmp(path, p->path, len)) {
found = 1;
memcpy(p->parent_sha1[n],
memcpy(p->parent[n].sha1,
q->queue[i]->one->sha1, 20);
p->parent[n].mode = q->queue[i]->one->mode;
break;
}
}
Expand Down Expand Up @@ -613,6 +618,7 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
unsigned long size, cnt, lno;
char *result, *cp, *ep;
struct sline *sline; /* survived lines */
int mode_differs = 0;
int i, show_hunks, shown_header = 0;
char ourtmp_buf[TMPPATHLEN];
char *ourtmp = ourtmp_buf;
Expand Down Expand Up @@ -688,20 +694,22 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
for (i = 0; i < num_parent; i++) {
int j;
for (j = 0; j < i; j++) {
if (!memcmp(elem->parent_sha1[i],
elem->parent_sha1[j], 20)) {
if (!memcmp(elem->parent[i].sha1,
elem->parent[j].sha1, 20)) {
reuse_combine_diff(sline, cnt, i, j);
break;
}
}
if (i <= j)
combine_diff(elem->parent_sha1[i], ourtmp, sline,
combine_diff(elem->parent[i].sha1, ourtmp, sline,
cnt, i, num_parent);
if (elem->parent[i].mode != elem->mode)
mode_differs = 1;
}

show_hunks = make_hunks(sline, cnt, num_parent, dense);

if (show_hunks) {
if (show_hunks || mode_differs) {
const char *abb;
char null_abb[DEFAULT_ABBREV + 1];

Expand All @@ -719,8 +727,10 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
putchar('\n');
printf("index ");
for (i = 0; i < num_parent; i++) {
if (memcmp(elem->parent_sha1[i], null_sha1, 20))
abb = find_unique_abbrev(elem->parent_sha1[i],
if (elem->parent[i].mode != elem->mode)
mode_differs = 1;
if (memcmp(elem->parent[i].sha1, null_sha1, 20))
abb = find_unique_abbrev(elem->parent[i].sha1,
DEFAULT_ABBREV);
else
abb = null_abb;
Expand All @@ -731,6 +741,16 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
else
abb = null_abb;
printf("..%s\n", abb);

if (mode_differs) {
printf("mode ");
for (i = 0; i < num_parent; i++) {
printf("%s%06o", i ? "," : "",
elem->parent[i].mode);
}
printf("..%06o\n", elem->mode);
}
/* if (show_hunks) perhaps */
dump_sline(sline, cnt, num_parent);
}
if (ourtmp == ourtmp_buf)
Expand Down
12 changes: 9 additions & 3 deletions diff-files.c
Expand Up @@ -119,7 +119,7 @@ int main(int argc, const char **argv)
if (ce_stage(ce)) {
struct {
struct combine_diff_path p;
unsigned char fill[4][20];
struct combine_diff_parent filler[5];
} combine;
int num_compare_stages = 0;

Expand All @@ -128,7 +128,10 @@ int main(int argc, const char **argv)
combine.p.path = xmalloc(combine.p.len + 1);
memcpy(combine.p.path, ce->name, combine.p.len);
combine.p.path[combine.p.len] = 0;
memset(combine.p.sha1, 0, 100);
combine.p.mode = 0;
memset(combine.p.sha1, 0, 20);
memset(&combine.p.parent[0], 0,
sizeof(combine.filler));

while (i < entries) {
struct cache_entry *nce = active_cache[i];
Expand All @@ -142,9 +145,12 @@ int main(int argc, const char **argv)
*/
stage = ce_stage(nce);
if (2 <= stage) {
int mode = ntohl(nce->ce_mode);
num_compare_stages++;
memcpy(combine.p.parent_sha1[stage-2],
memcpy(combine.p.parent[stage-2].sha1,
nce->sha1, 20);
combine.p.parent[stage-2].mode =
DIFF_FILE_CANON_MODE(mode);
}

/* diff against the proper unmerged stage */
Expand Down
9 changes: 8 additions & 1 deletion diff.h
Expand Up @@ -63,9 +63,16 @@ struct combine_diff_path {
struct combine_diff_path *next;
int len;
char *path;
unsigned int mode;
unsigned char sha1[20];
unsigned char parent_sha1[FLEX_ARRAY][20];
struct combine_diff_parent {
unsigned int mode;
unsigned char sha1[20];
} parent[FLEX_ARRAY];
};
#define combine_diff_path_size(n, l) \
(sizeof(struct combine_diff_path) + \
sizeof(struct combine_diff_parent) * (n) + (l) + 1)

int show_combined_diff(struct combine_diff_path *elem, int num_parent,
int dense, const char *header);
Expand Down

0 comments on commit 2454c96

Please sign in to comment.