{"thread":{"id":"4008","subject":"[PATCH] builtin-push: resurrect parsing of Push: lines","startedAt":"2006-04-30T12:05:55Z","lastAt":"2006-04-30T23:32:10Z","messageCount":4,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"19282","messageId":"Pine.LNX.4.63.0604301405150.2026@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4008","inReplyTo":null,"subject":"[PATCH] builtin-push: resurrect parsing of Push: lines","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-04-30T12:05:55Z","receivedAt":"2006-04-30T12:05:55Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThe C'ification of push left these behind.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n builtin-push.c |   26 +++++++++++++++++++++-----\n 1 files changed, 21 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin-push.c b/builtin-push.c\nindex a0c1caa..4e659f0 100644\n--- a/builtin-push.c\n+++ b/builtin-push.c\n@@ -68,6 +68,10 @@ static void set_refspecs(const char **re\n \texpand_refspecs();\n }\n \n+#define MAX_REFSPECS 10\n+static int current_refspec = 0;\n+static char *refspecs_[MAX_REFSPECS];\n+\n static int get_remotes_uri(const char *repo, const char *uri[MAX_URI])\n {\n \tint n = 0;\n@@ -76,11 +80,17 @@ static int get_remotes_uri(const char *r\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 (strncmp(\"URL: \", buffer, 5))\n+\t\tif (!strncmp(\"URL: \", buffer, 5)) {\n+\t\t\tis_refspec = 0;\n+\t\t\ts = buffer + 5;\n+\t\t} else if (!strncmp(\"Push: \", buffer, 6)) {\n+\t\t\tis_refspec = 1;\n+\t\t\ts = buffer + 6;\n+\t\t} else\n \t\t\tcontinue;\n-\t\ts = buffer + 5;\n \n \t\t/* Remove whitespace at the head.. */\n \t\twhile (isspace(*s))\n@@ -93,9 +103,10 @@ static int get_remotes_uri(const char *r\n \t\twhile (isspace(p[-1]))\n \t\t\t*--p = 0;\n \n-\t\turi[n++] = strdup(s);\n-\t\tif (n == MAX_URI)\n-\t\t\tbreak;\n+\t\tif (!is_refspec && n < MAX_URI)\n+\t\t\turi[n++] = strdup(s);\n+\t\telse if (is_refspec && current_refspec < MAX_REFSPECS)\n+\t\t\trefspecs_[current_refspec++] = strdup(s);\n \t}\n \tfclose(f);\n \tif (!n)\n@@ -140,6 +151,8 @@ static int get_uri(const char *repo, con\n \tint n;\n \n \tif (*repo != '/') {\n+\t\tcurrent_refspec = 0;\n+\n \t\tn = get_remotes_uri(repo, uri);\n \t\tif (n > 0)\n \t\t\treturn n;\n@@ -165,6 +178,9 @@ static int do_push(const char *repo)\n \tif (n <= 0)\n \t\tdie(\"bad repository '%s'\", repo);\n \n+\tif (refspec_nr == 0)\n+\t\tset_refspecs((const char**)refspecs_, current_refspec);\n+\n \targv = xmalloc((refspec_nr + 10) * sizeof(char *));\n \targv[0] = \"dummy-send-pack\";\n \targc = 1;\n"},{"id":"19308","messageId":"7viroqyb69.fsf@assigned-by-dhcp.cox.net","threadId":"4008","inReplyTo":"Pine.LNX.4.63.0604301405150.2026@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] builtin-push: resurrect parsing of Push: lines","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-04-30T22:02:22Z","receivedAt":"2006-04-30T22:02:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> The C'ification of push left these behind.\n\n> +#define MAX_REFSPECS 10\n> +static int current_refspec = 0;\n> +static char *refspecs_[MAX_REFSPECS];\n\nWhile this fix makes perfect sense, I think MAX_URI set to 16 is\nreasonable hard limit, but I am not happy about giving hard\nlimit to MAX_REFSPECS -- that's a regression from the shell\nscript one.\n"},{"id":"19310","messageId":"7vvesqwtza.fsf@assigned-by-dhcp.cox.net","threadId":"4008","inReplyTo":"7viroqyb69.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] builtin-push: resurrect parsing of Push: lines","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-04-30T22:59:05Z","receivedAt":"2006-04-30T22:59:05Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n>\n>> The C'ification of push left these behind.\n>\n>> +#define MAX_REFSPECS 10\n>> +static int current_refspec = 0;\n>> +static char *refspecs_[MAX_REFSPECS];\n>\n> While this fix makes perfect sense, I think MAX_URI set to 16 is\n> reasonable hard limit, but I am not happy about giving hard\n> limit to MAX_REFSPECS -- that's a regression from the shell\n> script one.\n\nSo how about this as a replacement?\n\n - You are going to discard refspecs_[] if there were any\n   command line stuff anyway, so do not even bother storing them\n   in a separate array.  Just do add_refspec() on them if you\n   are going to use it after you are done.\n\n - The function get_uri() is not about URI anymore, so rename it\n   appropriately.\n\n - Fix the double call to get_uri() Sean noticed.\n\n-- >8 --\ndiff --git a/builtin-push.c b/builtin-push.c\nindex 4e659f0..9a861b5 100644\n--- a/builtin-push.c\n+++ b/builtin-push.c\n@@ -68,14 +68,11 @@ static void set_refspecs(const char **re\n \texpand_refspecs();\n }\n \n-#define MAX_REFSPECS 10\n-static int current_refspec = 0;\n-static char *refspecs_[MAX_REFSPECS];\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;\n \n \tif (!f)\n \t\treturn -1;\n@@ -103,10 +100,14 @@ static int get_remotes_uri(const char *r\n \t\twhile (isspace(p[-1]))\n \t\t\t*--p = 0;\n \n-\t\tif (!is_refspec && n < MAX_URI)\n-\t\t\turi[n++] = strdup(s);\n-\t\telse if (is_refspec && current_refspec < MAX_REFSPECS)\n-\t\t\trefspecs_[current_refspec++] = strdup(s);\n+\t\tif (!is_refspec) {\n+\t\t\tif (n < MAX_URI)\n+\t\t\t\turi[n++] = strdup(s);\n+\t\t\telse\n+\t\t\t\terror(\"more than %d URL's specified, ignoreing the rest\", MAX_URI);\n+\t\t}\n+\t\telse if (is_refspec && !has_explicit_refspec)\n+\t\t\tadd_refspec(strdup(s));\n \t}\n \tfclose(f);\n \tif (!n)\n@@ -146,13 +147,17 @@ static int get_branches_uri(const char *\n \treturn 1;\n }\n \n-static int get_uri(const char *repo, const char *uri[MAX_URI])\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\tcurrent_refspec = 0;\n-\n \t\tn = get_remotes_uri(repo, uri);\n \t\tif (n > 0)\n \t\t\treturn n;\n@@ -169,18 +174,15 @@ static int get_uri(const char *repo, con\n static int do_push(const char *repo)\n {\n \tconst char *uri[MAX_URI];\n-\tint i, n = get_uri(repo, uri);\n+\tint i, n;\n \tint remote;\n \tconst char **argv;\n \tint argc;\n \n-\tn = get_uri(repo, uri);\n+\tn = read_config(repo, uri);\n \tif (n <= 0)\n \t\tdie(\"bad repository '%s'\", repo);\n \n-\tif (refspec_nr == 0)\n-\t\tset_refspecs((const char**)refspecs_, current_refspec);\n-\n \targv = xmalloc((refspec_nr + 10) * sizeof(char *));\n \targv[0] = \"dummy-send-pack\";\n \targc = 1;\n"},{"id":"19312","messageId":"Pine.LNX.4.63.0605010131420.9704@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4008","inReplyTo":"7vvesqwtza.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] builtin-push: resurrect parsing of Push: lines","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-04-30T23:32:10Z","receivedAt":"2006-04-30T23:32:10Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 30 Apr 2006, Junio C Hamano wrote:\n\n> So how about this as a replacement?\n\nLooks good. Will try tomorrow.\n\nCiao,\nDscho\n"}]}