@@ -398,24 +398,20 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
398
398
# otherwise there is a '-' character in front of the submodule listing
399
399
# a38efa84daef914e4de58d1905a500d8d14aaf45 mymodule (v0.9.0-1-ga38efa8)
400
400
# -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 )
404
403
405
404
# update configuration and index
406
405
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
419
415
420
416
# we deliberatly assume that our head matches our index !
421
417
sm .binsha = mrepo .head .commit .binsha
@@ -542,9 +538,8 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
542
538
# the default implementation will be offended and not update the repository
543
539
# Maybe this is a good way to assure it doesn't get into our way, but
544
540
# 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 )
548
543
# END handle dry_run
549
544
# END handle initalization
550
545
@@ -731,11 +726,9 @@ def move(self, module_path, configuration=True, module=True):
731
726
# END handle submodule doesn't exist
732
727
733
728
# 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
739
732
# END handle configuration flag
740
733
except Exception :
741
734
if renamed_module :
@@ -898,13 +891,11 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
898
891
899
892
# now git config - need the config intact, otherwise we can't query
900
893
# 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 ))
904
896
905
- writer = self .config_writer ()
906
- writer .remove_section ()
907
- writer .release ()
897
+ with self .config_writer () as writer :
898
+ writer .remove_section ()
908
899
# END delete configuration
909
900
910
901
return self
@@ -995,18 +986,15 @@ def rename(self, new_name):
995
986
return self
996
987
997
988
# .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 ))
1005
994
1006
995
# .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 ))
1010
998
1011
999
self ._name = new_name
1012
1000
0 commit comments