git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 03/22] git-config: add --remote option for reading config from remote repo

From
Sskimo@liacs.nl <skimo@liacs.nl>
Date
May 23, 2007, 22:22 UTC
Message-ID
<11799589913274-git-send-email-skimo@liacs.nl>
In-Reply-To
<11799589913153-git-send-email-skimo@liacs.nl>
From: Sven Verdoolaege <skimo@kotnet.org>
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
---
 Documentation/git-config.txt |   27 ++++++++++++++++---------
 builtin-config.c             |   44 ++++++++++++++++++++++++++++++++---------
 cache.h                      |    1 +
 config.c                     |   26 ++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 20 deletions(-)
diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
index 827a499..549ef4e 100644
--- a/Documentation/git-config.txt
+++ b/Documentation/git-config.txt
@@ -9,16 +9,16 @@ git-config - Get and set repository or global options
 SYNOPSIS
 --------
 [verse]
-'git-config' [--system | --global] name [value [value_regex]]
-'git-config' [--system | --global] --add name value
-'git-config' [--system | --global] --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] --unset name [value_regex]
-'git-config' [--system | --global] --unset-all name [value_regex]
-'git-config' [--system | --global] --rename-section old_name new_name
-'git-config' [--system | --global] --remove-section name
-'git-config' [--system | --global] -l | --list
+'git-config' [scope] name [value [value_regex]]
+'git-config' [scope] --add name value
+'git-config' [scope] --replace-all name [value [value_regex]]
+'git-config' [scope] [type] --get name [value_regex]
+'git-config' [scope] [type] --get-all name [value_regex]
+'git-config' [scope] --unset name [value_regex]
+'git-config' [scope] --unset-all name [value_regex]
+'git-config' [scope] --rename-section old_name new_name
+'git-config' [scope] --remove-section name
+'git-config' [scope] -l | --list
 
 DESCRIPTION
 -----------
@@ -33,6 +33,9 @@ existing values that match the regexp are updated or unset.  If
 you want to handle the lines that do *not* match the regex, just
 prepend a single exclamation mark in front (see EXAMPLES).
 
