[PATCH 1/2] Allow '-' in config variable names

Subsystems: the rest

DORMANTno replies

2 messages, 1 author, 2016-08-11 · open the first message on its own page

[PATCH 1/2] Allow '-' in config variable names

From: Linus Torvalds <torvalds@osdl.org>
Date: 2016-08-11 20:44:05

I need this in order to allow aliases of the same form as "ls-tree", 
"rev-parse" etc, so that I can use

	[alias]
		my-cat=--paginate cat-file -p

to add a "git my-cat" command.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

This will be followed by another patch to "builtin-push.c" to allow me to 
make a useful (to me) "push-all" alias.
diff --git a/config.c b/config.c
index e8f0caf..3cae390 100644
--- a/config.c
+++ b/config.c
@@ -103,6 +103,11 @@ static char *parse_value(void)
 	}
 }
 
+static inline int iskeychar(int c)
+{
+	return isalnum(c) || c == '-';
+}
+
 static int get_value(config_fn_t fn, char *name, unsigned int len)
 {
 	int c;
@@ -113,7 +118,7 @@ static int get_value(config_fn_t fn, cha
 		c = get_next_char();
 		if (c == EOF)
 			break;
-		if (!isalnum(c))
+		if (!iskeychar(c))
 			break;
 		name[len++] = tolower(c);
 		if (len >= MAXNAME)
@@ -181,7 +186,7 @@ static int get_base_var(char *name)
 			return baselen;
 		if (isspace(c))
 			return get_extended_base_var(name, baselen, c);
-		if (!isalnum(c) && c != '.')
+		if (!iskeychar(c) && c != '.')
 			return -1;
 		if (baselen > MAXNAME / 2)
 			return -1;
@@ -573,7 +578,7 @@ int git_config_set_multivar(const char*
 			dot = 1;
 		/* Leave the extended basename untouched.. */
 		if (!dot || i > store.baselen) {
-			if (!isalnum(c) || (i == store.baselen+1 && !isalpha(c))) {
+			if (!iskeychar(c) || (i == store.baselen+1 && !isalpha(c))) {
 				fprintf(stderr, "invalid key: %s\n", key);
 				free(store.key);

[PATCH 2/2] git push: add verbose flag and allow overriding of default target repository

From: Linus Torvalds <torvalds@osdl.org>
Date: 2016-08-11 20:39:44

This adds a command line flag "-v" to enable a more verbose mode, and 
"--repo=" to override the default target repository for "git push" (which 
otherwise always defaults to "origin").

This, together with the patch to allow dashes in config variable names, 
allows me to do

	[alias]
		push-all = push -v --repo=all

in my user-global config file, and then I can (for any project I maintain) 
add to the project-local config file

	[remote "all"]
		url=one.target.repo:/directory
		url=another.target:/pub/somewhere/else

and now "git push-all" just updates all the target repositories, and shows 
me what it does - regardless of which repo I am in.

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---

Maybe this is just useful to me? I dunno. I have long had a per-repository 
"push-all" script that I have in the root directory of the repos I 
maintain, but this is much more practical. With this, I can do things like

	git push-all --tags

and it will push all the new tags to all the public repositories I 
maintain for that particular repository.

Special Linus-only behaviour? Maybe. On the other hand, I think this is a 
pretty clean patch regardless.
diff --git a/builtin-push.c b/builtin-push.c
index f5150ed..3151fb7 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -10,7 +10,7 @@
 
 static const char push_usage[] = "git-push [--all] [--tags] [-f | --force] <repository> [<refspec>...]";
 
-static int all, tags, force, thin = 1;
+static int all, tags, force, thin = 1, verbose;
 static const char *execute;
 
 #define BUF_SIZE (2084)
@@ -248,6 +248,8 @@ static int do_push(const char *repo)
 		while (dest_refspec_nr--)
 			argv[dest_argc++] = *dest_refspec++;
 		argv[dest_argc] = NULL;
+		if (verbose)
+			fprintf(stderr, "Pushing to %s\n", dest);
 		err = run_command_v(argc, argv);
 		if (!err)
 			continue;
@@ -281,6 +283,14 @@ int cmd_push(int argc, const char **argv
 			i++;
 			break;
 		}
+		if (!strcmp(arg, "-v")) {
+			verbose=1;
+			continue;
+		}
+		if (!strncmp(arg, "--repo=", 7)) {
+			repo = arg+7;
+			continue;
+		}
 		if (!strcmp(arg, "--all")) {
 			all = 1;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help