git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / Atom feed
2924c09c21e50401d66fef2441c120bc282a6ee8 blob 6500 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
 
#include "test-tool.h"
#include "cache.h"
#include "config.h"
#include "string-list.h"
#include "submodule-config.h"
#include "parse-options.h"

/*
 * This program exposes the C API of the configuration mechanism
 * as a set of simple commands in order to facilitate testing.
 *
 * Usage: test-tool config [--submodule=<path>] <cmd> [<args>]
 *
 * If --submodule=<path> is given, <cmd> will operate on the submodule at the
 * given <path>. This option is not valid for the commands: read_early_config,
 * configset_get_value and configset_get_value_multi.
 *
 * Possible cmds are:
 *
 * get_value -> prints the value with highest priority for the entered key
 *
 * get_value_multi -> prints all values for the entered key in increasing order
 *		     of priority
 *
 * get_int -> print integer value for the entered key or die
 *
 * get_bool -> print bool value for the entered key or die
 *
 * get_string -> print string value for the entered key or die
 *
 * configset_get_value -> returns value with the highest priority for the entered key
 * 			from a config_set constructed from files entered as arguments.
 *
 * configset_get_value_multi -> returns value_list for the entered key sorted in
 * 				ascending order of priority from a config_set
 * 				constructed from files entered as arguments.
 *
 * iterate -> iterate over all values using git_config(), and print some
 *            data for each
 *
 * Exit codes:
 *     0:   success
 *     1:   value not found for the given config key
 *     2:   config file path given as argument is inaccessible or doesn't exist
 *
 * Examples:
 *
 * To print the value with highest priority for key "foo.bAr Baz.rock":
 * 	test-tool config get_value "foo.bAr Baz.rock"
 *
 */

static int iterate_cb(const char *var, const char *value, void *data)
{
	static int nr;

	if (nr++)
		putchar('\n');

	printf("key=%s\n", var);
	printf("value=%s\n", value ? value : "(null)");
	printf("origin=%s\n", current_config_origin_type());
	printf("name=%s\n", current_config_name());
	printf("lno=%d\n", current_config_line());
	printf("scope=%s\n", config_scope_name(current_config_scope()));

	return 0;
}

static int early_config_cb(const char *var, const char *value, void *vdata)
{
	const char *key = vdata;

	if (!strcmp(key, var))
		printf("%s\n", value);

	return 0;
}

#define TC_VALUE_NOT_FOUND 1
#define TC_CONFIG_FILE_ERROR 2

static const char *test_config_usage[] = {
	"test-tool config [--submodule=<path>] <cmd> [<args>]",
	NULL
};

