On Tue, Nov 21, 2017 at 10:07 PM, Jeff Hostetler <git@xxxxxxxxxxxxxxxxx> wrote: > From: Jonathan Tan <jonathantanmy@xxxxxxxxxx> > diff --git a/sha1_file.c b/sha1_file.c > index 10c3a00..fc7718a 100644 > --- a/sha1_file.c > +++ b/sha1_file.c > @@ -29,6 +29,7 @@ > #include "mergesort.h" > #include "quote.h" > #include "packfile.h" > +#include "fetch-object.h" > > const unsigned char null_sha1[GIT_MAX_RAWSZ]; > const struct object_id null_oid; > @@ -1144,6 +1145,8 @@ static int sha1_loose_object_info(const unsigned char *sha1, > return (status < 0) ? status : 0; > } > > +int fetch_if_missing = 1; > + > int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, unsigned flags) > { > static struct object_info blank_oi = OBJECT_INFO_INIT; > @@ -1152,6 +1155,7 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, > const unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ? > lookup_replace_object(sha1) : > sha1; > + int already_retried = 0; > > if (!oi) > oi = &blank_oi; > @@ -1176,28 +1180,36 @@ int sha1_object_info_extended(const unsigned char *sha1, struct object_info *oi, > } > } > > - if (!find_pack_entry(real, &e)) { > - /* Most likely it's a loose object. */ > - if (!sha1_loose_object_info(real, oi, flags)) > - return 0; > +retry: > + if (find_pack_entry(real, &e)) > + goto found_packed; > > - /* Not a loose object; someone else may have just packed it. */ > - if (flags & OBJECT_INFO_QUICK) { > - return -1; > - } else { > - reprepare_packed_git(); > - if (!find_pack_entry(real, &e)) > - return -1; > - } > + /* Most likely it's a loose object. */ > + if (!sha1_loose_object_info(real, oi, flags)) > + return 0; > + > + /* Not a loose object; someone else may have just packed it. */ > + reprepare_packed_git(); > + if (find_pack_entry(real, &e)) > + goto found_packed; > + > + /* Check if it is a missing object */ > + if (fetch_if_missing && repository_format_partial_clone && > + !already_retried) { > + fetch_object(repository_format_partial_clone, real); > + already_retried = 1; > + goto retry; > } > > + return -1; > + > +found_packed: > if (oi == &blank_oi) > /* > * We know that the caller doesn't actually need the > * information below, so return early. > */ > return 0; > - > rtype = packed_object_info(e.p, e.offset, oi); > if (rtype < 0) { > mark_bad_packed_object(e.p, real); The above is adding 2 different gotos into this function while there are quite simple ways to avoid them. See https://public-inbox.org/git/CAP8UFD2THRj7+RXmismUtUOpXQv4wM7aZsejpd_FHEOycP+ZJA@xxxxxxxxxxxxxx/ and the follow up email in the thread.