Cache the per-user configuration to avoid duplicate instances
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/git_config.py b/git_config.py
index f6c5bd1..76031a0 100644
--- a/git_config.py
+++ b/git_config.py
@@ -28,9 +28,13 @@
class GitConfig(object):
+ _ForUser = None
+
@classmethod
def ForUser(cls):
- return cls(file = os.path.expanduser('~/.gitconfig'))
+ if cls._ForUser is None:
+ cls._ForUser = cls(file = os.path.expanduser('~/.gitconfig'))
+ return cls._ForUser
@classmethod
def ForRepository(cls, gitdir, defaults=None):