Skip to content

Commit

Permalink
magic pathspec: add ":(icase)path" to match case insensitively
Browse files Browse the repository at this point in the history
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Apr 8, 2011
1 parent 2f6c976 commit d0546e2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
7 changes: 5 additions & 2 deletions Documentation/glossary-content.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,13 @@ top `/`;;
The magic word `top` (mnemonic: `/`) makes the pattern match
from the root of the working tree, even when you are running
the command from inside a subdirectory.
icase;;
The magic word `icase` (there is no mnemonic for it) makes the
pattern match case insensitively. E.g. `:(icase)makefile` matches
both `Makefile` and `makefile`.
--
+
Currently only the slash `/` is recognized as the "magic signature",
but it is envisioned that we will support more types of magic in later
It is envisioned that we will support more types of magic in later
versions of git.

[[def_parent]]parent::
Expand Down
31 changes: 27 additions & 4 deletions setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,20 @@ void verify_non_filename(const char *prefix, const char *arg)
* Possible future magic semantics include stuff like:
*
* { PATHSPEC_NOGLOB, '!', "noglob" },
* { PATHSPEC_ICASE, '\0', "icase" },
* { PATHSPEC_RECURSIVE, '*', "recursive" },
* { PATHSPEC_REGEXP, '\0', "regexp" },
*
*/
#define PATHSPEC_FROMTOP (1<<0)
#define PATHSPEC_ICASE (1<<1)

struct pathspec_magic {
unsigned bit;
char mnemonic; /* this cannot be ':'! */
const char *name;
} pathspec_magic[] = {
{ PATHSPEC_FROMTOP, '/', "top" },
{ PATHSPEC_ICASE, '\0', "icase" },
};

/*
Expand All @@ -168,7 +169,8 @@ const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
{
unsigned magic = 0;
const char *copyfrom = elt;
int i;
const char *retval;
int i, free_source = 0;

if (elt[0] != ':') {
; /* nothing to do */
Expand Down Expand Up @@ -222,10 +224,31 @@ const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
copyfrom++;
}

if (magic & PATHSPEC_ICASE) {
struct strbuf sb = STRBUF_INIT;
for (i = 0; copyfrom[i]; i++) {
int ch = copyfrom[i];
if (('a' <= ch && ch <= 'z') ||
('A' <= ch && ch <= 'Z')) {
strbuf_addf(&sb, "[%c%c]",
tolower(ch), toupper(ch));
} else {
strbuf_addch(&sb, ch);
}
}
if (sb.len) {
free_source = 1;
copyfrom = strbuf_detach(&sb, NULL);
}
}

if (magic & PATHSPEC_FROMTOP)
return xstrdup(copyfrom);
retval = xstrdup(copyfrom);
else
return prefix_path(prefix, prefixlen, copyfrom);
retval = prefix_path(prefix, prefixlen, copyfrom);
if (free_source)
free((char *)copyfrom);
return retval;
}

const char **get_pathspec(const char *prefix, const char **pathspec)
Expand Down

0 comments on commit d0546e2

Please sign in to comment.