Mercurial > hgsubversion
comparison hgsubversion/maps.py @ 1429:3a723188051e
AuthorMap: make local implementation concerns stop using self.meta
This is part of a series of changes which will let us stop passing
meta into the map layer.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Sun, 05 Jun 2016 20:26:17 -0400 |
parents | da272633997f |
children | 48beb467b2e5 |
comparison
equal
deleted
inserted
replaced
1428:da272633997f | 1429:3a723188051e |
---|---|
180 | 180 |
181 If the 'hgsubversion.caseignoreauthors' configuration option is set to true, | 181 If the 'hgsubversion.caseignoreauthors' configuration option is set to true, |
182 the userid from Subversion is always compared lowercase. | 182 the userid from Subversion is always compared lowercase. |
183 ''' | 183 ''' |
184 | 184 |
185 def __init__(self, meta): | 185 def __init__(self, meta, defaulthost, caseignoreauthors, |
186 mapauthorscmd, defaultauthors): | |
186 '''Initialise a new AuthorMap. | 187 '''Initialise a new AuthorMap. |
187 | 188 |
188 The ui argument is used to print diagnostic messages. | 189 The ui argument is used to print diagnostic messages. |
189 | 190 |
190 The path argument is the location of the backing store, | 191 The path argument is the location of the backing store, |
191 typically .hg/svn/authors. | 192 typically .hg/svn/authors. |
192 ''' | 193 ''' |
193 self.defaulthost = '' | 194 if defaulthost: |
194 if meta.defaulthost: | 195 self.defaulthost = '@%s' % defaulthost.lstrip('@') |
195 self.defaulthost = '@%s' % meta.defaulthost.lstrip('@') | 196 else: |
197 self.defaulthost = '' | |
198 self._caseignoreauthors = caseignoreauthors | |
199 self._mapauthorscmd = mapauthorscmd | |
200 self._defaulthost = defaulthost | |
201 self._defaultauthors = defaultauthors | |
196 | 202 |
197 super(AuthorMap, self).__init__(meta) | 203 super(AuthorMap, self).__init__(meta) |
198 | 204 |
199 def _lowercase(self, key): | 205 def _lowercase(self, key): |
200 '''Determine whether or not to lowercase a str or regex using the | 206 '''Determine whether or not to lowercase a str or regex using the |
201 meta.caseignoreauthors.''' | 207 meta.caseignoreauthors.''' |
202 k = key | 208 k = key |
203 if self.meta.caseignoreauthors: | 209 if self._caseignoreauthors: |
204 if isinstance(key, str): | 210 if isinstance(key, str): |
205 k = key.lower() | 211 k = key.lower() |
206 else: | 212 else: |
207 k = re.compile(key.pattern.lower()) | 213 k = re.compile(key.pattern.lower()) |
208 return k | 214 return k |
228 | 234 |
229 if not isinstance(author, str): | 235 if not isinstance(author, str): |
230 return super(AuthorMap, self).__getitem__(author) | 236 return super(AuthorMap, self).__getitem__(author) |
231 | 237 |
232 search_author = author | 238 search_author = author |
233 if self.meta.caseignoreauthors: | 239 if self._caseignoreauthors: |
234 search_author = author.lower() | 240 search_author = author.lower() |
235 | 241 |
236 result = None | 242 result = None |
237 if search_author in self: | 243 if search_author in self: |
238 result = super(AuthorMap, self).__getitem__(search_author) | 244 result = super(AuthorMap, self).__getitem__(search_author) |
239 elif self.meta.mapauthorscmd: | 245 elif self._mapauthorscmd: |
240 cmd = self.meta.mapauthorscmd % author | 246 cmd = self._mapauthorscmd % author |
241 process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) | 247 process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) |
242 output, err = process.communicate() | 248 output, err = process.communicate() |
243 retcode = process.poll() | 249 retcode = process.poll() |
244 if retcode: | 250 if retcode: |
245 msg = 'map author command "%s" exited with error' | 251 msg = 'map author command "%s" exited with error' |
246 raise hgutil.Abort(msg % cmd) | 252 raise hgutil.Abort(msg % cmd) |
247 self[author] = result = output.strip() | 253 self[author] = result = output.strip() |
248 if not result: | 254 if not result: |
249 if self.meta.defaultauthors: | 255 if self._defaultauthors: |
250 self[author] = result = '%s%s' % (author, self.defaulthost) | 256 self[author] = result = '%s%s' % (author, self.defaulthost) |
251 msg = 'substituting author "%s" for default "%s"\n' | 257 msg = 'substituting author "%s" for default "%s"\n' |
252 self._ui.debug(msg % (author, result)) | 258 self._ui.debug(msg % (author, result)) |
253 else: | 259 else: |
254 msg = 'author %s has no entry in the author map!' | 260 msg = 'author %s has no entry in the author map!' |