On 20 April 2017 at 14:52, Andrew Oakley <aoak...@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 <aoak...@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

Reply via email to