diff options
author | Junio C Hamano <gitster@pobox.com> | 2018-01-05 13:28:10 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-01-05 13:28:10 -0800 |
commit | a778ba1c71eca2e7f9978bd529efa3f2d393710d (patch) | |
tree | 1a24041dd72d21cfb1621b97724e8646ef3eb219 | |
parent | a741e2825b3a3045254f404696c0051714c0e7c3 (diff) | |
parent | 8cf422dbf1b4bc14a970b7ff5c5fa555f61dd9ed (diff) | |
download | git-a778ba1c71eca2e7f9978bd529efa3f2d393710d.tar.gz git-a778ba1c71eca2e7f9978bd529efa3f2d393710d.tar.xz |
Merge branch 'ld/p4-multiple-shelves'
"git p4" update.
* ld/p4-multiple-shelves:
git-p4: update multiple shelved change lists
-rw-r--r-- | Documentation/git-p4.txt | 8 | ||||
-rwxr-xr-x | git-p4.py | 41 | ||||
-rwxr-xr-x | t/t9807-git-p4-submit.sh | 24 |
3 files changed, 47 insertions, 26 deletions
diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt index 7436c64a9..d8c8f11c9 100644 --- a/Documentation/git-p4.txt +++ b/Documentation/git-p4.txt @@ -157,6 +157,12 @@ The p4 changes will be created as the user invoking 'git p4 submit'. The according to the author of the Git commit. This option requires admin privileges in p4, which can be granted using 'p4 protect'. +To shelve changes instead of submitting, use `--shelve` and `--update-shelve`: + +---- +$ git p4 submit --shelve +$ git p4 submit --update-shelve 1234 --update-shelve 2345 +---- OPTIONS ------- @@ -310,7 +316,7 @@ These options can be used to modify 'git p4 submit' behavior. --update-shelve CHANGELIST:: Update an existing shelved changelist with this commit. Implies - --shelve. + --shelve. Repeat for multiple shelved changelists. --conflict=(ask|skip|quit):: Conflicts can occur when applying a commit to p4. When this @@ -1178,6 +1178,12 @@ class Command: self.needsGit = True self.verbose = False + # This is required for the "append" cloneExclude action + def ensure_value(self, attr, value): + if not hasattr(self, attr) or getattr(self, attr) is None: + setattr(self, attr, value) + return getattr(self, attr) + class P4UserMap: def __init__(self): self.userMapFromPerforceServer = False @@ -1343,9 +1349,10 @@ class P4Submit(Command, P4UserMap): 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"), - optparse.make_option("--update-shelve", dest="update_shelve", action="store", type="int", + optparse.make_option("--update-shelve", dest="update_shelve", action="append", type="int", metavar="CHANGELIST", - help="update an existing shelved changelist, implies --shelve") + help="update an existing shelved changelist, implies --shelve, " + "repeat in-order for multiple shelved changelists") ] self.description = "Submit changes from git to the perforce depot." self.usage += " [name of git branch to submit into perforce depot]" @@ -1354,7 +1361,7 @@ class P4Submit(Command, P4UserMap): self.preserveUser = gitConfigBool("git-p4.preserveUser") self.dry_run = False self.shelve = False - self.update_shelve = None + self.update_shelve = list() self.prepare_p4_only = False self.conflict_behavior = None self.isWindows = (platform.system() == "Windows") @@ -1809,9 +1816,10 @@ class P4Submit(Command, P4UserMap): mode = filesToChangeExecBit[f] setP4ExecBit(f, mode) - if self.update_shelve: - print("all_files = %s" % str(all_files)) - p4_reopen_in_change(self.update_shelve, all_files) + update_shelve = 0 + if len(self.update_shelve) > 0: + update_shelve = self.update_shelve.pop(0) + p4_reopen_in_change(update_shelve, all_files) # # Build p4 change description, starting with the contents @@ -1821,7 +1829,7 @@ class P4Submit(Command, P4UserMap): logMessage = logMessage.strip() (logMessage, jobs) = self.separate_jobs_from_description(logMessage) - template = self.prepareSubmitTemplate(self.update_shelve) + template = self.prepareSubmitTemplate(update_shelve) submitTemplate = self.prepareLogMessage(template, logMessage, jobs) if self.preserveUser: @@ -1894,7 +1902,7 @@ class P4Submit(Command, P4UserMap): message = message.replace("\r\n", "\n") submitTemplate = message[:message.index(separatorLine)] - if self.update_shelve: + if update_shelve: p4_write_pipe(['shelve', '-r', '-i'], submitTemplate) elif self.shelve: p4_write_pipe(['shelve', '-i'], submitTemplate) @@ -2012,6 +2020,10 @@ class P4Submit(Command, P4UserMap): else: return False + for i in self.update_shelve: + if i <= 0: + sys.exit("invalid changelist %d" % i) + if self.master: allowSubmit = gitConfig("git-p4.allowSubmit") if len(allowSubmit) > 0 and not self.master in allowSubmit.split(","): @@ -2022,7 +2034,7 @@ class P4Submit(Command, P4UserMap): if len(self.origin) == 0: self.origin = upstream - if self.update_shelve: + if len(self.update_shelve) > 0: self.shelve = True if self.preserveUser: @@ -2134,6 +2146,11 @@ class P4Submit(Command, P4UserMap): if gitConfigBool("git-p4.detectCopiesHarder"): self.diffOpts += " --find-copies-harder" + num_shelves = len(self.update_shelve) + if num_shelves > 0 and num_shelves != len(commits): + sys.exit("number of commits (%d) must match number of shelved changelist (%d)" % + (len(commits), num_shelves)) + # # Apply the commits, one at a time. On failure, ask if should # continue to try the rest of the patches, or quit. @@ -2404,12 +2421,6 @@ class P4Sync(Command, P4UserMap): if gitConfig("git-p4.syncFromOrigin") == "false": self.syncWithOrigin = False - # This is required for the "append" cloneExclude action - def ensure_value(self, attr, value): - if not hasattr(self, attr) or getattr(self, attr) is None: - setattr(self, attr, value) - return getattr(self, attr) - # Force a checkpoint in fast-import and wait for it to finish def checkpoint(self): self.gitStream.write("checkpoint\n\n") diff --git a/t/t9807-git-p4-submit.sh b/t/t9807-git-p4-submit.sh index 3457d5db6..71cae2874 100755 --- a/t/t9807-git-p4-submit.sh +++ b/t/t9807-git-p4-submit.sh @@ -460,7 +460,13 @@ test_expect_success 'submit --shelve' ' ) ' -# Update an existing shelved changelist +make_shelved_cl() { + test_commit "$1" >/dev/null && + git p4 submit --origin HEAD^ --shelve >/dev/null && + p4 -G changes -s shelved -m 1 | marshal_dump change +} + +# Update existing shelved changelists test_expect_success 'submit --update-shelve' ' test_when_finished cleanup_git && @@ -470,21 +476,19 @@ test_expect_success 'submit --update-shelve' ' p4 revert ... && cd "$git" && git config git-p4.skipSubmitEdit true && - test_commit "test-update-shelved-change" && - git p4 submit --origin=HEAD^ --shelve && + shelved_cl0=$(make_shelved_cl "shelved-change-0") && + echo shelved_cl0=$shelved_cl0 && + shelved_cl1=$(make_shelved_cl "shelved-change-1") && - shelf_cl=$(p4 -G changes -s shelved -m 1 |\ - marshal_dump change) && - test -n $shelf_cl && - echo "updating shelved change list $shelf_cl" && + echo "updating shelved change lists $shelved_cl0 and $shelved_cl1" && echo "updated-line" >>shelf.t && echo added-file.t >added-file.t && git add shelf.t added-file.t && - git rm -f test-update-shelved-change.t && + git rm -f shelved-change-1.t && git commit --amend -C HEAD && git show --stat HEAD && - git p4 submit -v --origin HEAD^ --update-shelve $shelf_cl && + git p4 submit -v --origin HEAD~2 --update-shelve $shelved_cl0 --update-shelve $shelved_cl1 && echo "done git p4 submit" ) && ( @@ -494,7 +498,7 @@ test_expect_success 'submit --update-shelve' ' p4 unshelve -c $change -s $change && grep -q updated-line shelf.t && p4 describe -S $change | grep added-file.t && - test_path_is_missing test-update-shelved-change.t + test_path_is_missing shelved-change-1.t ) ' |