{"thread":{"id":"45758","subject":"[PATCH] git-p4: improve branch option handling","startedAt":"2017-04-20T13:54:12Z","lastAt":"2017-04-20T17:48:12Z","messageCount":2,"participants":["Andrew Oakley","Luke Diamand"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"317345","messageId":"20170420135232.16415-1-aoakley@roku.com","threadId":"45758","inReplyTo":null,"subject":"[PATCH] git-p4: improve branch option handling","fromName":"Andrew Oakley","fromEmail":"aoakley@roku.com","sentAt":"2017-04-20T13:52:32Z","receivedAt":"2017-04-20T13:54:12Z","isPatch":true,"sender":{"key":"aoakley@roku.com","avatar":"https://avatars.githubusercontent.com/u/20188136?v=4"},"body":"It is sometimes useful (much quicker) to request commands only operate\non a single branch.\n\nThe P4Sync command has been updated to handle self.branch being None for\nconsitency with the P4Submit.\n\nThe P4Rebase command has been given a branch option which is forwarded\nto the P4Sync command it runs.\n\nThe P4Submit command has been simplified to not call P4Sync itself, it\nlets P4Rebase do it instead (now that the branch can be handled).  This\nfixes an issue where P4Submit does a sync of the requested branch and\nthen does a rebase which does a sync of all branches.\n\nSigned-off-by: Andrew Oakley <aoakley@roku.com>\n---\n Documentation/git-p4.txt |  4 ++++\n git-p4.py                | 15 +++++++--------\n 2 files changed, 11 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt\nindex 7436c64..a03a291 100644\n--- a/Documentation/git-p4.txt\n+++ b/Documentation/git-p4.txt\n@@ -328,6 +328,10 @@ Rebase options\n ~~~~~~~~~~~~~~\n These options can be used to modify 'git p4 rebase' behavior.\n \n+--branch <branch>::\n+\tSync this named branch instead of the default p4/master.  See the\n+\t\"Sync options\" section above for more information.\n+\n --import-labels::\n \tImport p4 labels.\n \ndiff --git a/git-p4.py b/git-p4.py\nindex 8d151da..e58b34a 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -2161,13 +2161,9 @@ class P4Submit(Command, P4UserMap):\n         elif len(commits) == len(applied):\n             print (\"All commits {0}!\".format(shelved_applied))\n \n-            sync = P4Sync()\n-            if self.branch:\n-                sync.branch = self.branch\n-            sync.run([])\n-\n             rebase = P4Rebase()\n-            rebase.rebase()\n+            rebase.branch = self.branch\n+            rebase.run([])\n \n         else:\n             if len(applied) == 0:\n@@ -2343,7 +2339,7 @@ class P4Sync(Command, P4UserMap):\n         self.silent = False\n         self.createdBranches = set()\n         self.committedChanges = set()\n-        self.branch = \"\"\n+        self.branch = None\n         self.detectBranches = False\n         self.detectLabels = False\n         self.importLabels = False\n@@ -3281,7 +3277,7 @@ class P4Sync(Command, P4UserMap):\n                 system(\"git fetch origin\")\n \n         branch_arg_given = bool(self.branch)\n-        if len(self.branch) == 0:\n+        if not branch_arg_given:\n             self.branch = self.refPrefix + \"master\"\n             if gitBranchExists(\"refs/heads/p4\") and self.importIntoRemotes:\n                 system(\"git update-ref %s refs/heads/p4\" % self.branch)\n@@ -3567,14 +3563,17 @@ class P4Rebase(Command):\n     def __init__(self):\n         Command.__init__(self)\n         self.options = [\n+                optparse.make_option(\"--branch\", dest=\"branch\"),\n                 optparse.make_option(\"--import-labels\", dest=\"importLabels\", action=\"store_true\"),\n         ]\n+        self.branch = None\n         self.importLabels = False\n         self.description = (\"Fetches the latest revision from perforce and \"\n                             + \"rebases the current work (branch) against it\")\n \n     def run(self, args):\n         sync = P4Sync()\n+        sync.branch = self.branch\n         sync.importLabels = self.importLabels\n         sync.run([])\n \n-- \n2.10.2\n\n"},{"id":"317360","messageId":"CAE5ih7-V6JzG8RZBoVDxGAOPuFt86r+UC1t5adKre29CFu8bOw@mail.gmail.com","threadId":"45758","inReplyTo":"20170420135232.16415-1-aoakley@roku.com","subject":"Re: [PATCH] git-p4: improve branch option handling","fromName":"Luke Diamand","fromEmail":"luke@diamand.org","sentAt":"2017-04-20T17:48:04Z","receivedAt":"2017-04-20T17:48:12Z","isPatch":true,"sender":{"key":"luke@diamand.org","avatar":"https://avatars.githubusercontent.com/u/5330967?v=4"},"body":"On 20 April 2017 at 14:52, Andrew Oakley <aoakley@roku.com> wrote:\n> It is sometimes useful (much quicker) to request commands only operate\n> on a single branch.\n>\n> The P4Sync command has been updated to handle self.branch being None for\n> consitency with the P4Submit.\n\nShould that be consistency?\n\n\n>\n> The P4Rebase command has been given a branch option which is forwarded\n> to the P4Sync command it runs.\n>\n> The P4Submit command has been simplified to not call P4Sync itself, it\n> lets P4Rebase do it instead (now that the branch can be handled).  This\n> fixes an issue where P4Submit does a sync of the requested branch and\n> then does a rebase which does a sync of all branches.\n>\n> Signed-off-by: Andrew Oakley <aoakley@roku.com>\n> ---\n>  Documentation/git-p4.txt |  4 ++++\n>  git-p4.py                | 15 +++++++--------\n>  2 files changed, 11 insertions(+), 8 deletions(-)\n>\n> diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt\n> index 7436c64..a03a291 100644\n> --- a/Documentation/git-p4.txt\n> +++ b/Documentation/git-p4.txt\n> @@ -328,6 +328,10 @@ Rebase options\n>  ~~~~~~~~~~~~~~\n>  These options can be used to modify 'git p4 rebase' behavior.\n>\n> +--branch <branch>::\n> +       Sync this named branch instead of the default p4/master.  See the\n> +       \"Sync options\" section above for more information.\n> +\n>  --import-labels::\n>         Import p4 labels.\n>\n> diff --git a/git-p4.py b/git-p4.py\n> index 8d151da..e58b34a 100755\n> --- a/git-p4.py\n> +++ b/git-p4.py\n> @@ -2161,13 +2161,9 @@ class P4Submit(Command, P4UserMap):\n>          elif len(commits) == len(applied):\n>              print (\"All commits {0}!\".format(shelved_applied))\n>\n> -            sync = P4Sync()\n> -            if self.branch:\n> -                sync.branch = self.branch\n> -            sync.run([])\n> -\n>              rebase = P4Rebase()\n> -            rebase.rebase()\n> +            rebase.branch = self.branch\n> +            rebase.run([])\n>\n>          else:\n>              if len(applied) == 0:\n> @@ -2343,7 +2339,7 @@ class P4Sync(Command, P4UserMap):\n>          self.silent = False\n>          self.createdBranches = set()\n>          self.committedChanges = set()\n> -        self.branch = \"\"\n> +        self.branch = None\n>          self.detectBranches = False\n>          self.detectLabels = False\n>          self.importLabels = False\n> @@ -3281,7 +3277,7 @@ class P4Sync(Command, P4UserMap):\n>                  system(\"git fetch origin\")\n>\n>          branch_arg_given = bool(self.branch)\n> -        if len(self.branch) == 0:\n> +        if not branch_arg_given:\n>              self.branch = self.refPrefix + \"master\"\n>              if gitBranchExists(\"refs/heads/p4\") and self.importIntoRemotes:\n>                  system(\"git update-ref %s refs/heads/p4\" % self.branch)\n> @@ -3567,14 +3563,17 @@ class P4Rebase(Command):\n>      def __init__(self):\n>          Command.__init__(self)\n>          self.options = [\n> +                optparse.make_option(\"--branch\", dest=\"branch\"),\n>                  optparse.make_option(\"--import-labels\", dest=\"importLabels\", action=\"store_true\"),\n>          ]\n> +        self.branch = None\n>          self.importLabels = False\n>          self.description = (\"Fetches the latest revision from perforce and \"\n>                              + \"rebases the current work (branch) against it\")\n>\n>      def run(self, args):\n>          sync = P4Sync()\n> +        sync.branch = self.branch\n>          sync.importLabels = self.importLabels\n>          sync.run([])\n>\n> --\n> 2.10.2\n>\n\nApart from the typo above, this looks sensible to me. Would you be\nable to add a test case?\n\nThanks!\nLuke\n"}]}