git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-p4: add p4 shelf support
@ 2016-12-06  2:02 Nuno Subtil
  2016-12-06  8:36 ` Luke Diamand
  0 siblings, 1 reply; 4+ messages in thread
From: Nuno Subtil @ 2016-12-06  2:02 UTC (permalink / raw)
  To: git

Extends the submit command to support shelving a commit instead of
submitting it to p4 (similar to --prepare-p4-only).

Signed-off-by: Nuno Subtil <subtil@gmail.com>
---
 git-p4.py | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/git-p4.py b/git-p4.py
index fd5ca52..3c4be22 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1286,6 +1286,8 @@ def __init__(self):
                 optparse.make_option("--export-labels", dest="exportLabels", action="store_true"),
                 optparse.make_option("--dry-run", "-n", dest="dry_run", action="store_true"),
                 optparse.make_option("--prepare-p4-only", dest="prepare_p4_only", action="store_true"),
+                optparse.make_option("--shelve-only", dest="shelve_only", action="store_true", help="Create P4 shelf for first change that would be submitted (using a new CL)"),
+                optparse.make_option("--shelve-cl", dest="shelve_cl", help="Replace shelf under existing CL number (previously shelved files will be deleted)"),
                 optparse.make_option("--conflict", dest="conflict_behavior",
                                      choices=self.conflict_behavior_choices),
                 optparse.make_option("--branch", dest="branch"),
@@ -1297,6 +1299,8 @@ def __init__(self):
         self.preserveUser = gitConfigBool("git-p4.preserveUser")
         self.dry_run = False
         self.prepare_p4_only = False
+        self.shelve_only = False
+        self.shelve_cl = None
         self.conflict_behavior = None
         self.isWindows = (platform.system() == "Windows")
         self.exportLabels = False
@@ -1496,6 +1500,12 @@ def prepareSubmitTemplate(self):
                 else:
                     inFilesSection = False
             else:
+                if self.shelve_only and self.shelve_cl:
+                    if line.startswith("Change:"):
+                        line = "Change: %s\n" % self.shelve_cl
+                    if line.startswith("Status:"):
+                        line = "Status: pending\n"
+
                 if line.startswith("Files:"):
                     inFilesSection = True
 
@@ -1785,7 +1795,11 @@ def applyCommit(self, id):
                 if self.isWindows:
                     message = message.replace("\r\n", "\n")
                 submitTemplate = message[:message.index(separatorLine)]
-                p4_write_pipe(['submit', '-i'], submitTemplate)
+
+                if self.shelve_only:
+                    p4_write_pipe(['shelve', '-i', '-r'], submitTemplate)
+                else:
+                    p4_write_pipe(['submit', '-i'], submitTemplate)
 
                 if self.preserveUser:
                     if p4User:
@@ -1799,12 +1813,17 @@ def applyCommit(self, id):
                 # new file.  This leaves it writable, which confuses p4.
                 for f in pureRenameCopy:
                     p4_sync(f, "-f")
-                submitted = True
+
+                if not self.shelve_only:
+                    submitted = True
 
         finally:
             # skip this patch
             if not submitted:
-                print "Submission cancelled, undoing p4 changes."
+                if not self.shelve_only:
+                    print "Submission cancelled, undoing p4 changes."
+                else:
+                    print "Change shelved, undoing p4 changes."
                 for f in editedFiles:
                     p4_revert(f)
                 for f in filesToAdd:
@@ -2034,9 +2053,13 @@ def run(self, args):
             if ok:
                 applied.append(commit)
             else:
-                if self.prepare_p4_only and i < last:
-                    print "Processing only the first commit due to option" \
-                          " --prepare-p4-only"
+                if (self.prepare_p4_only or self.shelve_only) and i < last:
+                    if self.prepare_p4_only:
+                        print "Processing only the first commit due to option" \
+                              " --prepare-p4-only"
+                    else:
+                        print "Processing only the first commit due to option" \
+                              " --shelve-only"
                     break
                 if i < last:
                     quit = False
@@ -3638,6 +3661,7 @@ def printUsage(commands):
     "debug" : P4Debug,
     "submit" : P4Submit,
     "commit" : P4Submit,
+    "shelve" : P4Submit,
     "sync" : P4Sync,
     "rebase" : P4Rebase,
     "clone" : P4Clone,

--
https://github.com/git/git/pull/309

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

* Re: [PATCH] git-p4: add p4 shelf support
  2016-12-06  2:02 [PATCH] git-p4: add p4 shelf support Nuno Subtil
@ 2016-12-06  8:36 ` Luke Diamand
  2016-12-06 16:03   ` Vinicius Kursancew
       [not found]   ` <CALdXDfdXtc+FpePnGmE6_YDQ+8=wUZRqh4Xb65NJXUXaZnmELA@mail.gmail.com>
  0 siblings, 2 replies; 4+ messages in thread
