diff options
Diffstat (limited to 'editors/diff.c')
-rw-r--r-- | editors/diff.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/editors/diff.c b/editors/diff.c index 07594e8d8..a3ca2b660 100644 --- a/editors/diff.c +++ b/editors/diff.c | |||
@@ -121,6 +121,7 @@ typedef struct FILE_and_pos_t { | |||
121 | struct globals { | 121 | struct globals { |
122 | smallint exit_status; | 122 | smallint exit_status; |
123 | int opt_U_context; | 123 | int opt_U_context; |
124 | const char *other_dir; | ||
124 | char *label[2]; | 125 | char *label[2]; |
125 | struct stat stb[2]; | 126 | struct stat stb[2]; |
126 | }; | 127 | }; |
@@ -760,9 +761,11 @@ static int FAST_FUNC add_to_dirlist(const char *filename, | |||
760 | void *userdata, int depth UNUSED_PARAM) | 761 | void *userdata, int depth UNUSED_PARAM) |
761 | { | 762 | { |
762 | struct dlist *const l = userdata; | 763 | struct dlist *const l = userdata; |
764 | const char *file = filename + l->len; | ||
765 | while (*file == '/') | ||
766 | file++; | ||
763 | l->dl = xrealloc_vector(l->dl, 6, l->e); | 767 | l->dl = xrealloc_vector(l->dl, 6, l->e); |
764 | /* + 1 skips "/" after dirname */ | 768 | l->dl[l->e] = xstrdup(file); |
765 | l->dl[l->e] = xstrdup(filename + l->len + 1); | ||
766 | l->e++; | 769 | l->e++; |
767 | return TRUE; | 770 | return TRUE; |
768 | } | 771 | } |
@@ -778,6 +781,25 @@ static int FAST_FUNC skip_dir(const char *filename, | |||
778 | add_to_dirlist(filename, sb, userdata, depth); | 781 | add_to_dirlist(filename, sb, userdata, depth); |
779 | return SKIP; | 782 | return SKIP; |
780 | } | 783 | } |
784 | if (!(option_mask32 & FLAG(N))) { | ||
785 | /* -r without -N: no need to recurse into dirs | ||
786 | * which do not exist on the "other side". | ||
787 | * Testcase: diff -r /tmp / | ||
788 | * (it would recurse deep into /proc without this code) */ | ||
789 | struct dlist *const l = userdata; | ||
790 | filename += l->len; | ||
791 | if (filename[0]) { | ||
792 | struct stat osb; | ||
793 | char *othername = concat_path_file(G.other_dir, filename); | ||
794 | int r = stat(othername, &osb); | ||
795 | free(othername); | ||
796 | if (r != 0 || !S_ISDIR(osb.st_mode)) { | ||
797 | /* other dir doesn't have similarly named | ||
798 | * directory, don't recurse */ | ||
799 | return SKIP; | ||
800 | } | ||
801 | } | ||
802 | } | ||
781 | return TRUE; | 803 | return TRUE; |
782 | } | 804 | } |
783 | 805 | ||
@@ -791,6 +813,7 @@ static void diffdir(char *p[2], const char *s_start) | |||
791 | /*list[i].s = list[i].e = 0; - memset did it */ | 813 | /*list[i].s = list[i].e = 0; - memset did it */ |
792 | /*list[i].dl = NULL; */ | 814 | /*list[i].dl = NULL; */ |
793 | 815 | ||
816 | G.other_dir = p[1 - i]; | ||
794 | /* We need to trim root directory prefix. | 817 | /* We need to trim root directory prefix. |
795 | * Using list.len to specify its length, | 818 | * Using list.len to specify its length, |
796 | * add_to_dirlist will remove it. */ | 819 | * add_to_dirlist will remove it. */ |