##// END OF EJS Templates
libgit2: always cleanup after opening a repository, this way we don't lock the repo in multi-worker env
marcink -
r731:34168bd1 default
parent child Browse files
Show More
@@ -158,7 +158,8 b' class GitRemote(object):'
158 158
159 159 @reraise_safe_exceptions
160 160 def is_empty(self, wire):
161 repo = self._factory.repo_libgit2(wire)
161 repo_init = self._factory.repo_libgit2(wire)
162 with repo_init as repo:
162 163
163 164 try:
164 165 has_head = repo.head.name
@@ -174,7 +175,8 b' class GitRemote(object):'
174 175
175 176 @reraise_safe_exceptions
176 177 def add_object(self, wire, content):
177 repo = self._factory.repo(wire)
178 repo_init = self._factory.repo_libgit2(wire)
179 with repo_init as repo:
178 180 blob = objects.Blob()
179 181 blob.set_raw_string(content)
180 182 repo.object_store.add_object(blob)
@@ -183,7 +185,9 b' class GitRemote(object):'
183 185 @reraise_safe_exceptions
184 186 def assert_correct_path(self, wire):
185 187 try:
186 self._factory.repo_libgit2(wire)
188 repo_init = self._factory.repo_libgit2(wire)
189 with repo_init as repo:
190 pass
187 191 except pygit2.GitError:
188 192 path = wire.get('path')
189 193 tb = traceback.format_exc()
@@ -194,7 +198,8 b' class GitRemote(object):'
194 198
195 199 @reraise_safe_exceptions
196 200 def bare(self, wire):
197 repo = self._factory.repo_libgit2(wire)
201 repo_init = self._factory.repo_libgit2(wire)
202 with repo_init as repo:
198 203 return repo.is_bare
199 204
200 205 @reraise_safe_exceptions
@@ -232,7 +237,6 b' class GitRemote(object):'
232 237 @reraise_safe_exceptions
233 238 def is_large_file(self, wire, sha):
234 239 repo_init = self._factory.repo_libgit2(wire)
235
236 240 with repo_init as repo:
237 241 blob = repo[sha]
238 242 if blob.is_binary:
@@ -242,12 +246,14 b' class GitRemote(object):'
242 246
243 247 @reraise_safe_exceptions
244 248 def in_largefiles_store(self, wire, oid):
245 repo = self._factory.repo_libgit2(wire)
246 249 conf = self._wire_to_config(wire)
250 repo_init = self._factory.repo_libgit2(wire)
251 with repo_init as repo:
252 repo_name = repo.path
247 253
248 254 store_location = conf.get('vcs_git_lfs_store_location')
249 255 if store_location:
250 repo_name = repo.path
256
251 257 store = LFSOidStore(
252 258 oid=oid, repo=repo_name, store_location=store_location)
253 259 return store.has_oid()
@@ -256,12 +262,13 b' class GitRemote(object):'
256 262
257 263 @reraise_safe_exceptions
258 264 def store_path(self, wire, oid):
259 repo = self._factory.repo_libgit2(wire)
260 265 conf = self._wire_to_config(wire)
266 repo_init = self._factory.repo_libgit2(wire)
267 with repo_init as repo:
268 repo_name = repo.path
261 269
262 270 store_location = conf.get('vcs_git_lfs_store_location')
263 271 if store_location:
264 repo_name = repo.path
265 272 store = LFSOidStore(
266 273 oid=oid, repo=repo_name, store_location=store_location)
267 274 return store.oid_path
@@ -605,7 +612,8 b' class GitRemote(object):'
605 612
606 613 @reraise_safe_exceptions
607 614 def get_object(self, wire, sha):
608 repo = self._factory.repo_libgit2(wire)
615 repo_init = self._factory.repo_libgit2(wire)
616 with repo_init as repo:
609 617
610 618 missing_commit_err = 'Commit {} does not exist for `{}`'.format(sha, wire['path'])
611 619 try:
@@ -633,8 +641,8 b' class GitRemote(object):'
633 641
634 642 @reraise_safe_exceptions
635 643 def get_refs(self, wire):
636 repo = self._factory.repo_libgit2(wire)
637
644 repo_init = self._factory.repo_libgit2(wire)
645 with repo_init as repo:
638 646 result = {}
639 647 for ref in repo.references:
640 648 peeled_sha = repo.lookup_reference(ref).peel()
@@ -644,7 +652,8 b' class GitRemote(object):'
644 652
645 653 @reraise_safe_exceptions
646 654 def head(self, wire, show_exc=True):
647 repo = self._factory.repo_libgit2(wire)
655 repo_init = self._factory.repo_libgit2(wire)
656 with repo_init as repo:
648 657 try:
649 658 return repo.head.peel().hex
650 659 except Exception:
@@ -663,7 +672,8 b' class GitRemote(object):'
663 672
664 673 @reraise_safe_exceptions
665 674 def revision(self, wire, rev):
666 repo = self._factory.repo_libgit2(wire)
675 repo_init = self._factory.repo_libgit2(wire)
676 with repo_init as repo:
667 677 commit = repo[rev]
668 678 obj_data = {
669 679 'id': commit.id.hex,
@@ -676,14 +686,16 b' class GitRemote(object):'
676 686
677 687 @reraise_safe_exceptions
678 688 def date(self, wire, rev):
679 repo = self._factory.repo_libgit2(wire)
689 repo_init = self._factory.repo_libgit2(wire)
690 with repo_init as repo:
680 691 commit = repo[rev]
681 692 # TODO(marcink): check dulwich difference of offset vs timezone
682 693 return [commit.commit_time, commit.commit_time_offset]
683 694
684 695 @reraise_safe_exceptions
685 696 def author(self, wire, rev):
686 repo = self._factory.repo_libgit2(wire)
697 repo_init = self._factory.repo_libgit2(wire)
698 with repo_init as repo:
687 699 commit = repo[rev]
688 700 if commit.author.email:
689 701 return u"{} <{}>".format(commit.author.name, commit.author.email)
@@ -692,24 +704,28 b' class GitRemote(object):'
692 704
693 705 @reraise_safe_exceptions
694 706 def message(self, wire, rev):
695 repo = self._factory.repo_libgit2(wire)
707 repo_init = self._factory.repo_libgit2(wire)
708 with repo_init as repo:
696 709 commit = repo[rev]
697 710 return commit.message
698 711
699 712 @reraise_safe_exceptions
700 713 def parents(self, wire, rev):
701 repo = self._factory.repo_libgit2(wire)
714 repo_init = self._factory.repo_libgit2(wire)
715 with repo_init as repo:
702 716 commit = repo[rev]
703 717 return [x.hex for x in commit.parent_ids]
704 718
705 719 @reraise_safe_exceptions
706 720 def set_refs(self, wire, key, value):
707 repo = self._factory.repo_libgit2(wire)
721 repo_init = self._factory.repo_libgit2(wire)
722 with repo_init as repo:
708 723 repo.references.create(key, value, force=True)
709 724
710 725 @reraise_safe_exceptions
711 726 def create_branch(self, wire, branch_name, commit_id, force=False):
712 repo = self._factory.repo_libgit2(wire)
727 repo_init = self._factory.repo_libgit2(wire)
728 with repo_init as repo:
713 729 commit = repo[commit_id]
714 730
715 731 if force:
@@ -720,12 +736,14 b' class GitRemote(object):'
720 736
721 737 @reraise_safe_exceptions
722 738 def remove_ref(self, wire, key):
723 repo = self._factory.repo_libgit2(wire)
739 repo_init = self._factory.repo_libgit2(wire)
740 with repo_init as repo:
724 741 repo.references.delete(key)
725 742
726 743 @reraise_safe_exceptions
727 744 def tag_remove(self, wire, tag_name):
728 repo = self._factory.repo_libgit2(wire)
745 repo_init = self._factory.repo_libgit2(wire)
746 with repo_init as repo:
729 747 key = 'refs/tags/{}'.format(tag_name)
730 748 repo.references.delete(key)
731 749
General Comments 0
You need to be logged in to leave comments. Login now