git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] git-p4: improve branch option handling
@ 2017-04-20 13:52 Andrew Oakley
  2017-04-20 17:48 ` Luke Diamand
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Oakley @ 2017-04-20 13:52 UTC (permalink / raw)
  To: git; +Cc: luke, larsxschneider, 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.

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] git-p4: improve branch option handling
  2017-04-20 13:52 [PATCH] git-p4: improve branch option handling Andrew Oakley
@ 2017-04-20 17:48 ` Luke Diamand
  0 siblings, 0 replies; 2+ messages in thread
From: Luke Diamand @ 2017-04-20 17:48 UTC (permalink / raw)
  To: Andrew Oakley; +Cc: Git Users, Lars Schneider

On 20 April 2017 at 14:52, Andrew Oakley <aoakley@roku.com> wrote:
> 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?


>
> 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
>

Apart from the typo above, this looks sensible to me. Would you be
able to add a test case?

Thanks!
Luke

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-04-20 17:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-20 13:52 [PATCH] git-p4: improve branch option handling Andrew Oakley
2017-04-20 17:48 ` Luke Diamand

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).