@@ -33,6 +33,8 @@ |
|
|
33 |
33 |
import os.path as osp |
34 |
34 |
|
35 |
35 |
from .fun import rev_parse, is_git_dir, find_submodule_git_dir, touch |
|
36 |
+import gc |
|
37 |
+import gitdb |
36 |
38 |
|
37 |
39 |
|
38 |
40 |
log = logging.getLogger(__name__) |
@@ -177,9 +179,21 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals |
|
|
177 |
179 |
args.append(self.git) |
178 |
180 |
self.odb = odbt(*args) |
179 |
181 |
|
|
182 |
+def __enter__(self): |
|
183 |
+return self |
|
184 |
+ |
|
185 |
+def __exit__(self, exc_type, exc_value, traceback): |
|
186 |
+self.close() |
|
187 |
+ |
180 |
188 |
def __del__(self): |
|
189 |
+self.close() |
|
190 |
+ |
|
191 |
+def close(self): |
181 |
192 |
if self.git: |
182 |
193 |
self.git.clear_cache() |
|
194 |
+gc.collect() |
|
195 |
+gitdb.util.mman.collect() |
|
196 |
+gc.collect() |
183 |
197 |
|
184 |
198 |
def __eq__(self, rhs): |
185 |
199 |
if isinstance(rhs, Repo): |