magic pathspec: add ":(icase)path" to match case insensitively
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Apr 6, 2011 at 20:56 UTC
d0546e2d488b1ba185c430b638619ab1d91af509
2 files changed
+32
-6
Documentation/glossary-content.txt
+5
-2
@@ -319,10 +319,13 @@ top `/`;;
319
The magic word `top` (mnemonic: `/`) makes the pattern match
320
from the root of the working tree, even when you are running
321
the command from inside a subdirectory.
322
+icase;;
323
+ The magic word `icase` (there is no mnemonic for it) makes the
324
+ pattern match case insensitively. E.g. `:(icase)makefile` matches
325
+ both `Makefile` and `makefile`.
326
--
327
+
324
-Currently only the slash `/` is recognized as the "magic signature",
325
-but it is envisioned that we will support more types of magic in later
328
+It is envisioned that we will support more types of magic in later
329
versions of git.
330
331
[[def_parent]]parent::
setup.c
+27
-4
@@ -136,12 +136,12 @@ void verify_non_filename(const char *prefix, const char *arg)
136
* Possible future magic semantics include stuff like:
137
*
138
* { PATHSPEC_NOGLOB, '!', "noglob" },
139
- * { PATHSPEC_ICASE, '\0', "icase" },
139
* { PATHSPEC_RECURSIVE, '*', "recursive" },
140
* { PATHSPEC_REGEXP, '\0', "regexp" },
141
*
142
*/
143
#define PATHSPEC_FROMTOP (1<<0)
144
+#define PATHSPEC_ICASE (1<<1)
145
146
struct pathspec_magic {
147
unsigned bit;
@@ -149,6 +149,7 @@ struct pathspec_magic {
149
const char *name;
150
} pathspec_magic[] = {
151
{ PATHSPEC_FROMTOP, '/', "top" },
152
+ { PATHSPEC_ICASE, '\0', "icase" },
153
};
154
155
/*
@@ -168,7 +169,8 @@ const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
169
{
170
unsigned magic = 0;
171
const char *copyfrom = elt;
171
- int i;
172
+ const char *retval;
173
+ int i, free_source = 0;
174
175
if (elt[0] != ':') {
176
; /* nothing to do */
@@ -222,10 +224,31 @@ const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
224
copyfrom++;
225
}
226
227
+ if (magic & PATHSPEC_ICASE) {
228
+ struct strbuf sb = STRBUF_INIT;
229
+ for (i = 0; copyfrom[i]; i++) {
230
+ int ch = copyfrom[i];
231
+ if (('a' <= ch && ch <= 'z') ||
232
+ ('A' <= ch && ch <= 'Z')) {
233
+ strbuf_addf(&sb, "[%c%c]",
234
+ tolower(ch), toupper(ch));
235
+ } else {
236
+ strbuf_addch(&sb, ch);
237
+ }
238
+ }
239
+ if (sb.len) {
240
+ free_source = 1;
241
+ copyfrom = strbuf_detach(&sb, NULL);
242
+ }
243
+ }
244
+
245
if (magic & PATHSPEC_FROMTOP)
226
- return xstrdup(copyfrom);
246
+ retval = xstrdup(copyfrom);
247
else
228
- return prefix_path(prefix, prefixlen, copyfrom);
248
+ retval = prefix_path(prefix, prefixlen, copyfrom);
249
+ if (free_source)
250
+ free((char *)copyfrom);
251
+ return retval;
252
}
253
254
const char **get_pathspec(const char *prefix, const char **pathspec)