{"thread":{"id":"11127","subject":"[PATCH] Use a strbuf for copying the command line for the reflog.","startedAt":"2007-12-04T07:25:46Z","lastAt":"2007-12-04T15:46:16Z","messageCount":3,"participants":["Kristian Høgsberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"61872","messageId":"1196753147-20073-1-git-send-email-krh@redhat.com","threadId":"11127","inReplyTo":null,"subject":"[PATCH] Use a strbuf for copying the command line for the reflog.","fromName":"Kristian Høgsberg","fromEmail":"krh@redhat.com","sentAt":"2007-12-04T07:25:46Z","receivedAt":"2007-12-04T07:25:46Z","isPatch":true,"sender":{"key":"krh@redhat.com","avatar":"https://gravatar.com/avatar/763dee6f9594ac474f725b137a39565792928e583ddf59b32befc2907409027e?d=mp&s=160"},"body":"Signed-off-by: Kristian Høgsberg <krh@redhat.com>\n---\n builtin-fetch.c |   24 ++++++++----------------\n 1 files changed, 8 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin-fetch.c b/builtin-fetch.c\nindex de9947e..f6d16fe 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -14,7 +14,7 @@ static const char fetch_usage[] = \"git-fetch [-a | --append] [--upload-pack <upl\n \n static int append, force, tags, no_tags, update_head_ok, verbose, quiet;\n static const char *depth;\n-static char *default_rla = NULL;\n+static struct strbuf default_rla = STRBUF_INIT;\n static struct transport *transport;\n \n static void unlock_pack(void)\n@@ -142,7 +142,7 @@ static int s_update_ref(const char *action,\n \tstatic struct ref_lock *lock;\n \n \tif (!rla)\n-\t\trla = default_rla;\n+\t\trla = default_rla.buf;\n \tsnprintf(msg, sizeof(msg), \"%s: %s\", rla, action);\n \tlock = lock_any_ref_for_update(ref->name,\n \t\t\t\t       check_old ? ref->old_sha1 : NULL, 0);\n@@ -543,16 +543,19 @@ static void set_option(const char *name, const char *value)\n int cmd_fetch(int argc, const char **argv, const char *prefix)\n {\n \tstruct remote *remote;\n-\tint i, j, rla_offset;\n+\tint i;\n \tstatic const char **refs = NULL;\n \tint ref_nr = 0;\n-\tint cmd_len = 0;\n \tconst char *upload_pack = NULL;\n \tint keep = 0;\n \n+\t/* Record the command line for the reflog */\n+\tstrbuf_addstr(&default_rla, \"fetch\");\n+\tfor (i = 1; i < argc; i++)\n+\t\tstrbuf_addf(&default_rla, \" %s\", argv[i]);\n+\n \tfor (i = 1; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n-\t\tcmd_len += strlen(arg);\n \n \t\tif (arg[0] != '-')\n \t\t\tbreak;\n@@ -613,17 +616,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n \t\tusage(fetch_usage);\n \t}\n \n-\tfor (j = i; j < argc; j++)\n-\t\tcmd_len += strlen(argv[j]);\n-\n-\tdefault_rla = xmalloc(cmd_len + 5 + argc + 1);\n-\tsprintf(default_rla, \"fetch\");\n-\trla_offset = strlen(default_rla);\n-\tfor (j = 1; j < argc; j++) {\n-\t\tsprintf(default_rla + rla_offset, \" %s\", argv[j]);\n-\t\trla_offset += strlen(argv[j]) + 1;\n-\t}\n-\n \tif (i == argc)\n \t\tremote = remote_get(NULL);\n \telse\n-- \n1.5.3.4\n"},{"id":"61873","messageId":"1196753147-20073-2-git-send-email-krh@redhat.com","threadId":"11127","inReplyTo":"1196753147-20073-1-git-send-email-krh@redhat.com","subject":"[PATCH] Rewrite builtin-fetch option parsing to use parse_options().","fromName":"Kristian Høgsberg","fromEmail":"krh@redhat.com","sentAt":"2007-12-04T07:25:47Z","receivedAt":"2007-12-04T07:25:47Z","isPatch":true,"sender":{"key":"krh@redhat.com","avatar":"https://gravatar.com/avatar/763dee6f9594ac474f725b137a39565792928e583ddf59b32befc2907409027e?d=mp&s=160"},"body":"This gets a little tricky because of the way --tags and --no-tags\nare handled, and the \"tag <name>\" syntax needs a little hand-holding too.\n\nSigned-off-by: Kristian Høgsberg <krh@redhat.com>\n---\n builtin-fetch.c |  123 ++++++++++++++++++++----------------------------------\n 1 files changed, 46 insertions(+), 77 deletions(-)\n\ndiff --git a/builtin-fetch.c b/builtin-fetch.c\nindex f6d16fe..320e235 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -9,14 +9,45 @@\n #include \"remote.h\"\n #include \"transport.h\"\n #include \"run-command.h\"\n+#include \"parse-options.h\"\n \n-static const char fetch_usage[] = \"git-fetch [-a | --append] [--upload-pack <upload-pack>] [-f | --force] [--no-tags] [-t | --tags] [-k | --keep] [-u | --update-head-ok] [--depth <depth>] [-v | --verbose] [<repository> <refspec>...]\";\n+static const char * const builtin_fetch_usage[] = {\n+\t\"git-fetch [options] [<repository> <refspec>...]\",\n+\tNULL\n+};\n \n-static int append, force, tags, no_tags, update_head_ok, verbose, quiet;\n+enum {\n+\tTAGS_UNSET = 0,\n+\tTAGS_DEFAULT = 1,\n+\tTAGS_SET = 2\n+};\n+\n+static int append, force, keep, update_head_ok, verbose, quiet;\n+static int tags = TAGS_DEFAULT;\n static const char *depth;\n+static const char *upload_pack;\n static struct strbuf default_rla = STRBUF_INIT;\n static struct transport *transport;\n \n+static struct option builtin_fetch_options[] = {\n+\tOPT__QUIET(&quiet),\n+\tOPT__VERBOSE(&verbose),\n+\tOPT_BOOLEAN('a', \"append\", &append,\n+\t\t    \"append to .git/FETCH_HEAD instead of overwriting\"),\n+\tOPT_STRING(0, \"upload-pack\", &upload_pack, \"PATH\",\n+\t\t   \"path to upload pack on remote end\"),\n+\tOPT_BOOLEAN('f', \"force\", &force,\n+\t\t    \"force overwrite of local branch\"),\n+\tOPT_SET_INT('t', \"tags\", &tags,\n+\t\t    \"fetch all tags and associated objects\", TAGS_SET),\n+\tOPT_BOOLEAN('k', \"keep\", &keep, \"keep downloaded pack\"),\n+\tOPT_BOOLEAN('u', \"update-head-ok\", &update_head_ok,\n+\t\t    \"allow updating of HEAD ref\"),\n+\tOPT_STRING(0, \"depth\", &depth, \"DEPTH\",\n+\t\t   \"deepen history of shallow clone\"),\n+\tOPT_END()\n+};\n+\n static void unlock_pack(void)\n {\n \tif (transport)\n@@ -81,7 +112,7 @@ static struct ref *get_ref_map(struct transport *transport,\n \n \tconst struct ref *remote_refs = transport_get_remote_refs(transport);\n \n-\tif (ref_count || tags) {\n+\tif (ref_count || tags == TAGS_SET) {\n \t\tfor (i = 0; i < ref_count; i++) {\n \t\t\tget_fetch_map(remote_refs, &refs[i], &tail, 0);\n \t\t\tif (refs[i].dst && refs[i].dst[0])\n@@ -90,7 +121,7 @@ static struct ref *get_ref_map(struct transport *transport,\n \t\t/* Merge everything on the command line, but not --tags */\n \t\tfor (rm = ref_map; rm; rm = rm->next)\n \t\t\trm->merge = 1;\n-\t\tif (tags) {\n+\t\tif (tags == TAGS_SET) {\n \t\t\tstruct refspec refspec;\n \t\t\trefspec.src = \"refs/tags/\";\n \t\t\trefspec.dst = \"refs/tags/\";\n@@ -482,10 +513,10 @@ static int do_fetch(struct transport *transport,\n \tstruct ref *ref_map, *fetch_map;\n \tstruct ref *rm;\n \tint autotags = (transport->remote->fetch_tags == 1);\n-\tif (transport->remote->fetch_tags == 2 && !no_tags)\n-\t\ttags = 1;\n+\tif (transport->remote->fetch_tags == 2 && tags != TAGS_UNSET)\n+\t\ttags = TAGS_SET;\n \tif (transport->remote->fetch_tags == -1)\n-\t\tno_tags = 1;\n+\t\ttags = TAGS_UNSET;\n \n \tif (!transport->get_refs_list || !transport->fetch)\n \t\tdie(\"Don't know how to fetch from %s\", transport->url);\n@@ -515,7 +546,7 @@ static int do_fetch(struct transport *transport,\n \n \t/* if neither --no-tags nor --tags was specified, do automated tag\n \t * following ... */\n-\tif (!(tags || no_tags) && autotags) {\n+\tif (tags == TAGS_DEFAULT && autotags) {\n \t\tref_map = find_non_local_tags(transport, fetch_map);\n \t\tif (ref_map) {\n \t\t\ttransport_set_option(transport, TRANS_OPT_DEPTH, \"0\");\n@@ -546,80 +577,19 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n \tint i;\n \tstatic const char **refs = NULL;\n \tint ref_nr = 0;\n-\tconst char *upload_pack = NULL;\n-\tint keep = 0;\n \n \t/* Record the command line for the reflog */\n \tstrbuf_addstr(&default_rla, \"fetch\");\n \tfor (i = 1; i < argc; i++)\n \t\tstrbuf_addf(&default_rla, \" %s\", argv[i]);\n \n-\tfor (i = 1; i < argc; i++) {\n-\t\tconst char *arg = argv[i];\n-\n-\t\tif (arg[0] != '-')\n-\t\t\tbreak;\n-\t\tif (!strcmp(arg, \"--append\") || !strcmp(arg, \"-a\")) {\n-\t\t\tappend = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!prefixcmp(arg, \"--upload-pack=\")) {\n-\t\t\tupload_pack = arg + 14;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--upload-pack\")) {\n-\t\t\ti++;\n-\t\t\tif (i == argc)\n-\t\t\t\tusage(fetch_usage);\n-\t\t\tupload_pack = argv[i];\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--force\") || !strcmp(arg, \"-f\")) {\n-\t\t\tforce = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--no-tags\")) {\n-\t\t\tno_tags = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--tags\") || !strcmp(arg, \"-t\")) {\n-\t\t\ttags = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--keep\") || !strcmp(arg, \"-k\")) {\n-\t\t\tkeep = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--update-head-ok\") || !strcmp(arg, \"-u\")) {\n-\t\t\tupdate_head_ok = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!prefixcmp(arg, \"--depth=\")) {\n-\t\t\tdepth = arg + 8;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--depth\")) {\n-\t\t\ti++;\n-\t\t\tif (i == argc)\n-\t\t\t\tusage(fetch_usage);\n-\t\t\tdepth = argv[i];\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--quiet\") || !strcmp(arg, \"-q\")) {\n-\t\t\tquiet = 1;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (!strcmp(arg, \"--verbose\") || !strcmp(arg, \"-v\")) {\n-\t\t\tverbose++;\n-\t\t\tcontinue;\n-\t\t}\n-\t\tusage(fetch_usage);\n-\t}\n+\targc = parse_options(argc, argv,\n+\t\t\t     builtin_fetch_options, builtin_fetch_usage, 0);\n \n-\tif (i == argc)\n+\tif (argc == 0)\n \t\tremote = remote_get(NULL);\n \telse\n-\t\tremote = remote_get(argv[i++]);\n+\t\tremote = remote_get(argv[0]);\n \n \ttransport = transport_get(remote, remote->url[0]);\n \tif (verbose >= 2)\n@@ -636,10 +606,10 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n \tif (!transport->url)\n \t\tdie(\"Where do you want to fetch from today?\");\n \n-\tif (i < argc) {\n+\tif (argc > 1) {\n \t\tint j = 0;\n-\t\trefs = xcalloc(argc - i + 1, sizeof(const char *));\n-\t\twhile (i < argc) {\n+\t\trefs = xcalloc(argc + 1, sizeof(const char *));\n+\t\tfor (i = 1; i < argc; i++) {\n \t\t\tif (!strcmp(argv[i], \"tag\")) {\n \t\t\t\tchar *ref;\n \t\t\t\ti++;\n@@ -651,7 +621,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n \t\t\t\trefs[j++] = ref;\n \t\t\t} else\n \t\t\t\trefs[j++] = argv[i];\n-\t\t\ti++;\n \t\t}\n \t\trefs[j] = NULL;\n \t\tref_nr = j;\n-- \n1.5.3.4\n"},{"id":"61920","messageId":"1196783176.2606.2.camel@hinata.boston.redhat.com","threadId":"11127","inReplyTo":"1196753147-20073-1-git-send-email-krh@redhat.com","subject":"Re: [PATCH] Use a strbuf for copying the command line for the reflog.","fromName":"Kristian Høgsberg","fromEmail":"krh@redhat.com","sentAt":"2007-12-04T15:46:16Z","receivedAt":"2007-12-04T15:46:16Z","isPatch":true,"sender":{"key":"krh@redhat.com","avatar":"https://gravatar.com/avatar/763dee6f9594ac474f725b137a39565792928e583ddf59b32befc2907409027e?d=mp&s=160"},"body":"Doh, I forgot -n to git-format-patch again for this two patch series.\nMaybe git-format-patch should default to -n when there's more than one\npatch?  Anyway, it should have been:\n\n[PATCH 1/2] Use a strbuf for copying the command line for the reflog.\n[PATCH 2/2] Rewrite builtin-fetch option parsing to use parse_options().\n\ncheers,\nKristian\n"}]}