git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/7] Add caching to the new config class.

From
Yann Dirson <ydirson@altern.org>
Date
Jan 29, 2007, 23:05 UTC
Message-ID
<20070129230530.7102.65330.stgit@gandelf.nowhere.earth>
In-Reply-To
<20070129230117.7102.64322.stgit@gandelf.nowhere.earth>
Signed-off-by: Yann Dirson <ydirson@altern.org>
---
 stgit/config.py |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/stgit/config.py b/stgit/config.py
index d42754b..901f600 100644
--- a/stgit/config.py
+++ b/stgit/config.py
@@ -39,6 +39,8 @@ class GitConfig:
         'stgit.shortnr':	 '5'
         }
 
+    __cache={}
+
     def __run(self, cmd, args=None):
         """__run: runs cmd using spawnvp.
     
@@ -59,20 +61,31 @@ class GitConfig:
         return 0
     
     def get(self, name):
+        if self.__cache.has_key(name):
+            return self.__cache[name]
+
         stream = os.popen('git repo-config --get %s' % name, 'r')
         value = stream.readline().strip()
         stream.close()
         if len(value) > 0:
-            return value
+            pass
         elif (self.__defaults.has_key(name)):
-            return self.__defaults[name]
+            value = self.__defaults[name]
         else:
-            return None
+            value = None
+
+        self.__cache[name] = value
+        return value
 
     def getall(self, name):
+        if self.__cache.has_key(name):
+            return self.__cache[name]
+
         stream = os.popen('git repo-config --get-all %s' % name, 'r')
         values = [line.strip() for line in stream]
         stream.close()
+
+        self.__cache[name] = values
         return values
 
     def getint(self, name):
Previous: Yann DirsonNext: Yann Dirson
Message 3 of 10 in “StGIT, remotes, and parent”
  1. 0/7 StGIT, remotes, and parentYann Dirson, Jan 29, 2007
  2. 1/7 Make stgit.config use git-repo-config.Yann Dirson, Jan 29, 2007
  3. 2/7 Add caching to the new config class.Yann Dirson, Jan 29, 2007
  4. 3/7 Move identification of parent branch's remote def up into stack class.Yann Dirson, Jan 29, 2007
  5. 4/7 Allows extraction of information about remotes.Yann Dirson, Jan 29, 2007
  6. 5/7 Basic support for keeping a ref to the parent branch.Yann Dirson, Jan 29, 2007
  7. 6/7 Have 'stg branch --create' record parent information.Yann Dirson, Jan 29, 2007
  8. 7/7 Make 'stg pull' use git-fetch and not git-pull.Yann Dirson, Jan 29, 2007
  9. Catalin MarinasJan 31, 2007
  10. Yann DirsonFeb 1, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.