]> asedeno.scripts.mit.edu Git - git.git/blobdiff - builtin-send-pack.c
Free the path_lists used to find non-local tags in git-fetch
[git.git] / builtin-send-pack.c
index 3aab89ca1bb9202232448f16e44e939bff4c820d..930e0fb3fdfee2293d0fca650d7139f09f2d381e 100644 (file)
@@ -71,6 +71,7 @@ static int pack_objects(int fd, struct ref *refs)
                refs = refs->next;
        }
 
+       close(po.in);
        if (finish_command(&po))
                return error("pack-objects died with strange error");
        return 0;
@@ -263,9 +264,7 @@ static void print_ref_status(char flag, const char *summary, struct ref *to, str
 
 static const char *status_abbrev(unsigned char sha1[20])
 {
-       const char *abbrev;
-       abbrev = find_unique_abbrev(sha1, DEFAULT_ABBREV);
-       return abbrev ? abbrev : sha1_to_hex(sha1);
+       return find_unique_abbrev(sha1, DEFAULT_ABBREV);
 }
 
 static void print_ok_ref_status(struct ref *ref)
@@ -298,52 +297,65 @@ static void print_ok_ref_status(struct ref *ref)
        }
 }
 
+static int print_one_push_status(struct ref *ref, const char *dest, int count)
+{
+       if (!count)
+               fprintf(stderr, "To %s\n", dest);
+
+       switch(ref->status) {
+       case REF_STATUS_NONE:
+               print_ref_status('X', "[no match]", ref, NULL, NULL);
+               break;
+       case REF_STATUS_REJECT_NODELETE:
+               print_ref_status('!', "[rejected]", ref, NULL,
+                               "remote does not support deleting refs");
+               break;
+       case REF_STATUS_UPTODATE:
+               print_ref_status('=', "[up to date]", ref,
+                               ref->peer_ref, NULL);
+               break;
+       case REF_STATUS_REJECT_NONFASTFORWARD:
+               print_ref_status('!', "[rejected]", ref, ref->peer_ref,
+                               "non-fast forward");
+               break;
+       case REF_STATUS_REMOTE_REJECT:
+               print_ref_status('!', "[remote rejected]", ref,
+                               ref->deletion ? NULL : ref->peer_ref,
+                               ref->remote_status);
+               break;
+       case REF_STATUS_EXPECTING_REPORT:
+               print_ref_status('!', "[remote failure]", ref,
+                               ref->deletion ? NULL : ref->peer_ref,
+                               "remote failed to report status");
+               break;
+       case REF_STATUS_OK:
+               print_ok_ref_status(ref);
+               break;
+       }
+
+       return 1;
+}
+
 static void print_push_status(const char *dest, struct ref *refs)
 {
        struct ref *ref;
-       int shown_dest = 0;
+       int n = 0;
 
-       for (ref = refs; ref; ref = ref->next) {
-               if (!ref->status)
-                       continue;
-               if (ref->status == REF_STATUS_UPTODATE && !args.verbose)
-                       continue;
+       if (args.verbose) {
+               for (ref = refs; ref; ref = ref->next)
+                       if (ref->status == REF_STATUS_UPTODATE)
+                               n += print_one_push_status(ref, dest, n);
+       }
 
-               if (!shown_dest) {
-                       fprintf(stderr, "To %s\n", dest);
-                       shown_dest = 1;
-               }
+       for (ref = refs; ref; ref = ref->next)
+               if (ref->status == REF_STATUS_OK)
+                       n += print_one_push_status(ref, dest, n);
 
-               switch(ref->status) {
-               case REF_STATUS_NONE:
-                       print_ref_status('X', "[no match]", ref, NULL, NULL);
-                       break;
-               case REF_STATUS_REJECT_NODELETE:
-                       print_ref_status('!', "[rejected]", ref, NULL,
-                                       "remote does not support deleting refs");
-                       break;
-               case REF_STATUS_UPTODATE:
-                       print_ref_status('=', "[up to date]", ref,
-                                       ref->peer_ref, NULL);
-                       break;
-               case REF_STATUS_REJECT_NONFASTFORWARD:
-                       print_ref_status('!', "[rejected]", ref, ref->peer_ref,
-                                       "non-fast forward");
-                       break;
-               case REF_STATUS_REMOTE_REJECT:
-                       print_ref_status('!', "[remote rejected]", ref,
-                                       ref->deletion ? NULL : ref->peer_ref,
-                                       ref->remote_status);
-                       break;
-               case REF_STATUS_EXPECTING_REPORT:
-                       print_ref_status('!', "[remote failure]", ref,
-                                       ref->deletion ? NULL : ref->peer_ref,
-                                       "remote failed to report status");
-                       break;
-               case REF_STATUS_OK:
-                       print_ok_ref_status(ref);
-                       break;
-               }
+       for (ref = refs; ref; ref = ref->next) {
+               if (ref->status != REF_STATUS_NONE &&
+                   ref->status != REF_STATUS_UPTODATE &&
+                   ref->status != REF_STATUS_OK)
+                       n += print_one_push_status(ref, dest, n);
        }
 }
 
@@ -390,12 +402,15 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
        if (!remote_tail)
                remote_tail = &remote_refs;
        if (match_refs(local_refs, remote_refs, &remote_tail,
-                                              nr_refspec, refspec, flags))
+                      nr_refspec, refspec, flags)) {
+               close(out);
                return -1;
+       }
 
        if (!remote_refs) {
                fprintf(stderr, "No refs in common and none specified; doing nothing.\n"
                        "Perhaps you should specify a branch such as 'master'.\n");
+               close(out);
                return 0;
        }
 
@@ -482,12 +497,11 @@ static int do_send_pack(int in, int out, struct remote *remote, const char *dest
 
        packet_flush(out);
        if (new_refs && !args.dry_run) {
-               if (pack_objects(out, remote_refs) < 0) {
-                       close(out);
+               if (pack_objects(out, remote_refs) < 0)
                        return -1;
-               }
        }
-       close(out);
+       else
+               close(out);
 
        if (expect_status_report)
                ret = receive_status(in, remote_refs);
@@ -528,10 +542,12 @@ static void verify_remote_names(int nr_heads, const char **heads)
                remote = remote ? (remote + 1) : heads[i];
                switch (check_ref_format(remote)) {
                case 0: /* ok */
-               case -2: /* ok but a single level -- that is fine for
-                         * a match pattern.
-                         */
-               case -3: /* ok but ends with a pattern-match character */
+               case CHECK_REF_FORMAT_ONELEVEL:
+                       /* ok but a single level -- that is fine for
+                        * a match pattern.
+                        */
+               case CHECK_REF_FORMAT_WILDCARD:
+                       /* ok but ends with a pattern-match character */
                        continue;
                }
                die("remote part of refspec is not a valid name in %s",
@@ -633,7 +649,7 @@ int send_pack(struct send_pack_args *my_args,
        conn = git_connect(fd, dest, args.receivepack, args.verbose ? CONNECT_VERBOSE : 0);
        ret = do_send_pack(fd[0], fd[1], remote, dest, nr_heads, heads);
        close(fd[0]);
-       close(fd[1]);
+       /* do_send_pack always closes fd[1] */
        ret |= finish_connect(conn);
        return !!ret;
 }