| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -133,18 +133,15 @@ def set_tracking_branch(self, remote_reference): | |||
| 133 | 133 | raise ValueError("Incorrect parameter type: %r" % remote_reference) | |
| 134 | 134 | # END handle type | |
| 135 | 135 | ||
| 136 | - writer = self.config_writer() | ||
| 137 | - if remote_reference is None: | ||
| 138 | - writer.remove_option(self.k_config_remote) | ||
| 139 | - writer.remove_option(self.k_config_remote_ref) | ||
| 140 | - if len(writer.options()) == 0: | ||
| 141 | - writer.remove_section() | ||
| 142 | - # END handle remove section | ||
| 143 | - else: | ||
| 144 | - writer.set_value(self.k_config_remote, remote_reference.remote_name) | ||
| 145 | - writer.set_value(self.k_config_remote_ref, Head.to_full_path(remote_reference.remote_head)) | ||
| 146 | - # END handle ref value | ||
| 147 | - writer.release() | ||
| 136 | + with self.config_writer() as writer: | ||
| 137 | + if remote_reference is None: | ||
| 138 | + writer.remove_option(self.k_config_remote) | ||
| 139 | + writer.remove_option(self.k_config_remote_ref) | ||
| 140 | + if len(writer.options()) == 0: | ||
| 141 | + writer.remove_section() | ||
| 142 | + else: | ||
| 143 | + writer.set_value(self.k_config_remote, remote_reference.remote_name) | ||
| 144 | + writer.set_value(self.k_config_remote_ref, Head.to_full_path(remote_reference.remote_head)) | ||
| 148 | 145 | ||
| 149 | 146 | return self | |
| 150 | 147 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -924,10 +924,8 @@ def _clone(cls, git, url, path, odb_default_type, progress, **kwargs): | |||
| 924 | 924 | # sure | |
| 925 | 925 | repo = cls(os.path.abspath(path), odbt=odbt) | |
| 926 | 926 | if repo.remotes: | |
| 927 | - writer = repo.remotes[0].config_writer | ||
| 928 | - writer.set_value('url', repo.remotes[0].url.replace("\\\\", "\\").replace("\\", "/")) | ||
| 929 | - # PY3: be sure cleanup is performed and lock is released | ||
| 930 | - writer.release() | ||
| 927 | + with repo.remotes[0].config_writer as writer: | ||
| 928 | + writer.set_value('url', repo.remotes[0].url.replace("\\\\", "\\").replace("\\", "/")) | ||
| 931 | 929 | # END handle remote repo | |
| 932 | 930 | return repo | |
| 933 | 931 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -237,16 +237,13 @@ def remote_repo_creator(self): | |||
| 237 | 237 | rw_remote_repo.daemon_export = True | |
| 238 | 238 | ||
| 239 | 239 | # this thing is just annoying ! | |
| 240 | - crw = rw_remote_repo.config_writer() | ||
| 241 | - section = "daemon" | ||
| 242 | - try: | ||
| 243 | - crw.add_section(section) | ||
| 244 | - except Exception: | ||
| 245 | - pass | ||
| 246 | - crw.set(section, "receivepack", True) | ||
| 247 | - # release lock | ||
| 248 | - crw.release() | ||
| 249 | - del(crw) | ||
| 240 | + with rw_remote_repo.config_writer() as crw: | ||
| 241 | + section = "daemon" | ||
| 242 | + try: | ||
| 243 | + crw.add_section(section) | ||
| 244 | + except Exception: | ||
| 245 | + pass | ||
| 246 | + crw.set(section, "receivepack", True) | ||
| 250 | 247 | ||
| 251 | 248 | # initialize the remote - first do it as local remote and pull, then | |
| 252 | 249 | # we change the url to point to the daemon. The daemon should be started | |
@@ -255,7 +252,8 @@ def remote_repo_creator(self): | |||
| 255 | 252 | d_remote.fetch() | |
| 256 | 253 | remote_repo_url = "git://localhost:%s%s" % (GIT_DAEMON_PORT, remote_repo_dir) | |
| 257 | 254 | ||
| 258 | - d_remote.config_writer.set('url', remote_repo_url) | ||
| 255 | + with d_remote.config_writer as cw: | ||
| 256 | + cw.set('url', remote_repo_url) | ||
| 259 | 257 | ||
| 260 | 258 | temp_dir = osp(_mktemp()) | |
| 261 | 259 | gd = launch_git_daemon(temp_dir, '127.0.0.1', GIT_DAEMON_PORT) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,8 +39,8 @@ def test_init_repo_object(self, rw_dir): | |||
| 39 | 39 | ||
| 40 | 40 | # [3-test_init_repo_object] | |
| 41 | 41 | repo.config_reader() # get a config reader for read-only access | |
| 42 | - cw = repo.config_writer() # get a config writer to change configuration | ||
| 43 | - cw.release() # call release() to be sure changes are written and locks are released | ||
| 42 | + with repo.config_writer(): # get a config writer to change configuration | ||
| 43 | + pass # call release() to be sure changes are written and locks are released | ||
| 44 | 44 | # ![3-test_init_repo_object] | |
| 45 | 45 | ||
| 46 | 46 | # [4-test_init_repo_object] | |
@@ -398,9 +398,8 @@ def test_references_and_objects(self, rw_dir): | |||
| 398 | 398 | ||
| 399 | 399 | # [26-test_references_and_objects] | |
| 400 | 400 | assert origin.url == repo.remotes.origin.url | |
| 401 | - cw = origin.config_writer | ||
| 402 | - cw.set("pushurl", "other_url") | ||
| 403 | - cw.release() | ||
| 401 | + with origin.config_writer as cw: | ||
| 402 | + cw.set("pushurl", "other_url") | ||
| 404 | 403 | ||
| 405 | 404 | # Please note that in python 2, writing origin.config_writer.set(...) is totally safe. | |
| 406 | 405 | # In py3 __del__ calls can be delayed, thus not writing changes in time. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -412,10 +412,9 @@ def test_index_mutation(self, rw_repo): | |||
| 412 | 412 | ||
| 413 | 413 | uname = u"Thomas Müller" | |
| 414 | 414 | umail = "sd@company.com" | |
| 415 | - writer = rw_repo.config_writer() | ||
| 416 | - writer.set_value("user", "name", uname) | ||
| 417 | - writer.set_value("user", "email", umail) | ||
| 418 | - writer.release() | ||
| 415 | + with rw_repo.config_writer() as writer: | ||
| 416 | + writer.set_value("user", "name", uname) | ||
| 417 | + writer.set_value("user", "email", umail) | ||
| 419 | 418 | self.assertEqual(writer.get_value("user", "name"), uname) | |
| 420 | 419 | ||
| 421 | 420 | # remove all of the files, provide a wild mix of paths, BaseIndexEntries, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -101,15 +101,13 @@ def test_heads(self, rwrepo): | |||
| 101 | 101 | assert prev_object == cur_object # represent the same git object | |
| 102 | 102 | assert prev_object is not cur_object # but are different instances | |
| 103 | 103 | ||
| 104 | - writer = head.config_writer() | ||
| 105 | - tv = "testopt" | ||
| 106 | - writer.set_value(tv, 1) | ||
| 107 | - assert writer.get_value(tv) == 1 | ||
| 108 | - writer.release() | ||
| 104 | + with head.config_writer() as writer: | ||
| 105 | + tv = "testopt" | ||
| 106 | + writer.set_value(tv, 1) | ||
| 107 | + assert writer.get_value(tv) == 1 | ||
| 109 | 108 | assert head.config_reader().get_value(tv) == 1 | |
| 110 | - writer = head.config_writer() | ||
| 111 | - writer.remove_option(tv) | ||
| 112 | - writer.release() | ||
| 109 | + with head.config_writer() as writer: | ||
| 110 | + writer.remove_option(tv) | ||
| 113 | 111 | ||
| 114 | 112 | # after the clone, we might still have a tracking branch setup | |
| 115 | 113 | head.set_tracking_branch(None) | |
@@ -175,7 +173,7 @@ def test_is_valid(self): | |||
| 175 | 173 | ||
| 176 | 174 | def test_orig_head(self): | |
| 177 | 175 | assert type(self.rorepo.head.orig_head()) == SymbolicReference | |
| 178 | - | ||
| 176 | + | ||
| 179 | 177 | @with_rw_repo('0.1.6') | |
| 180 | 178 | def test_head_checkout_detached_head(self, rw_repo): | |
| 181 | 179 | res = rw_repo.remotes.origin.refs.master.checkout() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -267,7 +267,8 @@ def get_info(res, remote, name): | |||
| 267 | 267 | ||
| 268 | 268 | # put origin to git-url | |
| 269 | 269 | other_origin = other_repo.remotes.origin | |
| 270 | - other_origin.config_writer.set("url", remote_repo_url) | ||
| 270 | + with other_origin.config_writer as cw: | ||
| 271 | + cw.set("url", remote_repo_url) | ||
| 271 | 272 | # it automatically creates alternates as remote_repo is shared as well. | |
| 272 | 273 | # It will use the transport though and ignore alternates when fetching | |
| 273 | 274 | # assert not other_repo.alternates # this would fail | |
@@ -416,13 +417,12 @@ def test_base(self, rw_repo, remote_repo): | |||
| 416 | 417 | self.failUnlessRaises(IOError, reader.set, opt, "test") | |
| 417 | 418 | ||
| 418 | 419 | # change value | |
| 419 | - writer = remote.config_writer | ||
| 420 | - new_val = "myval" | ||
| 421 | - writer.set(opt, new_val) | ||
| 422 | - assert writer.get(opt) == new_val | ||
| 423 | - writer.set(opt, val) | ||
| 424 | - assert writer.get(opt) == val | ||
| 425 | - del(writer) | ||
| 420 | + with remote.config_writer as writer: | ||
| 421 | + new_val = "myval" | ||
| 422 | + writer.set(opt, new_val) | ||
| 423 | + assert writer.get(opt) == new_val | ||
| 424 | + writer.set(opt, val) | ||
| 425 | + assert writer.get(opt) == val | ||
| 426 | 426 | assert getattr(remote, opt) == val | |
| 427 | 427 | # END for each default option key | |
| 428 | 428 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments