summaryrefslogtreecommitdiff
path: root/config-set.c
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2005-11-20 13:24:18 +0100
committerJunio C Hamano <junkio@cox.net>2005-11-20 10:53:06 -0800
commitf98d863d2122e1b8781dfb9889df98876a26f315 (patch)
tree3b688c9ff010bd74cde0027fe63f1d225a53b0ab /config-set.c
parenta6322d079b1d2e2cb72da1271171b35a173f3d22 (diff)
downloadgit-f98d863d2122e1b8781dfb9889df98876a26f315.tar.gz
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-set.c')
-rw-r--r--config-set.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/config-set.c b/config-set.c
index 90a28b381f..5f654f7aff 100644
--- a/config-set.c
+++ b/config-set.c
@@ -8,13 +8,15 @@ static char* key = NULL;
static char* value = NULL;
static regex_t* regex = NULL;
static int do_all = 0;
+static int do_not_match = 0;
static int seen = 0;
static int show_config(const char* key_, const char* value_)
{
if (!strcmp(key_, key) &&
(regex == NULL ||
- !regexec(regex, value_, 0, NULL, 0))) {
+ (do_not_match ^
+ !regexec(regex, value_, 0, NULL, 0)))) {
if (do_all) {
printf("%s\n", value_);
return 0;
@@ -38,6 +40,11 @@ static int get_value(const char* key_, const char* regex_)
key[i] = tolower(key_[i]);
if (regex_) {
+ if (regex_[0] == '!') {
+ do_not_match = 1;
+ regex_++;
+ }
+
regex = (regex_t*)malloc(sizeof(regex_t));
if (regcomp(regex, regex_, REG_EXTENDED)) {
fprintf(stderr, "Invalid pattern: %s\n", regex_);