{"thread":{"id":"21537","subject":"[RFC/PATCH 4/4] Re-implement 'git remote update' using 'git fetch'","startedAt":"2009-11-08T15:48:53Z","lastAt":"2009-11-09T06:37:48Z","messageCount":5,"participants":["Björn Gustavsson","Paolo Bonzini","Jay Soffian"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"127085","messageId":"4AF6E865.1030900@gmail.com","threadId":"21537","inReplyTo":null,"subject":"[RFC/PATCH 4/4] Re-implement 'git remote update' using 'git fetch'","fromName":"Björn Gustavsson","fromEmail":"bgustavsson@gmail.com","sentAt":"2009-11-08T15:48:53Z","receivedAt":"2009-11-08T15:48:53Z","isPatch":true,"sender":{"key":"bgustavsson@gmail.com","avatar":"https://avatars.githubusercontent.com/u/74840?v=4"},"body":"In order to not duplicate functionality, re-implement 'git remote\nupdate' in terms of 'git fetch'.\n\nThere is one incompatibility: the skipDefaultUpdate configuration\nvariable will only be honored if remotes.default is not set (i.e.\nwhen 'git remote update' will invoke 'git fetch --all', not when\nit will invoke 'git fetch default').\n\nSigned-off-by: Björn Gustavsson <bgustavsson@gmail.com>\n---\n builtin-remote.c |   86 ++++++++++++++++-------------------------------------\n 1 files changed, 26 insertions(+), 60 deletions(-)\n\ndiff --git a/builtin-remote.c b/builtin-remote.c\nindex 0777dd7..fd7e0b2 100644\n--- a/builtin-remote.c\n+++ b/builtin-remote.c\n@@ -1189,88 +1189,54 @@ 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+4));\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 (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"},{"id":"127095","messageId":"hd7c4k$aul$3@ger.gmane.org","threadId":"21537","inReplyTo":"4AF6E865.1030900@gmail.com","subject":"Re: [RFC/PATCH 4/4] Re-implement 'git remote update' using 'git fetch'","fromName":"Paolo Bonzini","fromEmail":"bonzini@gnu.org","sentAt":"2009-11-08T21:10:44Z","receivedAt":"2009-11-08T21:10:44Z","isPatch":true,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"On 11/08/2009 04:48 PM, Björn Gustavsson wrote:\n> In order to not duplicate functionality, re-implement 'git remote\n> update' in terms of 'git fetch'.\n>\n> There is one incompatibility: the skipDefaultUpdate configuration\n> variable will only be honored if remotes.default is not set (i.e.\n> when 'git remote update' will invoke 'git fetch --all', not when\n> it will invoke 'git fetch default').\n\nRather than introducing this incompatibility, I'd rather see 'git remote \nupdate' deprecated (so that the code will one day go away for good) and, \nfor now, leave duplicated functionality for the incompatible case.\n\nIt would be great if the deprecation message for \"git remote update\" \nspewed out commands to convert the old configuration to what is needed \nfor \"git fetch --all\" to work in the same way.\n\nPaolo\n"},{"id":"127100","messageId":"6672d0160911081423u41f7faa6md50190b04a71069d@mail.gmail.com","threadId":"21537","inReplyTo":"hd7c4k$aul$3@ger.gmane.org","subject":"Re: [RFC/PATCH 4/4] Re-implement 'git remote update' using 'git fetch'","fromName":"Björn Gustavsson","fromEmail":"bgustavsson@gmail.com","sentAt":"2009-11-08T22:23:18Z","receivedAt":"2009-11-08T22:23:18Z","isPatch":true,"sender":{"key":"bgustavsson@gmail.com","avatar":"https://avatars.githubusercontent.com/u/74840?v=4"},"body":"On Sun, Nov 8, 2009 at 10:10 PM, Paolo Bonzini <bonzini@gnu.org> wrote:\n> On 11/08/2009 04:48 PM, Björn Gustavsson wrote:\n>> There is one incompatibility: the skipDefaultUpdate configuration\n>> variable will only be honored if remotes.default is not set (i.e.\n>> when 'git remote update' will invoke 'git fetch --all', not when\n>> it will invoke 'git fetch default').\n>\n> Rather than introducing this incompatibility, I'd rather see 'git remote\n> update' deprecated (so that the code will one day go away for good) and, for\n> now, leave duplicated functionality for the incompatible case.\n\nI didn't check my facts properly before writing that commit message.\nLooking again at the old code in builtin_remote.c (after a long break), and\nactually testing the behavior, I see that there is no incompatibility.\n\nBoth the old and the new code use skipDefaultUpdate only if remotes.default\nis not set. If remotes.default is set, that list of remotes will be used. Only\nif remotes.default is not set, will 'git remote update' go through the list\nof all remotes and filter away those that have skipDefaultUpdate set to true.\n\nSorry for the confusion. I will correct the commit message in my re-roll\nof the patch.\n\n-- \nBjörn Gustavsson, Erlang/OTP, Ericsson AB\n"},{"id":"127110","messageId":"76718490911081643w46e34858kd82270be0482f8b9@mail.gmail.com","threadId":"21537","inReplyTo":"4AF6E865.1030900@gmail.com","subject":"Re: [RFC/PATCH 4/4] Re-implement 'git remote update' using 'git fetch'","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2009-11-09T00:43:53Z","receivedAt":"2009-11-09T00:43:53Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"2009/11/8 Björn Gustavsson <bgustavsson@gmail.com>:\n> In order to not duplicate functionality, re-implement 'git remote\n> update' in terms of 'git fetch'.\n\nJunio, I guess I'll wait for this to hit pu and then rebase my fetch\n--prune changes on top of it?\n\nj.\n"},{"id":"127121","messageId":"6672d0160911082237p4645b8d3n8f667b8fc7c80732@mail.gmail.com","threadId":"21537","inReplyTo":"76718490911081643w46e34858kd82270be0482f8b9@mail.gmail.com","subject":"Re: [RFC/PATCH 4/4] Re-implement 'git remote update' using 'git fetch'","fromName":"Björn Gustavsson","fromEmail":"bgustavsson@gmail.com","sentAt":"2009-11-09T06:37:48Z","receivedAt":"2009-11-09T06:37:48Z","isPatch":true,"sender":{"key":"bgustavsson@gmail.com","avatar":"https://avatars.githubusercontent.com/u/74840?v=4"},"body":"2009/11/9 Jay Soffian <jaysoffian@gmail.com>:\n> 2009/11/8 Björn Gustavsson <bgustavsson@gmail.com>:\n>> In order to not duplicate functionality, re-implement 'git remote\n>> update' in terms of 'git fetch'.\n>\n> Junio, I guess I'll wait for this to hit pu and then rebase my fetch\n> --prune changes on top of it?\n\nIt has hit pu now.\n\nIf you'll rebase and finish your patch series, I can base my final\npatch in my series on your changes, because that patch will need a\nfetch that supports --prune in order to support 'git remote update --prune'.\n\n-- \nBjörn Gustavsson, Erlang/OTP, Ericsson AB\n"}]}