1 This adds the --ignore-case option, which makes rsync compare filenames
2 in a case-insensitive manner.
4 To use this patch, run these commands for a successful build:
6 patch -p1 <patches/ignore-case.diff
7 ./configure (optional if already run)
12 - Make this code handle multibyte character encodings, and honor the
13 --iconv setting when converting case.
17 @@ -32,6 +32,7 @@ extern int io_error;
18 extern int local_server;
19 extern int prune_empty_dirs;
20 extern int ignore_perishable;
21 +extern int ignore_case;
22 extern int delete_mode;
23 extern int delete_excluded;
24 extern int cvs_exclude;
25 @@ -580,16 +581,17 @@ static int rule_matches(char *name, stru
26 if (litmatch_array(pattern, strings, slash_handling))
28 } else if (anchored_match) {
29 - if (strcmp(name, pattern) == 0)
30 + if ((ignore_case ? strcasecmp(name, pattern)
31 + : strcmp(name, pattern)) == 0)
34 int l1 = strlen(name);
35 int l2 = strlen(pattern);
37 - strcmp(name+(l1-l2),pattern) == 0 &&
38 - (l1==l2 || name[l1-(l2+1)] == '/')) {
40 + && (ignore_case ? strcasecmp(name + (l1-l2), pattern)
41 + : strcmp(name + (l1-l2), pattern)) == 0
42 + && (l1 == l2 || name[l1 - (l2+1)] == '/'))
50 @@ -35,6 +35,7 @@ extern int inc_recurse;
51 extern int do_progress;
52 extern int always_checksum;
54 +extern int ignore_case;
55 extern int ignore_errors;
56 extern int numeric_ids;
58 @@ -2454,7 +2455,7 @@ enum fnc_type { t_PATH, t_ITEM };
59 int f_name_cmp(struct file_struct *f1, struct file_struct *f2)
62 - const uchar *c1, *c2;
63 + const uchar *c1, *c2, ch1, ch2;
64 enum fnc_state state1, state2;
65 enum fnc_type type1, type2;
66 enum fnc_type t_path = protocol_version >= 29 ? t_PATH : t_ITEM;
67 @@ -2564,7 +2565,15 @@ int f_name_cmp(struct file_struct *f1, s
69 return type1 == t_PATH ? 1 : -1;
71 - } while ((dif = (int)*c1++ - (int)*c2++) == 0);
72 + ch1 = CVAL(c1++, 0);
73 + ch2 = CVAL(c2++, 0);
80 + } while ((dif = ch1 - ch2) == 0);
84 --- old/lib/wildmatch.c
85 +++ new/lib/wildmatch.c
87 #define ISUPPER(c) (ISASCII(c) && isupper(c))
88 #define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
90 +extern int ignore_case;
92 #ifdef WILD_TEST_ITERATIONS
93 int wildmatch_iteration_count;
95 @@ -72,6 +74,8 @@ static int dowild(const uchar *p, const
96 for ( ; (p_ch = *p) != '\0'; text++, p++) {
99 + if (ignore_case && ISUPPER(p_ch))
100 + p_ch = tolower(p_ch);
101 while ((t_ch = *text) == '\0') {
104 @@ -237,12 +241,21 @@ static int dowild(const uchar *p, const
105 * of "text" and any strings in array "a". */
106 static int doliteral(const uchar *s, const uchar *text, const uchar*const *a)
109 for ( ; *s != '\0'; text++, s++) {
110 while (*text == '\0') {
111 if ((text = *a++) == NULL)
119 + s_ch = tolower(s_ch);
121 + t_ch = tolower(t_ch);
127 @@ -288,10 +301,14 @@ static const uchar *trailing_N_elements(
128 int wildmatch(const char *pattern, const char *text)
130 static const uchar *nomore[1]; /* A NULL pointer. */
132 #ifdef WILD_TEST_ITERATIONS
133 wildmatch_iteration_count = 0;
135 - return dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
136 + force_lower_case = ignore_case;
137 + ret = dowild((const uchar*)pattern, (const uchar*)text, nomore) == TRUE;
138 + force_lower_case = 0;
142 /* Match the "pattern" against the forced-to-lower-case "text" string. */
143 @@ -331,12 +348,14 @@ int wildmatch_array(const char *pattern,
147 + force_lower_case = ignore_case;
149 if ((matched = dowild(p, text, a)) != TRUE && where < 0
150 && matched != ABORT_ALL) {
153 if ((text = (uchar*)*a++) == NULL)
158 if (*text++ == '/' && (matched = dowild(p, text, a)) != FALSE
159 @@ -344,6 +363,9 @@ int wildmatch_array(const char *pattern,
164 + force_lower_case = 0;
166 return matched == TRUE;
171 @@ -114,6 +114,7 @@ OFF_T max_size = 0;
173 int ignore_errors = 0;
174 int modify_window = 0;
175 +int ignore_case = 0;
176 int blocking_io = -1;
177 int checksum_seed = 0;
179 @@ -389,6 +390,7 @@ void usage(enum logcode F)
180 rprintf(F," --include-from=FILE read include patterns from FILE\n");
181 rprintf(F," --files-from=FILE read list of source-file names from FILE\n");
182 rprintf(F," -0, --from0 all *-from/filter files are delimited by 0s\n");
183 + rprintf(F," --ignore-case ignore case when comparing filenames\n");
184 rprintf(F," --address=ADDRESS bind address for outgoing socket to daemon\n");
185 rprintf(F," --port=PORT specify double-colon alternate port number\n");
186 rprintf(F," --sockopts=OPTIONS specify custom TCP options\n");
187 @@ -577,6 +579,8 @@ static struct poptOption long_options[]
188 {"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
189 {"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
190 {"only-write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_ONLY_WRITE_BATCH, 0, 0 },
191 + {"ignore-case", 0, POPT_ARG_VAL, &ignore_case, 1, 0, 0 },
192 + {"no-ignore-case", 0, POPT_ARG_VAL, &ignore_case, 0, 0, 0 },
193 {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
194 {"from0", '0', POPT_ARG_VAL, &eol_nulls, 1, 0, 0},
195 {"no-from0", 0, POPT_ARG_VAL, &eol_nulls, 0, 0, 0},
196 @@ -1850,6 +1854,9 @@ void server_options(char **args,int *arg
201 + args[ac++] = "--ignore-case";
203 if (partial_dir && am_sender) {
204 if (partial_dir != tmp_partialdir) {
205 args[ac++] = "--partial-dir";
208 @@ -31,6 +31,7 @@ int fnmatch_errors = 0;
211 int wildmatch_errors = 0;
212 +int ignore_case = 0;