Merge branch 'jt/partial-clone-fsck-connectivity'
authorJunio C Hamano <gitster@pobox.com>
Tue, 24 Jul 2018 21:50:47 +0000 (14:50 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 24 Jul 2018 21:50:47 +0000 (14:50 -0700)
Partial clone support of "git clone" has been updated to correctly
validate the objects it receives from the other side. The server
side has been corrected to send objects that are directly
requested, even if they may match the filtering criteria (e.g. when
doing a "lazy blob" partial clone).

* jt/partial-clone-fsck-connectivity:
clone: check connectivity even if clone is partial
upload-pack: send refs' objects despite "filter"

1  2 
builtin/clone.c
list-objects.c
object.h
revision.c
revision.h
diff --combined builtin/clone.c
index 2f84717e11c22e6176cd28f850c756aad0b3e2fe,fa535507587959a345bcfa65cc17b760b95039ab..5c439f1394c9a097e48f24d73790f276a958bf2d
@@@ -15,7 -15,6 +15,7 @@@
  #include "fetch-pack.h"
  #include "refs.h"
  #include "refspec.h"
 +#include "object-store.h"
  #include "tree.h"
  #include "tree-walk.h"
  #include "unpack-trees.h"
@@@ -1078,7 -1077,7 +1078,7 @@@ int cmd_clone(int argc, const char **ar
        if (option_required_reference.nr || option_optional_reference.nr)
                setup_reference();
  
 -      refspec_item_init(&refspec, value.buf, REFSPEC_FETCH);
 +      refspec_item_init_or_die(&refspec, value.buf, REFSPEC_FETCH);
  
        strbuf_reset(&value);
  
  
        update_remote_refs(refs, mapped_refs, remote_head_points_at,
                           branch_top.buf, reflog_msg.buf, transport,
-                          !is_local && !filter_options.choice);
+                          !is_local);
  
        update_head(our_head_points_at, remote_head, reflog_msg.buf);
  
diff --combined list-objects.c
index 3e5e1992eb0cd1c535ed42e9729941403ca89054,be4118889a086b4fa91578c0dbafc21c376d9654..b1f2138c294adb50cacdcf43601ff82d69eebbae
@@@ -10,7 -10,6 +10,7 @@@
  #include "list-objects-filter.h"
  #include "list-objects-filter-options.h"
  #include "packfile.h"
 +#include "object-store.h"
  
  static void process_blob(struct rev_info *revs,
                         struct blob *blob,
@@@ -48,7 -47,7 +48,7 @@@
  
        pathlen = path->len;
        strbuf_addstr(path, name);
-       if (filter_fn)
+       if (!(obj->flags & USER_GIVEN) && filter_fn)
                r = filter_fn(LOFS_BLOB, obj,
                              path->buf, &path->buf[pathlen],
                              filter_data);
@@@ -133,7 -132,7 +133,7 @@@ static void process_tree(struct rev_inf
        }
  
        strbuf_addstr(base, name);
-       if (filter_fn)
+       if (!(obj->flags & USER_GIVEN) && filter_fn)
                r = filter_fn(LOFS_BEGIN_TREE, obj,
                              base->buf, &base->buf[baselen],
                              filter_data);
                                     cb_data, filter_fn, filter_data);
        }
  
