зеркало из https://github.com/microsoft/git.git
parse_pathspec: add PATHSPEC_PREFER_{CWD,FULL} flags
We have two ways of dealing with empty pathspec: 1. limit it to current prefix 2. match the entire working directory Some commands go with #1, some #2. get_pathspec() and parse_pathspec() only support #1. Make parse_pathspec() reject empty pathspec by default. #1 and #2 can be specified via new flags. This makes it more expressive about default behavior at command level. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
d2ce133195
Коммит
fc12261fea
13
pathspec.c
13
pathspec.c
|
@ -271,10 +271,20 @@ void parse_pathspec(struct pathspec *pathspec,
|
||||||
if (!entry && !prefix)
|
if (!entry && !prefix)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if ((flags & PATHSPEC_PREFER_CWD) &&
|
||||||
|
(flags & PATHSPEC_PREFER_FULL))
|
||||||
|
die("BUG: PATHSPEC_PREFER_CWD and PATHSPEC_PREFER_FULL are incompatible");
|
||||||
|
|
||||||
/* No arguments with prefix -> prefix pathspec */
|
/* No arguments with prefix -> prefix pathspec */
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
static const char *raw[2];
|
static const char *raw[2];
|
||||||
|
|
||||||
|
if (flags & PATHSPEC_PREFER_FULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!(flags & PATHSPEC_PREFER_CWD))
|
||||||
|
die("BUG: PATHSPEC_PREFER_CWD requires arguments");
|
||||||
|
|
||||||
pathspec->items = item = xmalloc(sizeof(*item));
|
pathspec->items = item = xmalloc(sizeof(*item));
|
||||||
memset(item, 0, sizeof(*item));
|
memset(item, 0, sizeof(*item));
|
||||||
item->match = prefix;
|
item->match = prefix;
|
||||||
|
@ -340,7 +350,8 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
|
||||||
struct pathspec ps;
|
struct pathspec ps;
|
||||||
parse_pathspec(&ps,
|
parse_pathspec(&ps,
|
||||||
PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP,
|
PATHSPEC_ALL_MAGIC & ~PATHSPEC_FROMTOP,
|
||||||
0, prefix, pathspec);
|
PATHSPEC_PREFER_CWD,
|
||||||
|
prefix, pathspec);
|
||||||
return ps.raw;
|
return ps.raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,10 @@ struct pathspec {
|
||||||
} *items;
|
} *items;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* parse_pathspec flags */
|
||||||
|
#define PATHSPEC_PREFER_CWD (1<<0) /* No args means match cwd */
|
||||||
|
#define PATHSPEC_PREFER_FULL (1<<1) /* No args means match everything */
|
||||||
|
|
||||||
extern int init_pathspec(struct pathspec *, const char **);
|
extern int init_pathspec(struct pathspec *, const char **);
|
||||||
extern void parse_pathspec(struct pathspec *pathspec,
|
extern void parse_pathspec(struct pathspec *pathspec,
|
||||||
unsigned magic_mask,
|
unsigned magic_mask,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче