Re-implement 'git remote update' using 'git fetch'

In order not to duplicate functionality, re-implement 'git remote
update' in terms of 'git fetch'.

Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Björn Gustavsson 2009-11-10 09:21:32 +01:00 коммит произвёл Junio C Hamano
Родитель 28a1540132
Коммит 8db355964d
1 изменённых файлов: 28 добавлений и 60 удалений

Просмотреть файл

@ -1173,88 +1173,56 @@ static int prune_remote(const char *remote, int dry_run)
return result; return result;
} }
static int get_one_remote_for_update(struct remote *remote, void *priv) static int get_remote_default(const char *key, const char *value, void *priv)
{ {
struct string_list *list = priv; if (strcmp(key, "remotes.default") == 0) {
if (!remote->skip_default_update) int *found = priv;
string_list_append(remote->name, list); *found = 1;
return 0;
}
static struct remote_group {
const char *name;
struct string_list *list;
} remote_group;
static int get_remote_group(const char *key, const char *value, void *num_hits)
{
if (!prefixcmp(key, "remotes.") &&
!strcmp(key + 8, remote_group.name)) {
/* split list by white space */
int space = strcspn(value, " \t\n");
while (*value) {
if (space > 1) {
string_list_append(xstrndup(value, space),
remote_group.list);
++*((int *)num_hits);
}
value += space + (value[space] != '\0');
space = strcspn(value, " \t\n");
}
} }
return 0; return 0;
} }
static int update(int argc, const char **argv) static int update(int argc, const char **argv)
{ {
int i, result = 0, prune = 0; int i, prune = 0;
struct string_list list = { NULL, 0, 0, 0 };
static const char *default_argv[] = { NULL, "default", NULL };
struct option options[] = { struct option options[] = {
OPT_GROUP("update specific options"), OPT_GROUP("update specific options"),
OPT_BOOLEAN('p', "prune", &prune, OPT_BOOLEAN('p', "prune", &prune,
"prune remotes after fetching"), "prune remotes after fetching"),
OPT_END() OPT_END()
}; };
const char **fetch_argv;
int fetch_argc = 0;
int default_defined = 0;
fetch_argv = xmalloc(sizeof(char *) * (argc+5));
argc = parse_options(argc, argv, NULL, options, builtin_remote_usage, argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
PARSE_OPT_KEEP_ARGV0); PARSE_OPT_KEEP_ARGV0);
fetch_argv[fetch_argc++] = "fetch";
if (prune)
fetch_argv[fetch_argc++] = "--prune";
if (verbose)
fetch_argv[fetch_argc++] = "-v";
if (argc < 2) { if (argc < 2) {
argc = 2; fetch_argv[fetch_argc++] = "default";
argv = default_argv; } else {
fetch_argv[fetch_argc++] = "--multiple";
for (i = 1; i < argc; i++)
fetch_argv[fetch_argc++] = argv[i];
} }
remote_group.list = &list; if (strcmp(fetch_argv[fetch_argc-1], "default") == 0) {
for (i = 1; i < argc; i++) { git_config(get_remote_default, &default_defined);
int groups_found = 0; if (!default_defined)
remote_group.name = argv[i]; fetch_argv[fetch_argc-1] = "--all";
result = git_config(get_remote_group, &groups_found);
if (!groups_found && (i != 1 || strcmp(argv[1], "default"))) {
struct remote *remote;
if (!remote_is_configured(argv[i]))
die("No such remote or remote group: %s",
argv[i]);
remote = remote_get(argv[i]);
string_list_append(remote->name, remote_group.list);
}
} }
if (!result && !list.nr && argc == 2 && !strcmp(argv[1], "default")) fetch_argv[fetch_argc] = NULL;
result = for_each_remote(get_one_remote_for_update, &list);
for (i = 0; i < list.nr; i++) { return run_command_v_opt(fetch_argv, RUN_GIT_CMD);
int err = fetch_remote(list.items[i].string);
result |= err;
if (!err && prune)
result |= prune_remote(list.items[i].string, 0);
}
/* all names were strdup()ed or strndup()ed */
list.strdup_strings = 1;
string_list_clear(&list, 0);
return result;
} }
static int get_one_entry(struct remote *remote, void *priv) static int get_one_entry(struct remote *remote, void *priv)