int cmd__config(int argc, const char **argv)
{
	int i, val, ret = 0;
	const char *v;
	const struct string_list *strptr;
	struct config_set cs;
	struct repository subrepo, *repo = the_repository;
	const char *subrepo_path = NULL;

	struct option options[] = {
		OPT_STRING(0, "submodule", &subrepo_path, "path",
			   "run <cmd> on the submodule at <path>"),
		OPT_END()
	};

	argc = parse_options(argc, argv, NULL, options, test_config_usage,
			     PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_STOP_AT_NON_OPTION);
	if (argc < 2)
		die("Please, provide a command name on the command-line");

	if (argc == 3 && !strcmp(argv[1], "read_early_config")) {
		if (subrepo_path)
			die("cannot use --submodule with read_early_config");
		read_early_config(early_config_cb, (void *)argv[2]);
		return ret;
	}

	setup_git_directory();

	git_configset_init(&cs);

	if (subrepo_path) {
		const struct submodule *sub;

		sub = submodule_from_path(the_repository, &null_oid, subrepo_path);
		if (!sub || repo_submodule_init(&subrepo, the_repository, sub))
			die("invalid argument to --submodule: '%s'", subrepo_path);

		repo = &subrepo;
	}

	if (argc == 3 && !strcmp(argv[1], "get_value")) {
		if (!repo_config_get_value(repo, argv[2], &v)) {
			if (!v)
				printf("(NULL)\n");
			else
				printf("%s\n", v);
		} else {
			printf("Value not found for \"%s\"\n", argv[2]);
			ret = TC_VALUE_NOT_FOUND;
		}
	} else if (argc == 3 && !strcmp(argv[1], "get_value_multi")) {
		strptr = repo_config_get_value_multi(repo, argv[2]);
		if (strptr) {
			for (i = 0; i < strptr->nr; i++) {
				v = strptr->items[i].string;
				if (!v)
					printf("(NULL)\n");
				else
					printf("%s\n", v);
			}
		} else {
			printf("Value not found for \"%s\"\n", argv[2]);
			ret = TC_VALUE_NOT_FOUND;
		}
	} else if (argc == 3 && !strcmp(argv[1], "get_int")) {
		if (!repo_config_get_int(repo, argv[2], &val)) {
			printf("%d\n", val);
		} else {
			printf("Value not found for \"%s\"\n", argv[2]);
			ret = TC_VALUE_NOT_FOUND;
		}
	} else if (argc == 3 && !strcmp(argv[1], "get_bool")) {
		if (!repo_config_get_bool(repo, argv[2], &val)) {
			printf("%d\n", val);
		} else {

			printf("Value not found for \"%s\"\n", argv[2]);
			ret = TC_VALUE_NOT_FOUND;
		}
	} else if (argc == 3 && !strcmp(argv[1], "get_string")) {
		if (!repo_config_get_string_tmp(repo, argv[2], &v)) {
			printf("%s\n", v);
		} else {
			printf("Value not found for \"%s\"\n", argv[2]);
			ret = TC_VALUE_NOT_FOUND;
		}
	} else if (argc >= 3 && !strcmp(argv[1], "configset_get_value")) {
		if (subrepo_path)
			die("cannot use --submodule with configset_get_value");

		for (i = 3; i < argc; i++) {
			int err;
			if ((err = git_configset_add_file(&cs, argv[i]))) {
				fprintf(stderr, "Error (%d) reading configuration file %s.\n", err, argv[i]);
				ret = TC_CONFIG_FILE_ERROR;
				goto out;
			}
		}
		if (!git_configset_get_value(&cs, argv[2], &v)) {
			if (!v)
				printf("(NULL)\n");
			else
				printf("%s\n", v);
		} else {
			printf("Value not found for \"%s\"\n", argv[2]);
			ret = TC_VALUE_NOT_FOUND;
		}
	} else if (argc >= 3 && !strcmp(argv[1], "configset_get_value_multi")) {
		if (subrepo_path)
			die("cannot use --submodule with configset_get_value_multi");

		for (i = 3; i < argc; i++) {
			int err;
			if ((err = git_configset_add_file(&cs, argv[i]))) {
				fprintf(stderr, "Error (%d) reading configuration file %s.\n", err, argv[i]);
				ret = TC_CONFIG_FILE_ERROR;
				goto out;
			}
		}
		strptr = git_configset_get_value_multi(&cs, argv[2]);
		if (strptr) {
			for (i = 0; i < strptr->nr; i++) {
				v = strptr->items[i].string;
				if (!v)
					printf("(NULL)\n");
				else
					printf("%s\n", v);
			}
		} else {
			printf("Value not found for \"%s\"\n", argv[2]);
			ret = TC_VALUE_NOT_FOUND;
		}
	} else if (!strcmp(argv[1], "iterate")) {
		repo_config(repo, iterate_cb, NULL);
	} else {
		die("%s: Please check the syntax and the function name", argv[0]);
	}

out:
	git_configset_clear(&cs);
	if (repo != the_repository)
		repo_clear(repo);
	return ret;
}
debug log:

solving 2924c09c21 ...
found 2924c09c21 in https://public-inbox.org/git/3e02e1bd248438e0b435a19d857432edcaa15a2c.1599026986.git.matheus.bernardino@usp.br/
found 8fe43e9775 in https://public-inbox.org/git/56535b0e36e94dc73aa570f4f3c0466305c6432f.1599026986.git.matheus.bernardino@usp.br/
found 26d9c2ac4c in https://80x24.org/mirrors/git.git
preparing index
index prepared:
100644 26d9c2ac4cc6ed05c31eabf43b3b5d8ffaa17ed9	t/helper/test-config.c

applying [1/2] https://public-inbox.org/git/56535b0e36e94dc73aa570f4f3c0466305c6432f.1599026986.git.matheus.bernardino@usp.br/
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index 26d9c2ac4c..8fe43e9775 100644


applying [2/2] https://public-inbox.org/git/3e02e1bd248438e0b435a19d857432edcaa15a2c.1599026986.git.matheus.bernardino@usp.br/
diff --git a/t/helper/test-config.c b/t/helper/test-config.c
index 8fe43e9775..2924c09c21 100644

Checking patch t/helper/test-config.c...
Applied patch t/helper/test-config.c cleanly.
Checking patch t/helper/test-config.c...
Applied patch t/helper/test-config.c cleanly.

index at:
100644 2924c09c21e50401d66fef2441c120bc282a6ee8	t/helper/test-config.c

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git