git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-p4: improve branch option handling

From
Andrew Oakley <aoakley@roku.com>
Date
Apr 20, 2017, 13:52 UTC
Message-ID
<20170420135232.16415-1-aoakley@roku.com>

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.

Signed-off-by: Andrew Oakley <aoakley@roku.com>
---
 Documentation/git-p4.txt |  4 ++++
 git-p4.py                | 15 +++++++--------
 2 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt
index 7436c64..a03a291 100644
--- a/Documentation/git-p4.txt
+++ b/Documentation/git-p4.txt
@@ -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.
 
diff --git a/git-p4.py b/git-p4.py
index 8d151da..e58b34a 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -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([])
 
-- 
2.10.2
Next: Luke Diamand
Message 1 of 2 in “git-p4: improve branch option handling”
  1. git-p4: improve branch option handlingAndrew Oakley, Apr 20, 2017
  2. Luke DiamandApr 20, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.