Skip to content

Commit a778ba1

Browse files
committed
Merge branch 'ld/p4-multiple-shelves'
"git p4" update. * ld/p4-multiple-shelves: git-p4: update multiple shelved change lists
2 parents a741e28 + 8cf422d commit a778ba1

File tree

3 files changed

+47
-26
lines changed

3 files changed

+47
-26
lines changed

Documentation/git-p4.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ The p4 changes will be created as the user invoking 'git p4 submit'. The
157157
according to the author of the Git commit. This option requires admin
158158
privileges in p4, which can be granted using 'p4 protect'.
159159

160+
To shelve changes instead of submitting, use `--shelve` and `--update-shelve`:
161+
162+
----
163+
$ git p4 submit --shelve
164+
$ git p4 submit --update-shelve 1234 --update-shelve 2345
165+
----
160166

161167
OPTIONS
162168
-------
@@ -310,7 +316,7 @@ These options can be used to modify 'git p4 submit' behavior.
310316

311317
--update-shelve CHANGELIST::
312318
Update an existing shelved changelist with this commit. Implies
313-
--shelve.
319+
--shelve. Repeat for multiple shelved changelists.
314320

315321
--conflict=(ask|skip|quit)::
316322
Conflicts can occur when applying a commit to p4. When this

git-p4.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,12 @@ def __init__(self):
11781178
self.needsGit = True
11791179
self.verbose = False
11801180

1181+
# This is required for the "append" cloneExclude action
1182+
def ensure_value(self, attr, value):
1183+
if not hasattr(self, attr) or getattr(self, attr) is None:
1184+
setattr(self, attr, value)
1185+
return getattr(self, attr)
1186+
11811187
class P4UserMap:
11821188
def __init__(self):
11831189
self.userMapFromPerforceServer = False
@@ -1343,9 +1349,10 @@ def __init__(self):
13431349
optparse.make_option("--shelve", dest="shelve", action="store_true",
13441350
help="Shelve instead of submit. Shelved files are reverted, "
13451351
"restoring the workspace to the state before the shelve"),
1346-
optparse.make_option("--update-shelve", dest="update_shelve", action="store", type="int",
1352+
optparse.make_option("--update-shelve", dest="update_shelve", action="append", type="int",
13471353
metavar="CHANGELIST",
1348-
help="update an existing shelved changelist, implies --shelve")
1354+
help="update an existing shelved changelist, implies --shelve, "
1355+
"repeat in-order for multiple shelved changelists")
13491356
]
13501357
self.description = "Submit changes from git to the perforce depot."
13511358
self.usage += " [name of git branch to submit into perforce depot]"
@@ -1354,7 +1361,7 @@ def __init__(self):
13541361
self.preserveUser = gitConfigBool("git-p4.preserveUser")
13551362
self.dry_run = False
13561363
self.shelve = False
1357-
self.update_shelve = None
1364+
self.update_shelve = list()
13581365
self.prepare_p4_only = False
13591366
self.conflict_behavior = None
13601367
self.isWindows = (platform.system() == "Windows")
@@ -1809,9 +1816,10 @@ def applyCommit(self, id):
18091816
mode = filesToChangeExecBit[f]
18101817
setP4ExecBit(f, mode)
18111818

1812-
if self.update_shelve:
1813-
print("all_files = %s" % str(all_files))
1814-
p4_reopen_in_change(self.update_shelve, all_files)
1819+
update_shelve = 0
1820+
if len(self.update_shelve) > 0:
1821+
update_shelve = self.update_shelve.pop(0)
1822+
p4_reopen_in_change(update_shelve, all_files)
18151823

18161824
#
18171825
# Build p4 change description, starting with the contents
@@ -1821,7 +1829,7 @@ def applyCommit(self, id):
18211829
logMessage = logMessage.strip()
18221830
(logMessage, jobs) = self.separate_jobs_from_description(logMessage)
18231831

1824-
template = self.prepareSubmitTemplate(self.update_shelve)
1832+
template = self.prepareSubmitTemplate(update_shelve)
18251833
submitTemplate = self.prepareLogMessage(template, logMessage, jobs)
18261834

18271835
if self.preserveUser:
@@ -1894,7 +1902,7 @@ def applyCommit(self, id):
18941902
message = message.replace("\r\n", "\n")
18951903
submitTemplate = message[:message.index(separatorLine)]
18961904

1897-
if self.update_shelve:
1905+
if update_shelve:
18981906
p4_write_pipe(['shelve', '-r', '-i'], submitTemplate)
18991907
elif self.shelve:
19001908
p4_write_pipe(['shelve', '-i'], submitTemplate)
@@ -2012,6 +2020,10 @@ def run(self, args):
20122020
else:
20132021
return False
20142022

