git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: "Karl Hasselström" <kha@treskal.com>
Cc: git@vger.kernel.org
Subject: [StGit PATCH 1/3] Populate the cached config options with the defaults
Date: Fri, 08 Jan 2010 12:35:59 +0000	[thread overview]
Message-ID: <20100108123559.24161.14842.stgit@pc1117.cambridge.arm.com> (raw)
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()

  reply	other threads:[~2010-01-08 12:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-08 12:35 [StGit PATCH 0/3] Support for command aliases Catalin Marinas
2010-01-08 12:35 ` Catalin Marinas [this message]
2010-01-08 14:30   ` [StGit PATCH 1/3] Populate the cached config options with the defaults Karl Wiberg
2010-01-08 14:34     ` Karl Wiberg
2010-01-08 12:36 ` [StGit PATCH 2/3] Add support for command aliases Catalin Marinas
2010-01-08 12:36 ` [StGit PATCH 3/3] Replace some git commands with stg aliases in test scripts Catalin Marinas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100108123559.24161.14842.stgit@pc1117.cambridge.arm.com \
    --to=catalin.marinas@arm.com \
    --cc=catalin.marinas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=kha@treskal.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).