submodule: use cheaper check for submodule pushes
PATCH 1/1 submodule: use cheaper check for submodule pushes
In the function push_submodule[1] we use add_submodule_odb[2] to determine if a submodule has been populated. However the function does not work with the submodules objects that are added, instead a new child process is used to perform the actual push in the submodule.
Use is_submodule_populated[3] that is cheaper to guard from unpopulated submodules.
[1] 'push_submodule' was added in eb21c732d6 (push: teach
--recurse-submodules the on-demand option, 2012-03-29)
[2] 'add_submodule_odb' was introduced in 752c0c2492 (Add the --submodule option to the diff option family, 2009-10-19)
[3] 'is_submodule_populated' was added in 5688c28d81 (submodules:
add helper to determine if a submodule is populated, 2016-12-16)
--- submodule.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
submodule.c +3 -1
@@ -976,7 +976,9 @@ static int push_submodule(const char *path,const struct string_list *push_options, int dry_run) { - if (add_submodule_odb(path)) + int code; + +if (!is_submodule_populated_gently (path, &code))return 1 ;if (for_each_remote_ref_submodule (path, has_remote,NULL ) >0 ) {
Signature · 1 line
2.13.2.695.g117ddefdb4
Hi,
Quoted 8 lines · Stefan Beller
In the function push_submodule[1] we use add_submodule_odb[2] to determine if a submodule has been populated. However the function does not work with the submodules objects that are added, instead a new child process is used to perform the actual push in the submodule.
Use is_submodule_populated[3] that is cheaper to guard from unpopulated submodules.
Quoted 6 lines
[1] '
push_submodule' was added ineb21c732d6(push: teach--recurse-submodules the on-demand option, 2012-03-29)[2] '
add_submodule_odb' was introduced in752c0c2492(Add the --submodule option to the diff option family, 2009-10-19)
[3] 'is_submodule_populated' was added in5688c28d81(submodules:
add helper to determine if a submodule is populated, 2016-12-16)
These footnotes don't answer the question that I really have: why did this use add_submodule_odb in the first place?
E.g. did the ref iteration code require access to the object store previously and stop requiring it later?
Quoted 10 lines
Signed-off-by Stefan Beller <[email protected]>--- submodule.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)submodule.c +0
-0
submodule.c static int push_submodule(const char *path, · line 981
Quoted 7 lines
submodule.c +3
-1@@ -976,7 +976,9 @@ static int push_submodule(const char *path,const struct string_list *push_options, int dry_run) { - if (add_submodule_odb(path)) + int code; + +if (!is_submodule_populated_gently (path, &code))
Should this examine the code to distinguish between hard errors (e.g. "Error reading .git") and a missing repository?
Thanks,
Jonathan
Quoted 2 lines · Jonathan Nieder
These footnotes don't answer the question that I really have: why did this use
add_submodule_odbin the first place?
oh, I forgot to put that down: presumably add_submodule_odb was used because it was available back then? Note the dates!
Quoted 2 lines
E.g. did the ref iteration code require access to the object store previously and stop requiring it later?
No. See [1], it was overkill since the beginning of time.
Quoted 7 lines
submodule.c static int push_submodule(const char *path, · line 981
Quoted 4 lines
submodule.c +3
-1-if (add_submodule_odb (path)) +int code; + +if (!is_submodule_populated_gently (path, &code))Should this examine the code to distinguish between hard errors (e.g. "Error reading .git") and a missing repository?
add_submodule_odb does neither, so I think this is best kept without additional checks.
Thanks!
Quoted 15 lines · Jonathan Nieder
Quoted 8 lines
In the function push_submodule[1] we use add_submodule_odb[2] to determine if a submodule has been populated. However the function does not work with the submodules objects that are added, instead a new child process is used to perform the actual push in the submodule.
Use is_submodule_populated[3] that is cheaper to guard from unpopulated submodules.
Quoted 6 lines
[1] '
push_submodule' was added ineb21c732d6(push: teach--recurse-submodules the on-demand option, 2012-03-29)[2] '
add_submodule_odb' was introduced in752c0c2492(Add the --submodule option to the diff option family, 2009-10-19)
[3] 'is_submodule_populated' was added in5688c28d81(submodules:
add helper to determine if a submodule is populated, 2016-12-16)
Quoted 5 lines
These footnotes don't answer the question that I really have: why did this use
add_submodule_odbin the first place?E.g. did the ref iteration code require access to the object store previously and stop requiring it later?
Yes, the most important question is if it is safe to lose the access to the object store of the submodule. It is an endgame we should aim for to get rid of add_submodule_odb(), but does the rest of this codepath not require objects in the submodule at all or do we still need to change something to make it so?
Quoted 20 lines · Junio C Hamano
Quoted 18 lines · Jonathan Nieder
Quoted 8 lines
In the function push_submodule[1] we use add_submodule_odb[2] to determine if a submodule has been populated. However the function does not work with the submodules objects that are added, instead a new child process is used to perform the actual push in the submodule.
Use is_submodule_populated[3] that is cheaper to guard from unpopulated submodules.
Quoted 6 lines
[1] '
push_submodule' was added ineb21c732d6(push: teach--recurse-submodules the on-demand option, 2012-03-29)[2] '
add_submodule_odb' was introduced in752c0c2492(Add the --submodule option to the diff option family, 2009-10-19)
[3] 'is_submodule_populated' was added in5688c28d81(submodules:
add helper to determine if a submodule is populated, 2016-12-16)These footnotes don't answer the question that I really have: why did this use
add_submodule_odbin the first place?
Quoted 8 lines
Quoted 2 lines
E.g. did the ref iteration code require access to the object store previously and stop requiring it later?
Yes, the most important question is if it is safe to lose the access to the object store of the submodule. It is an endgame we should aim for to get rid of
add_submodule_odb(), but does the rest of this codepath not require objects in the submodule at all or do we still need to change something to make it so?
Yes, as the code in the current form as well as in its first occurrence used the result of add_submodule_odb to determine if to spawn a child process.
Quoted 24 lines · Stefan Beller
Quoted 23 lines · Junio C Hamano
Quoted 20 lines · Jonathan Nieder
Quoted 8 lines
In the function push_submodule[1] we use add_submodule_odb[2] to determine if a submodule has been populated. However the function does not work with the submodules objects that are added, instead a new child process is used to perform the actual push in the submodule.
Use is_submodule_populated[3] that is cheaper to guard from unpopulated submodules.
Quoted 6 lines
[1] '
push_submodule' was added ineb21c732d6(push: teach--recurse-submodules the on-demand option, 2012-03-29)[2] '
add_submodule_odb' was introduced in752c0c2492(Add the --submodule option to the diff option family, 2009-10-19)
[3] 'is_submodule_populated' was added in5688c28d81(submodules:
add helper to determine if a submodule is populated, 2016-12-16)These footnotes don't answer the question that I really have: why did this use
add_submodule_odbin the first place?E.g. did the ref iteration code require access to the object store previously and stop requiring it later?
Quoted 8 lines
Quoted 5 lines
Yes, the most important question is if it is safe to lose the access to the object store of the submodule. It is an endgame we should aim for to get rid of
add_submodule_odb(), but does the rest of this codepath not require objects in the submodule at all or do we still need to change something to make it so?Yes, as the code in the current form as well as in its first occurrence used the result of
add_submodule_odbto determine if to spawn a child process.
The original added so that the return value of the call can be used for that, and the current code still uses the return value for that purpose.
That much is already known.
I think Jonathan's question (which I concurred) is if we also ended up relying on the side effect of calling that function (i.e. being able to now find objects that are not in our repository but in the submodule's object store). By looking at the eb21c732d6, we can tell that the original didn't mean to and didn't add any code that relies on the ability to be able to read from the submodule object store. I am not sure if that is still true after 5 years (i.e. is there any new code added in the meantime that made us depend on the ability to read from submodule object store?).
My hunch (and hope) is that we are probably safe, but that is a lot weaker than "yes this is a good change we want to apply".
Quoted 10 lines · Junio C Hamano
I think Jonathan's question (which I concurred) is if we also ended up relying on the side effect of calling that function (i.e. being able to now find objects that are not in our repository but in the submodule's object store). By looking at the
eb21c732d6, we can tell that the original didn't mean to and didn't add any code that relies on the ability to be able to read from the submodule object store. I am not sure if that is still true after 5 years (i.e. is there any new code added in the meantime that made us depend on the ability to read from submodule object store?).
Yes we are safe, because the function itself only spawns a child process (not using any of the objects).
It's only caller push_unpushed_submodules also doesn't rely on objects loaded after calling push_submodule.
The caller of push_unpushed_submodules (transport.c, transport_push) also doesn't need submodule objects loaded.
Quoted 2 lines
My hunch (and hope) is that we are probably safe, but that is a lot weaker than "yes this is a good change we want to apply".
Given the above (I went through the code), all I can do is repeating "yes this is a good change we want to apply".
Thanks,
Stefan
Hi,
Quoted 8 lines · Stefan Beller
Yes we are safe, because the function itself only spawns a child process (not using any of the objects).
It's only caller
push_unpushed_submodulesalso doesn't rely on objects loaded after callingpush_submodule.The caller of
push_unpushed_submodules(transport.c,transport_push) also doesn't need submodule objects loaded.
Thanks for looking into it. This is what the commit message should say to help reviewers or people trying to understand it later. The footnotes don't help and are distracting, except that it makes sense to point out the original GSoC patch to say the alternate submodule odb wasn't needed even then.
E.g.:
Subject: push: do not add submodule odb as an alternate when recursing on demand
"git push --recurse-submodules=on-demand" adds each submodule as an alternate with add_submodule_odb before checking whether the submodule has anything to push and pushing it if so.
However, it never accesses any objects from the submodule. In the parent process it uses the submodule's ref database to see if there is anything to push. The actual push (which does rely on objects) occurs in a child process.
The same was try when this call was originally added in v1.7.11-rc0~111^2 (push: teach --recurse-submodules the on-demand option, 2012-03-29). Most likely it was added by analogy with fetch --recurse-submodules=on-demand, which did use the submodule's object database.
Use is_submodule_populated_gently instead, which is simpler and cheaper.
[...]
Quoted 7 lines · Junio C Hamano
Quoted 3 lines
My hunch (and hope) is that we are probably safe, but that is a lot weaker than "yes this is a good change we want to apply".
Given the above (I went through the code), all I can do is repeating "yes this is a good change we want to apply".
With such a commit message change, this seems like a reasonable change in principle (though I haven't looked carefully to verify it).
My one doubt is the is_submodule_populated_gently. Why are we using that instead of simpler is_submodule_populated? The names and API comments don't explain.
Thanks for your patient explanations,
Jonathan
Quoted 32 lines · Jonathan Nieder
Hi,
Quoted 8 lines · Stefan Beller
Yes we are safe, because the function itself only spawns a child process (not using any of the objects).
It's only caller
push_unpushed_submodulesalso doesn't rely on objects loaded after callingpush_submodule.The caller of
push_unpushed_submodules(transport.c,transport_push) also doesn't need submodule objects loaded.Thanks for looking into it. This is what the commit message should say to help reviewers or people trying to understand it later. The footnotes don't help and are distracting, except that it makes sense to point out the original GSoC patch to say the alternate submodule odb wasn't needed even then.
E.g.:
Subject: push: do not add submodule odb as an alternate when recursing on demand
"git push --recurse-submodules=on-demand" adds each submodule as an alternate with
add_submodule_odbbefore checking whether the submodule has anything to push and pushing it if so.However, it never accesses any objects from the submodule. In the parent process it uses the submodule's ref database to see if there is anything to push. The actual push (which does rely on objects) occurs in a child process.
Quoted 8 lines
The same was try when this call was originally added in v1.7.11-rc0~111^2 (push: teach --recurse-submodules the on-demand option, 2012-03-29). Most likely it was added by analogy with fetch --recurse-submodules=on-demand, which did use the submodule's object database.
Use
is_submodule_populated_gentlyinstead, which is simpler and cheaper.
Thanks for giving a good example of commit message that I could use in a reroll.
Quoted 6 lines
With such a commit message change, this seems like a reasonable change in principle (though I haven't looked carefully to verify it).
My one doubt is the
is_submodule_populated_gently. Why are we using that instead of simpleris_submodule_populated? The names and API comments don't explain.
One could posit this is laziness of thinking.
See 15cdc64776 (make is_submodule_populated gently, 2017-03-14), and discover there is no non-gentle version of is_submodule_populated. And for each new use, it may be cheaper to just use the gentle version instead of adding a non-gentle version.
Thanks,
Stefan
PATCH 1/1 push: do not add submodule odb as an alternate when recursing on demand
"git push --recurse-submodules=on-demand" adds each submodule as an alternate with add_submodule_odb before checking whether the submodule has anything to push and pushing it if so.
However, it never accesses any objects from the submodule. In the parent process it uses the submodule's ref database to see if there is anything to push. The actual push (which does rely on objects) occurs in a child process.
The same was true when this call was originally added in v1.7.11-rc0~111^2 (push: teach --recurse-submodules the on-demand option, 2012-03-29). Most likely it was added by analogy with fetch --recurse-submodules=on-demand, which did use the submodule's object database.
Use is_submodule_populated_gently instead, which is simpler and cheaper.
---
Originally I intended to send this out as part of a larger series, but the series is getting too large series, sending all things in smaller units!
Thanks,
Stefan
submodule.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
submodule.c +3 -1
@@ -966,7 +966,9 @@ static int push_submodule(const char *path,const struct string_list *push_options, int dry_run) { - if (add_submodule_odb(path)) + int code; + +if (!is_submodule_populated_gently (path, &code))return 1 ;if (for_each_remote_ref_submodule (path, has_remote,NULL ) >0 ) {
Signature · 1 line
2.14.0.rc0.3.g6c2e499285
Re: [PATCH] push: do not add submodule odb as an alternate when recursing on demand
Quoted 15 lines · Stefan Beller
"git push --recurse-submodules=on-demand" adds each submodule as an alternate with
add_submodule_odbbefore checking whether the submodule has anything to push and pushing it if so.However, it never accesses any objects from the submodule. In the parent process it uses the submodule's ref database to see if there is anything to push. The actual push (which does rely on objects) occurs in a child process.
The same was true when this call was originally added in v1.7.11-rc0~111^2 (push: teach --recurse-submodules the on-demand option, 2012-03-29). Most likely it was added by analogy with fetch --recurse-submodules=on-demand, which did use the submodule's object database.
Quoted 7 lines
Use
is_submodule_populated_gentlyinstead, which is simpler and cheaper.Signed-off-by Stefan Beller <[email protected]>--- submodule.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Thanks for picking up this loose end.
Quoted 15 lines
submodule.c +3
-1@@ -966,7 +966,9 @@ static int push_submodule(const char *path,const struct string_list *push_options, int dry_run) { - if (add_submodule_odb(path)) + int code; + +if (!is_submodule_populated_gently (path, &code))return 1 ;if (for_each_remote_ref_submodule (path, has_remote,NULL ) >0 ) {
Re: [PATCH] push: do not add submodule odb as an alternate when recursing on demand
In reply to Stefan BellerQuoted 2 lines · Stefan Beller
Use
is_submodule_populated_gentlyinstead, which is simpler and cheaper.
[...]
submodule.c static int push_submodule(const char *path, · line 972
Quoted 11 lines
submodule.c +3
-1@@ -966,7 +966,9 @@ static int push_submodule(const char *path,const struct string_list *push_options, int dry_run) { - if (add_submodule_odb(path)) + int code; + +if (!is_submodule_populated_gently (path, &code))return 1 ;
Ah, I forgot about this detail. I don't think it should block this patch (so my Reviewed-by still stands), but I wonder why this needs to be gentle. add_submodule_odb is gentle so that is the conservative thing to do, but that doesn't mean it is the *right* thing to do.
If this passed NULL instead of &code as the second argument, would anything break?
Could there be a comment explaining what kind of error we are expecting and why it is okay to continue when that error is encountered without any error handling?
Thanks,
Jonathan
Re: [PATCH] push: do not add submodule odb as an alternate when recursing on demand
In reply to Stefan BellerQuoted 9 lines · Stefan Beller
"git push --recurse-submodules=on-demand" adds each submodule as an alternate with
add_submodule_odbbefore checking whether the submodule has anything to push and pushing it if so.However, it never accesses any objects from the submodule.
...
Useis_submodule_populated_gentlyinstead, which is simpler and cheaper.
Quoted 6 lines
Signed-off-by Stefan Beller <[email protected]>---
Originally I intended to send this out as part of a larger series, but the series is getting too large series, sending all things in smaller units!
This vaguely reminds me that you sent something imilar perhaps for a different codepath.
Is "is it populated" a good thing to check here, though? IIRC, add-submodule-odb allows you to add the object database of an inactivated submodule, so this seems to change the behaviour. I do not know if the behaviour change is a good thing (i.e. bugfix) or not (i.e. regression) offhand, though.
Thanks.
Quoted 15 lines
submodule.c +3
-1@@ -966,7 +966,9 @@ static int push_submodule(const char *path,const struct string_list *push_options, int dry_run) { - if (add_submodule_odb(path)) + int code; + +if (!is_submodule_populated_gently (path, &code))return 1 ;if (for_each_remote_ref_submodule (path, has_remote,NULL ) >0 ) {
Re: [PATCH] push: do not add submodule odb as an alternate when recursing on demand
In reply to Jonathan NiederQuoted 22 lines · Jonathan Nieder
Quoted 2 lines · Stefan Beller
Use
is_submodule_populated_gentlyinstead, which is simpler and cheaper.[...]
submodule.c static int push_submodule(const char *path, · line 972
Quoted 11 lines
submodule.c +3
-1@@ -966,7 +966,9 @@ static int push_submodule(const char *path,const struct string_list *push_options, int dry_run) { - if (add_submodule_odb(path)) + int code; + +if (!is_submodule_populated_gently (path, &code))return 1 ;Ah, I forgot about this detail. I don't think it should block this patch (so my Reviewed-by still stands), but I wonder why this needs to be gentle.
add_submodule_odbis gentle so that is the conservative thing to do, but that doesn't mean it is the *right* thing to do.
Quoted 2 lines
If this passed NULL instead of &code as the second argument, would anything break?
push_submodule, which is called by push_unpushed_submodules just issues warnings on submodule push error, (which happen all before the main push,) such that any submodule error does not prevent the main push.
We could tighten that, but I would suggest another patch for that.
Quoted 3 lines
Could there be a comment explaining what kind of error we are expecting and why it is okay to continue when that error is encountered without any error handling?
The same as in add_submodule_odb, digging through the logs. I up to now we did not care about the submodule succeeding as much, it was just an aid for the main repo push.
Quoted 3 lines
Thanks,
Jonathan
Re: [PATCH] push: do not add submodule odb as an alternate when recursing on demand
In reply to Junio C HamanoQuoted 14 lines · Junio C Hamano
Quoted 12 lines · Stefan Beller
"git push --recurse-submodules=on-demand" adds each submodule as an alternate with
add_submodule_odbbefore checking whether the submodule has anything to push and pushing it if so.However, it never accesses any objects from the submodule.
...
Useis_submodule_populated_gentlyinstead, which is simpler and cheaper.Signed-off-by Stefan Beller <[email protected]>---
Quoted 6 lines
Quoted 3 lines
Originally I intended to send this out as part of a larger series, but the series is getting too large series, sending all things in smaller units!
This vaguely reminds me that you sent something imilar perhaps for a different codepath.
https://public-inbox.org/git/[email protected]/
Quoted 5 lines
Is "is it populated" a good thing to check here, though? IIRC, add-submodule-odb allows you to add the object database of an inactivated submodule, so this seems to change the behaviour. I do not know if the behaviour change is a good thing (i.e. bugfix) or not (i.e. regression) offhand, though.
Good point, we should be able to push non-populated, even inactive(?) submodules. For that we strictly need add_submodule_odb here (or the repo object of the submodule, eventually).
So let's retract this patch for now.
Thanks.
Re: [PATCH] push: do not add submodule odb as an alternate when recursing on demand
Quoted 11 lines · Stefan Beller
Quoted 5 lines
Is "is it populated" a good thing to check here, though? IIRC, add-submodule-odb allows you to add the object database of an inactivated submodule, so this seems to change the behaviour. I do not know if the behaviour change is a good thing (i.e. bugfix) or not (i.e. regression) offhand, though.
Good point, we should be able to push non-populated, even inactive(?) submodules. For that we strictly need
add_submodule_odbhere (or the repo object of the submodule, eventually).So let's retract this patch for now.
Not so fast.
I am not convinced "push --recursive" should touch a submodule that was once cloned from the upstream and then deactivated, so using add-submodule-odb to decide if the push should go through may be a bug that we may want to fix, in which case the diff of the patch in question may be good as-is. We need to sell it as a bugfix to the users, who may complain about behaviour change (if there is one).
On the other hand, even if it were desirable for such a deactivated submodule to be pushed, as your log message explained, there is no reason to contaminate the in-core object hash by calling the add-submodule-odb helper, when the only thing we care about is "do we have the refs and object store for this submodule? we do not care if it is activated or not". Perhaps there is a more appropriate helper in submodule.c that answers that question that we should be using instead of add-submodule-odb, and if there is not yet such a helper, perhaps this indicates that we need to add such a helper, which essentially is the early half of what add-submodule-odb does, i.e. ask git_path_submodule() for the object store and check if that directory exists.
Thanks.
Re: [PATCH] push: do not add submodule odb as an alternate when recursing on demand
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Stefan Beller
Quoted 5 lines
Is "is it populated" a good thing to check here, though? IIRC, add-submodule-odb allows you to add the object database of an inactivated submodule, so this seems to change the behaviour. I do not know if the behaviour change is a good thing (i.e. bugfix) or not (i.e. regression) offhand, though.
Quoted 7 lines
Quoted 5 lines
Good point, we should be able to push non-populated, even inactive(?) submodules. For that we strictly need
add_submodule_odbhere (or the repo object of the submodule, eventually).So let's retract this patch for now.
Not so fast.
Ok, I took another look at the code.
While we may desire that un-populated submodules can be pushed (due to checking out another revision where the submodule doesn't exist, before pushing), this is not supported currently, because the call to run the push in the submodule assumes there is a "<path>/.git" on which the child process can operate.
So for now we HAVE to have the submodule populated.
In the future we may have the a lighter version just checking the object store of the submodule. Maybe this use case in the submodule can be covered by the .remote/.imported mechanism as well, such that we'd know if we have any local objects.
Quoted 6 lines
I am not convinced "push --recursive" should touch a submodule that was once cloned from the upstream and then deactivated, so using add-submodule-odb to decide if the push should go through may be a bug that we may want to fix, in which case the diff of the patch in question may be good as-is. We need to sell it as a bugfix to the users, who may complain about behaviour change (if there is one).
correct. Coupled with the observation above, we want really need both "is active and populated" (your paragraph suggest not-active submodules don't need pushing, the populated bit comes from the observation above)
Quoted 4 lines
On the other hand, even if it were desirable for such a deactivated submodule to be pushed, as your log message explained, there is no reason to contaminate the in-core object hash by calling the add-submodule-odb helper, when the only thing we care about is "do
Quoted 8 lines
we have the refs and object store for this submodule? we do not care if it is activated or not". Perhaps there is a more appropriate helper in
submodule.cthat answers that question that we should be using instead of add-submodule-odb, and if there is not yet such a helper, perhaps this indicates that we need to add such a helper, which essentially is the early half of what add-submodule-odb does, i.e. askgit_path_submodule()for the object store and check if that directory exists.
I think due to the constraint of also needing a worktree the is_populated helper is the correct choice here.
Quoted 2 lines
Thanks.
Re: [PATCH] push: do not add submodule odb as an alternate when recursing on demand
Hi,
Quoted 18 lines · Stefan Beller
Quoted 9 lines · Junio C Hamano
Quoted 8 lines · Stefan Beller
Quoted 5 lines · Junio C Hamano
Is "is it populated" a good thing to check here, though? IIRC, add-submodule-odb allows you to add the object database of an inactivated submodule, so this seems to change the behaviour. I do not know if the behaviour change is a good thing (i.e. bugfix) or not (i.e. regression) offhand, though.
Quoted 7 lines
Quoted 5 lines
Good point, we should be able to push non-populated, even inactive(?) submodules. For that we strictly need
add_submodule_odbhere (or the repo object of the submodule, eventually).So let's retract this patch for now.
Not so fast.
Quoted 8 lines
Ok, I took another look at the code.
While we may desire that un-populated submodules can be pushed (due to checking out another revision where the submodule doesn't exist, before pushing), this is not supported currently, because the call to run the push in the submodule assumes there is a "<path>/.git" on which the child process can operate.
So for now we HAVE to have the submodule populated.
It was not immediately obvious to me that this is just "for now".
I would be really confused if I had deactivated a submodule and "git push --recurse-submodules" pushed from it anyway. If the submodule is active but not populated, then the question becomes "Why wasn't it populated?"
If this is a bare repository, then nothing is populated, and pushing from an active-but-unpopulated submodule sounds like a plausible wish. But in a non-bare repository, I'm having trouble imagining the use case that brings this situation about.
And where people have been needing this so far has been non-bare repositories. In that context, the check "is active and populated" does not seem unusual or provisional. Are you hinting that replacing the check with "is active" would make it work well in bare repositories? I think I agree, though you'd have to be careful about the case where the submodule is active but hasn't been fetched to $GIT_DIR/modules yet.
Thanks,
Jonathan
Re: [PATCH] push: do not add submodule odb as an alternate when recursing on demand
Quoted 30 lines · Jonathan Nieder
Hi,
Quoted 18 lines · Stefan Beller
Quoted 9 lines · Junio C Hamano
Quoted 8 lines · Stefan Beller
Quoted 5 lines · Junio C Hamano
Is "is it populated" a good thing to check here, though? IIRC, add-submodule-odb allows you to add the object database of an inactivated submodule, so this seems to change the behaviour. I do not know if the behaviour change is a good thing (i.e. bugfix) or not (i.e. regression) offhand, though.
Quoted 7 lines
Quoted 5 lines
Good point, we should be able to push non-populated, even inactive(?) submodules. For that we strictly need
add_submodule_odbhere (or the repo object of the submodule, eventually).So let's retract this patch for now.
Not so fast.
Quoted 8 lines
Ok, I took another look at the code.
While we may desire that un-populated submodules can be pushed (due to checking out another revision where the submodule doesn't exist, before pushing), this is not supported currently, because the call to run the push in the submodule assumes there is a "<path>/.git" on which the child process can operate.
So for now we HAVE to have the submodule populated.
Quoted 4 lines
It was not immediately obvious to me that this is just "for now".
I would be really confused if I had deactivated a submodule and "git push --recurse-submodules" pushed from it anyway.
agreed.
Quoted 3 lines
If the
submodule is active but not populated, then the question becomes "Why wasn't it populated?"
because you checked out a different revision where the sub is not part of the working tree, for example. As long as you have locally interesting "stuff" you want to transfer it. (IMHO even when the sub is not active)
Quoted 1 line
If this is a bare repository, then nothing is populated,
Currently bare repos do not support having submodules AT ALL, i.e. there is no modules/<name> directory where the submodules would have any valuable information. instead we *only* have the .gitmodules files at e.g. HEAD.
Quoted 2 lines
and pushing
from an active-but-unpopulated submodule sounds like a plausible wish.
it seems we're on the same page here.
Quoted 2 lines
But in a non-bare repository, I'm having trouble imagining the use case that brings this situation about.
git checkout revision-with-sub
# hack.. hack.. hack.. "git commit --recurse-submodules -m bugfix" # ^ not yet implemented git checkout revision-without-sub # Oh! I forgot to push the bugfix git push --recurse-submodule <bugfix>
Quoted 5 lines
And where people have been needing this so far has been non-bare repositories. In that context, the check "is active and populated" does not seem unusual or provisional. Are you hinting that replacing the check with "is active" would make it work well in bare repositories?
No I was saying:
* currently the code only works when "is populated"
* currently "is active" seems not to be considered
* in the future the code shall work even when not "is populated", (but submodule git dir is there at the very least)
* we may want to discuss if we want to care about "is active" additionally
Quoted 3 lines
I think I agree, though you'd have to be careful about
the case where the submodule is active but hasn't been fetched to $GIT_DIR/modules yet.
When not fetched yet, there is no modules/<name> git dir and we are sure there is no locally interesting information, so we want to omit the push. (see above "has git dir" is the minimum requirement, as opposed to current "is populated".
Quoted 2 lines
Thanks,
Jonathan
Re: [PATCH] push: do not add submodule odb as an alternate when recursing on demand
In reply to Stefan BellerHi,
was about to write that we are maybe overly cautious here. Because the current way a submodule ends up in the list to be pushed is through:
find_unpushed_submodules()
that itself collects all changed submodules when submodule_needs_pushing() is true. In there we have this:
if (!submodule_has_commits(path, commits))
/*
* NOTE: We do consider it safe to return "no" here. The
* correct answer would be "We do not know" instead of
* "No push needed", but it is quite hard to change
* the submodule pointer without having the submodule
* around. If a user did however change the submodules
* without having the submodule around, this indicates
* an expert who knows what they are doing or a
* maintainer integrating work from other people. In
* both cases it should be safe to skip this check. */
return 0;
So if the check, whether a submodule has commits, fails for any reason it will not end up in the list to be pushed.
As a side note: inside submodule_has_commits() there is an add_submodule_odb() followed by a process to really make sure that the commits are in the submodule.
So IMO at this point we can be sure that the *database* exists and this extra check could be dropped if we said that a caller to push_submodule() should make sure that the submodule exists. The current ones are doing it already (if I did not miss anything).
Quoted 17 lines · Stefan Beller
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Stefan Beller
Quoted 5 lines
Is "is it populated" a good thing to check here, though? IIRC, add-submodule-odb allows you to add the object database of an inactivated submodule, so this seems to change the behaviour. I do not know if the behaviour change is a good thing (i.e. bugfix) or not (i.e. regression) offhand, though.
Quoted 7 lines
Quoted 5 lines
Good point, we should be able to push non-populated, even inactive(?) submodules. For that we strictly need
add_submodule_odbhere (or the repo object of the submodule, eventually).So let's retract this patch for now.
Not so fast.
Quoted 8 lines
Ok, I took another look at the code.
While we may desire that un-populated submodules can be pushed (due to checking out another revision where the submodule doesn't exist, before pushing), this is not supported currently, because the call to run the push in the submodule assumes there is a "<path>/.git" on which the child process can operate.
So for now we HAVE to have the submodule populated.
That is a good point though. In the current form of push_submodule() we need to have a populated submodule. So IMO to check whether the submodule is actually *populated* instead of adding the odb is correct and a possible bug fix.
Cheers Heiko