git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] allow git-p4 to create shelved changelists
@ 2016-11-28  9:33 Vinicius Kursancew
  2016-11-28  9:33 ` [PATCH] git-p4: allow submit " Vinicius Kursancew
  2016-11-28 19:06 ` [PATCH] allow git-p4 " Junio C Hamano
  0 siblings, 2 replies; 5+ messages in thread
From: Vinicius Kursancew @ 2016-11-28  9:33 UTC (permalink / raw)
  To: gitster, git; +Cc: Vinicius Kursancew

This patch adds a "--shelve" option to the submit subcommand, it will
save the changes to a perforce shelve instead of commiting them.

Vinicius Kursancew (1):
  git-p4: allow submit to create shelved changelists.

 Documentation/git-p4.txt |  5 +++++
 git-p4.py                | 36 ++++++++++++++++++++++--------------
 t/t9807-git-p4-submit.sh | 31 +++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 14 deletions(-)

-- 
2.6.0-rc1


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

* [PATCH] git-p4: allow submit to create shelved changelists.
  2016-11-28  9:33 [PATCH] allow git-p4 to create shelved changelists Vinicius Kursancew
@ 2016-11-28  9:33 ` Vinicius Kursancew
  2016-11-28 19:06 ` [PATCH] allow git-p4 " Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Vinicius Kursancew @ 2016-11-28  9:33 UTC (permalink / raw)
  To: gitster, git; +Cc: Vinicius Kursancew

Add a --shelve command line argument which invokes p4 shelve instead
of submitting changes. After shelving the changes are reverted from the
p4 workspace.

Signed-off-by: Vinicius Kursancew <viniciusalexandre@gmail.com>
---
 Documentation/git-p4.txt |  5 +++++
 git-p4.py                | 36 ++++++++++++++++++++++--------------
 t/t9807-git-p4-submit.sh | 31 +++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 14 deletions(-)

diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt
index c83aaf3..1bbf43d 100644
--- a/Documentation/git-p4.txt
+++ b/Documentation/git-p4.txt
@@ -303,6 +303,11 @@ These options can be used to modify 'git p4 submit' behavior.
 	submit manually or revert.  This option always stops after the
 	first (oldest) commit.  Git tags are not exported to p4.
 
+--shelve::
+	Instead of submitting create a series of shelved changelists.
+	After creating each shelve, the relevant files are reverted/deleted.
+	If you have multiple commits pending multiple shelves will be created.
+
 --conflict=(ask|skip|quit)::
 	Conflicts can occur when applying a commit to p4.  When this
 	happens, the default behavior ("ask") is to prompt whether to
diff --git a/git-p4.py b/git-p4.py
index fd5ca52..0c4f2af 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1289,6 +1289,9 @@ class P4Submit(Command, P4UserMap):
                 optparse.make_option("--conflict", dest="conflict_behavior",
                                      choices=self.conflict_behavior_choices),
                 optparse.make_option("--branch", dest="branch"),
+                optparse.make_option("--shelve", dest="shelve", action="store_true",
+                                     help="Shelve instead of submit. Shelved files are reverted, "
+                                     "restoring the workspace to the state before the shelve"),
         ]
         self.description = "Submit changes from git to the perforce depot."
         self.usage += " [name of git branch to submit into perforce depot]"
@@ -1296,6 +1299,7 @@ class P4Submit(Command, P4UserMap):
         self.detectRenames = False
         self.preserveUser = gitConfigBool("git-p4.preserveUser")
         self.dry_run = False
+        self.shelve = False
         self.prepare_p4_only = False
         self.conflict_behavior = None
         self.isWindows = (platform.system() == "Windows")
@@ -1785,7 +1789,14 @@ class P4Submit(Command, P4UserMap):
                 if self.isWindows:
                     message = message.replace("\r\n", "\n")
                 submitTemplate = message[:message.index(separatorLine)]
