From dbb866a7500f7045a6d6f78697eeb06a51a7beec Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Fri, 30 Aug 2013 19:00:10 +0200 Subject: [PATCH] Don't create the repository for each change --- radicale/storage/filesystem.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/radicale/storage/filesystem.py b/radicale/storage/filesystem.py index d2b5b14..c6efa45 100644 --- a/radicale/storage/filesystem.py +++ b/radicale/storage/filesystem.py @@ -35,11 +35,9 @@ FOLDER = os.path.expanduser(config.get("storage", "filesystem_folder")) try: from dulwich.repo import Repo -except ImportError: - GIT_FOLDER = None -else: - GIT_FOLDER = (os.path.join(FOLDER, ".git") - if os.path.isdir(os.path.join(FOLDER, ".git")) else None) + GIT_REPOSITORY = Repo(os.path.join(FOLDER, ".git")) +except: + GIT_REPOSITORY = None # This function overrides the builtin ``open`` function for this module @@ -52,11 +50,10 @@ def open(path, mode="r"): with codecs.open(abs_path, mode, config.get("encoding", "stock")) as fd: yield fd # On exit - if GIT_FOLDER and mode == "w": - repo = Repo(FOLDER) + if GIT_REPOSITORY and mode == "w": path = os.path.relpath(abs_path, FOLDER) - repo.stage([path]) - repo.do_commit("Commit by Radicale") + GIT_REPOSITORY.stage([path]) + GIT_REPOSITORY.do_commit("Commit by Radicale") # pylint: enable=W0622