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