@matheusbsbs / matheus-bagliano / commits / 4fc970c438
Fork 0

diff --cc: fix display of symlink conflicts during a merge.

"git-diff-files --cc" to show conflicts during merge did not pass the correct mode information for the working tree down, and showed bogus combined diff. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 25, 2007 at 22:24 UTC 4fc970c43884e6215c13d6944a2def1eb2134ed5
2 files changed +34 -7
combine-diff.c
+21 -4
@@ -678,9 +678,25 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
678 else {
679 /* Used by diff-tree to read from the working tree */
680 struct stat st;
681 - int fd;
682 - if (0 <= (fd = open(elem->path, O_RDONLY)) &&
683 - !fstat(fd, &st)) {
681 + int fd = -1;
682 +
683 + if (lstat(elem->path, &st) < 0)
684 + goto deleted_file;
685 +
686 + if (S_ISLNK(st.st_mode)) {
687 + int len = st.st_size;
688 + result_size = len;
689 + result = xmalloc(len + 1);
690 + if (result_size != readlink(elem->path, result, len)) {
691 + error("readlink(%s): %s", elem->path,
692 + strerror(errno));
693 + return;
694 + }
695 + result[len] = 0;
696 + elem->mode = canon_mode(st.st_mode);
697 + }
698 + else if (0 <= (fd = open(elem->path, O_RDONLY)) &&
699 + !fstat(fd, &st)) {
700 int len = st.st_size;
701 int sz = 0;
702
@@ -698,11 +714,12 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
714 result[len] = 0;
715 }
716 else {
701 - /* deleted file */
717 + deleted_file:
718 result_size = 0;
719 elem->mode = 0;
720 result = xcalloc(1, 1);
721 }
722 +
723 if (0 <= fd)
724 close(fd);
725 }
diff-lib.c
+13 -3
@@ -41,17 +41,27 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed)
41
42 path_len = ce_namelen(ce);
43
44 - dpath = xmalloc (combine_diff_path_size (5, path_len));
44 + dpath = xmalloc(combine_diff_path_size(5, path_len));
45 dpath->path = (char *) &(dpath->parent[5]);
46
47 dpath->next = NULL;
48 dpath->len = path_len;
49 memcpy(dpath->path, ce->name, path_len);
50 dpath->path[path_len] = '\0';
51 - dpath->mode = 0;
51 hashclr(dpath->sha1);
52 memset(&(dpath->parent[0]), 0,
54 - sizeof(struct combine_diff_parent)*5);
53 + sizeof(struct combine_diff_parent)*5);
54 +
55 + if (lstat(ce->name, &st) < 0) {
56 + if (errno != ENOENT && errno != ENOTDIR) {
57 + perror(ce->name);
58 + continue;
59 + }
60 + if (silent_on_removed)
61 + continue;
62 + }
63 + else
64 + dpath->mode = canon_mode(st.st_mode);
65
66 while (i < entries) {
67 struct cache_entry *nce = active_cache[i];