diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2016-09-11 17:40:44 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2016-09-11 17:43:18 +0200 |
commit | 2ba897b12024fd20681b7c2f1b40bdbbccd5df59 (patch) | |
tree | fe1fca314bd72dfceadd36179867e43e9d66e341 /git/cmd.py | |
parent | ae6e26ed4abac8b5e4e0a893da5546cd165d48e7 (diff) | |
download | gitpython-2ba897b12024fd20681b7c2f1b40bdbbccd5df59.tar.gz |
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
Diffstat (limited to 'git/cmd.py')
-rw-r--r-- | git/cmd.py | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -213,6 +213,17 @@ def handle_process_output(process, stdout_handler, stderr_handler, finalizer): def dashify(string): return string.replace('_', '-') + + +def slots_to_dict(self, exclude=()): + return dict((s, getattr(self, s)) for s in self.__slots__ if s not in exclude) + + +def dict_to_slots_and__excluded_are_none(self, d, excluded=()): + for k, v in d.items(): + setattr(self, k, v) + for k in excluded: + setattr(self, k, None) ## -- End Utilities -- @} @@ -235,7 +246,15 @@ class Git(LazyMixin): """ __slots__ = ("_working_dir", "cat_file_all", "cat_file_header", "_version_info", "_git_options", "_environment") - + + _excluded_ = ('cat_file_all', 'cat_file_header', '_version_info') + + def __getstate__(self): + return slots_to_dict(self, exclude=self._excluded_) + + def __setstate__(self, d): + dict_to_slots_and__excluded_are_none(self, d, excluded=self._excluded_) + # CONFIGURATION # The size in bytes read from stdout when copying git's output to another stream max_chunk_size = 1024 * 64 |