2023+
for i in self.update_shelve:
2024+
if i <= 0:
2025+
sys.exit("invalid changelist %d" % i)
2026+
20152027
if self.master:
20162028
allowSubmit = gitConfig("git-p4.allowSubmit")
20172029
if len(allowSubmit) > 0 and not self.master in allowSubmit.split(","):
@@ -2022,7 +2034,7 @@ def run(self, args):
20222034
if len(self.origin) == 0:
20232035
self.origin = upstream
20242036

2025-
if self.update_shelve:
2037+
if len(self.update_shelve) > 0:
20262038
self.shelve = True
20272039

20282040
if self.preserveUser:
@@ -2134,6 +2146,11 @@ def run(self, args):
21342146
if gitConfigBool("git-p4.detectCopiesHarder"):
21352147
self.diffOpts += " --find-copies-harder"
21362148

2149+
num_shelves = len(self.update_shelve)
2150+
if num_shelves > 0 and num_shelves != len(commits):
2151+
sys.exit("number of commits (%d) must match number of shelved changelist (%d)" %
2152+
(len(commits), num_shelves))
2153+
21372154
#
21382155
# Apply the commits, one at a time. On failure, ask if should
21392156
# continue to try the rest of the patches, or quit.
@@ -2404,12 +2421,6 @@ def __init__(self):
24042421
if gitConfig("git-p4.syncFromOrigin") == "false":
24052422
self.syncWithOrigin = False
24062423

2407-
# This is required for the "append" cloneExclude action
2408-
def ensure_value(self, attr, value):
2409-
if not hasattr(self, attr) or getattr(self, attr) is None:
2410-
setattr(self, attr, value)
2411-
return getattr(self, attr)
2412-
24132424
# Force a checkpoint in fast-import and wait for it to finish
24142425
def checkpoint(self):
24152426
self.gitStream.write("checkpoint\n\n")

t/t9807-git-p4-submit.sh

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,13 @@ test_expect_success 'submit --shelve' '
460460
)
461461
'
462462

463-
# Update an existing shelved changelist
463+
make_shelved_cl() {
464+
test_commit "$1" >/dev/null &&
465+
git p4 submit --origin HEAD^ --shelve >/dev/null &&
466+
p4 -G changes -s shelved -m 1 | marshal_dump change
467+
}
468+
469+
# Update existing shelved changelists
464470

465471
test_expect_success 'submit --update-shelve' '
466472
test_when_finished cleanup_git &&
@@ -470,21 +476,19 @@ test_expect_success 'submit --update-shelve' '
470476
p4 revert ... &&
471477
cd "$git" &&
472478
git config git-p4.skipSubmitEdit true &&
473-
test_commit "test-update-shelved-change" &&
474-
git p4 submit --origin=HEAD^ --shelve &&
479+
shelved_cl0=$(make_shelved_cl "shelved-change-0") &&
480+
echo shelved_cl0=$shelved_cl0 &&
481+
shelved_cl1=$(make_shelved_cl "shelved-change-1") &&
475482
476-
shelf_cl=$(p4 -G changes -s shelved -m 1 |\
477-
marshal_dump change) &&
478-
test -n $shelf_cl &&
479-
echo "updating shelved change list $shelf_cl" &&
483+
echo "updating shelved change lists $shelved_cl0 and $shelved_cl1" &&
480484
481485
echo "updated-line" >>shelf.t &&
482486
echo added-file.t >added-file.t &&
483487
git add shelf.t added-file.t &&
484-
git rm -f test-update-shelved-change.t &&
488+
git rm -f shelved-change-1.t &&
485489
git commit --amend -C HEAD &&
486490
git show --stat HEAD &&
487-
git p4 submit -v --origin HEAD^ --update-shelve $shelf_cl &&
491+
git p4 submit -v --origin HEAD~2 --update-shelve $shelved_cl0 --update-shelve $shelved_cl1 &&
488492
echo "done git p4 submit"
489493
) &&
490494
(
@@ -494,7 +498,7 @@ test_expect_success 'submit --update-shelve' '
494498
p4 unshelve -c $change -s $change &&
495499
grep -q updated-line shelf.t &&
496500
p4 describe -S $change | grep added-file.t &&
497-
test_path_is_missing test-update-shelved-change.t
501+
test_path_is_missing shelved-change-1.t
498502
)
499503
'
500504

0 commit comments

Comments
 (0)