@@ -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+
11811187class 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 " )
0 commit comments