-       if (filter_fn) {
+       if (!(obj->flags & USER_GIVEN) && filter_fn) {
                r = filter_fn(LOFS_END_TREE, obj,
                              base->buf, &base->buf[baselen],
                              filter_data);
diff --combined object.h
index 1b96073601f2cd239e7fe6923a078572ee820bcc,cf8da6ba8301062903929263059b917fa812b1db..3afd123d735d1d5ac45da096e889d00f0b901161
+++ b/object.h
@@@ -1,32 -1,6 +1,32 @@@
  #ifndef OBJECT_H
  #define OBJECT_H
  
 +struct parsed_object_pool {
 +      struct object **obj_hash;
 +      int nr_objs, obj_hash_size;
 +
 +      /* TODO: migrate alloc_states to mem-pool? */
 +      struct alloc_state *blob_state;
 +      struct alloc_state *tree_state;
 +      struct alloc_state *commit_state;
 +      struct alloc_state *tag_state;
 +      struct alloc_state *object_state;
 +      unsigned commit_count;
 +
 +      /* parent substitutions from .git/info/grafts and .git/shallow */
 +      struct commit_graft **grafts;
 +      int grafts_alloc, grafts_nr;
 +
 +      int is_shallow;
 +      struct stat_validity *shallow_stat;
 +      char *alternate_shallow_file;
 +
 +      int commit_graft_prepared;
 +};
 +
 +struct parsed_object_pool *parsed_object_pool_new(void);
 +void parsed_object_pool_clear(struct parsed_object_pool *o);
 +
  struct object_list {
        struct object *item;
        struct object_list *next;
@@@ -53,7 -27,7 +53,7 @@@ struct object_array 
  
  /*
   * object flag allocation:
-  * revision.h:               0---------10                                26
+  * revision.h:               0---------10                              2526
   * fetch-pack.c:             0----5
   * walker.c:                 0-2
   * upload-pack.c:                4       11----------------19
@@@ -68,7 -42,6 +68,7 @@@
   * builtin/index-pack.c:                                     2021
   * builtin/pack-objects.c:                                   20
   * builtin/reflog.c:                   10--12
 + * builtin/show-branch.c:    0-------------------------------------------26
   * builtin/unpack-objects.c:                                 2021
   */
  #define FLAG_BITS  27
@@@ -111,7 -84,7 +111,7 @@@ extern struct object *get_indexed_objec
   */
  struct object *lookup_object(const unsigned char *sha1);
  
 -extern void *create_object(const unsigned char *sha1, void *obj);
 +extern void *create_object(struct repository *r, const unsigned char *sha1, void *obj);
  
  void *object_as_type(struct object *obj, enum object_type type, int quiet);
  
diff --combined revision.c
index 72abe235e4a8045b92d40b18c7d1fb574456e38c,1b37da988d2dc8e8b357e4375583a072d5fed82a..a2570397b6685fbd6e3a7d77ad7e2c554cc03772
@@@ -1,5 -1,4 +1,5 @@@
  #include "cache.h"
 +#include "object-store.h"
  #include "tag.h"
  #include "blob.h"
  #include "tree.h"
@@@ -30,8 -29,6 +30,8 @@@ volatile show_early_output_fn_t show_ea
  static const char *term_bad;
  static const char *term_good;
  
 +implement_shared_commit_slab(revision_sources, char *);
 +
  void show_object_with_name(FILE *out, struct object *obj, const char *name)
  {
        const char *p;
@@@ -175,6 -172,7 +175,7 @@@ static void add_pending_object_with_pat
                strbuf_release(&buf);
                return; /* do not add the commit itself */
        }
+       obj->flags |= USER_GIVEN;
        add_object_array_with_path(obj, name, &revs->pending, mode, path);
  }
  
@@@ -268,19 -266,14 +269,19 @@@ static struct commit *handle_commit(str
         */
        if (object->type == OBJ_COMMIT) {
                struct commit *commit = (struct commit *)object;
 +
                if (parse_commit(commit) < 0)
                        die("unable to parse commit %s", name);
                if (flags & UNINTERESTING) {
                        mark_parents_uninteresting(commit);
                        revs->limited = 1;
                }
 -              if (revs->show_source && !commit->util)
 -                      commit->util = xstrdup(name);
 +              if (revs->sources) {
 +                      char **slot = revision_sources_at(revs->sources, commit);
 +
 +                      if (!*slot)
 +                              *slot = xstrdup(name);
 +              }
                return commit;
        }
  
@@@ -832,12 -825,8 +833,12 @@@ static int add_parents_to_list(struct r
                        }
                        return -1;
                }
 -              if (revs->show_source && !p->util)
 -                      p->util = commit->util;
 +              if (revs->sources) {
 +                      char **slot = revision_sources_at(revs->sources, p);
 +
 +                      if (!*slot)
 +                              *slot = *revision_sources_at(revs->sources, commit);
 +              }
                p->object.flags |= left_flag;
                if (!(p->object.flags & SEEN)) {
                        p->object.flags |= SEEN;
diff --combined revision.h
index bf2239f87689d9486c4b888bed5cba6affa21953,dc8f96366e3636d3de3e0b36288a425c1ca9d531..c599c34da91e57572b1c5b315c353d33399e8a09
@@@ -6,7 -6,6 +6,7 @@@
  #include "notes.h"
  #include "pretty.h"
  #include "diff.h"
 +#include "commit-slab-decl.h"
  
  /* Remember to update object flag allocation in object.h */
  #define SEEN          (1u<<0)
@@@ -20,8 -19,9 +20,9 @@@
  #define SYMMETRIC_LEFT        (1u<<8)
  #define PATCHSAME     (1u<<9)
  #define BOTTOM                (1u<<10)
+ #define USER_GIVEN    (1u<<25) /* given directly by the user */
  #define TRACK_LINEAR  (1u<<26)
- #define ALL_REV_FLAGS (((1u<<11)-1) | TRACK_LINEAR)
+ #define ALL_REV_FLAGS (((1u<<11)-1) | USER_GIVEN | TRACK_LINEAR)
  
  #define DECORATE_SHORT_REFS   1
  #define DECORATE_FULL_REFS    2
@@@ -30,7 -30,6 +31,7 @@@ struct rev_info
  struct log_info;
  struct string_list;
  struct saved_parents;
 +define_shared_commit_slab(revision_sources, char *);
  
  struct rev_cmdline_info {
        unsigned int nr;
@@@ -113,6 -112,7 +114,6 @@@ struct rev_info 
                        right_only:1,
                        rewrite_parents:1,
                        print_parents:1,
 -                      show_source:1,
                        show_decorations:1,
                        reverse:1,
                        reverse_output_stage:1,
  
        struct commit_list *previous_parents;
        const char *break_bar;
 +
 +      struct revision_sources *sources;
  };
  
  extern int ref_excluded(struct string_list *, const char *path);