Merge branch 'nd/fetch-depth-is-broken'
authorJunio C Hamano <gitster@pobox.com>
Fri, 1 Feb 2013 20:39:24 +0000 (12:39 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Feb 2013 20:39:24 +0000 (12:39 -0800)
"git fetch --depth" was broken in at least three ways. The
resulting history was deeper than specified by one commit, it was
unclear how to wipe the shallowness of the repository with the
command, and documentation was misleading.

* nd/fetch-depth-is-broken:
fetch: elaborate --depth action
upload-pack: fix off-by-one depth calculation in shallow clone
fetch: add --unshallow for turning shallow repo into complete one

1  2 
commit.h
upload-pack.c
diff --combined commit.h
index c16c8a75349f2ef4dba1f3c05528d04750a925da,0adfce96e46aa9e9017d7c39eed54b01e24bc2d6..95b8350a5b5109bf2d8a1e60fa4d8065501a031d
+++ b/commit.h
@@@ -86,11 -86,9 +86,11 @@@ struct pretty_print_context 
        enum date_mode date_mode;
        unsigned date_mode_explicit:1;
        int need_8bit_cte;
 -      int show_notes;
 +      char *notes_message;
        struct reflog_walk_info *reflog_info;
        const char *output_encoding;
 +      struct string_list *mailmap;
 +      int color;
  };
  
  struct userformat_want {
@@@ -101,6 -99,8 +101,6 @@@ extern int has_non_ascii(const char *te
  struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
  extern char *logmsg_reencode(const struct commit *commit,
                             const char *output_encoding);
 -extern char *reencode_commit_message(const struct commit *commit,
 -                                   const char **encoding_p);
  extern void get_commit_format(const char *arg, struct rev_info *);
  extern const char *format_subject(struct strbuf *sb, const char *msg,
                                  const char *line_separator);
@@@ -163,6 -163,9 +163,9 @@@ extern struct commit_list *get_merge_ba
  extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup);
  extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
  
+ /* largest postive number a signed 32-bit integer can contain */
+ #define INFINITE_DEPTH 0x7fffffff
  extern int register_shallow(const unsigned char *sha1);
  extern int unregister_shallow(const unsigned char *sha1);
  extern int for_each_commit_graft(each_commit_graft_fn, void *);
@@@ -222,8 -225,4 +225,8 @@@ struct commit *get_merge_parent(const c
  
  extern int parse_signed_commit(const unsigned char *sha1,
                               struct strbuf *message, struct strbuf *signature);
 +extern void print_commit_list(struct commit_list *list,
 +                            const char *format_cur,
 +                            const char *format_last);
 +
  #endif /* COMMIT_H */
diff --combined upload-pack.c
index 95d83135ae95b2fa7980c69cbd7b49e3a6ff2d0a,8740002817c0fdcd02d5c0c6a6402df222f4d965..7c05b15e68d6deed45a172df397e814fcf2032b0
@@@ -603,8 -603,6 +603,8 @@@ static void receive_needs(void
                        object = parse_object(sha1);
                        if (!object)
                                die("did not find object for %s", line);
 +                      if (object->type != OBJ_COMMIT)
 +                              die("invalid shallow object %s", sha1_to_hex(sha1));
                        object->flags |= CLIENT_SHALLOW;
                        add_object_array(object, NULL, &shallows);
                        continue;
        if (depth == 0 && shallows.nr == 0)
                return;
        if (depth > 0) {
-               struct commit_list *result, *backup;
+               struct commit_list *result = NULL, *backup = NULL;
                int i;
-               backup = result = get_shallow_commits(&want_obj, depth,
-                       SHALLOW, NOT_SHALLOW);
+               if (depth == INFINITE_DEPTH)
+                       for (i = 0; i < shallows.nr; i++) {
+                               struct object *object = shallows.objects[i].item;
+                               object->flags |= NOT_SHALLOW;
+                       }
+               else
+                       backup = result =
+                               get_shallow_commits(&want_obj, depth,
+                                                   SHALLOW, NOT_SHALLOW);
                while (result) {
                        struct object *object = &result->item->object;
                        if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
@@@ -729,7 -734,12 +736,7 @@@ static int send_ref(const char *refname
                " include-tag multi_ack_detailed";
        struct object *o = lookup_unknown_object(sha1);
        const char *refname_nons = strip_namespace(refname);
 -
 -      if (o->type == OBJ_NONE) {
 -              o->type = sha1_object_info(sha1, NULL);
 -              if (o->type < 0)
 -                  die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
 -      }
 +      unsigned char peeled[20];
  
        if (capabilities)
                packet_write(1, "%s %s%c%s%s agent=%s\n",
                o->flags |= OUR_REF;
                nr_our_refs++;
        }
 -      if (o->type == OBJ_TAG) {
 -              o = deref_tag_noverify(o);
 -              if (o)
 -                      packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname_nons);
 -      }
 +      if (!peel_ref(refname, peeled))
 +              packet_write(1, "%s %s^{}\n", sha1_to_hex(peeled), refname_nons);
        return 0;
  }