Code

alloc_ref_from_str(): factor out a common pattern of alloc_ref from string
[git.git] / builtin-fetch.c
index 55f611e3c26e55df43eca1f40df74d335c850cc0..f6584ecea165704208059b632bb1a1ac2b6a6d1f 100644 (file)
@@ -40,6 +40,8 @@ static struct option builtin_fetch_options[] = {
                    "force overwrite of local branch"),
        OPT_SET_INT('t', "tags", &tags,
                    "fetch all tags and associated objects", TAGS_SET),
+       OPT_SET_INT('n', NULL, &tags,
+                   "do not fetch all tags (--no-tags)", TAGS_UNSET),
        OPT_BOOLEAN('k', "keep", &keep, "keep downloaded pack"),
        OPT_BOOLEAN('u', "update-head-ok", &update_head_ok,
                    "allow updating of HEAD ref"),
@@ -213,13 +215,6 @@ static int update_local_ref(struct ref *ref,
        if (type < 0)
                die("object %s not found", sha1_to_hex(ref->new_sha1));
 
-       if (!*ref->name) {
-               /* Not storing */
-               if (verbose)
-                       sprintf(display, "* branch %s -> FETCH_HEAD", remote);
-               return 0;
-       }
-
        if (!hashcmp(ref->old_sha1, ref->new_sha1)) {
                if (verbose)
                        sprintf(display, "= %-*s %-*s -> %s", SUMMARY_WIDTH,
@@ -363,16 +358,19 @@ static int store_updated_refs(const char *url, struct ref *ref_map)
                        rm->merge ? "" : "not-for-merge",
                        note);
 
-               if (ref) {
+               if (ref)
                        update_local_ref(ref, what, verbose, note);
-                       if (*note) {
-                               if (!shown_url) {
-                                       fprintf(stderr, "From %.*s\n",
-                                                       url_len, url);
-                                       shown_url = 1;
-                               }
-                               fprintf(stderr, " %s\n", note);
+               else
+                       sprintf(note, "* %-*s %-*s -> FETCH_HEAD",
+                               SUMMARY_WIDTH, *kind ? kind : "branch",
+                                REFCOL_WIDTH, *what ? what : "HEAD");
+               if (*note) {
+                       if (!shown_url) {
+                               fprintf(stderr, "From %.*s\n",
+                                               url_len, url);
+                               shown_url = 1;
                        }
+                       fprintf(stderr, " %s\n", note);
                }
        }
        fclose(fp);
@@ -510,10 +508,8 @@ static void find_non_local_tags(struct transport *transport,
                     will_fetch(head, ref->old_sha1))) {
                        path_list_insert(ref_name, &new_refs);
 
-                       rm = alloc_ref(strlen(ref_name) + 1);
-                       strcpy(rm->name, ref_name);
-                       rm->peer_ref = alloc_ref(strlen(ref_name) + 1);
-                       strcpy(rm->peer_ref->name, ref_name);
+                       rm = alloc_ref_from_str(ref_name);
+                       rm->peer_ref = alloc_ref_from_str(ref_name);
                        hashcpy(rm->old_sha1, ref_sha1);
 
                        **tail = rm;
@@ -577,8 +573,6 @@ static int do_fetch(struct transport *transport,
                free_refs(ref_map);
        }
 
-       transport_disconnect(transport);
-
        return 0;
 }
 
@@ -599,6 +593,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
        int i;
        static const char **refs = NULL;
        int ref_nr = 0;
+       int exit_code;
 
        /* Record the command line for the reflog */
        strbuf_addstr(&default_rla, "fetch");
@@ -635,6 +630,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
                        if (!strcmp(argv[i], "tag")) {
                                char *ref;
                                i++;
+                               if (i >= argc)
+                                       die("You need to specify a tag name.");
                                ref = xmalloc(strlen(argv[i]) * 2 + 22);
                                strcpy(ref, "refs/tags/");
                                strcat(ref, argv[i]);
@@ -650,5 +647,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 
        signal(SIGINT, unlock_pack_on_signal);
        atexit(unlock_pack);
-       return do_fetch(transport, parse_ref_spec(ref_nr, refs), ref_nr);
+       exit_code = do_fetch(transport,
+                       parse_fetch_refspec(ref_nr, refs), ref_nr);
+       transport_disconnect(transport);
+       transport = NULL;
+       return exit_code;
 }