From 2ba897b12024fd20681b7c2f1b40bdbbccd5df59 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 11 Sep 2016 17:40:44 +0200 Subject: 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 --- git/cmd.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'git/cmd.py') diff --git a/git/cmd.py b/git/cmd.py index 62eef9e4..ceea2442 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -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 -- cgit v1.2.1