@@ -398,24 +398,20 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
398398 # otherwise there is a '-' character in front of the submodule listing
399399 # a38efa84daef914e4de58d1905a500d8d14aaf45 mymodule (v0.9.0-1-ga38efa8)
400400 # -a38efa84daef914e4de58d1905a500d8d14aaf45 submodules/intermediate/one
401- writer = sm .repo .config_writer ()
402- writer .set_value (sm_section (name ), 'url' , url )
403- writer .release ()
401+ with sm .repo .config_writer () as writer :
402+ writer .set_value (sm_section (name ), 'url' , url )
404403
405404 # update configuration and index
406405 index = sm .repo .index
407- writer = sm .config_writer (index = index , write = False )
408- writer .set_value ('url' , url )
409- writer .set_value ('path' , path )
410-
411- sm ._url = url
412- if not branch_is_default :
413- # store full path
414- writer .set_value (cls .k_head_option , br .path )
415- sm ._branch_path = br .path
416- # END handle path
417- writer .release ()
418- del (writer )
406+ with sm .config_writer (index = index , write = False ) as writer :
407+ writer .set_value ('url' , url )
408+ writer .set_value ('path' , path )
409+
410+ sm ._url = url
411+ if not branch_is_default :
412+ # store full path
413+ writer .set_value (cls .k_head_option , br .path )
414+ sm ._branch_path = br .path
419415
420416 # we deliberatly assume that our head matches our index !
421417 sm .binsha = mrepo .head .commit .binsha
@@ -542,9 +538,8 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
542538 # the default implementation will be offended and not update the repository
543539 # Maybe this is a good way to assure it doesn't get into our way, but
544540 # we want to stay backwards compatible too ... . Its so redundant !
545- writer = self .repo .config_writer ()
546- writer .set_value (sm_section (self .name ), 'url' , self .url )
547- writer .release ()
541+ with self .repo .config_writer () as writer :
542+ writer .set_value (sm_section (self .name ), 'url' , self .url )
548543 # END handle dry_run
549544 # END handle initalization
550545
@@ -731,11 +726,9 @@ def move(self, module_path, configuration=True, module=True):
731726 # END handle submodule doesn't exist
732727
733728 # update configuration
734- writer = self .config_writer (index = index ) # auto-write
735- writer .set_value ('path' , module_checkout_path )
736- self .path = module_checkout_path
737- writer .release ()
738- del (writer )
729+ with self .config_writer (index = index ) as writer : # auto-write
730+ writer .set_value ('path' , module_checkout_path )
731+ self .path = module_checkout_path
739732 # END handle configuration flag
740733 except Exception :
741734 if renamed_module :
@@ -898,13 +891,11 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
898891
899892 # now git config - need the config intact, otherwise we can't query
900893 # information anymore
901- writer = self .repo .config_writer ()
902- writer .remove_section (sm_section (self .name ))
903- writer .release ()
894+ with self .repo .config_writer () as writer :
895+ writer .remove_section (sm_section (self .name ))
904896
905- writer = self .config_writer ()
906- writer .remove_section ()
907- writer .release ()
897+ with self .config_writer () as writer :
898+ writer .remove_section ()
908899 # END delete configuration
909900
910901 return self
@@ -995,18 +986,15 @@ def rename(self, new_name):
995986 return self
996987
997988 # .git/config
998- pw = self .repo .config_writer ()
999- # As we ourselves didn't write anything about submodules into the parent .git/config, we will not require
1000- # it to exist, and just ignore missing entries
1001- if pw .has_section (sm_section (self .name )):
1002- pw .rename_section (sm_section (self .name ), sm_section (new_name ))
1003- # end
1004- pw .release ()
989+ with self .repo .config_writer () as pw :
990+ # As we ourselves didn't write anything about submodules into the parent .git/config,
991+ # we will not require it to exist, and just ignore missing entries.
992+ if pw .has_section (sm_section (self .name )):
993+ pw .rename_section (sm_section (self .name ), sm_section (new_name ))
1005994
1006995 # .gitmodules
1007- cw = self .config_writer (write = True ).config
1008- cw .rename_section (sm_section (self .name ), sm_section (new_name ))
1009- cw .release ()
996+ with self .config_writer (write = True ) as cw :
997+ cw .config .rename_section (sm_section (self .name ), sm_section (new_name ))
1010998
1011999 self ._name = new_name
10121000
0 commit comments