Skip to content

Commit 2454c96

Browse files
author
Junio C Hamano
committed
combine-diff: show mode changes as well.
Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 9843a1f commit 2454c96

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

combine-diff.c

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
2828
continue;
2929
path = q->queue[i]->two->path;
3030
len = strlen(path);
31-
32-
p = xmalloc(sizeof(*p) + len + 1 + num_parent * 20);
33-
p->path = (char*) &(p->parent_sha1[num_parent][0]);
31+
p = xmalloc(combine_diff_path_size(num_parent, len));
32+
p->path = (char*) &(p->parent[num_parent]);
3433
memcpy(p->path, path, len);
3534
p->path[len] = 0;
3635
p->len = len;
3736
p->next = NULL;
37+
memset(p->parent, 0,
38+
sizeof(p->parent[0]) * num_parent);
39+
3840
memcpy(p->sha1, q->queue[i]->two->sha1, 20);
39-
memcpy(p->parent_sha1[n], q->queue[i]->one->sha1, 20);
41+
p->mode = q->queue[i]->two->mode;
42+
memcpy(p->parent[n].sha1, q->queue[i]->one->sha1, 20);
43+
p->parent[n].mode = q->queue[i]->one->mode;
4044
*tail = p;
4145
tail = &p->next;
4246
}
@@ -57,8 +61,9 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
5761
len = strlen(path);
5862
if (len == p->len && !memcmp(path, p->path, len)) {
5963
found = 1;
60-
memcpy(p->parent_sha1[n],
64+
memcpy(p->parent[n].sha1,
6165
q->queue[i]->one->sha1, 20);
66+
p->parent[n].mode = q->queue[i]->one->mode;
6267
break;
6368
}
6469
}
@@ -613,6 +618,7 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
613618
unsigned long size, cnt, lno;
614619
char *result, *cp, *ep;
615620
struct sline *sline; /* survived lines */
621+
int mode_differs = 0;
616622
int i, show_hunks, shown_header = 0;
617623
char ourtmp_buf[TMPPATHLEN];
618624
char *ourtmp = ourtmp_buf;
@@ -688,20 +694,22 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
688694
for (i = 0; i < num_parent; i++) {
689695
int j;
690696
for (j = 0; j < i; j++) {
691-
if (!memcmp(elem->parent_sha1[i],
692-
elem->parent_sha1[j], 20)) {
697+
if (!memcmp(elem->parent[i].sha1,
698+
elem->parent[j].sha1, 20)) {
693699
reuse_combine_diff(sline, cnt, i, j);
694700
break;
695701
}
696702
}
697703
if (i <= j)
698-
combine_diff(elem->parent_sha1[i], ourtmp, sline,
704+
combine_diff(elem->parent[i].sha1, ourtmp, sline,
699705
cnt, i, num_parent);
706+
if (elem->parent[i].mode != elem->mode)
707+
mode_differs = 1;
700708
}
701709

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

704-
if (show_hunks) {
712+
if (show_hunks || mode_differs) {
705713
const char *abb;
706714
char null_abb[DEFAULT_ABBREV + 1];
707715

@@ -719,8 +727,10 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
719727
putchar('\n');
720728
printf("index ");
721729
for (i = 0; i < num_parent; i++) {
722-
if (memcmp(elem->parent_sha1[i], null_sha1, 20))
723-
abb = find_unique_abbrev(elem->parent_sha1[i],
730+
if (elem->parent[i].mode != elem->mode)
731+
mode_differs = 1;
732+
if (memcmp(elem->parent[i].sha1, null_sha1, 20))
733+
abb = find_unique_abbrev(elem->parent[i].sha1,
724734
DEFAULT_ABBREV);
725735
else
726736
abb = null_abb;
@@ -731,6 +741,16 @@ int show_combined_diff(struct combine_diff_path *elem, int num_parent,
731741
else
732742
abb = null_abb;
733743
printf("..%s\n", abb);
744+
745+
if (mode_differs) {
746+
printf("mode ");
747+
for (i = 0; i < num_parent; i++) {
748+
printf("%s%06o", i ? "," : "",
749+
elem->parent[i].mode);
750+
}
751+
printf("..%06o\n", elem->mode);
752+
}
753+
/* if (show_hunks) perhaps */
734754
dump_sline(sline, cnt, num_parent);
735755
}
736756
if (ourtmp == ourtmp_buf)

diff-files.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ int main(int argc, const char **argv)
119119
if (ce_stage(ce)) {
120120
struct {
121121
struct combine_diff_path p;
122-
unsigned char fill[4][20];
122+
struct combine_diff_parent filler[5];
123123
} combine;
124124
int num_compare_stages = 0;
125125

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

133136
while (i < entries) {
134137
struct cache_entry *nce = active_cache[i];
@@ -142,9 +145,12 @@ int main(int argc, const char **argv)
142145
*/
143146
stage = ce_stage(nce);
144147
if (2 <= stage) {
148+
int mode = ntohl(nce->ce_mode);
145149
num_compare_stages++;
146-
memcpy(combine.p.parent_sha1[stage-2],
150+
memcpy(combine.p.parent[stage-2].sha1,
147151
nce->sha1, 20);
152+
combine.p.parent[stage-2].mode =
153+
DIFF_FILE_CANON_MODE(mode);
148154
}
149155

150156
/* diff against the proper unmerged stage */

diff.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,16 @@ struct combine_diff_path {
6363
struct combine_diff_path *next;
6464
int len;
6565
char *path;
66+
unsigned int mode;
6667
unsigned char sha1[20];
67-
unsigned char parent_sha1[FLEX_ARRAY][20];
68+
struct combine_diff_parent {
69+
unsigned int mode;
70+
unsigned char sha1[20];
71+
} parent[FLEX_ARRAY];
6872
};
73+
#define combine_diff_path_size(n, l) \
74+
(sizeof(struct combine_diff_path) + \
75+
sizeof(struct combine_diff_parent) * (n) + (l) + 1)
6976

7077
int show_combined_diff(struct combine_diff_path *elem, int num_parent,
7178
int dense, const char *header);

0 commit comments

Comments
 (0)