+The scope specifier can be either '--system', '--global' or
+'--remote=[<host>:]<directory>'.
+
 The type specifier can be either '--int' or '--bool', which will make
 'git-config' ensure that the variable(s) are of the given type and
 convert the value to the canonical form (simple decimal number for int,
@@ -81,6 +84,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 ec85d93..6ca65ac 100644
--- a/cache.h
+++ b/cache.h
@@ -499,6 +499,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.784.g5532e
Previous: skimo@liacs.nlNext: skimo@liacs.nl
Message 4 of 94 in “[RFC] Fourth round of support for cloning submodules”
  1. skimo@liacs.nlMay 23, 2007
  2. 01/22 git_connect: unset CONFIG_ENVIRONMENT in childskimo@liacs.nl, May 23, 2007
  3. 02/22 Add dump-configskimo@liacs.nl, May 23, 2007
  4. 03/22 git-config: add --remote option for reading config from remote reposkimo@liacs.nl, May 23, 2007
  5. 04/22 http.h: make fill_active_slots a function pointerskimo@liacs.nl, May 23, 2007
  6. 05/22 git-config: read remote config files over HTTPskimo@liacs.nl, May 23, 2007
  7. 06/22 unpack-trees.c: pass cache_entry * to verify_absent rather than just the nameskimo@liacs.nl, May 23, 2007
  8. 07/22 git-read-tree: take --submodules optionskimo@liacs.nl, May 23, 2007
  9. 08/22 unpack-trees.c: assume submodules are cleanskimo@liacs.nl, May 23, 2007
  10. 09/22 Add run_command_v_opt_cd: chdir into a directory before execskimo@liacs.nl, May 23, 2007
  11. 10/22 run-command: optionally clear git environmentskimo@liacs.nl, May 23, 2007
  12. Alex RiesenMay 24, 2007
  13. Shawn O. PearceMay 24, 2007
  14. Alex RiesenMay 24, 2007
  15. 11/22 entry.c: optionally checkout submodulesskimo@liacs.nl, May 23, 2007
  16. Alex RiesenMay 24, 2007
  17. Shawn O. PearceMay 24, 2007
  18. Sven VerdoolaegeMay 24, 2007
  19. Alex RiesenMay 24, 2007
  20. Martin WaitzMay 24, 2007
  21. Shawn O. PearceMay 25, 2007
  22. 12/22 git-checkout: pass --submodules option to git-read-treeskimo@liacs.nl, May 23, 2007
  23. 13/22 git-read-tree: treat null commit as empty treeskimo@liacs.nl, May 23, 2007
  24. 14/22 git_config: add void * for callback dataskimo@liacs.nl, May 23, 2007
  25. 15/22 make redirecting stdout to /dev/null available via run_command_v_optskimo@liacs.nl, May 23, 2007
  26. 16/22 unpack-trees.c: optionally clone submodules for later checkoutskimo@liacs.nl, May 23, 2007
  27. 17/22 entry.c: optionally checkout newly cloned submodulesskimo@liacs.nl, May 23, 2007
  28. Johannes SixtMay 24, 2007
  29. 18/22 git-clone: add --submodules for cloning submodulesskimo@liacs.nl, May 23, 2007
  30. 19/22 test for simple submodule checkout supportskimo@liacs.nl, May 23, 2007
  31. 20/22 checkout_submodule: checkout submodule on forced checkout of submodule dirskimo@liacs.nl, May 23, 2007
  32. 21/22 run-command: optionally redirect stderr to /dev/nullskimo@liacs.nl, May 23, 2007
  33. 22/22 ensure_submodule: fetch missing revisionsskimo@liacs.nl, May 23, 2007
  34. Johannes SchindelinMay 23, 2007
  35. Junio C HamanoMay 24, 2007
  36. Sven VerdoolaegeMay 24, 2007
  37. Shawn O. PearceMay 24, 2007
  38. Sven VerdoolaegeMay 24, 2007
  39. Johannes SchindelinMay 24, 2007
  40. Sven VerdoolaegeMay 24, 2007
  41. Johannes SchindelinMay 24, 2007
  42. Sven VerdoolaegeMay 24, 2007
  43. Johannes SchindelinMay 24, 2007
  44. Sven VerdoolaegeMay 24, 2007
  45. Johannes SchindelinMay 24, 2007
  46. Johannes SixtMay 24, 2007
  47. Johannes SchindelinMay 24, 2007
  48. Sven VerdoolaegeMay 24, 2007
  49. Johannes SchindelinMay 24, 2007
  50. Sven VerdoolaegeMay 24, 2007
  51. Johannes SchindelinMay 24, 2007
  52. Sven VerdoolaegeMay 24, 2007
  53. Johannes SchindelinMay 24, 2007
  54. Lars HjemliMay 24, 2007
  55. Junio C HamanoMay 24, 2007
  56. Lars HjemliMay 24, 2007
  57. Sven VerdoolaegeMay 24, 2007
  58. Linus TorvaldsMay 24, 2007
  59. Sven VerdoolaegeMay 24, 2007
  60. Linus TorvaldsMay 24, 2007
  61. Junio C HamanoMay 24, 2007
  62. Lars HjemliMay 24, 2007
  63. Johannes SchindelinMay 24, 2007
  64. Johannes SchindelinMay 24, 2007
  65. Sven VerdoolaegeMay 25, 2007
  66. Junio C HamanoMay 25, 2007
  67. Sven VerdoolaegeMay 25, 2007
  68. Johannes SchindelinMay 25, 2007
  69. Junio C HamanoMay 24, 2007
  70. Josef WeidendorferMay 25, 2007
  71. Johannes SchindelinMay 25, 2007
  72. Josef WeidendorferMay 25, 2007
  73. Johannes SchindelinMay 25, 2007
  74. Sven VerdoolaegeMay 25, 2007
  75. Johannes SchindelinMay 25, 2007
  76. Josef WeidendorferMay 25, 2007
  77. Johannes SchindelinMay 25, 2007
  78. Linus TorvaldsMay 25, 2007
  79. Josef WeidendorferMay 25, 2007
  80. Johannes SchindelinMay 25, 2007
  81. Josef WeidendorferMay 25, 2007
  82. Jakub NarebskiMay 25, 2007
  83. Johannes SchindelinMay 25, 2007
  84. Santi BéjarMay 24, 2007
  85. Sven VerdoolaegeMay 24, 2007
  86. Lars HjemliMay 24, 2007
  87. Martin WaitzMay 27, 2007
  88. Sven VerdoolaegeMay 27, 2007
  89. Martin WaitzMay 24, 2007
  90. Sven VerdoolaegeMay 24, 2007
  91. Johannes SchindelinMay 24, 2007
  92. Sven VerdoolaegeMay 24, 2007
  93. Petr BaudisMay 24, 2007
  94. Johannes SchindelinMay 24, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.