On Fri, Sep 16, 2016 at 10:59:37AM -0700, Junio C Hamano wrote: > Heiko Voigt <hvoigt@xxxxxxxxxx> writes: > > +static void check_has_hash(const unsigned char sha1[20], void *data) > > +{ > > + int *has_hash = (int *) data; > > + > > + if (!lookup_commit_reference(sha1)) > > + *has_hash = 0; > > +} > > + > > +static int submodule_has_hashes(const char *path, struct sha1_array *hashes) > > +{ > > + int has_hash = 1; > > + > > + if (add_submodule_odb(path)) > > + return 0; > > + > > + sha1_array_for_each_unique(hashes, check_has_hash, &has_hash); > > + return has_hash; > > +} > > + > > +static int submodule_needs_pushing(const char *path, struct sha1_array *hashes) > > +{ > > + if (!submodule_has_hashes(path, hashes)) > > return 0; > > I think you meant well, but this optimization is wrong. A mere > presence of an object does not mean that the current tip can reach > that object. Imagine you pushed commit A earlier to them at the > tip, then pushed commit A~ to them at the tip, which is the current > state of the remote of the submodule, and since them they may have > GC'ed. They no longer have the commit A. > > For that matter, because you are doing this check by pretending as > if all the submodule objects are in the object store of the current > superproject you are working in, and saying "it exists there in the > submodule repository" when the only thing you know is it exists in > an object store of either the submodule repository, the superproject > repository, or any of the other submodule repositories, you really > cannot tell much from a mere presence of an object. Not just the > remote of the submodule repository you are interested in, but the > submodule repository you are interested in itself, may not have that > object. > > Drop the previous two helper functions and this short-cut. This is nothing I added. This came from the original code which I simply extended to check for all sha1's. The diff is a little bit misleading. This would be the local diff: - if (add_submodule_odb(path) || !lookup_commit_reference(sha1)) + if (!submodule_has_hashes(path, hashes)) return 0; I think that this is more a shortcut for: If we can not find the sha1, we do not need to bother spawning a process for the real check. We default to the answer no in that case. It looks like the reason for the sha1 check is to avoid error output from the spawned 'rev-list' process. The error output might be confusing to the user in case the sha1 does not exist in the submodule. We should probably die here since we were not able to check a submodule that has a diff in the revisions we would push. After thinking about this further: I think it is actually bad to proceed here, as the current revisions (just in the superproject) would still be pushed and the user possibly gets an inconsistent state on the remote side which he tried to avoid with check/on-demand-push enabled. So in short this deserves some further love. Will have a look into adding another patch for this if we agree on my suggestion to die above. Cheers Heiko