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

[StGit PATCH 1/3] Populate the cached config options with the defaults

From
CMCatalin Marinas <catalin.marinas@arm.com>
Date
Jan 8, 2010, 12:35 UTC
Message-ID
<20100108123559.24161.14842.stgit@pc1117.cambridge.arm.com>
In-Reply-To
<20100108123403.24161.3495.stgit@pc1117.cambridge.arm.com>

The patch pre-populates the cached config options with the default values. It also removes an unused option (stgit.extensions).

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
 stgit/config.py |   28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/stgit/config.py b/stgit/config.py
index 796f2c9..811138d 100644
--- a/stgit/config.py
+++ b/stgit/config.py
@@ -28,16 +28,15 @@ class GitConfigException(StgException):
 
 class GitConfig:
     __defaults={
-        'stgit.smtpserver':	'localhost:25',
-        'stgit.smtpdelay':	'5',
-        'stgit.pullcmd':	'git pull',
-        'stgit.fetchcmd':	'git fetch',
-        'stgit.pull-policy':	'pull',
-        'stgit.autoimerge':	'no',
-        'stgit.keepoptimized':	'no',
-        'stgit.extensions':	'.ancestor .current .patched',
-        'stgit.shortnr': '5',
-        'stgit.pager':  'less'
+        'stgit.smtpserver':     ['localhost:25'],
+        'stgit.smtpdelay':      ['5'],
+        'stgit.pullcmd':        ['git pull'],
+        'stgit.fetchcmd':       ['git fetch'],
+        'stgit.pull-policy':    ['pull'],
+        'stgit.autoimerge':     ['no'],
+        'stgit.keepoptimized':  ['no'],
+        'stgit.shortnr':        ['5'],
+        'stgit.pager':          ['less']
         }
 
     __cache = None
@@ -47,7 +46,7 @@ class GitConfig:
         done already."""
         if self.__cache is not None:
             return
-        self.__cache = {}
+        self.__cache = self.__defaults
         lines = Run('git', 'config', '--null', '--list'
                    ).discard_exitcode().raw_output()
         for line in filter(None, lines.split('\0')):
@@ -56,9 +55,10 @@ class GitConfig:
 
     def get(self, name):
         self.load()
-        if name not in self.__cache:
-            self.__cache[name] = [self.__defaults.get(name, None)]
-        return self.__cache[name][-1]
+        try:
+            return self.__cache[name][-1]
+        except KeyError:
+            return None
 
     def getall(self, name):
         self.load()
Previous: Catalin MarinasNext: Karl Wiberg
Message 2 of 6 in “Support for command aliases”
  1. 0/3 Support for command aliasesCatalin Marinas, Jan 8, 2010
  2. 1/3 Populate the cached config options with the defaultsCatalin Marinas, Jan 8, 2010
  3. Karl WibergJan 8, 2010
  4. Karl WibergJan 8, 2010
  5. 2/3 Add support for command aliasesCatalin Marinas, Jan 8, 2010
  6. 3/3 Replace some git commands with stg aliases in test scriptsCatalin Marinas, Jan 8, 2010

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.