-                p4_write_pipe(['submit', '-i'], submitTemplate)
+                if self.shelve:
+                    p4_write_pipe(['shelve', '-i'], submitTemplate)
+                else:
+                    p4_write_pipe(['submit', '-i'], submitTemplate)
+                    # The rename/copy happened by applying a patch that created a
+                    # new file.  This leaves it writable, which confuses p4.
+                    for f in pureRenameCopy:
+                        p4_sync(f, "-f")
 
                 if self.preserveUser:
                     if p4User:
@@ -1795,23 +1806,20 @@ class P4Submit(Command, P4UserMap):
                         changelist = self.lastP4Changelist()
                         self.modifyChangelistUser(changelist, p4User)
 
-                # The rename/copy happened by applying a patch that created a
-                # new file.  This leaves it writable, which confuses p4.
-                for f in pureRenameCopy:
-                    p4_sync(f, "-f")
                 submitted = True
 
         finally:
             # skip this patch
-            if not submitted:
-                print "Submission cancelled, undoing p4 changes."
-                for f in editedFiles:
+            if not submitted or self.shelve:
+                if self.shelve:
+                    print ("Reverting shelved files.")
+                else:
+                    print ("Submission cancelled, undoing p4 changes.")
+                for f in editedFiles | filesToDelete:
                     p4_revert(f)
                 for f in filesToAdd:
                     p4_revert(f)
                     os.remove(f)
-                for f in filesToDelete:
-                    p4_revert(f)
 
         os.remove(fileName)
         return submitted
@@ -2067,13 +2075,13 @@ class P4Submit(Command, P4UserMap):
                         break
 
         chdir(self.oldWorkingDirectory)
-
+        shelved_applied = "shelved" if self.shelve else "applied"
         if self.dry_run:
             pass
         elif self.prepare_p4_only:
             pass
         elif len(commits) == len(applied):
-            print "All commits applied!"
+            print ("All commits {0}!".format(shelved_applied))
 
             sync = P4Sync()
             if self.branch:
@@ -2085,9 +2093,9 @@ class P4Submit(Command, P4UserMap):
 
         else:
             if len(applied) == 0:
-                print "No commits applied."
+                print ("No commits {0}.".format(shelved_applied))
             else:
-                print "Applied only the commits marked with '*':"
+                print ("{0} only the commits marked with '*':".format(shelved_applied.capitalize()))
                 for c in commits:
                     if c in applied:
                         star = "*"
diff --git a/t/t9807-git-p4-submit.sh b/t/t9807-git-p4-submit.sh
index 5931528..42a5fad 100755
--- a/t/t9807-git-p4-submit.sh
+++ b/t/t9807-git-p4-submit.sh
@@ -413,6 +413,37 @@ test_expect_success 'submit --prepare-p4-only' '
 	)
 '
 
+test_expect_success 'submit --shelve' '
+	test_when_finished cleanup_git &&
+	git p4 clone --dest="$git" //depot &&
+	(
+		cd "$cli" &&
+		p4 revert ... &&
+		cd "$git" &&
+		git config git-p4.skipSubmitEdit true &&
+		test_commit "shelveme1" &&
+		git p4 submit --origin=HEAD^ &&
+
+		echo 654321 >shelveme2.t &&
+		echo 123456 >>shelveme1.t &&
+		git add shelveme* &&
+		git commit -m"shelvetest" &&
+		git p4 submit --shelve --origin=HEAD^ &&
+
+		test_path_is_file shelveme1.t &&
+		test_path_is_file shelveme2.t
+	) &&
+	(
+		cd "$cli" &&
+		change=$(p4 -G changes -s shelved -m 1 //depot/... | \
+			 marshal_dump change) &&
+		p4 describe -S $change | grep shelveme2 &&
+		p4 describe -S $change | grep 123456 &&
+		test_path_is_file shelveme1.t &&
+		test_path_is_missing shelveme2.t
+	)
+'
+
 test_expect_success 'kill p4d' '
 	kill_p4d
 '