From: Luke Diamand @ 2016-12-06  8:36 UTC (permalink / raw)
  To: Nuno Subtil; +Cc: Git Users, Junio C Hamano, Vinicius Kursancew, Lars Schneider

On 6 December 2016 at 02:02, Nuno Subtil <subtil@gmail.com> wrote:
> Extends the submit command to support shelving a commit instead of
> submitting it to p4 (similar to --prepare-p4-only).

Is this just the same as these two changes?

http://www.spinics.net/lists/git/msg290755.html
http://www.spinics.net/lists/git/msg291103.html

Thanks,
Luke

>
> Signed-off-by: Nuno Subtil <subtil@gmail.com>
> ---
>  git-p4.py | 36 ++++++++++++++++++++++++++++++------
>  1 file changed, 30 insertions(+), 6 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index fd5ca52..3c4be22 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -1286,6 +1286,8 @@ def __init__(self):
>                  optparse.make_option("--export-labels", dest="exportLabels", action="store_true"),
>                  optparse.make_option("--dry-run", "-n", dest="dry_run", action="store_true"),
>                  optparse.make_option("--prepare-p4-only", dest="prepare_p4_only", action="store_true"),
> +                optparse.make_option("--shelve-only", dest="shelve_only", action="store_true", help="Create P4 shelf for first change that would be submitted (using a new CL)"),
> +                optparse.make_option("--shelve-cl", dest="shelve_cl", help="Replace shelf under existing CL number (previously shelved files will be deleted)"),
>                  optparse.make_option("--conflict", dest="conflict_behavior",
>                                       choices=self.conflict_behavior_choices),
>                  optparse.make_option("--branch", dest="branch"),
> @@ -1297,6 +1299,8 @@ def __init__(self):
>          self.preserveUser = gitConfigBool("git-p4.preserveUser")
>          self.dry_run = False
>          self.prepare_p4_only = False
> +        self.shelve_only = False
> +        self.shelve_cl = None
>          self.conflict_behavior = None
>          self.isWindows = (platform.system() == "Windows")
>          self.exportLabels = False
> @@ -1496,6 +1500,12 @@ def prepareSubmitTemplate(self):
>                  else:
>                      inFilesSection = False
>              else:
> +                if self.shelve_only and self.shelve_cl:
> +                    if line.startswith("Change:"):
> +                        line = "Change: %s\n" % self.shelve_cl
> +                    if line.startswith("Status:"):
> +                        line = "Status: pending\n"
> +
>                  if line.startswith("Files:"):
>                      inFilesSection = True
>
> @@ -1785,7 +1795,11 @@ def applyCommit(self, id):
>                  if self.isWindows:
>                      message = message.replace("\r\n", "\n")
>                  submitTemplate = message[:message.index(separatorLine)]
> -                p4_write_pipe(['submit', '-i'], submitTemplate)
> +
> +                if self.shelve_only:
> +                    p4_write_pipe(['shelve', '-i', '-r'], submitTemplate)
> +                else:
> +                    p4_write_pipe(['submit', '-i'], submitTemplate)
>
>                  if self.preserveUser:
>                      if p4User:
> @@ -1799,12 +1813,17 @@ def applyCommit(self, id):
>                  # new file.  This leaves it writable, which confuses p4.
>                  for f in pureRenameCopy:
>                      p4_sync(f, "-f")
> -                submitted = True
> +
> +                if not self.shelve_only:
> +                    submitted = True
>
>          finally:
>              # skip this patch
>              if not submitted:
> -                print "Submission cancelled, undoing p4 changes."
> +                if not self.shelve_only:
> +                    print "Submission cancelled, undoing p4 changes."
> +                else:
> +                    print "Change shelved, undoing p4 changes."
>                  for f in editedFiles:
>                      p4_revert(f)
>                  for f in filesToAdd:
> @@ -2034,9 +2053,13 @@ def run(self, args):
>              if ok:
>                  applied.append(commit)
>              else:
> -                if self.prepare_p4_only and i < last:
> -                    print "Processing only the first commit due to option" \
> -                          " --prepare-p4-only"
> +                if (self.prepare_p4_only or self.shelve_only) and i < last:
> +                    if self.prepare_p4_only:
> +                        print "Processing only the first commit due to option" \
> +                              " --prepare-p4-only"
> +                    else:
> +                        print "Processing only the first commit due to option" \
> +                              " --shelve-only"
>                      break
>                  if i < last:
>                      quit = False
> @@ -3638,6 +3661,7 @@ def printUsage(commands):
>      "debug" : P4Debug,
>      "submit" : P4Submit,
>      "commit" : P4Submit,
> +    "shelve" : P4Submit,
>      "sync" : P4Sync,
>      "rebase" : P4Rebase,
>      "clone" : P4Clone,
>
> --
> https://github.com/git/git/pull/309

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

