Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0181a40

Browse files
authored
Merge pull request#555 from ankostis/cntxtmman
Retrofit `repo` class as context-man to cleanup global mman on repo-delete
2 parents88732b6 +f858c44 commit0181a40

File tree

4 files changed

+45
-23
lines changed

4 files changed

+45
-23
lines changed

‎git/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def _init_externals():
4949
LockFile,
5050
BlockingLockFile,
5151
Stats,
52-
Actor
52+
Actor,
53+
rmtree,
5354
)
5455

5556
#} END imports

‎git/cmd.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -823,27 +823,30 @@ def _call_process(self, method, *args, **kwargs):
823823
is realized as non-existent
824824
825825
:param kwargs:
826-
is a dict of keyword arguments.
827-
This function accepts the same optional keyword arguments
828-
as execute().
829-
830-
``Examples``::
826+
It contains key-values for the following:
827+
- the :meth:`execute()` kwds, as listed in :var:`execute_kwargs`;
828+
- "command options" to be converted by :meth:`transform_kwargs()`;
829+
- the `'insert_kwargs_after'` key which its value must match one of ``*args``,
830+
and any cmd-options will be appended after the matched arg.
831+
832+
Examples::
833+
831834
git.rev_list('master', max_count=10, header=True)
835+
836+
turns into::
837+
838+
git rev-list max-count 10 --header master
832839
833840
:return: Same as ``execute``"""
834841
# Handle optional arguments prior to calling transform_kwargs
835842
# otherwise these'll end up in args, which is bad.
836-
_kwargs=dict()
837-
forkwarginexecute_kwargs:
838-
try:
839-
_kwargs[kwarg]=kwargs.pop(kwarg)
840-
exceptKeyError:
841-
pass
843+
exec_kwargs=dict((k,v)fork,vinkwargs.items()ifkinexecute_kwargs)
844+
opts_kwargs=dict((k,v)fork,vinkwargs.items()ifknotinexecute_kwargs)
842845

843-
insert_after_this_arg=kwargs.pop('insert_kwargs_after',None)
846+
insert_after_this_arg=opts_kwargs.pop('insert_kwargs_after',None)
844847

845848
# Prepare the argument list
846-
opt_args=self.transform_kwargs(**kwargs)
849+
opt_args=self.transform_kwargs(**opts_kwargs)
847850
ext_args=self.__unpack_args([aforainargsifaisnotNone])
848851

849852
ifinsert_after_this_argisNone:
@@ -852,11 +855,11 @@ def _call_process(self, method, *args, **kwargs):
852855
try:
853856
index=ext_args.index(insert_after_this_arg)
854857
exceptValueError:
855-
raiseValueError("Couldn't find argument '%s' in args %s to insertkwargs after"
858+
raiseValueError("Couldn't find argument '%s' in args %s to insertcmd options after"
856859
% (insert_after_this_arg,str(ext_args)))
857860
# end handle error
858861
args=ext_args[:index+1]+opt_args+ext_args[index+1:]
859-
# end handlekwargs
862+
# end handleopts_kwargs
860863

861864
call= [self.GIT_PYTHON_GIT_EXECUTABLE]
862865

@@ -871,7 +874,7 @@ def _call_process(self, method, *args, **kwargs):
871874
call.append(dashify(method))
872875
call.extend(args)
873876

874-
returnself.execute(call,**_kwargs)
877+
returnself.execute(call,**exec_kwargs)
875878

876879
def_parse_object_header(self,header_line):
877880
"""

‎git/repo/base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
importos.pathasosp
3434

3535
from .funimportrev_parse,is_git_dir,find_submodule_git_dir,touch
36+
importgc
37+
importgitdb
3638

3739

3840
log=logging.getLogger(__name__)
@@ -177,9 +179,21 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
177179
args.append(self.git)
178180
self.odb=odbt(*args)
179181

182+
def__enter__(self):
183+
returnself
184+
185+
def__exit__(self,exc_type,exc_value,traceback):
186+
self.close()
187+
180188
def__del__(self):
189+
self.close()
190+
191+
defclose(self):
181192
ifself.git:
182193
self.git.clear_cache()
194+
gc.collect()
195+
gitdb.util.mman.collect()
196+
gc.collect()
183197

184198
def__eq__(self,rhs):
185199
ifisinstance(rhs,Repo):

‎git/test/lib/helper.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@
77

88
importcontextlib
99
fromfunctoolsimportwraps
10-
importsys
10+
importgc
1111
importio
1212
importlogging
1313
importos
14+
importsys
1415
importtempfile
1516
importtextwrap
1617
importtime
1718

1819
fromgit.compatimportstring_types,is_win
1920
fromgit.utilimportrmtree,cwd
21+
importgitdb
2022

2123
importos.pathasosp
24+
25+
2226
ifsys.version_info[0:2]== (2,6):
2327
importunittest2asunittest
2428
else:
@@ -96,7 +100,6 @@ def wrapper(self):
96100
# a windows-only issue. In fact things should be deleted, as well as
97101
# memory maps closed, once objects go out of scope. For some reason
98102
# though this is not the case here unless we collect explicitly.
99-
importgc
100103
gc.collect()
101104
ifnotkeep:
102105
rmtree(path)
@@ -144,9 +147,10 @@ def repo_creator(self):
144147
os.chdir(prev_cwd)
145148
rw_repo.git.clear_cache()
146149
rw_repo=None
147-
importgc
148-
gc.collect()
149150
ifrepo_dirisnotNone:
151+
gc.collect()
152+
gitdb.util.mman.collect()
153+
gc.collect()
150154
rmtree(repo_dir)
151155
# END rm test repo if possible
152156
# END cleanup
@@ -303,7 +307,8 @@ def remote_repo_creator(self):
303307
rw_daemon_repo.git.clear_cache()
304308
delrw_repo
305309
delrw_daemon_repo
306-
importgc
310+
gc.collect()
311+
gitdb.util.mman.collect()
307312
gc.collect()
308313
ifrw_repo_dir:
309314
rmtree(rw_repo_dir)
@@ -357,7 +362,6 @@ def setUpClass(cls):
357362
each test type has its own repository
358363
"""
359364
fromgitimportRepo
360-
importgc
361365
gc.collect()
362366
cls.rorepo=Repo(GIT_REPO)
363367

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp