Merge branch 'nd/fetch-pack-shallow-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 5 Sep 2013 21:40:58 +0000 (14:40 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Sep 2013 21:40:58 +0000 (14:40 -0700)
The recent "short-cut clone connectivity check" topic broke a shallow
repository when a fetch operation tries to auto-follow tags.

* nd/fetch-pack-shallow-fix:
fetch-pack: do not remove .git/shallow file when --depth is not specified

1  2 
fetch-pack.c
diff --combined fetch-pack.c
index 6684348c0ec9ea742eb98666b56a0bfcef316560,76190a8fbd58f2ada7f073f1035003823f55fbdb..f5d99c11813b1ae2eee0bb7dfd94eab60c721b64
@@@ -11,7 -11,6 +11,7 @@@
  #include "run-command.h"
  #include "transport.h"
  #include "version.h"
 +#include "prio-queue.h"
  
  static int transfer_unpack_limit = -1;
  static int fetch_unpack_limit = -1;
@@@ -38,7 -37,7 +38,7 @@@ static int marked
   */
  #define MAX_IN_VAIN 256
  
 -static struct commit_list *rev_list;
 +static struct prio_queue rev_list = { compare_commits_by_commit_date };
  static int non_common_revs, multi_ack, use_sideband, allow_tip_sha1_in_want;
  
  static void rev_list_push(struct commit *commit, int mark)
@@@ -50,7 -49,7 +50,7 @@@
                        if (parse_commit(commit))
                                return;
  
 -              commit_list_insert_by_date(commit, &rev_list);
 +              prio_queue_put(&rev_list, commit);
  
                if (!(commit->object.flags & COMMON))
                        non_common_revs++;
@@@ -123,10 -122,10 +123,10 @@@ static const unsigned char *get_rev(voi
                unsigned int mark;
                struct commit_list *parents;
  
 -              if (rev_list == NULL || non_common_revs == 0)
 +              if (rev_list.nr == 0 || non_common_revs == 0)
                        return NULL;
  
 -              commit = rev_list->item;
 +              commit = prio_queue_get(&rev_list);
                if (!commit->object.parsed)
                        parse_commit(commit);
                parents = commit->parents;
                                mark_common(parents->item, 1, 0);
                        parents = parents->next;
                }
 -
 -              rev_list = rev_list->next;
        }
  
        return commit->object.sha1;
@@@ -441,7 -442,7 +441,7 @@@ static int find_common(struct fetch_pac
                                        in_vain = 0;
                                        got_continue = 1;
                                        if (ack == ACK_ready) {
 -                                              rev_list = NULL;
 +                                              clear_prio_queue(&rev_list);
                                                got_ready = 1;
                                        }
                                        break;
@@@ -504,7 -505,7 +504,7 @@@ static int mark_complete(const char *re
                struct commit *commit = (struct commit *)o;
                if (!(commit->object.flags & COMPLETE)) {
                        commit->object.flags |= COMPLETE;
 -                      commit_list_insert_by_date(commit, &complete);
 +                      commit_list_insert(commit, &complete);
                }
        }
        return 0;
@@@ -621,7 -622,6 +621,7 @@@ static int everything_local(struct fetc
        if (!args->depth) {
                for_each_ref(mark_complete, NULL);
                for_each_alternate_ref(mark_alternate_complete, NULL);
 +              commit_list_sort_by_date(&complete);
                if (cutoff)
                        mark_recent_complete_commits(args, cutoff);
        }
@@@ -691,7 -691,6 +691,7 @@@ static int get_pack(struct fetch_pack_a
        const char **av;
        int do_keep = args->keep_pack;
        struct child_process cmd;
 +      int ret;
  
        memset(&demux, 0, sizeof(demux));
        if (use_sideband) {
                                strcpy(keep_arg + s, "localhost");
                        *av++ = keep_arg;
                }
 +              if (args->check_self_contained_and_connected)
 +                      *av++ = "--check-self-contained-and-connected";
        }
        else {
                *av++ = "unpack-objects";
                if (args->quiet || args->no_progress)
                        *av++ = "-q";
 +              args->check_self_contained_and_connected = 0;
        }
        if (*hdr_arg)
                *av++ = hdr_arg;
                close(cmd.out);
        }
  
 -      if (finish_command(&cmd))
 +      ret = finish_command(&cmd);
 +      if (!ret || (args->check_self_contained_and_connected && ret == 1))
 +              args->self_contained_and_connected =
 +                      args->check_self_contained_and_connected &&
 +                      ret == 0;
 +      else
                die("%s failed", argv[0]);
        if (use_sideband && finish_async(&demux))
                die("error in sideband demultiplexer");
@@@ -897,6 -888,8 +897,8 @@@ static struct ref *do_fetch_pack(struc
                packet_flush(fd[1]);
        if (args->depth > 0)
                setup_alternate_shallow();
+       else
+               alternate_shallow_file = NULL;
        if (get_pack(args, fd, pack_lockfile))
                die("git fetch-pack: fetch failed.");
  
@@@ -987,7 -980,7 +989,7 @@@ struct ref *fetch_pack(struct fetch_pac
        }
        ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought, pack_lockfile);
  
-       if (alternate_shallow_file) {
+       if (args->depth > 0 && alternate_shallow_file) {
                if (*alternate_shallow_file == '\0') { /* --unshallow */
                        unlink_or_warn(git_path("shallow"));
                        rollback_lock_file(&shallow_lock);