Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2005-11-20 15:24:18 +0300
committerJunio C Hamano <junkio@cox.net>2005-11-20 21:53:06 +0300
commitf98d863d2122e1b8781dfb9889df98876a26f315 (patch)
tree3b688c9ff010bd74cde0027fe63f1d225a53b0ab /config.c
parenta6322d079b1d2e2cb72da1271171b35a173f3d22 (diff)
git-config-set: support selecting values by non-matching regex
Extend the regex syntax of value_regex so that prepending an exclamation mark means non-match: [core] quetzal = "Dodo" for Brainf*ck quetzal = "T. Rex" for Malbolge quetzal = "cat" You can match the third line with git-config-set --get quetzal '! for ' Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'config.c')
-rw-r--r--config.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/config.c b/config.c
index 697d79f536..5d237c862d 100644
--- a/config.c
+++ b/config.c
@@ -269,6 +269,7 @@ int git_config(config_fn_t fn)
static struct {
int baselen;
char* key;
+ int do_not_match;
regex_t* value_regex;
int multi_replace;
off_t offset[MAX_MATCHES];
@@ -276,13 +277,19 @@ static struct {
int seen;
} store;
+static int matches(const char* key, const char* value)
+{
+ return !strcmp(key, store.key) &&
+ (store.value_regex == NULL ||
+ (store.do_not_match ^
+ !regexec(store.value_regex, value, 0, NULL, 0)));
+}
+
static int store_aux(const char* key, const char* value)
{
switch (store.state) {
case KEY_SEEN:
- if (!strcmp(key, store.key) &&
- (store.value_regex == NULL ||
- !regexec(store.value_regex, value, 0, NULL, 0))) {
+ if (matches(key, value)) {
if (store.seen == 1 && store.multi_replace == 0) {
fprintf(stderr,
"Warning: %s has multiple values\n",
@@ -306,9 +313,7 @@ static int store_aux(const char* key, const char* value)
/* fallthru */
case SECTION_END_SEEN:
case START:
- if (!strcmp(key, store.key) &&
- (store.value_regex == NULL ||
- !regexec(store.value_regex, value, 0, NULL, 0))) {
+ if (matches(key, value)) {
store.offset[store.seen] = ftell(config_file);
store.state = KEY_SEEN;
store.seen++;
@@ -471,6 +476,12 @@ int git_config_set_multivar(const char* key, const char* value,
if (value_regex == NULL)
store.value_regex = NULL;
else {
+ if (value_regex[0] == '!') {
+ store.do_not_match = 1;
+ value_regex++;
+ } else
+ store.do_not_match = 0;
+
store.value_regex = (regex_t*)malloc(sizeof(regex_t));
if (regcomp(store.value_regex, value_regex,
REG_EXTENDED)) {