summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2009-04-17 11:00:31 -0700
committerShawn O. Pearce <sop@google.com>2009-04-17 11:00:31 -0700
commitf8e3273decd883f334939cb24e542d47aba21a43 (patch)
treea66cbf8e107ee6914abb2ad1c4fd6a3c54807fe1
parent006734b7981289856f71501f3685fd0ee6d27a6d (diff)
downloadgit-repo-f8e3273decd883f334939cb24e542d47aba21a43.tar.gz
Supporrt mixed case subsection names in Git config files
In the case of: [url "Foo"] insteadOf = Bar We should return "Bar" for the key "url.Foo.insteadof", but not for the key "url.foo.insteadof". This requires splitting the key into its components and only lower casing the section and value name, leaving the subsection portion alone. Signed-off-by: Shawn O. Pearce <sop@google.com>
-rw-r--r--git_config.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/git_config.py b/git_config.py
index 1d45d92f..9b63417e 100644
--- a/git_config.py
+++ b/git_config.py
@@ -29,6 +29,13 @@ REVIEW_CACHE = dict()
29def IsId(rev): 29def IsId(rev):
30 return ID_RE.match(rev) 30 return ID_RE.match(rev)
31 31
32def _key(name):
33 parts = name.split('.')
34 if len(parts) < 2:
35 return name.lower()
36 parts[ 0] = parts[ 0].lower()
37 parts[-1] = parts[-1].lower()
38 return '.'.join(parts)
32 39
33class GitConfig(object): 40class GitConfig(object):
34 _ForUser = None 41 _ForUser = None
@@ -54,8 +61,7 @@ class GitConfig(object):
54 def Has(self, name, include_defaults = True): 61 def Has(self, name, include_defaults = True):
55 """Return true if this configuration file has the key. 62 """Return true if this configuration file has the key.
56 """ 63 """
57 name = name.lower() 64 if _key(name) in self._cache:
58 if name in self._cache:
59 return True 65 return True
60 if include_defaults and self.defaults: 66 if include_defaults and self.defaults:
61 return self.defaults.Has(name, include_defaults = True) 67 return self.defaults.Has(name, include_defaults = True)
@@ -83,10 +89,8 @@ class GitConfig(object):
83 This configuration file is used first, if the key is not 89 This configuration file is used first, if the key is not
84 defined or all = True then the defaults are also searched. 90 defined or all = True then the defaults are also searched.
85 """ 91 """
86 name = name.lower()
87
88 try: 92 try:
89 v = self._cache[name] 93 v = self._cache[_key(name)]
90 except KeyError: 94 except KeyError:
91 if self.defaults: 95 if self.defaults:
92 return self.defaults.GetString(name, all = all) 96 return self.defaults.GetString(name, all = all)
@@ -110,16 +114,16 @@ class GitConfig(object):
110 The supplied value should be either a string, 114 The supplied value should be either a string,
111 or a list of strings (to store multiple values). 115 or a list of strings (to store multiple values).
112 """ 116 """
113 name = name.lower() 117 key = _key(name)
114 118
115 try: 119 try:
116 old = self._cache[name] 120 old = self._cache[key]
117 except KeyError: 121 except KeyError:
118 old = [] 122 old = []
119 123
120 if value is None: 124 if value is None:
121 if old: 125 if old:
122 del self._cache[name] 126 del self._cache[key]
123 self._do('--unset-all', name) 127 self._do('--unset-all', name)
124 128
125 elif isinstance(value, list): 129 elif isinstance(value, list):
@@ -130,13 +134,13 @@ class GitConfig(object):
130 self.SetString(name, value[0]) 134 self.SetString(name, value[0])
131 135
132 elif old != value: 136 elif old != value:
133 self._cache[name] = list(value) 137 self._cache[key] = list(value)
134 self._do('--replace-all', name, value[0]) 138 self._do('--replace-all', name, value[0])
135 for i in xrange(1, len(value)): 139 for i in xrange(1, len(value)):
136 self._do('--add', name, value[i]) 140 self._do('--add', name, value[i])
137 141
138 elif len(old) != 1 or old[0] != value: 142 elif len(old) != 1 or old[0] != value:
139 self._cache[name] = [value] 143 self._cache[key] = [value]
140 self._do('--replace-all', name, value) 144 self._do('--replace-all', name, value)
141 145
142 def GetRemote(self, name): 146 def GetRemote(self, name):
@@ -172,7 +176,7 @@ class GitConfig(object):
172 lf = d.index('\n') 176 lf = d.index('\n')
173 nul = d.index('\0', lf + 1) 177 nul = d.index('\0', lf + 1)
174 178
175 key = d[0:lf] 179 key = _key(d[0:lf])
176 val = d[lf + 1:nul] 180 val = d[lf + 1:nul]
177 181
178 if key in c: 182 if key in c: