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

Commit2ba897b

Browse files
committed
fix(repo): make it serializable with pickle
It's entirely untested if this repo still does the right thing,but I'd think it does.Fixes#504
1 parentae6e26e commit2ba897b

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

‎doc/source/changes.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Changelog
66
=============================
77

88
* `tag.commit` will now resolve commits deeply.
9+
* `Repo` objects can now be pickled, which helps with multi-processing.
910

1011
* `DiffIndex.iter_change_type(...)` produces better results when diffing
1112
2.0.8 - Features and Bugfixes

‎git/cmd.py‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,17 @@ def _deplete_buffer(fno, handler, buf_list, wg=None):
213213

214214
defdashify(string):
215215
returnstring.replace('_','-')
216+
217+
218+
defslots_to_dict(self,exclude=()):
219+
returndict((s,getattr(self,s))forsinself.__slots__ifsnotinexclude)
220+
221+
222+
defdict_to_slots_and__excluded_are_none(self,d,excluded=()):
223+
fork,vind.items():
224+
setattr(self,k,v)
225+
forkinexcluded:
226+
setattr(self,k,None)
216227

217228
## -- End Utilities -- @}
218229

@@ -235,7 +246,15 @@ class Git(LazyMixin):
235246
"""
236247
__slots__= ("_working_dir","cat_file_all","cat_file_header","_version_info",
237248
"_git_options","_environment")
238-
249+
250+
_excluded_= ('cat_file_all','cat_file_header','_version_info')
251+
252+
def__getstate__(self):
253+
returnslots_to_dict(self,exclude=self._excluded_)
254+
255+
def__setstate__(self,d):
256+
dict_to_slots_and__excluded_are_none(self,d,excluded=self._excluded_)
257+
239258
# CONFIGURATION
240259
# The size in bytes read from stdout when copying git's output to another stream
241260
max_chunk_size=1024*64

‎git/repo/base.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ class Repo(object):
9393
9494
'git_dir' is the .git repository directory, which is always set."""
9595
DAEMON_EXPORT_FILE='git-daemon-export-ok'
96-
__slots__= ("working_dir","_working_tree_dir","git_dir","_bare","git","odb")
9796

9897
# precompiled regex
9998
re_whitespace=re.compile(r'\s+')

‎git/test/test_repo.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#
55
# This module is part of GitPython and is released under
66
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
7+
importpickle
8+
79
fromgit.test.libimport (
810
patch,
911
TestBase,
@@ -104,13 +106,15 @@ def test_tree_from_revision(self):
104106

105107
# try from invalid revision that does not exist
106108
self.failUnlessRaises(BadName,self.rorepo.tree,'hello world')
109+
110+
deftest_pickleable(self):
111+
pickle.loads(pickle.dumps(self.rorepo))
107112

108113
deftest_commit_from_revision(self):
109114
commit=self.rorepo.commit('0.1.4')
110115
assertcommit.type=='commit'
111116
assertself.rorepo.commit(commit)==commit
112117

113-
deftest_commits(self):
114118
mc=10
115119
commits=list(self.rorepo.iter_commits('0.1.6',max_count=mc))
116120
assertlen(commits)==mc

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp