git-p4.py: Don't try to rebase on submit from bare repository
PATCH 1/1 git-p4.py: Don't try to rebase on submit from bare repository
git-p4 can be successfully used from bare repository (which acts as a bridge between Perforce repository and pure Git repositories). On submit git-p4 performs unconditional rebase. Do rebase only on non-bare repositories.
--- git-p4.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
git-p4.py +3 -2
@@ -2059,8 +2059,9 @@ class P4Submit(Command, P4UserMap): sync.branch = self.branch sync.run([]) - rebase = P4Rebase() - rebase.rebase() + if not gitConfigBool("core.bare"): + rebase = P4Rebase() + rebase.rebase() else: if len(applied) == 0:
Signature · 1 line
2.7.0
Quoted 4 lines · Amadeusz Żołnowski
git-p4 can be successfully used from bare repository (which acts as a bridge between Perforce repository and pure Git repositories). On submit git-p4 performs unconditional rebase. Do rebase only on non-bare repositories.
This looks obviously sensible and good to me, ack.
Thanks!
Luke
Quoted 27 lines
--- git-p4.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)git-p4.py +3
-3@@ -2059,8 +2059,9 @@ class P4Submit(Command, P4UserMap): sync.branch = self.branch sync.run([]) - rebase = P4Rebase() - rebase.rebase() + if not gitConfigBool("core.bare"): + rebase = P4Rebase() + rebase.rebase() else: if len(applied) == 0: --2.7.0
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · Luke Diamand
Quoted 4 lines · Amadeusz Żołnowski
git-p4 can be successfully used from bare repository (which acts as a bridge between Perforce repository and pure Git repositories). On submit git-p4 performs unconditional rebase. Do rebase only on non-bare repositories.
This looks obviously sensible and good to me, ack.
Thanks!
Luke
Luke, thanks for a prompt feedback.
Amadeusz, can you sign off your patch (cf. Documentation/SubmittingPatches)?
Quoted 30 lines
Quoted 30 lines
--- git-p4.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)git-p4.py +3
-3@@ -2059,8 +2059,9 @@ class P4Submit(Command, P4UserMap): sync.branch = self.branch sync.run([]) - rebase = P4Rebase() - rebase.rebase() + if not gitConfigBool("core.bare"): + rebase = P4Rebase() + rebase.rebase() else: if len(applied) == 0: --2.7.0
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/1 git-p4.py: Don't try to rebase on submit from bare repository
git-p4 can be successfully used from bare repository (which acts as a bridge between Perforce repository and pure Git repositories). On submit git-p4 performs unconditional rebase. Do rebase only on non-bare repositories.
--- git-p4.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
git-p4.py +3 -2
@@ -2059,8 +2059,9 @@ class P4Submit(Command, P4UserMap): sync.branch = self.branch sync.run([]) - rebase = P4Rebase() - rebase.rebase() + if not gitConfigBool("core.bare"): + rebase = P4Rebase() + rebase.rebase() else: if len(applied) == 0:
Signature · 1 line
2.7.0
Quoted 4 lines · Amadeusz Żołnowski
git-p4 can be successfully used from bare repository (which acts as a bridge between Perforce repository and pure Git repositories). On submit git-p4 performs unconditional rebase. Do rebase only on non-bare repositories.
As a person who does not use Perforce, it is not obvious to me from the commit message why this change is beneficial or even what the consequences are. Will Perforce users understand this change given only the explanation above? If not, perhaps it would be helpful to expand the commit message to explain more thoroughly the impact of this change and why it is a good idea.
Thanks.
Quoted 23 lines
Signed-off-by Amadeusz Żołnowski <[email protected]>--- git-p4.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)git-p4.py +3
-3@@ -2059,8 +2059,9 @@ class P4Submit(Command, P4UserMap): sync.branch = self.branch sync.run([]) - rebase = P4Rebase() - rebase.rebase() + if not gitConfigBool("core.bare"): + rebase = P4Rebase() + rebase.rebase() else: if len(applied) == 0: --2.7.0
PATCH 1/1 git-p4.py: Make submit working on bare repository
git-p4 can be successfully used from bare repository (which may act as a bridge between Perforce repository and pure Git repositories). After submitting changelist to Perforce, git-p4 performs unconditional rebase which obviously fails.
Perform rebase only on non-bare repositories, so submit command can be successful on bare repository.
--- git-p4.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
git-p4.py +3 -2
@@ -2059,8 +2059,9 @@ class P4Submit(Command, P4UserMap): sync.branch = self.branch sync.run([]) - rebase = P4Rebase() - rebase.rebase() + if not gitConfigBool("core.bare"): + rebase = P4Rebase() + rebase.rebase() else: if len(applied) == 0:
Signature · 1 line
2.7.0
Re: [PATCH] git-p4.py: Make submit working on bare repository
Quoted 7 lines · Amadeusz Żołnowski
git-p4 can be successfully used from bare repository (which may act as a bridge between Perforce repository and pure Git repositories). After submitting changelist to Perforce, git-p4 performs unconditional rebase which obviously fails.
Perform rebase only on non-bare repositories, so submit command can be successful on bare repository.
It is obvious that an attempt to run rebase would fail in a bare repository, and skipping it would obviously make it not fail.
I think that part is well understood.
What is unclear is what the ramification of _not_ rebasing after submitting is.
In other words, why do we have to rebase after submitting when we are in a non-bare repository? There must be a reason behind it, i.e. "If we do not rebase, then the repository would be in a state where future operations like X and Y do not work correctly because of Z".
And why does that same reason Z not apply when we submit from a bare repository?
A possible explanation might be that X and Y are operations that happen only in a non-bare repository that we do not have to worry about happening in a bare repository after we finish submitting.
But these X, Y and Z are left unexplained--that is what is unclear in the original proposed log message, and it is still unclear in the above update.
Thanks.
Quoted 21 lines
Signed-off-by Amadeusz Żołnowski <[email protected]>--- git-p4.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)git-p4.py +3
-2@@ -2059,8 +2059,9 @@ class P4Submit(Command, P4UserMap): sync.branch = self.branch sync.run([]) - rebase = P4Rebase() - rebase.rebase() + if not gitConfigBool("core.bare"): + rebase = P4Rebase() + rebase.rebase() else: if len(applied) == 0:
Re: [PATCH] git-p4.py: Make submit working on bare repository
Hi Junio,
To submit changes from master branch to Perforce, new commits should be based on a remote branch p4/master:
(1)
E'---F' master
/
A---B---C---D p4/masterCommits from A to D map to Perforce changelists. These commits include additional metadata in commit message which most important is changelist number.
On submit git-p4 prepares changelists for commits E'-F' and submits these to Perforce repository. After this operation it syncs back remote branch p4/master. This is the common part for both bare and non-bare repository.
(2)
E'---F' master
/
A---B---C---D---E---F p4/masterIn non-bare repository git rebase is performed and it results in following state:
(3)
A---B---C---D---E---F p4/master, master
In bare repository this operation cannot be performed, so it remains in state (2).
With special care state (2) can be transformed to state (3) with manual update of refs/heads/master with refs/remotes/p4/master.
I understand that implementing rebase for bare repository is unsafe and it wouldn't be appreciated. Therefore we have to resort to such a barbarity and git-p4 submit shouldn't attempt to perform a rebase operation itself. Especially because it performs other operations before and we end up in the intermediate state (2) anyway.
Is this explanation satisfactory? If yes, I'll include it in patch description.
Kind regards,
Signature · 1 line
Amadeusz Żołnowski
Re: [PATCH] git-p4.py: Make submit working on bare repository
Quoted 22 lines · Amadeusz Żołnowski
To submit changes from master branch to Perforce, new commits should be based on a remote branch p4/master:
(1)
E'---F' master / A---B---C---D p4/masterCommits from A to D map to Perforce changelists. These commits include additional metadata in commit message which most important is changelist number.
On submit git-p4 prepares changelists for commits E'-F' and submits these to Perforce repository. After this operation it syncs back remote branch p4/master. This is the common part for both bare and non-bare repository.
(2)
E'---F' master / A---B---C---D---E---F p4/master
Quoted 5 lines
In non-bare repository git rebase is performed and it results in following state:
(3)
A---B---C---D---E---F p4/master, master
That is because you would want your further work to be built on top of F, not F'.
Quoted 2 lines
In bare repository this operation cannot be performed, so it remains in state (2).
And that is what made me wonder.
Quoted 2 lines
With special care state (2) can be transformed to state (3) with manual update of refs/heads/master with refs/remotes/p4/master.
What do you mean by transforming with special care? Do you mean running
$ git update-ref master remotes/p4/master
or does it involve something else? Is it a fairly involved procedure, I wonder if it makes sense to just silently allowing submit without rebasing, and without telling the user how to clean it up.
And if it is really is the matter of update-ref, wouldn't that procedure apply equally well to a submit made from a non-bare repository?
Quoted 7 lines
I understand that implementing rebase for bare repository is unsafe and it wouldn't be appreciated. Therefore we have to resort to such a barbarity and git-p4 submit shouldn't attempt to perform a rebase operation itself. Especially because it performs other operations before and we end up in the intermediate state (2) anyway.
Is this explanation satisfactory?
Not quite yet. It is better than no explanation, but it does not quite convince me (a non-git-p4 user) that it makes sense to allow submitting in a bare repository in the first place.
This is not an informed objection; I want to first understand why doing this is safe and does not hurt the end users.
Re: [PATCH] git-p4.py: Make submit working on bare repository
Quoted 2 lines · Junio C Hamano
I wonder if it makes sense to just silently allowing submit without rebasing, and without telling the user how to clean it up.
It is a good point. Maybe submit shouldn't be allowed by default at all From bare repository. What do you think about following approach? If core.base is true, then if git-p4.submitFromBare is also true then submit without performing proper rebase, but update master ref from p4/master. If core.base is true, but git-p4.submitFromBare is false, abort immediately. Submitting from bare repository would require aware decision from a user.
Kind regards,
Signature · 1 line
Amadeusz Żołnowski
Re: [PATCH] git-p4.py: Make submit working on bare repository
Quoted 11 lines · Amadeusz Żołnowski
Quoted 2 lines · Junio C Hamano
I wonder if it makes sense to just silently allowing submit without rebasing, and without telling the user how to clean it up.
It is a good point. Maybe submit shouldn't be allowed by default at all From bare repository. What do you think about following approach? If core.base is true, then if git-p4.submitFromBare is also true then submit without performing proper rebase, but update master ref from p4/master. If core.base is true, but git-p4.submitFromBare is false, abort immediately. Submitting from bare repository would require aware decision from a user.
(I think you meant "bare" where you wrote "base" in the above).
As a non user of git-p4, the above sounds a safe and sensible approach, but I'd like to hear from Luke, who has been active in this area and is far more expert than I am ;-)
Thanks.
Re: [PATCH] git-p4.py: Make submit working on bare repository
Quoted 14 lines · Junio C Hamano
Quoted 11 lines · Amadeusz Żołnowski
Quoted 2 lines · Junio C Hamano
I wonder if it makes sense to just silently allowing submit without rebasing, and without telling the user how to clean it up.
It is a good point. Maybe submit shouldn't be allowed by default at all From bare repository. What do you think about following approach? If core.base is true, then if git-p4.submitFromBare is also true then submit without performing proper rebase, but update master ref from p4/master. If core.base is true, but git-p4.submitFromBare is false, abort immediately. Submitting from bare repository would require aware decision from a user.
Quoted 5 lines
(I think you meant "bare" where you wrote "base" in the above).
As a non user of git-p4, the above sounds a safe and sensible approach, but I'd like to hear from Luke, who has been active in this area and is far more expert than I am ;-)
Sorry, I've been travelling so not been able to reply earlier. Jetlag has now kicked-in, and 4am is the perfect time to reply to this!
I think it would help to understand why we're doing a git-p4 submit from a bare repo in the first place.
The usual workflow is you have a normal repo and submit from that.
I'm guessing that the reason for using a bare repo is so that changes can be pushed to it from several different git repos. This then saves doing the initial git-p4 clone multiple times.
As Amadeusz pointed out, the submit fails:
$ git p4 submit --git-dir=/path/to/bare/repo ... ... fatal: This operation must be run in a work tree Some files in your working directory are modified and different than what is in your index. You can use git update-index <filename> to bring the index up-to-date or stash away all your changes with git stash.
If this had actually worked, I think the next thing I would want to do is to rebase one or more branches in the bare repo against p4/master. I don't think there's any way that git-p4 can work out which branches would be rebased, and nor should it.
I think the approach of using a submitFromBare config variable to force the user to make a choice feels a bit bogus, since they clearly *want* to submit from this bare repo, as otherwise they wouldn't have done "git-p4 submit" in the first place.
It might make sense to have a command-line or config option ("--skip-rebase" ?) to tell "submit" to only do the submit part, and skip the rebase stage (and get the rebase stage to give a more useful error message on a bare repo when the option isn't used). That would then mean that git-p4 does not have to know if it's running in a bare repo or not, and the submit-without-rebase functionality is available to people doing other different things not involving bare repos (which we haven't though of yet) but still requiring submit without rebase.
Luke
Quoted 3 lines
Thanks.
Re: [PATCH] git-p4.py: Make submit working on bare repository
Hi Luke,
Quoted 3 lines · Luke Diamand
I'm guessing that the reason for using a bare repo is so that changes can be pushed to it from several different git repos. This then saves doing the initial git-p4 clone multiple times.
I have created a Git repository acting as a bridge between Perforce and pure Git repos. Changes pushed to master branch on this bridge repo get submitted to Perforce repository (referenced via remote p4/master).
Quoted 4 lines
If this had actually worked, I think the next thing I would want to do is to rebase one or more branches in the bare repo against p4/master. I don't think there's any way that git-p4 can work out which branches would be rebased, and nor should it.
It actually has all information needed. It submits commits from a given branch to a branch specified with --branch option (or default p4 remote). When submitting from a non-bare repo git-p4 has the same set of
information: the current branch and a branch specified with --branch (or default p4 remote).
Quoted 4 lines
I think the approach of using a submitFromBare config variable to force the user to make a choice feels a bit bogus, since they clearly *want* to submit from this bare repo, as otherwise they wouldn't have done "git-p4 submit" in the first place.
I agree, a good point.
Quoted 8 lines
It might make sense to have a command-line or config option ("--skip-rebase" ?) to tell "submit" to only do the submit part, and skip the rebase stage (and get the rebase stage to give a more useful error message on a bare repo when the option isn't used). That would then mean that git-p4 does not have to know if it's running in a bare repo or not, and the submit-without-rebase functionality is available to people doing other different things not involving bare repos (which we haven't though of yet) but still requiring submit without rebase.
While having additional --skip-rebase is a good idea, having git-p4 doing rebase would be more elegant for those who actually use GitP4 in bare repository. In message [email protected] I have described how state of branches changes during submit. It clearly shows that in case of a bare repository it ends up in undesired state.
To simplify things, why not just update ref during submit from bare repository? As you have pointed out, if user invokes submit in this context he/she actually wants to submit from bare repo and probably knows what he/she is doing - especially if he/she reads man page. (-:
Kind regards,
Signature · 1 line
Amadeusz Żołnowski
Re: [PATCH] git-p4.py: Make submit working on bare repository
Quoted 5 lines · Amadeusz Żołnowski
To simplify things, why not just update ref during submit from bare repository? As you have pointed out, if user invokes submit in this context he/she actually wants to submit from bare repo and probably knows what he/she is doing - especially if he/she reads man page. (-:
Will it do something sensible if anything goes wrong?
I'm thinking about what happens if you submit and one of the commits fails to go to P4 due to a merge conflict.
But I guess just doing an update-ref could be an OK thing to do. Without actually trying it out for real though I can't be sure. It might make sense to get some practical experience of how this works out.
Luke
Re: [PATCH] git-p4.py: Make submit working on bare repository
Quoted 11 lines · Luke Diamand
Quoted 5 lines · Amadeusz Żołnowski
To simplify things, why not just update ref during submit from bare repository? As you have pointed out, if user invokes submit in this context he/she actually wants to submit from bare repo and probably knows what he/she is doing - especially if he/she reads man page. (-:
Will it do something sensible if anything goes wrong?
I'm thinking about what happens if you submit and one of the commits fails to go to P4 due to a merge conflict.
Handling failures in this case is a bit tricky, indeed.
Quoted 4 lines
But I guess just doing an update-ref could be an OK thing to do. Without actually trying it out for real though I can't be sure. It might make sense to get some practical experience of how this works out.
True. For now I have these cases covered by wrapper scripts. The minimum I need from git-p4 is just not to fail on git submit from bare repository which is covered by patch I have submitted. If I get my solution enough testing, I'd think of transforming it into patch for git-p4.py as well.
Signature · 1 line
Amadeusz Żołnowski
Re: [PATCH] git-p4.py: Make submit working on bare repository
Quoted 6 lines · Amadeusz Żołnowski
True. For now I have these cases covered by wrapper scripts. The minimum I need from git-p4 is just not to fail on git submit from bare repository which is covered by patch I have submitted. If I get my solution enough testing, I'd think of transforming it into patch for
git-p4.pyas well.
Could you change the patch to add a command-line option to suppress the rebase? I think this would be a bit more obvious: instead of having some special magical behaviour kick-in on a bare repo, git-p4 just does what it's told on the command-line.
It means that if we find another situation where we don't want to rebase, we don't have an ever-growing list of special-case circumstances, which could become hard to make sense of in future. Instead, the user (who hopefully knows better) just tells git-p4 what to do.
Thanks!
Luke
Re: [PATCH] git-p4.py: Make submit working on bare repository
Quoted 14 lines · Luke Diamand
Quoted 6 lines · Amadeusz Żołnowski
True. For now I have these cases covered by wrapper scripts. The minimum I need from git-p4 is just not to fail on git submit from bare repository which is covered by patch I have submitted. If I get my solution enough testing, I'd think of transforming it into patch for
git-p4.pyas well.Could you change the patch to add a command-line option to suppress the rebase? I think this would be a bit more obvious: instead of having some special magical behaviour kick-in on a bare repo, git-p4 just does what it's told on the command-line.
Quoted 5 lines
It means that if we find another situation where we don't want to rebase, we don't have an ever-growing list of special-case circumstances, which could become hard to make sense of in future. Instead, the user (who hopefully knows better) just tells git-p4 what to do.
Has anything happened to this topic after this? I am wondering if I should discard the topic az/p4-bare-no-rebase without prejudice.
Thanks.
Re: [PATCH] git-p4.py: Make submit working on bare repository
Hi,
Quoted 2 lines · Junio C Hamano
Has anything happened to this topic after this? I am wondering if I should discard the topic az/p4-bare-no-rebase without prejudice.
Sorry, I haven't got time to take a loot at this, but I'll return to that soon, OK? I'll prepare a patch with an option to skip rebase rather than do it only for bare repos.
Signature · 1 line
Amadeusz Żołnowski
Re: [PATCH] git-p4.py: Make submit working on bare repository
Quoted 6 lines · Amadeusz Żołnowski
Quoted 2 lines
Has anything happened to this topic after this? I am wondering if I should discard the topic az/p4-bare-no-rebase without prejudice.
Sorry, I haven't got time to take a loot at this, but I'll return to that soon, OK? I'll prepare a patch with an option to skip rebase rather than do it only for bare repos.
No hurries.
With or without an option, I think the documentation needs to clarify when it is safe to omit rebase and why.
Re: [PATCH] git-p4.py: Make submit working on bare repository
Quoted 4 lines · Junio C Hamano
Quoted 2 lines · Amadeusz Żołnowski
Quoted 2 lines
Has anything happened to this topic after this? I am wondering if I should discard the topic az/p4-bare-no-rebase without prejudice.
I think you can discard the topic, because we're moving away from Perforce and while I have tested my original patch I haven't found time to change it to --skip-rebase option as suggested and test it.
Thanks,
Signature · 1 line
Amadeusz Żołnowski