1010__all__ = ["RootModule" ]
1111
1212
13+ class RootUpdateProgress (UpdateProgress ):
14+ """Utility class which adds more opcodes to the UpdateProgress"""
15+ REMOVE , PATHCHANGE , BRANCHCHANGE , URLCHANGE = [1 << x for x in range (UpdateProgress ._num_op_codes , UpdateProgress ._num_op_codes + 4 )]
16+ _num_op_codes = UpdateProgress ._num_op_codes + 4
17+
18+ __slots__ = tuple ()
19+
20+ BEGIN = RootUpdateProgress .BEGIN
21+ END = RootUpdateProgress .END
22+ REMOVE = RootUpdateProgress .REMOVE
23+ BRANCHCHANGE = RootUpdateProgress .BRANCHCHANGE
24+ URLCHANGE = RootUpdateProgress .URLCHANGE
25+ PATHCHANGE = RootUpdateProgress .PATHCHANGE
26+
1327class RootModule (Submodule ):
1428 """A (virtual) Root of all submodules in the given repository. It can be used
1529 to more easily traverse all submodules of the master repository"""
@@ -59,21 +73,21 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
5973 :param to_latest_revision: If True, instead of checking out the revision pointed to
6074 by this submodule's sha, the checked out tracking branch will be merged with the
6175 newest remote branch fetched from the repository's origin
62- :param progress: UpdateProgress instance or None if no progress should be sent
76+ :param progress: RootUpdateProgress instance or None if no progress should be sent
6377 :param dry_run: if True, operations will not actually be performed. Progress messages
6478 will change accordingly to indicate the WOULD DO state of the operation."""
6579 if self .repo .bare :
6680 raise InvalidGitRepositoryError ("Cannot update submodules in bare repositories" )
6781 # END handle bare
6882
6983 if progress is None :
70- progress = UpdateProgress ()
84+ progress = RootUpdateProgress ()
7185 #END assure progress is set
7286
7387 repo = self .repo
7488
75- # HANDLE COMMITS
76- ##################
89+ # SETUP BASE COMMIT
90+ ###################
7791 cur_commit = repo .head .commit
7892 if previous_commit is None :
7993 try :
@@ -97,29 +111,50 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
97111
98112 # HANDLE REMOVALS
99113 ###################
100- for rsm in (spsms - ssms ):
114+ rrsm = (spsms - ssms )
115+ len_rrsm = len (rrsm )
116+ for i , rsm in enumerate (rrsm ):
117+ op = REMOVE
118+ if i == 0 :
119+ op |= BEGIN
120+ #END handle begin
121+
101122 # fake it into thinking its at the current commit to allow deletion
102123 # of previous module. Trigger the cache to be updated before that
103- # rsm.url
124+ progress . update ( op , i , len_rrsm , "Removing submodule %s at %s" % ( rsm .name , rsm . abspath ))
104125 rsm ._parent_commit = repo .head .commit
105126 rsm .remove (configuration = False , module = True , force = force_remove )
127+
128+ if i == len_rrsm - 1 :
129+ op |= END
130+ #END handle end
131+ progress .update (op , i , len_rrsm , "Done removing submodule %s" % rsm .name )
106132 # END for each removed submodule
107133
108134 # HANDLE PATH RENAMES
109135 #####################
110136 # url changes + branch changes
111- for csm in (spsms & ssms ):
137+ csms = (spsms & ssms )
138+ len_csms = len (csms )
139+ for i , csm in enumerate (csms ):
112140 psm = psms [csm .name ]
113141 sm = sms [csm .name ]
114142
143+ #PATH CHANGES
144+ ##############
115145 if sm .path != psm .path and psm .module_exists ():
146+ progress .update (BEGIN | PATHCHANGE , i , len_csms , "Moving submodule's %s repository from %s to %s" % (sm .name , psm .abspath , sm .abspath ))
116147 # move the module to the new path
117148 psm .move (sm .path , module = True , configuration = False )
149+ progress .update (END | PATHCHANGE , i , len_csms , "Done moving repository of submodule %s" % sm .name )
118150 # END handle path changes
119151
120152 if sm .module_exists ():
121- # handle url change
153+ # HANDLE URL CHANGE
154+ ###################
122155 if sm .url != psm .url :
156+ progress .update (BEGIN | URLCHANGE , i , len_csms , "Changing url of submodule %s from %s to %s" % (sm .name , psm .url , sm .url ))
157+
123158 # Add the new remote, remove the old one
124159 # This way, if the url just changes, the commits will not
125160 # have to be re-retrieved
@@ -130,7 +165,6 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
130165 # don't do anything if we already have the url we search in place
131166 if len ([r for r in rmts if r .url == sm .url ]) == 0 :
132167
133-
134168 assert nn not in [r .name for r in rmts ]
135169 smr = smm .create_remote (nn , sm .url )
136170 smr .fetch (progress = progress )
@@ -202,12 +236,16 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
202236
203237 #NOTE: All checkout is performed by the base implementation of update
204238
239+ progress .update (END | URLCHANGE , i , len_csms , "Done adjusting url of submodule %s" % (sm .name ))
205240 # END skip remote handling if new url already exists in module
206241 # END handle url
207242
243+ # HANDLE PATH CHANGES
244+ #####################
208245 if sm .branch_path != psm .branch_path :
209246 # finally, create a new tracking branch which tracks the
210247 # new remote branch
248+ progress .update (BEGIN | BRANCHCHANGE , i , len_csms , "Changing branch of submodule %s from %s to %s" % (sm .name , psm .branch_path , sm .branch_path ))
211249 smm = sm .module ()
212250 smmr = smm .remotes
213251 try :
@@ -234,6 +272,7 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
234272
235273 #NOTE: All checkout is done in the base implementation of update
236274
275+ progress .update (END | BRANCHCHANGE , i , len_csms , "Done changing branch of submodule %s" % sm .name )
237276 #END handle branch
238277 #END handle
239278 # END for each common submodule
@@ -242,15 +281,17 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
242281 ######################################
243282 for sm in sms :
244283 # update the submodule using the default method
245- sm .update (recursive = False , init = init , to_latest_revision = to_latest_revision , progress = progress )
284+ sm .update (recursive = False , init = init , to_latest_revision = to_latest_revision ,
285+ progress = progress , dry_run = dry_run )
246286
247287 # update recursively depth first - question is which inconsitent
248288 # state will be better in case it fails somewhere. Defective branch
249289 # or defective depth. The RootSubmodule type will never process itself,
250290 # which was done in the previous expression
251291 if recursive :
252- type (self )(sm .module ()).update (recursive = True , force_remove = force_remove ,
253- init = init , to_latest_revision = to_latest_revision )
292+ type (self )(sm .module ()).update ( recursive = True , force_remove = force_remove ,
293+ init = init , to_latest_revision = to_latest_revision ,
294+ progress = progress , dry_run = dry_run )
254295 #END handle recursive
255296 # END for each submodule to update
256297
0 commit comments