Mercurial > public > mercurial-scm > hg
comparison mercurial/state.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 2372284d9457 |
children | 8ff1ecfadcd1 |
comparison
equal
deleted
inserted
replaced
43076:2372284d9457 | 43077:687b865b95ad |
---|---|
58 | 58 |
59 we use third-party library cbor to serialize data to write in the file. | 59 we use third-party library cbor to serialize data to write in the file. |
60 """ | 60 """ |
61 if not isinstance(version, int): | 61 if not isinstance(version, int): |
62 raise error.ProgrammingError( | 62 raise error.ProgrammingError( |
63 "version of state file should be" " an integer" | 63 b"version of state file should be" b" an integer" |
64 ) | 64 ) |
65 | 65 |
66 with self._repo.vfs(self.fname, 'wb', atomictemp=True) as fp: | 66 with self._repo.vfs(self.fname, b'wb', atomictemp=True) as fp: |
67 fp.write('%d\n' % version) | 67 fp.write(b'%d\n' % version) |
68 for chunk in cborutil.streamencode(data): | 68 for chunk in cborutil.streamencode(data): |
69 fp.write(chunk) | 69 fp.write(chunk) |
70 | 70 |
71 def _read(self): | 71 def _read(self): |
72 """reads the state file and returns a dictionary which contain | 72 """reads the state file and returns a dictionary which contain |
73 data in the same format as it was before storing""" | 73 data in the same format as it was before storing""" |
74 with self._repo.vfs(self.fname, 'rb') as fp: | 74 with self._repo.vfs(self.fname, b'rb') as fp: |
75 try: | 75 try: |
76 int(fp.readline()) | 76 int(fp.readline()) |
77 except ValueError: | 77 except ValueError: |
78 raise error.CorruptedState( | 78 raise error.CorruptedState( |
79 "unknown version of state file" " found" | 79 b"unknown version of state file" b" found" |
80 ) | 80 ) |
81 | 81 |
82 return cborutil.decodeall(fp.read())[0] | 82 return cborutil.decodeall(fp.read())[0] |
83 | 83 |
84 def delete(self): | 84 def delete(self): |
131 """returns the hint message corresponding to the command for | 131 """returns the hint message corresponding to the command for |
132 hg status --verbose | 132 hg status --verbose |
133 """ | 133 """ |
134 if not self._statushint: | 134 if not self._statushint: |
135 hint = _( | 135 hint = _( |
136 'To continue: hg %s --continue\n' | 136 b'To continue: hg %s --continue\n' |
137 'To abort: hg %s --abort' | 137 b'To abort: hg %s --abort' |
138 ) % (self._opname, self._opname) | 138 ) % (self._opname, self._opname) |
139 if self._stopflag: | 139 if self._stopflag: |
140 hint = hint + ( | 140 hint = hint + ( |
141 _('\nTo stop: hg %s --stop') % (self._opname) | 141 _(b'\nTo stop: hg %s --stop') % (self._opname) |
142 ) | 142 ) |
143 return hint | 143 return hint |
144 return self._statushint | 144 return self._statushint |
145 | 145 |
146 def hint(self): | 146 def hint(self): |
147 """returns the hint message corresponding to an interrupted | 147 """returns the hint message corresponding to an interrupted |
148 operation | 148 operation |
149 """ | 149 """ |
150 if not self._cmdhint: | 150 if not self._cmdhint: |
151 return _("use 'hg %s --continue' or 'hg %s --abort'") % ( | 151 return _(b"use 'hg %s --continue' or 'hg %s --abort'") % ( |
152 self._opname, | 152 self._opname, |
153 self._opname, | 153 self._opname, |
154 ) | 154 ) |
155 return self._cmdhint | 155 return self._cmdhint |
156 | 156 |
157 def msg(self): | 157 def msg(self): |
158 """returns the status message corresponding to the command""" | 158 """returns the status message corresponding to the command""" |
159 if not self._cmdmsg: | 159 if not self._cmdmsg: |
160 return _('%s in progress') % (self._opname) | 160 return _(b'%s in progress') % (self._opname) |
161 return self._cmdmsg | 161 return self._cmdmsg |
162 | 162 |
163 def continuemsg(self): | 163 def continuemsg(self): |
164 """ returns appropriate continue message corresponding to command""" | 164 """ returns appropriate continue message corresponding to command""" |
165 return _('hg %s --continue') % (self._opname) | 165 return _(b'hg %s --continue') % (self._opname) |
166 | 166 |
167 def isunfinished(self, repo): | 167 def isunfinished(self, repo): |
168 """determines whether a multi-step operation is in progress | 168 """determines whether a multi-step operation is in progress |
169 or not | 169 or not |
170 """ | 170 """ |
171 if self._opname == 'merge': | 171 if self._opname == b'merge': |
172 return len(repo[None].parents()) > 1 | 172 return len(repo[None].parents()) > 1 |
173 else: | 173 else: |
174 return repo.vfs.exists(self._fname) | 174 return repo.vfs.exists(self._fname) |
175 | 175 |
176 | 176 |
184 clearable=False, | 184 clearable=False, |
185 allowcommit=False, | 185 allowcommit=False, |
186 reportonly=False, | 186 reportonly=False, |
187 continueflag=False, | 187 continueflag=False, |
188 stopflag=False, | 188 stopflag=False, |
189 cmdmsg="", | 189 cmdmsg=b"", |
190 cmdhint="", | 190 cmdhint=b"", |
191 statushint="", | 191 statushint=b"", |
192 abortfunc=None, | 192 abortfunc=None, |
193 continuefunc=None, | 193 continuefunc=None, |
194 ): | 194 ): |
195 """this registers a new command or operation to unfinishedstates | 195 """this registers a new command or operation to unfinishedstates |
196 opname is the name the command or operation | 196 opname is the name the command or operation |
231 cmdhint, | 231 cmdhint, |
232 statushint, | 232 statushint, |
233 abortfunc, | 233 abortfunc, |
234 continuefunc, | 234 continuefunc, |
235 ) | 235 ) |
236 if opname == 'merge': | 236 if opname == b'merge': |
237 _unfinishedstates.append(statecheckobj) | 237 _unfinishedstates.append(statecheckobj) |
238 else: | 238 else: |
239 _unfinishedstates.insert(0, statecheckobj) | 239 _unfinishedstates.insert(0, statecheckobj) |
240 | 240 |
241 | 241 |
242 addunfinished( | 242 addunfinished( |
243 'update', | 243 b'update', |
244 fname='updatestate', | 244 fname=b'updatestate', |
245 clearable=True, | 245 clearable=True, |
246 cmdmsg=_('last update was interrupted'), | 246 cmdmsg=_(b'last update was interrupted'), |
247 cmdhint=_("use 'hg update' to get a consistent checkout"), | 247 cmdhint=_(b"use 'hg update' to get a consistent checkout"), |
248 statushint=_("To continue: hg update ."), | 248 statushint=_(b"To continue: hg update ."), |
249 ) | 249 ) |
250 addunfinished( | 250 addunfinished( |
251 'bisect', | 251 b'bisect', |
252 fname='bisect.state', | 252 fname=b'bisect.state', |
253 allowcommit=True, | 253 allowcommit=True, |
254 reportonly=True, | 254 reportonly=True, |
255 statushint=_( | 255 statushint=_( |
256 'To mark the changeset good: hg bisect --good\n' | 256 b'To mark the changeset good: hg bisect --good\n' |
257 'To mark the changeset bad: hg bisect --bad\n' | 257 b'To mark the changeset bad: hg bisect --bad\n' |
258 'To abort: hg bisect --reset\n' | 258 b'To abort: hg bisect --reset\n' |
259 ), | 259 ), |
260 ) | 260 ) |
261 | 261 |
262 | 262 |
263 def getrepostate(repo): | 263 def getrepostate(repo): |
264 # experimental config: commands.status.skipstates | 264 # experimental config: commands.status.skipstates |
265 skip = set(repo.ui.configlist('commands', 'status.skipstates')) | 265 skip = set(repo.ui.configlist(b'commands', b'status.skipstates')) |
266 for state in _unfinishedstates: | 266 for state in _unfinishedstates: |
267 if state._opname in skip: | 267 if state._opname in skip: |
268 continue | 268 continue |
269 if state.isunfinished(repo): | 269 if state.isunfinished(repo): |
270 return (state._opname, state.statusmsg()) | 270 return (state._opname, state.statusmsg()) |