{"thread":{"id":"21562","subject":"[PATCH 8/8] Re-implement 'git remote update' using 'git fetch'","startedAt":"2009-11-10T08:21:32Z","lastAt":"2009-11-10T08:21:32Z","messageCount":1,"participants":["Björn Gustavsson"],"isPatch":true,"patchVersion":1,"patchTotal":8},"messages":[{"id":"127225","messageId":"4AF9228C.1010005@gmail.com","threadId":"21562","inReplyTo":null,"subject":"[PATCH 8/8] Re-implement 'git remote update' using 'git fetch'","fromName":"Björn Gustavsson","fromEmail":"bgustavsson@gmail.com","sentAt":"2009-11-10T08:21:32Z","receivedAt":"2009-11-10T08:21:32Z","isPatch":true,"sender":{"key":"bgustavsson@gmail.com","avatar":"https://avatars.githubusercontent.com/u/74840?v=4"},"body":"In order not to duplicate functionality, re-implement 'git remote\nupdate' in terms of 'git fetch'.\n\nSigned-off-by: Björn Gustavsson <bgustavsson@gmail.com>\n---\nThe --prune option will be passed on, as 'git fetch' now\nsupports it.\n\n builtin-remote.c |   88 +++++++++++++++++------------------------------------\n 1 files changed, 28 insertions(+), 60 deletions(-)\n\ndiff --git a/builtin-remote.c b/builtin-remote.c\nindex 56cd5af..fb0d66d 100644\n--- a/builtin-remote.c\n+++ b/builtin-remote.c\n@@ -1173,88 +1173,56 @@ static int prune_remote(const char *remote, int dry_run)\n \treturn result;\n }\n \n-static int get_one_remote_for_update(struct remote *remote, void *priv)\n+static int get_remote_default(const char *key, const char *value, void *priv)\n {\n-\tstruct string_list *list = priv;\n-\tif (!remote->skip_default_update)\n-\t\tstring_list_append(remote->name, list);\n-\treturn 0;\n-}\n-\n-static struct remote_group {\n-\tconst char *name;\n-\tstruct string_list *list;\n-} remote_group;\n-\n-static int get_remote_group(const char *key, const char *value, void *num_hits)\n-{\n-\tif (!prefixcmp(key, \"remotes.\") &&\n-\t\t\t!strcmp(key + 8, remote_group.name)) {\n-\t\t/* split list by white space */\n-\t\tint space = strcspn(value, \" \\t\\n\");\n-\t\twhile (*value) {\n-\t\t\tif (space > 1) {\n-\t\t\t\tstring_list_append(xstrndup(value, space),\n-\t\t\t\t\t\tremote_group.list);\n-\t\t\t\t++*((int *)num_hits);\n-\t\t\t}\n-\t\t\tvalue += space + (value[space] != '\\0');\n-\t\t\tspace = strcspn(value, \" \\t\\n\");\n-\t\t}\n+\tif (strcmp(key, \"remotes.default\") == 0) {\n+\t\tint *found = priv;\n+\t\t*found = 1;\n \t}\n-\n \treturn 0;\n }\n \n static int update(int argc, const char **argv)\n {\n-\tint i, result = 0, prune = 0;\n-\tstruct string_list list = { NULL, 0, 0, 0 };\n-\tstatic const char *default_argv[] = { NULL, \"default\", NULL };\n+\tint i, prune = 0;\n \tstruct option options[] = {\n \t\tOPT_GROUP(\"update specific options\"),\n \t\tOPT_BOOLEAN('p', \"prune\", &prune,\n \t\t\t    \"prune remotes after fetching\"),\n \t\tOPT_END()\n \t};\n+\tconst char **fetch_argv;\n+\tint fetch_argc = 0;\n+\tint default_defined = 0;\n+\n+\tfetch_argv = xmalloc(sizeof(char *) * (argc+5));\n \n \targc = parse_options(argc, argv, NULL, options, builtin_remote_usage,\n \t\t\t     PARSE_OPT_KEEP_ARGV0);\n-\tif (argc < 2) {\n-\t\targc = 2;\n-\t\targv = default_argv;\n-\t}\n \n-\tremote_group.list = &list;\n-\tfor (i = 1; i < argc; i++) {\n-\t\tint groups_found = 0;\n-\t\tremote_group.name = argv[i];\n-\t\tresult = git_config(get_remote_group, &groups_found);\n-\t\tif (!groups_found && (i != 1 || strcmp(argv[1], \"default\"))) {\n-\t\t\tstruct remote *remote;\n-\t\t\tif (!remote_is_configured(argv[i]))\n-\t\t\t\tdie(\"No such remote or remote group: %s\",\n-\t\t\t\t    argv[i]);\n-\t\t\tremote = remote_get(argv[i]);\n-\t\t\tstring_list_append(remote->name, remote_group.list);\n-\t\t}\n-\t}\n+\tfetch_argv[fetch_argc++] = \"fetch\";\n \n-\tif (!result && !list.nr  && argc == 2 && !strcmp(argv[1], \"default\"))\n-\t\tresult = for_each_remote(get_one_remote_for_update, &list);\n+\tif (prune)\n+\t\tfetch_argv[fetch_argc++] = \"--prune\";\n+\tif (verbose)\n+\t\tfetch_argv[fetch_argc++] = \"-v\";\n+\tif (argc < 2) {\n+\t\tfetch_argv[fetch_argc++] = \"default\";\n+\t} else {\n+\t\tfetch_argv[fetch_argc++] = \"--multiple\";\n+\t\tfor (i = 1; i < argc; i++)\n+\t\t\tfetch_argv[fetch_argc++] = argv[i];\n+\t}\n \n-\tfor (i = 0; i < list.nr; i++) {\n-\t\tint err = fetch_remote(list.items[i].string);\n-\t\tresult |= err;\n-\t\tif (!err && prune)\n-\t\t\tresult |= prune_remote(list.items[i].string, 0);\n+\tif (strcmp(fetch_argv[fetch_argc-1], \"default\") == 0) {\n+\t\tgit_config(get_remote_default, &default_defined);\n+\t\tif (!default_defined)\n+\t\t\tfetch_argv[fetch_argc-1] = \"--all\";\n \t}\n \n-\t/* all names were strdup()ed or strndup()ed */\n-\tlist.strdup_strings = 1;\n-\tstring_list_clear(&list, 0);\n+\tfetch_argv[fetch_argc] = NULL;\n \n-\treturn result;\n+\treturn run_command_v_opt(fetch_argv, RUN_GIT_CMD);\n }\n \n static int get_one_entry(struct remote *remote, void *priv)\n-- \n1.6.5.1.69.g36942\n"}]}