{"thread":{"id":"7885","subject":"[PATCH 3/5] Use remote functions in git-push","startedAt":"2007-04-28T17:05:14Z","lastAt":"2007-04-29T05:45:39Z","messageCount":2,"participants":["Daniel Barkalow","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"40662","messageId":"Pine.LNX.4.64.0704281304190.28708@iabervon.org","threadId":"7885","inReplyTo":null,"subject":"[PATCH 3/5] Use remote functions in git-push","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2007-04-28T17:05:14Z","receivedAt":"2007-04-28T17:05:14Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"Replace the local parsing implementation with the library\nimplementation. Note that this incidentally makes the config file\noverride remotes files.\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n builtin-push.c |  188 ++++++--------------------------------------------------\n 1 files changed, 20 insertions(+), 168 deletions(-)\n\ndiff --git a/builtin-push.c b/builtin-push.c\nindex cb78401..2e944cd 100644\n--- a/builtin-push.c\n+++ b/builtin-push.c\n@@ -5,6 +5,7 @@\n #include \"refs.h\"\n #include \"run-command.h\"\n #include \"builtin.h\"\n+#include \"remote.h\"\n \n #define MAX_URI (16)\n \n@@ -13,9 +14,6 @@ static const char push_usage[] = \"git-push [--all] [--tags] [--receive-pack=<git\n static int all, tags, force, thin = 1, verbose;\n static const char *receivepack;\n \n-#define BUF_SIZE (2084)\n-static char buffer[BUF_SIZE];\n-\n static const char **refspec;\n static int refspec_nr;\n \n@@ -137,175 +135,29 @@ static void set_refspecs(const char **refs, int nr)\n \texpand_refspecs();\n }\n \n-static int get_remotes_uri(const char *repo, const char *uri[MAX_URI])\n-{\n-\tint n = 0;\n-\tFILE *f = fopen(git_path(\"remotes/%s\", repo), \"r\");\n-\tint has_explicit_refspec = refspec_nr || all || tags;\n-\n-\tif (!f)\n-\t\treturn -1;\n-\twhile (fgets(buffer, BUF_SIZE, f)) {\n-\t\tint is_refspec;\n-\t\tchar *s, *p;\n-\n-\t\tif (!prefixcmp(buffer, \"URL:\")) {\n-\t\t\tis_refspec = 0;\n-\t\t\ts = buffer + 4;\n-\t\t} else if (!prefixcmp(buffer, \"Push:\")) {\n-\t\t\tis_refspec = 1;\n-\t\t\ts = buffer + 5;\n-\t\t} else\n-\t\t\tcontinue;\n-\n-\t\t/* Remove whitespace at the head.. */\n-\t\twhile (isspace(*s))\n-\t\t\ts++;\n-\t\tif (!*s)\n-\t\t\tcontinue;\n-\n-\t\t/* ..and at the end */\n-\t\tp = s + strlen(s);\n-\t\twhile (isspace(p[-1]))\n-\t\t\t*--p = 0;\n-\n-\t\tif (!is_refspec) {\n-\t\t\tif (n < MAX_URI)\n-\t\t\t\turi[n++] = xstrdup(s);\n-\t\t\telse\n-\t\t\t\terror(\"more than %d URL's specified, ignoring the rest\", MAX_URI);\n-\t\t}\n-\t\telse if (is_refspec && !has_explicit_refspec) {\n-\t\t\tif (!wildcard_ref(s))\n-\t\t\t\tadd_refspec(xstrdup(s));\n-\t\t}\n-\t}\n-\tfclose(f);\n-\tif (!n)\n-\t\tdie(\"remote '%s' has no URL\", repo);\n-\treturn n;\n-}\n-\n-static const char **config_uri;\n-static const char *config_repo;\n-static int config_repo_len;\n-static int config_current_uri;\n-static int config_get_refspecs;\n-static int config_get_receivepack;\n-\n-static int get_remote_config(const char* key, const char* value)\n-{\n-\tif (!prefixcmp(key, \"remote.\") &&\n-\t    !strncmp(key + 7, config_repo, config_repo_len)) {\n-\t\tif (!strcmp(key + 7 + config_repo_len, \".url\")) {\n-\t\t\tif (config_current_uri < MAX_URI)\n-\t\t\t\tconfig_uri[config_current_uri++] = xstrdup(value);\n-\t\t\telse\n-\t\t\t\terror(\"more than %d URL's specified, ignoring the rest\", MAX_URI);\n-\t\t}\n-\t\telse if (config_get_refspecs &&\n-\t\t\t !strcmp(key + 7 + config_repo_len, \".push\")) {\n-\t\t\tif (!wildcard_ref(value))\n-\t\t\t\tadd_refspec(xstrdup(value));\n-\t\t}\n-\t\telse if (config_get_receivepack &&\n-\t\t\t !strcmp(key + 7 + config_repo_len, \".receivepack\")) {\n-\t\t\tif (!receivepack) {\n-\t\t\t\tchar *rp = xmalloc(strlen(value) + 16);\n-\t\t\t\tsprintf(rp, \"--receive-pack=%s\", value);\n-\t\t\t\treceivepack = rp;\n-\t\t\t} else\n-\t\t\t\terror(\"more than one receivepack given, using the first\");\n-\t\t}\n-\t}\n-\treturn 0;\n-}\n-\n-static int get_config_remotes_uri(const char *repo, const char *uri[MAX_URI])\n-{\n-\tconfig_repo_len = strlen(repo);\n-\tconfig_repo = repo;\n-\tconfig_current_uri = 0;\n-\tconfig_uri = uri;\n-\tconfig_get_refspecs = !(refspec_nr || all || tags);\n-\tconfig_get_receivepack = (receivepack == NULL);\n-\n-\tgit_config(get_remote_config);\n-\treturn config_current_uri;\n-}\n-\n-static int get_branches_uri(const char *repo, const char *uri[MAX_URI])\n-{\n-\tconst char *slash = strchr(repo, '/');\n-\tint n = slash ? slash - repo : 1000;\n-\tFILE *f = fopen(git_path(\"branches/%.*s\", n, repo), \"r\");\n-\tchar *s, *p;\n-\tint len;\n-\n-\tif (!f)\n-\t\treturn 0;\n-\ts = fgets(buffer, BUF_SIZE, f);\n-\tfclose(f);\n-\tif (!s)\n-\t\treturn 0;\n-\twhile (isspace(*s))\n-\t\ts++;\n-\tif (!*s)\n-\t\treturn 0;\n-\tp = s + strlen(s);\n-\twhile (isspace(p[-1]))\n-\t\t*--p = 0;\n-\tlen = p - s;\n-\tif (slash)\n-\t\tlen += strlen(slash);\n-\tp = xmalloc(len + 1);\n-\tstrcpy(p, s);\n-\tif (slash)\n-\t\tstrcat(p, slash);\n-\turi[0] = p;\n-\treturn 1;\n-}\n-\n-/*\n- * Read remotes and branches file, fill the push target URI\n- * list.  If there is no command line refspecs, read Push: lines\n- * to set up the *refspec list as well.\n- * return the number of push target URIs\n- */\n-static int read_config(const char *repo, const char *uri[MAX_URI])\n-{\n-\tint n;\n-\n-\tif (*repo != '/') {\n-\t\tn = get_remotes_uri(repo, uri);\n-\t\tif (n > 0)\n-\t\t\treturn n;\n-\n-\t\tn = get_config_remotes_uri(repo, uri);\n-\t\tif (n > 0)\n-\t\t\treturn n;\n-\n-\t\tn = get_branches_uri(repo, uri);\n-\t\tif (n > 0)\n-\t\t\treturn n;\n-\t}\n-\n-\turi[0] = repo;\n-\treturn 1;\n-}\n-\n static int do_push(const char *repo)\n {\n-\tconst char *uri[MAX_URI];\n-\tint i, n, errs;\n+\tint i, errs;\n \tint common_argc;\n \tconst char **argv;\n \tint argc;\n+\tstruct remote *remote;\n+\n+\tremote = remote_get(repo);\n \n-\tn = read_config(repo, uri);\n-\tif (n <= 0)\n+\tif (!remote)\n \t\tdie(\"bad repository '%s'\", repo);\n \n+\tif (remote->receivepack) {\n+\t\tchar *rp = xmalloc(strlen(remote->receivepack) + 16);\n+\t\tsprintf(rp, \"--receive-pack=%s\", remote->receivepack);\n+\t\treceivepack = rp;\n+\t}\n+\tif (!refspec && !all && !tags && remote->push_refspec_nr) {\n+\t\trefspec_nr = remote->push_refspec_nr;\n+\t\trefspec = remote->push_refspec;\n+\t}\n+\n \targv = xmalloc((refspec_nr + 10) * sizeof(char *));\n \targv[0] = \"dummy-send-pack\";\n \targc = 1;\n@@ -318,12 +170,12 @@ static int do_push(const char *repo)\n \tcommon_argc = argc;\n \n \terrs = 0;\n-\tfor (i = 0; i < n; i++) {\n+\tfor (i = 0; remote->uri[i]; i++) {\n \t\tint err;\n \t\tint dest_argc = common_argc;\n \t\tint dest_refspec_nr = refspec_nr;\n \t\tconst char **dest_refspec = refspec;\n-\t\tconst char *dest = uri[i];\n+\t\tconst char *dest = remote->uri[i];\n \t\tconst char *sender = \"send-pack\";\n \t\tif (!prefixcmp(dest, \"http://\") ||\n \t\t    !prefixcmp(dest, \"https://\"))\n@@ -341,7 +193,7 @@ static int do_push(const char *repo)\n \t\tif (!err)\n \t\t\tcontinue;\n \n-\t\terror(\"failed to push to '%s'\", uri[i]);\n+\t\terror(\"failed to push to '%s'\", remote->uri[i]);\n \t\tswitch (err) {\n \t\tcase -ERR_RUN_COMMAND_FORK:\n \t\t\terror(\"unable to fork for %s\", sender);\n@@ -362,7 +214,7 @@ static int do_push(const char *repo)\n int cmd_push(int argc, const char **argv, const char *prefix)\n {\n \tint i;\n-\tconst char *repo = \"origin\";\t/* default repository */\n+\tconst char *repo = NULL;\t/* default repository */\n \n \tfor (i = 1; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n-- \n1.5.1.2.255.g6ead4-dirty\n"},{"id":"40687","messageId":"7vzm4rg2d8.fsf@assigned-by-dhcp.cox.net","threadId":"7885","inReplyTo":"Pine.LNX.4.64.0704281304190.28708@iabervon.org","subject":"Re: [PATCH 3/5] Use remote functions in git-push","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-04-29T05:45:39Z","receivedAt":"2007-04-29T05:45:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Daniel Barkalow <barkalow@iabervon.org> writes:\n\n> diff --git a/builtin-push.c b/builtin-push.c\n> index cb78401..2e944cd 100644\n> --- a/builtin-push.c\n> +++ b/builtin-push.c\n> @@ -5,6 +5,7 @@\n>  #include \"refs.h\"\n>  #include \"run-command.h\"\n>  #include \"builtin.h\"\n> +#include \"remote.h\"\n\nAs I am rejecting the initial round of [PATCH 2/5], I only gave\na cursory look at this one, but it seems straightforward code\nshuffling and nothing controversial.\n\nI however would have liked a patch that moves bulk of remote\nparsing code from builtin-push.c to remote.c without adding\nanything that builtin-push.c did not have (i.e. fetch refspecs\nhandling).  That is, half of [PATCH 2/5] and this patch should\nhave been a single patch that says \"this moves code from\nbuiltin-push.c to remote.c, while abstracting out the static\nvariables into struct remote, without doing anything else\".\n\nThen later you enhance the remote.c interface to deal with fetch\nrefspecs and stuff in separate patches.\n\n>  \n>  #define MAX_URI (16)\n\nI do not think you need this anymore...\n"}]}