git-p4: improve branch option handling
PATCH 1/1 git-p4: improve branch option handling
It is sometimes useful (much quicker) to request commands only operate on a single branch.
The P4Sync command has been updated to handle self.branch being None for consitency with the P4Submit.
The P4Rebase command has been given a branch option which is forwarded to the P4Sync command it runs.
The P4Submit command has been simplified to not call P4Sync itself, it lets P4Rebase do it instead (now that the branch can be handled). This fixes an issue where P4Submit does a sync of the requested branch and then does a rebase which does a sync of all branches.
--- Documentation/git-p4.txt | 4 ++++ git-p4.py | 15 +++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-)
Documentation/git-p4.txt +4 -0
@@ -328,6 +328,10 @@ Rebase options ~~~~~~~~~~~~~~ These options can be used to modify 'git p4 rebase' behavior. +--branch <branch>:: + Sync this named branch instead of the default p4/master. See the + "Sync options" section above for more information. + --import-labels:: Import p4 labels.
git-p4.py +7 -8
@@ -2161,13 +2161,9 @@ class P4Submit(Command, P4UserMap): elif len(commits) == len(applied): print ("All commits {0}!".format(shelved_applied)) - sync = P4Sync() - if self.branch: - sync.branch = self.branch - sync.run([]) - rebase = P4Rebase() - rebase.rebase() + rebase.branch = self.branch + rebase.run([]) else: if len(applied) == 0:
@@ -2343,7 +2339,7 @@ class P4Sync(Command, P4UserMap): self.silent = False self.createdBranches = set() self.committedChanges = set() - self.branch = "" + self.branch = None self.detectBranches = False self.detectLabels = False self.importLabels = False
@@ -3281,7 +3277,7 @@ class P4Sync(Command, P4UserMap): system("git fetch origin") branch_arg_given = bool(self.branch) - if len(self.branch) == 0: + if not branch_arg_given: self.branch = self.refPrefix + "master" if gitBranchExists("refs/heads/p4") and self.importIntoRemotes: system("git update-ref %s refs/heads/p4" % self.branch)
@@ -3567,14 +3563,17 @@ class P4Rebase(Command): def __init__(self): Command.__init__(self) self.options = [ + optparse.make_option("--branch", dest="branch"), optparse.make_option("--import-labels", dest="importLabels", action="store_true"), ] + self.branch = None self.importLabels = False self.description = ("Fetches the latest revision from perforce and " + "rebases the current work (branch) against it") def run(self, args): sync = P4Sync() + sync.branch = self.branch sync.importLabels = self.importLabels sync.run([])
Signature · 1 line
2.10.2
Quoted 5 lines · Andrew Oakley
It is sometimes useful (much quicker) to request commands only operate on a single branch.
The P4Sync command has been updated to handle self.branch being None for consitency with the P4Submit.
Should that be consistency?
Quoted 87 lines
The P4Rebase command has been given a branch option which is forwarded to the P4Sync command it runs.
The P4Submit command has been simplified to not call P4Sync itself, it lets P4Rebase do it instead (now that the branch can be handled). This fixes an issue where P4Submit does a sync of the requested branch and then does a rebase which does a sync of all branches.
Signed-off-by Andrew Oakley <[email protected]>--- Documentation/git-p4.txt | 4 ++++ git-p4.py | 15 +++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-)Documentation/git-p4.txt +4
-0@@ -328,6 +328,10 @@ Rebase options ~~~~~~~~~~~~~~ These options can be used to modify 'git p4 rebase' behavior. +--branch <branch>:: + Sync this named branch instead of the default p4/master. See the + "Sync options" section above for more information. + --import-labels:: Import p4 labels.git-p4.py +7
-9@@ -2161,13 +2161,9 @@ class P4Submit(Command, P4UserMap): elif len(commits) == len(applied): print ("All commits {0}!".format(shelved_applied)) - sync = P4Sync() - if self.branch: - sync.branch = self.branch - sync.run([]) - rebase = P4Rebase() - rebase.rebase() + rebase.branch = self.branch + rebase.run([]) else: if len(applied) == 0:@@ -2343,7 +2339,7 @@ class P4Sync(Command, P4UserMap): self.silent = False self.createdBranches = set() self.committedChanges = set() - self.branch = "" + self.branch = None self.detectBranches = False self.detectLabels = False self.importLabels = False@@ -3281,7 +3277,7 @@ class P4Sync(Command, P4UserMap): system("git fetch origin") branch_arg_given = bool(self.branch) - if len(self.branch) == 0: + if not branch_arg_given: self.branch = self.refPrefix + "master" if gitBranchExists("refs/heads/p4") and self.importIntoRemotes: system("git update-ref %s refs/heads/p4" % self.branch)@@ -3567,14 +3563,17 @@ class P4Rebase(Command): def __init__(self): Command.__init__(self) self.options = [ + optparse.make_option("--branch", dest="branch"), optparse.make_option("--import-labels", dest="importLabels", action="store_true"), ] + self.branch = None self.importLabels = False self.description = ("Fetches the latest revision from perforce and " + "rebases the current work (branch) against it") def run(self, args): sync = P4Sync() + sync.branch = self.branch sync.importLabels = self.importLabels sync.run([]) --
Quoted 2 lines
2.10.2
Apart from the typo above, this looks sensible to me. Would you be able to add a test case?
Thanks!
Luke