summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <junkio@cox.net>2006-02-06 12:53:07 -0800
committerLibravatar Junio C Hamano <junkio@cox.net>2006-02-06 13:06:49 -0800
commit2454c962fbe82f23aac4a5d78a0c3b5ffaed83a0 (patch)
tree2949196ba80a30573248981cc6d1d39879a2987f
parentcombine-diff: do not send NULL to printf (diff)
downloadtgif-2454c962fbe82f23aac4a5d78a0c3b5ffaed83a0.tar.xz
combine-diff: show mode changes as well.
Signed-off-by: Junio C Hamano <junkio@cox.net>
-rw-r--r--combine-diff.c42
-rw-r--r--diff-files.c12
-rw-r--r--diff.h9
3 files changed, 48 insertions, 15 deletions
diff --git a/combine-diff.c b/combine-diff.c
index 50db39b852..506c095997 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -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;
}
@@ -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;
}
}
@@ -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;
@@ -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];
@@ -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;
@@ -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)
diff --git a/diff-files.c b/diff-files.c
index 4ba59f1a25..d24d11c28d 100644
--- a/diff-files.c
+++ b/diff-files.c
@@ -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;
@@ -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];
@@ -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 */
diff --git a/diff.h b/diff.h
index ff41c5859d..5c5e7fa91f 100644
--- a/diff.h
+++ b/diff.h
@@ -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);