From: skimo@liacs.nl
To: git@vger.kernel.org, Junio C Hamano <junkio@cox.net>
Subject: [PATCH 02/16] git-config: add --remote option for reading config from remote repo
Date: Fri, 18 May 2007 21:24:51 +0200 [thread overview]
Message-ID: <11795163064160-git-send-email-skimo@liacs.nl> (raw)
In-Reply-To: <11795163053812-git-send-email-skimo@liacs.nl>
From: Sven Verdoolaege <skimo@kotnet.org>
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
---
Documentation/git-config.txt | 33 +++++++++++++++++++++---------
builtin-config.c | 44 ++++++++++++++++++++++++++++++++---------
cache.h | 1 +
config.c | 26 ++++++++++++++++++++++++
4 files changed, 84 insertions(+), 20 deletions(-)
diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
index 280ef20..76398ab 100644
--- a/Documentation/git-config.txt
+++ b/Documentation/git-config.txt
@@ -9,16 +9,25 @@ git-config - Get and set repository or global options
SYNOPSIS
--------
[verse]
-'git-config' [--system | --global] [type] name [value [value_regex]]
-'git-config' [--system | --global] [type] --add name value
-'git-config' [--system | --global] [type] --replace-all name [value [value_regex]]
-'git-config' [--system | --global] [type] --get name [value_regex]
-'git-config' [--system | --global] [type] --get-all name [value_regex]
-'git-config' [--system | --global] [type] --unset name [value_regex]
-'git-config' [--system | --global] [type] --unset-all name [value_regex]
-'git-config' [--system | --global] [type] --rename-section old_name new_name
-'git-config' [--system | --global] [type] --remove-section name
-'git-config' [--system | --global] -l | --list
+'git-config' [--system | --global | --remote=[<host>:]<directory ]
+ [type] name [value [value_regex]]
+'git-config' [--system | --global | --remote=[<host>:]<directory ]
+ [type] --add name value
+'git-config' [--system | --global | --remote=[<host>:]<directory ]
+ [type] --replace-all name [value [value_regex]]
+'git-config' [--system | --global | --remote=[<host>:]<directory ]
+ [type] --get name [value_regex]
+'git-config' [--system | --global | --remote=[<host>:]<directory ]
+ [type] --get-all name [value_regex]
+'git-config' [--system | --global | --remote=[<host>:]<directory ]
+ [type] --unset name [value_regex]
+'git-config' [--system | --global | --remote=[<host>:]<directory ]
+ [type] --unset-all name [value_regex]
+'git-config' [--system | --global | --remote=[<host>:]<directory ]
+ [type] --rename-section old_name new_name
+'git-config' [--system | --global | --remote=[<host>:]<directory ]
+ [type] --remove-section name
+'git-config' [--system | --global | --remote=[<host>:]<directory ] -l | --list
DESCRIPTION
-----------
@@ -80,6 +89,10 @@ OPTIONS
Use system-wide $(prefix)/etc/gitconfig rather than the repository
.git/config.
+--remote=[<host>:]<directory
+ Use remote config instead of the repository .git/config.
+ Only available for reading options.
+
--remove-section::
Remove the given section from the configuration file.
diff --git a/builtin-config.c b/builtin-config.c
index b2515f7..3a1e86c 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -2,8 +2,10 @@
#include "cache.h"
static const char git_config_set_usage[] =
-"git-config [ --global | --system ] [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --rename-section old_name new_name | --remove-section name | --list";
+"git-config [ --global | --system | --remote=[<host>:]<directory ] "
+"[ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --rename-section old_name new_name | --remove-section name | --list";
+static char *dest;
static char *key;
static regex_t *key_regexp;
static regex_t *regexp;
@@ -104,15 +106,19 @@ static int get_value(const char* key_, const char* regex_)
}
}
- if (do_all && system_wide)
- git_config_from_file(show_config, system_wide);
- if (do_all && global)
- git_config_from_file(show_config, global);
- git_config_from_file(show_config, local);
- if (!do_all && !seen && global)
- git_config_from_file(show_config, global);
- if (!do_all && !seen && system_wide)
- git_config_from_file(show_config, system_wide);
+ if (dest)
+ git_config_from_remote(show_config, dest);
+ else {
+ if (do_all && system_wide)
+ git_config_from_file(show_config, system_wide);
+ if (do_all && global)
+ git_config_from_file(show_config, global);
+ git_config_from_file(show_config, local);
+ if (!do_all && !seen && global)
+ git_config_from_file(show_config, global);
+ if (!do_all && !seen && system_wide)
+ git_config_from_file(show_config, system_wide);
+ }
free(key);
if (regexp) {
@@ -155,8 +161,14 @@ int cmd_config(int argc, const char **argv, const char *prefix)
}
else if (!strcmp(argv[1], "--system"))
setenv("GIT_CONFIG", ETC_GITCONFIG, 1);
+ else if (!prefixcmp(argv[1], "--remote="))
+ dest = xstrdup(argv[1]+9);
else if (!strcmp(argv[1], "--rename-section")) {
int ret;
+ if (dest) {
+ fprintf(stderr, "Cannot rename on remote\n");
+ return 1;
+ }
if (argc != 4)
usage(git_config_set_usage);
ret = git_config_rename_section(argv[2], argv[3]);
@@ -170,6 +182,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
}
else if (!strcmp(argv[1], "--remove-section")) {
int ret;
+ if (dest) {
+ fprintf(stderr, "Cannot remove on remote\n");
+ return 1;
+ }
if (argc != 3)
usage(git_config_set_usage);
ret = git_config_rename_section(argv[2], NULL);
@@ -191,6 +207,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
case 2:
return get_value(argv[1], NULL);
case 3:
+ if (dest && prefixcmp(argv[1], "--get")) {
+ fprintf(stderr, "Cannot (un)set on remote\n");
+ return 1;
+ }
if (!strcmp(argv[1], "--unset"))
return git_config_set(argv[2], NULL);
else if (!strcmp(argv[1], "--unset-all"))
@@ -209,6 +229,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
return git_config_set(argv[1], argv[2]);
case 4:
+ if (dest && prefixcmp(argv[1], "--get")) {
+ fprintf(stderr, "Cannot (un)set on remote\n");
+ return 1;
+ }
if (!strcmp(argv[1], "--unset"))
return git_config_set_multivar(argv[2], NULL, argv[3], 0);
else if (!strcmp(argv[1], "--unset-all"))
diff --git a/cache.h b/cache.h
index e34958b..6acc330 100644
--- a/cache.h
+++ b/cache.h
@@ -501,6 +501,7 @@ extern int update_server_info(int);
typedef int (*config_fn_t)(const char *, const char *);
extern int git_default_config(const char *, const char *);
extern int git_config_from_file(config_fn_t fn, const char *);
+extern int git_config_from_remote(config_fn_t fn, char *dest);
extern int git_config(config_fn_t fn);
extern int git_config_int(const char *, const char *);
extern int git_config_bool(const char *, const char *);
diff --git a/config.c b/config.c
index 0614c2b..dbfae3f 100644
--- a/config.c
+++ b/config.c
@@ -6,9 +6,12 @@
*
*/
#include "cache.h"
+#include "pkt-line.h"
#define MAXNAME (256)
+static const char *dumpconfig = "git-dump-config";
+
static FILE *config_file;
static const char *config_file_name;
static int config_linenr;
@@ -403,6 +406,29 @@ int git_config_from_file(config_fn_t fn, const char *filename)
return ret;
}
+int git_config_from_remote(config_fn_t fn, char *dest)
+{
+ int ret;
+ int fd[2];
+ pid_t pid;
+ static char var[MAXNAME];
+ static char value[1024];
+
+ pid = git_connect(fd, dest, dumpconfig);
+ if (pid < 0)
+ return 1;
+ ret = 0;
+ while (packet_read_line(fd[0], var, sizeof(var))) {
+ if (!packet_read_line(fd[0], value, sizeof(value)))
+ die("Missing value");
+ fn(var, value);
+ }
+ close(fd[0]);
+ close(fd[1]);
+ ret |= finish_connect(pid);
+ return !!ret;
+}
+
int git_config(config_fn_t fn)
{
int ret = 0;
--
1.5.2.rc3.783.gc7476-dirty
next prev parent reply other threads:[~2007-05-18 19:25 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-18 19:24 Second round of support for cloning submodules skimo
2007-05-18 19:24 ` [PATCH 01/16] Add dump-config skimo
2007-05-18 19:24 ` skimo [this message]
2007-05-18 19:24 ` [PATCH 03/16] http.h: make fill_active_slots a function pointer skimo
2007-05-18 19:24 ` [PATCH 04/16] git-config: read remote config files over HTTP skimo
2007-05-18 19:24 ` [PATCH 05/16] unpack-trees.c: verify_uptodate: remove dead code skimo
2007-05-18 22:33 ` Junio C Hamano
2007-05-18 19:24 ` [PATCH 06/16] unpack-trees.c: pass cache_entry * to verify_absent rather than just the name skimo
2007-05-18 19:24 ` [PATCH 07/16] git-read-tree: take --submodules option skimo
2007-05-18 21:53 ` Alex Riesen
2007-05-18 22:08 ` Sven Verdoolaege
2007-05-18 22:42 ` Alex Riesen
2007-05-19 3:59 ` Junio C Hamano
2007-05-19 4:27 ` Shawn O. Pearce
2007-05-19 9:19 ` Alex Riesen
2007-05-19 13:05 ` Sven Verdoolaege
2007-05-19 18:20 ` Junio C Hamano
2007-05-20 15:54 ` Jan Hudec
2007-05-20 18:33 ` Junio C Hamano
2007-05-20 20:22 ` Sven Verdoolaege
2007-05-21 16:59 ` Jan Hudec
2007-05-21 18:05 ` Sven Verdoolaege
2007-05-21 19:01 ` Junio C Hamano
2007-05-21 20:02 ` Jan Hudec
2007-05-21 21:11 ` Martin Waitz
2007-05-22 19:37 ` Jan Hudec
2007-05-24 15:48 ` Martin Waitz
2007-05-25 10:06 ` Jakub Narebski
2007-05-25 20:15 ` Jan Hudec
2007-05-24 18:26 ` Junio C Hamano
2007-05-24 18:45 ` Sven Verdoolaege
2007-05-24 18:58 ` Junio C Hamano
2007-05-24 19:14 ` Sven Verdoolaege
2007-05-24 20:32 ` Junio C Hamano
2007-05-24 20:55 ` Petr Baudis
2007-05-24 20:59 ` Junio C Hamano
2007-05-24 19:43 ` Junio C Hamano
2007-05-24 20:57 ` Petr Baudis
2007-05-25 20:35 ` Jan Hudec
2007-05-25 21:05 ` Junio C Hamano
2007-05-25 21:16 ` Steven Grimm
2007-05-25 22:11 ` Junio C Hamano
2007-05-19 0:34 ` Petr Baudis
2007-05-18 19:24 ` [PATCH 08/16] unpack-trees.c: assume submodules are clean skimo
2007-05-18 19:24 ` [PATCH 09/16] entry.c: optionally checkout submodules skimo
2007-05-18 21:56 ` Alex Riesen
2007-05-18 22:03 ` Sven Verdoolaege
2007-05-18 22:33 ` Alex Riesen
2007-05-18 22:00 ` Alex Riesen
2007-05-18 22:20 ` [PATCH] Add run_command_v_opt_cd: chdir into a directory before exec Alex Riesen
2007-05-18 22:48 ` [PATCH] Use run_command_v_opt_cd when checking out a submodule Alex Riesen
2007-05-18 19:24 ` [PATCH 10/16] git-checkout: pass --submodules option to git-read-tree skimo
2007-05-19 0:36 ` Petr Baudis
2007-05-18 19:25 ` [PATCH 11/16] git-fetch: skip empty arguments skimo
2007-05-18 22:33 ` Junio C Hamano
2007-05-18 19:25 ` [PATCH 12/16] builtin-fetch--tool: extend "native-store" for use in cloning skimo
2007-05-18 22:52 ` Alex Riesen
2007-05-19 12:17 ` Sven Verdoolaege
2007-05-18 19:25 ` [PATCH 13/16] git-clone: rely on git-fetch for fetching for most protocols skimo
2007-05-18 19:25 ` [PATCH 14/16] git-clone: rely on git-fetch for non-bare fetching over http skimo
2007-05-18 19:25 ` [PATCH 15/16] git-read-tree: treat null commit as empty tree skimo
2007-05-18 19:25 ` [PATCH 16/16] git-clone: add --submodules for cloning submodules skimo
2007-05-18 19:34 ` Second round of support " Sven Verdoolaege
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=11795163064160-git-send-email-skimo@liacs.nl \
--to=skimo@liacs.nl \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/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.