From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: 1425896314-10941-1-git-send-email-pclouds@gmail.com,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 23/25] pathspec: move getenv() code out of prefix_pathspec()
Date: Mon, 6 Apr 2015 20:52:32 +0700 [thread overview]
Message-ID: <1428328354-14897-24-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1428328354-14897-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
pathspec.c | 55 +++++++++++++++++++++++++++----------------------------
1 file changed, 27 insertions(+), 28 deletions(-)
diff --git a/pathspec.c b/pathspec.c
index 9304ee3..5573127 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -88,6 +88,13 @@ static void prefix_short_magic(struct strbuf *sb, int prefixlen,
strbuf_addf(sb, ",prefix:%d)", prefixlen);
}
+struct global_flags {
+ unsigned literal : 1;
+ unsigned glob : 1;
+ unsigned noglob : 1;
+ unsigned icase : 1;
+};
+
/*
* Take an element of a pathspec and check for magic signatures.
* Append the result to the prefix. Return the magic bitmap.
@@ -105,39 +112,20 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
unsigned *p_short_magic,
const char **raw, unsigned flags,
const char *prefix, int prefixlen,
- const char *elt)
+ const char *elt,
+ const struct global_flags *global)
{
- static int literal_global = -1;
- static int glob_global = -1;
- static int noglob_global = -1;
- static int icase_global = -1;
unsigned magic = 0, short_magic = 0, global_magic = 0;
const char *copyfrom = elt, *long_magic_end = NULL;
char *match;
int i, pathspec_prefix = -1;
- if (literal_global < 0)
- literal_global = git_env_bool(GIT_LITERAL_PATHSPECS_ENVIRONMENT, 0);
- if (literal_global)
+ if (global->literal)
global_magic |= PATHSPEC_LITERAL;
-
- if (glob_global < 0)
- glob_global = git_env_bool(GIT_GLOB_PATHSPECS_ENVIRONMENT, 0);
- if (glob_global)
+ if (global->glob)
global_magic |= PATHSPEC_GLOB;
-
- if (noglob_global < 0)
- noglob_global = git_env_bool(GIT_NOGLOB_PATHSPECS_ENVIRONMENT, 0);
-
- if (glob_global && noglob_global)
- die(_("global 'glob' and 'noglob' pathspec settings are incompatible"));
-
-
- if (icase_global < 0)
- icase_global = git_env_bool(GIT_ICASE_PATHSPECS_ENVIRONMENT, 0);
- if (icase_global)
+ if (global->icase)
global_magic |= PATHSPEC_ICASE;
-
if ((global_magic & PATHSPEC_LITERAL) &&
(global_magic & ~PATHSPEC_LITERAL))
die(_("global 'literal' pathspec setting is incompatible "
@@ -146,7 +134,8 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
if (flags & PATHSPEC_LITERAL_PATH)
global_magic = 0;
- if (elt[0] != ':' || literal_global ||
+
+ if (elt[0] != ':' || global->literal ||
(flags & PATHSPEC_LITERAL_PATH)) {
; /* nothing to do */
} else if (elt[1] == '(') {
@@ -213,7 +202,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
*p_short_magic = short_magic;
/* --noglob-pathspec adds :(literal) _unless_ :(glob) is specified */
- if (noglob_global && !(magic & PATHSPEC_GLOB))
+ if (global->noglob && !(magic & PATHSPEC_GLOB))
global_magic |= PATHSPEC_LITERAL;
/* --glob-pathspec is overridden by :(literal) */
@@ -247,7 +236,7 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
*/
if (flags & PATHSPEC_PREFIX_ORIGIN) {
struct strbuf sb = STRBUF_INIT;
- if (prefixlen && !literal_global) {
+ if (prefixlen && !global->literal) {
/* Preserve the actual prefix length of each pattern */
if (short_magic)
prefix_short_magic(&sb, prefixlen, short_magic);
@@ -365,6 +354,7 @@ void parse_pathspec(struct pathspec *pathspec,
struct pathspec_item *item;
const char *entry = argv ? *argv : NULL;
int i, n, prefixlen, nr_exclude = 0;
+ struct global_flags global;
memset(pathspec, 0, sizeof(*pathspec));
@@ -401,6 +391,14 @@ void parse_pathspec(struct pathspec *pathspec,
return;
}
+ memset(&global, 0, sizeof(global));
+ global.literal = git_env_bool(GIT_LITERAL_PATHSPECS_ENVIRONMENT, 0) != 0;
+ global.glob = git_env_bool(GIT_GLOB_PATHSPECS_ENVIRONMENT, 0) != 0;
+ global.noglob = git_env_bool(GIT_NOGLOB_PATHSPECS_ENVIRONMENT, 0) != 0;
+ global.icase = git_env_bool(GIT_ICASE_PATHSPECS_ENVIRONMENT, 0) != 0;
+ if (global.glob && global.noglob)
+ die(_("global 'glob' and 'noglob' pathspec settings are incompatible"));
+
n = 0;
while (argv[n])
n++;
@@ -416,7 +414,8 @@ void parse_pathspec(struct pathspec *pathspec,
item[i].magic = prefix_pathspec(item + i, &short_magic,
argv + i, flags,
- prefix, prefixlen, entry);
+ prefix, prefixlen, entry,
+ &global);
if ((flags & PATHSPEC_LITERAL_PATH) &&
!(magic_mask & PATHSPEC_LITERAL))
item[i].magic |= PATHSPEC_LITERAL;
--
2.3.0.rc1.137.g477eb31
next prev parent reply other threads:[~2015-04-06 13:55 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-06 13:52 [PATCH v2 00/25] list-files redesign Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 01/25] ls_colors.c: add $LS_COLORS parsing code Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 02/25] ls_colors.c: parse color.ls.* from config file Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 03/25] ls_colors.c: add a function to color a file name Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 04/25] ls_colors.c: highlight submodules like directories Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 05/25] list-files: command skeleton Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 06/25] list-files: show paths relative to cwd Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 07/25] list-files: add tag to each entry, filter duplicate tags Nguyễn Thái Ngọc Duy
2015-04-06 21:32 ` Eric Sunshine
2015-04-06 13:52 ` [PATCH 08/25] list-files: add --[no-]column, -C and -1 Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 09/25] list-files: add --max-depth, -R and default to --max-depth=0 Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 10/25] list-files: show directories as well as files Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 11/25] list-files: add --color Nguyễn Thái Ngọc Duy
2015-04-06 21:33 ` Eric Sunshine
2015-04-06 13:52 ` [PATCH 12/25] list-files: add -F/--classify Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 13/25] list-files: new indicator '&' for submodules when -F is used Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 14/25] list-files: add --cached and --others Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 15/25] list-files: add --ignored Nguyễn Thái Ngọc Duy
2015-04-06 21:34 ` Eric Sunshine
2015-04-06 13:52 ` [PATCH 16/25] list-files: add --unmerged Nguyễn Thái Ngọc Duy
2015-04-06 21:34 ` Eric Sunshine
2015-04-06 13:52 ` [PATCH 17/25] list-files: add file modification options -[admADM] Nguyễn Thái Ngọc Duy
2015-04-06 21:34 ` Eric Sunshine
2015-04-06 13:52 ` [PATCH 18/25] list-files: delete redundant cached entries Nguyễn Thái Ngọc Duy
2015-04-06 21:35 ` Eric Sunshine
2015-04-08 2:39 ` Junio C Hamano
2015-04-06 13:52 ` [PATCH 19/25] list-files: make alias 'ls' default to 'list-files' Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 20/25] list-files: preload index Nguyễn Thái Ngọc Duy
2015-04-06 21:35 ` Eric Sunshine
2015-04-06 13:52 ` [PATCH 21/25] list-files: reduce match_pathspec calls in matched() Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 22/25] list-files: only do diff that is actually useful Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` Nguyễn Thái Ngọc Duy [this message]
2015-04-06 13:52 ` [PATCH 24/25] list-files: make :(glob) pathspec default Nguyễn Thái Ngọc Duy
2015-04-06 13:52 ` [PATCH 25/25] list-files: documentation Nguyễn Thái Ngọc Duy
2015-04-06 21:37 ` Eric Sunshine
2015-04-06 13:58 ` [PATCH v2 00/25] list-files redesign Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1428328354-14897-24-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=1425896314-10941-1-git-send-email-pclouds@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.