-- 
2.6.0-rc1


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

* Re: [PATCH] allow git-p4 to create shelved changelists
  2016-11-28  9:33 [PATCH] allow git-p4 to create shelved changelists Vinicius Kursancew
  2016-11-28  9:33 ` [PATCH] git-p4: allow submit " Vinicius Kursancew
@ 2016-11-28 19:06 ` Junio C Hamano
  2016-11-29 12:47   ` Luke Diamand
  1 sibling, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2016-11-28 19:06 UTC (permalink / raw)
  To: Vinicius Kursancew, Luke Diamand, Lars Schneider; +Cc: git

Vinicius Kursancew <viniciusalexandre@gmail.com> writes:

> This patch adds a "--shelve" option to the submit subcommand, it will
> save the changes to a perforce shelve instead of commiting them.
>
> Vinicius Kursancew (1):
>   git-p4: allow submit to create shelved changelists.
>
>  Documentation/git-p4.txt |  5 +++++
>  git-p4.py                | 36 ++++++++++++++++++++++--------------
>  t/t9807-git-p4-submit.sh | 31 +++++++++++++++++++++++++++++++
>  3 files changed, 58 insertions(+), 14 deletions(-)

Thanks, but I am a wrong person to review this change, so I'll
summon two people who appear in "git shortlog --since=18.months"
output to help review it.



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

* Re: [PATCH] allow git-p4 to create shelved changelists
  2016-11-28 19:06 ` [PATCH] allow git-p4 " Junio C Hamano
@ 2016-11-29 12:47   ` Luke Diamand
  2016-11-29 18:59     ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Luke Diamand @ 2016-11-29 12:47 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Vinicius Kursancew, Lars Schneider, Git Users

On 28 November 2016 at 19:06, Junio C Hamano <gitster@pobox.com> wrote:
> Vinicius Kursancew <viniciusalexandre@gmail.com> writes:
>
>> This patch adds a "--shelve" option to the submit subcommand, it will
>> save the changes to a perforce shelve instead of commiting them.

Looks good to me, thanks!

Works a treat.

Ack.

>>
>> Vinicius Kursancew (1):
>>   git-p4: allow submit to create shelved changelists.
>>
>>  Documentation/git-p4.txt |  5 +++++
>>  git-p4.py                | 36 ++++++++++++++++++++++--------------
>>  t/t9807-git-p4-submit.sh | 31 +++++++++++++++++++++++++++++++
>>  3 files changed, 58 insertions(+), 14 deletions(-)
>
> Thanks, but I am a wrong person to review this change, so I'll
> summon two people who appear in "git shortlog --since=18.months"
> output to help review it.
>
>

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

* Re: [PATCH] allow git-p4 to create shelved changelists
  2016-11-29 12:47   ` Luke Diamand
@ 2016-11-29 18:59     ` Junio C Hamano
  0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2016-11-29 18:59 UTC (permalink / raw)
  To: Luke Diamand; +Cc: Vinicius Kursancew, Lars Schneider, Git Users

Luke Diamand <luke@diamand.org> writes:

> On 28 November 2016 at 19:06, Junio C Hamano <gitster@pobox.com> wrote:
>> Vinicius Kursancew <viniciusalexandre@gmail.com> writes:
>>
>>> This patch adds a "--shelve" option to the submit subcommand, it will
>>> save the changes to a perforce shelve instead of commiting them.
>
> Looks good to me, thanks!
>
> Works a treat.

Thanks.

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

end of thread, other threads:[~2016-11-29 18:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-28  9:33 [PATCH] allow git-p4 to create shelved changelists Vinicius Kursancew
2016-11-28  9:33 ` [PATCH] git-p4: allow submit " Vinicius Kursancew
2016-11-28 19:06 ` [PATCH] allow git-p4 " Junio C Hamano
2016-11-29 12:47   ` Luke Diamand
2016-11-29 18:59     ` Junio C Hamano

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