* Re: [PATCH] git-p4: add p4 shelf support
  2016-12-06  8:36 ` Luke Diamand
@ 2016-12-06 16:03   ` Vinicius Kursancew
       [not found]   ` <CALdXDfdXtc+FpePnGmE6_YDQ+8=wUZRqh4Xb65NJXUXaZnmELA@mail.gmail.com>
  1 sibling, 0 replies; 4+ messages in thread
From: Vinicius Kursancew @ 2016-12-06 16:03 UTC (permalink / raw)
  To: Luke Diamand; +Cc: Nuno Subtil, Git Users, Junio C Hamano, Lars Schneider

It seems if you do shelve and then later submit the p4 workspace is
left dirty (just like --prepare-p4-only would've done).
Vinicius Alexandre Kursancew <viniciusalexandre@gmail.com>



On Tue, Dec 6, 2016 at 8:36 AM, Luke Diamand <luke@diamand.org> wrote:
> On 6 December 2016 at 02:02, Nuno Subtil <subtil@gmail.com> wrote:
>> Extends the submit command to support shelving a commit instead of
>> submitting it to p4 (similar to --prepare-p4-only).
>
> Is this just the same as these two changes?
>
> http://www.spinics.net/lists/git/msg290755.html
> http://www.spinics.net/lists/git/msg291103.html
>
> Thanks,
> Luke
>
>>
>> Signed-off-by: Nuno Subtil <subtil@gmail.com>
>> ---
>>  git-p4.py | 36 ++++++++++++++++++++++++++++++------
>>  1 file changed, 30 insertions(+), 6 deletions(-)
>>
>> diff --git a/git-p4.py b/git-p4.py
>> index fd5ca52..3c4be22 100755
>> --- a/git-p4.py
>> +++ b/git-p4.py
>> @@ -1286,6 +1286,8 @@ def __init__(self):
>>                  optparse.make_option("--export-labels", dest="exportLabels", action="store_true"),
>>                  optparse.make_option("--dry-run", "-n", dest="dry_run", action="store_true"),
>>                  optparse.make_option("--prepare-p4-only", dest="prepare_p4_only", action="store_true"),
>> +                optparse.make_option("--shelve-only", dest="shelve_only", action="store_true", help="Create P4 shelf for first change that would be submitted (using a new CL)"),
>> +                optparse.make_option("--shelve-cl", dest="shelve_cl", help="Replace shelf under existing CL number (previously shelved files will be deleted)"),
>>                  optparse.make_option("--conflict", dest="conflict_behavior",
>>                                       choices=self.conflict_behavior_choices),
>>                  optparse.make_option("--branch", dest="branch"),
>> @@ -1297,6 +1299,8 @@ def __init__(self):
>>          self.preserveUser = gitConfigBool("git-p4.preserveUser")
>>          self.dry_run = False
>>          self.prepare_p4_only = False
>> +        self.shelve_only = False
>> +        self.shelve_cl = None
>>          self.conflict_behavior = None
>>          self.isWindows = (platform.system() == "Windows")
>>          self.exportLabels = False
>> @@ -1496,6 +1500,12 @@ def prepareSubmitTemplate(self):
>>                  else:
>>                      inFilesSection = False
>>              else:
>> +                if self.shelve_only and self.shelve_cl:
>> +                    if line.startswith("Change:"):
>> +                        line = "Change: %s\n" % self.shelve_cl
>> +                    if line.startswith("Status:"):
>> +                        line = "Status: pending\n"
>> +
>>                  if line.startswith("Files:"):
>>                      inFilesSection = True
>>
>> @@ -1785,7 +1795,11 @@ def applyCommit(self, id):
>>                  if self.isWindows:
>>                      message = message.replace("\r\n", "\n")
>>                  submitTemplate = message[:message.index(separatorLine)]
>> -                p4_write_pipe(['submit', '-i'], submitTemplate)
>> +
>> +                if self.shelve_only:
>> +                    p4_write_pipe(['shelve', '-i', '-r'], submitTemplate)
>> +                else:
>> +                    p4_write_pipe(['submit', '-i'], submitTemplate)
>>
>>                  if self.preserveUser:
>>                      if p4User:
>> @@ -1799,12 +1813,17 @@ def applyCommit(self, id):
>>                  # new file.  This leaves it writable, which confuses p4.
>>                  for f in pureRenameCopy:
>>                      p4_sync(f, "-f")
>> -                submitted = True
>> +
>> +                if not self.shelve_only:
>> +                    submitted = True
>>
>>          finally:
>>              # skip this patch
>>              if not submitted:
>> -                print "Submission cancelled, undoing p4 changes."
>> +                if not self.shelve_only:
>> +                    print "Submission cancelled, undoing p4 changes."
>> +                else:
>> +                    print "Change shelved, undoing p4 changes."
>>                  for f in editedFiles:
>>                      p4_revert(f)
>>                  for f in filesToAdd:
>> @@ -2034,9 +2053,13 @@ def run(self, args):
>>              if ok:
>>                  applied.append(commit)
>>              else:
>> -                if self.prepare_p4_only and i < last:
>> -                    print "Processing only the first commit due to option" \
>> -                          " --prepare-p4-only"
>> +                if (self.prepare_p4_only or self.shelve_only) and i < last:
>> +                    if self.prepare_p4_only:
>> +                        print "Processing only the first commit due to option" \
>> +                              " --prepare-p4-only"
>> +                    else:
>> +                        print "Processing only the first commit due to option" \
>> +                              " --shelve-only"
>>                      break
>>                  if i < last:
>>                      quit = False
>> @@ -3638,6 +3661,7 @@ def printUsage(commands):
>>      "debug" : P4Debug,
>>      "submit" : P4Submit,
>>      "commit" : P4Submit,
>> +    "shelve" : P4Submit,
>>      "sync" : P4Sync,
>>      "rebase" : P4Rebase,
>>      "clone" : P4Clone,
>>
>> --
>> https://github.com/git/git/pull/309

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

* Re: [PATCH] git-p4: add p4 shelf support
       [not found]   ` <CALdXDfdXtc+FpePnGmE6_YDQ+8=wUZRqh4Xb65NJXUXaZnmELA@mail.gmail.com>
@ 2016-12-07 11:09     ` Luke Diamand
  0 siblings, 0 replies; 4+ messages in thread
From: Luke Diamand @ 2016-12-07 11:09 UTC (permalink / raw)
  To: Nuno Subtil; +Cc: Git Users, Junio C Hamano, Vinicius Kursancew, Lars Schneider

On 6 December 2016 at 16:12, Nuno Subtil <subtil@gmail.com> wrote:
> Yeah, it looks similar. This change can be ignored if those have already
> been accepted.

Thanks, that's appreciated!

Luke

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

end of thread, other threads:[~2016-12-07 11:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-06  2:02 [PATCH] git-p4: add p4 shelf support Nuno Subtil
2016-12-06  8:36 ` Luke Diamand
2016-12-06 16:03   ` Vinicius Kursancew
     [not found]   ` <CALdXDfdXtc+FpePnGmE6_YDQ+8=wUZRqh4Xb65NJXUXaZnmELA@mail.gmail.com>
2016-12-07 11:09     ` Luke Diamand

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 NNTP newsgroup(s).