Mercurial > public > mercurial-scm > python-hglib
comparison hglib/context.py @ 142:fe74d5599539
hglib: wrap all application string literals in util.b() (issue4520)
Conversion also included changing use of string interpolation to
string concatenation as bytes interpolation does not exist in Python
3. Indexing related to bytes was also changed to length-1 bytes
through slicing as Python 3 returns an int in this instance.
Tests have not been switched to using util.b() so that the change to
application code can be independently verified as not being broken.
author | Brett Cannon <brett@python.org> |
---|---|
date | Sun, 08 Mar 2015 13:08:37 -0400 |
parents | a05cdc1579df |
children | c1b966866ed7 |
comparison
equal
deleted
inserted
replaced
141:ea80bd2775f6 | 142:fe74d5599539 |
---|---|
1 from hglib.error import CommandError | 1 from hglib.error import CommandError |
2 import client, util, templates | 2 import client, util, templates |
3 | 3 from hglib.util import b |
4 _nullcset = ['-1', '0000000000000000000000000000000000000000', '', '', | 4 |
5 '', '', ''] | 5 _nullcset = [b('-1'), b('0000000000000000000000000000000000000000'), b(''), |
6 b(''), b(''), b(''), b('')] | |
6 | 7 |
7 class changectx(object): | 8 class changectx(object): |
8 """A changecontext object makes access to data related to a particular | 9 """A changecontext object makes access to data related to a particular |
9 changeset convenient.""" | 10 changeset convenient.""" |
10 def __init__(self, repo, changeid=''): | 11 def __init__(self, repo, changeid=b('')): |
11 """changeid is a revision number, node, or tag""" | 12 """changeid is a revision number, node, or tag""" |
12 if changeid == '': | 13 if changeid == b(''): |
13 changeid = '.' | 14 changeid = b('.') |
14 self._repo = repo | 15 self._repo = repo |
15 if isinstance(changeid, client.revision): | 16 if isinstance(changeid, client.revision): |
16 cset = changeid | 17 cset = changeid |
17 elif changeid == -1: | 18 elif changeid == -1: |
18 cset = _nullcset | 19 cset = _nullcset |
19 else: | 20 else: |
20 if isinstance(changeid, (long, int)): | 21 if isinstance(changeid, (long, int)): |
21 changeid = 'rev(%d)' % changeid | 22 changeid = b('rev(') + str(changeid).encode('latin-1') + b(')') |
22 | 23 |
23 notfound = False | 24 notfound = False |
24 try: | 25 try: |
25 cset = self._repo.log(changeid) | 26 cset = self._repo.log(changeid) |
26 # hg bbf4f3dfd700 gave a null result for tip+1 | 27 # hg bbf4f3dfd700 gave a null result for tip+1 |
41 | 42 |
42 self._rev = int(self._rev) | 43 self._rev = int(self._rev) |
43 | 44 |
44 self._tags = self._tags.split() | 45 self._tags = self._tags.split() |
45 try: | 46 try: |
46 self._tags.remove('tip') | 47 self._tags.remove(b('tip')) |
47 except ValueError: | 48 except ValueError: |
48 pass | 49 pass |
49 | 50 |
50 self._ignored = None | 51 self._ignored = None |
51 self._clean = None | 52 self._clean = None |
87 @util.propertycache | 88 @util.propertycache |
88 def _status(self): | 89 def _status(self): |
89 return self._parsestatus(self._repo.status(change=self))[:4] | 90 return self._parsestatus(self._repo.status(change=self))[:4] |
90 | 91 |
91 def _parsestatus(self, stat): | 92 def _parsestatus(self, stat): |
92 d = dict((c, []) for c in 'MAR!?IC ') | 93 d = dict((c, []) |
94 for c in (b('M'), b('A'), b('R'), b('!'), b('?'), b('I'), | |
95 b('C'), b(' '))) | |
93 for k, path in stat: | 96 for k, path in stat: |
94 d[k].append(path) | 97 d[k].append(path) |
95 return d['M'], d['A'], d['R'], d['!'], d['?'], d['I'], d['C'] | 98 return (d[b('M')], d[b('A')], d[b('R')], d[b('!')], d[b('?')], |
99 d[b('I')], d[b('C')]) | |
96 | 100 |
97 def status(self, ignored=False, clean=False): | 101 def status(self, ignored=False, clean=False): |
98 """Explicit status query | 102 """Explicit status query |
99 Unless this method is used to query the working copy status, the | 103 Unless this method is used to query the working copy status, the |
100 _status property will implicitly read the status using its default | 104 _status property will implicitly read the status using its default |
199 def bookmarks(self): | 203 def bookmarks(self): |
200 return self._bookmarks | 204 return self._bookmarks |
201 | 205 |
202 def hidden(self): | 206 def hidden(self): |
203 """return True if the changeset is hidden, else False""" | 207 """return True if the changeset is hidden, else False""" |
204 return bool(self._repo.log(revrange='%s and hidden()' % self._node, | 208 return bool(self._repo.log(revrange=self._node + b(' and hidden()'), |
205 hidden=True)) | 209 hidden=True)) |
206 | 210 |
207 def phase(self): | 211 def phase(self): |
208 """return the phase of the changeset (public, draft or secret)""" | 212 """return the phase of the changeset (public, draft or secret)""" |
209 return self._repo.phase(str(self._rev))[0][1] | 213 return self._repo.phase(str(self._rev))[0][1] |
210 | 214 |
211 def children(self): | 215 def children(self): |
212 """return contexts for each child changeset""" | 216 """return contexts for each child changeset""" |
213 for c in self._repo.log('children(%s)' % self._node): | 217 for c in self._repo.log(b('children(') + self._node + b(')')): |
214 yield changectx(self._repo, c) | 218 yield changectx(self._repo, c) |
215 | 219 |
216 def ancestors(self): | 220 def ancestors(self): |
217 for a in self._repo.log('ancestors(%s)' % self._node): | 221 for a in self._repo.log(b('ancestors(') + self._node + b(')')): |
218 yield changectx(self._repo, a) | 222 yield changectx(self._repo, a) |
219 | 223 |
220 def descendants(self): | 224 def descendants(self): |
221 for d in self._repo.log('descendants(%s)' % self._node): | 225 for d in self._repo.log(b('descendants(') + self._node + b(')')): |
222 yield changectx(self._repo, d) | 226 yield changectx(self._repo, d) |
223 | 227 |
224 def ancestor(self, c2): | 228 def ancestor(self, c2): |
225 """ | 229 """ |
226 return the ancestor context of self and c2 | 230 return the ancestor context of self and c2 |
227 """ | 231 """ |
228 return changectx(self._repo, 'ancestor(%s, %s)' % (self, c2)) | 232 return changectx(self._repo, |
233 b('ancestor(') + self + b(', ') + c2 + b(')')) |