Show More
@@ -15,7 +15,6 b' import stat' | |||||
15 | from .i18n import _ |
|
15 | from .i18n import _ | |
16 | from .node import ( |
|
16 | from .node import ( | |
17 | addednodeid, |
|
17 | addednodeid, | |
18 | bin, |
|
|||
19 | hex, |
|
18 | hex, | |
20 | modifiednodeid, |
|
19 | modifiednodeid, | |
21 | nullid, |
|
20 | nullid, | |
@@ -385,70 +384,11 b' class changectx(basectx):' | |||||
385 | """A changecontext object makes access to data related to a particular |
|
384 | """A changecontext object makes access to data related to a particular | |
386 | changeset convenient. It represents a read-only context already present in |
|
385 | changeset convenient. It represents a read-only context already present in | |
387 | the repo.""" |
|
386 | the repo.""" | |
388 |
def __init__(self, repo, |
|
387 | def __init__(self, repo, rev, node): | |
389 | """changeid is a revision number, node, or tag""" |
|
388 | """changeid is a revision number, node, or tag""" | |
390 | super(changectx, self).__init__(repo) |
|
389 | super(changectx, self).__init__(repo) | |
391 |
|
390 | self._rev = rev | ||
392 | try: |
|
391 | self._node = node | |
393 | if isinstance(changeid, int): |
|
|||
394 | self._node = repo.changelog.node(changeid) |
|
|||
395 | self._rev = changeid |
|
|||
396 | return |
|
|||
397 | elif changeid == 'null': |
|
|||
398 | self._node = nullid |
|
|||
399 | self._rev = nullrev |
|
|||
400 | return |
|
|||
401 | elif changeid == 'tip': |
|
|||
402 | self._node = repo.changelog.tip() |
|
|||
403 | self._rev = repo.changelog.rev(self._node) |
|
|||
404 | return |
|
|||
405 | elif (changeid == '.' |
|
|||
406 | or repo.local() and changeid == repo.dirstate.p1()): |
|
|||
407 | # this is a hack to delay/avoid loading obsmarkers |
|
|||
408 | # when we know that '.' won't be hidden |
|
|||
409 | self._node = repo.dirstate.p1() |
|
|||
410 | self._rev = repo.unfiltered().changelog.rev(self._node) |
|
|||
411 | return |
|
|||
412 | elif len(changeid) == 20: |
|
|||
413 | try: |
|
|||
414 | self._node = changeid |
|
|||
415 | self._rev = repo.changelog.rev(changeid) |
|
|||
416 | return |
|
|||
417 | except error.FilteredLookupError: |
|
|||
418 | changeid = hex(changeid) # for the error message |
|
|||
419 | raise |
|
|||
420 | except LookupError: |
|
|||
421 | # check if it might have come from damaged dirstate |
|
|||
422 | # |
|
|||
423 | # XXX we could avoid the unfiltered if we had a recognizable |
|
|||
424 | # exception for filtered changeset access |
|
|||
425 | if (repo.local() |
|
|||
426 | and changeid in repo.unfiltered().dirstate.parents()): |
|
|||
427 | msg = _("working directory has unknown parent '%s'!") |
|
|||
428 | raise error.Abort(msg % short(changeid)) |
|
|||
429 | changeid = hex(changeid) # for the error message |
|
|||
430 |
|
||||
431 | elif len(changeid) == 40: |
|
|||
432 | try: |
|
|||
433 | self._node = bin(changeid) |
|
|||
434 | self._rev = repo.changelog.rev(self._node) |
|
|||
435 | return |
|
|||
436 | except error.FilteredLookupError: |
|
|||
437 | raise |
|
|||
438 | except LookupError: |
|
|||
439 | pass |
|
|||
440 | else: |
|
|||
441 | raise error.ProgrammingError( |
|
|||
442 | "unsupported changeid '%s' of type %s" % |
|
|||
443 | (changeid, type(changeid))) |
|
|||
444 |
|
||||
445 | except (error.FilteredIndexError, error.FilteredLookupError): |
|
|||
446 | raise error.FilteredRepoLookupError(_("filtered revision '%s'") |
|
|||
447 | % pycompat.bytestr(changeid)) |
|
|||
448 | except IndexError: |
|
|||
449 | pass |
|
|||
450 | raise error.RepoLookupError( |
|
|||
451 | _("unknown revision '%s'") % changeid) |
|
|||
452 |
|
392 | |||
453 | def __hash__(self): |
|
393 | def __hash__(self): | |
454 | try: |
|
394 | try: |
@@ -17,8 +17,10 b' import weakref' | |||||
17 |
|
17 | |||
18 | from .i18n import _ |
|
18 | from .i18n import _ | |
19 | from .node import ( |
|
19 | from .node import ( | |
|
20 | bin, | |||
20 | hex, |
|
21 | hex, | |
21 | nullid, |
|
22 | nullid, | |
|
23 | nullrev, | |||
22 | short, |
|
24 | short, | |
23 | ) |
|
25 | ) | |
24 | from . import ( |
|
26 | from . import ( | |
@@ -1214,9 +1216,67 b' class localrepository(object):' | |||||
1214 | for i in pycompat.xrange(*changeid.indices(len(self))) |
|
1216 | for i in pycompat.xrange(*changeid.indices(len(self))) | |
1215 | if i not in self.changelog.filteredrevs] |
|
1217 | if i not in self.changelog.filteredrevs] | |
1216 | try: |
|
1218 | try: | |
1217 | return context.changectx(self, changeid) |
|
1219 | if isinstance(changeid, int): | |
|
1220 | node = self.changelog.node(changeid) | |||
|
1221 | rev = changeid | |||
|
1222 | return context.changectx(self, rev, node) | |||
|
1223 | elif changeid == 'null': | |||
|
1224 | node = nullid | |||
|
1225 | rev = nullrev | |||
|
1226 | return context.changectx(self, rev, node) | |||
|
1227 | elif changeid == 'tip': | |||
|
1228 | node = self.changelog.tip() | |||
|
1229 | rev = self.changelog.rev(node) | |||
|
1230 | return context.changectx(self, rev, node) | |||
|
1231 | elif (changeid == '.' | |||
|
1232 | or self.local() and changeid == self.dirstate.p1()): | |||
|
1233 | # this is a hack to delay/avoid loading obsmarkers | |||
|
1234 | # when we know that '.' won't be hidden | |||
|
1235 | node = self.dirstate.p1() | |||
|
1236 | rev = self.unfiltered().changelog.rev(node) | |||
|
1237 | return context.changectx(self, rev, node) | |||
|
1238 | elif len(changeid) == 20: | |||
|
1239 | try: | |||
|
1240 | node = changeid | |||
|
1241 | rev = self.changelog.rev(changeid) | |||
|
1242 | return context.changectx(self, rev, node) | |||
|
1243 | except error.FilteredLookupError: | |||
|
1244 | changeid = hex(changeid) # for the error message | |||
|
1245 | raise | |||
|
1246 | except LookupError: | |||
|
1247 | # check if it might have come from damaged dirstate | |||
|
1248 | # | |||
|
1249 | # XXX we could avoid the unfiltered if we had a recognizable | |||
|
1250 | # exception for filtered changeset access | |||
|
1251 | if (self.local() | |||
|
1252 | and changeid in self.unfiltered().dirstate.parents()): | |||
|
1253 | msg = _("working directory has unknown parent '%s'!") | |||
|
1254 | raise error.Abort(msg % short(changeid)) | |||
|
1255 | changeid = hex(changeid) # for the error message | |||
|
1256 | ||||
|
1257 | elif len(changeid) == 40: | |||
|
1258 | try: | |||
|
1259 | node = bin(changeid) | |||
|
1260 | rev = self.changelog.rev(node) | |||
|
1261 | return context.changectx(self, rev, node) | |||
|
1262 | except error.FilteredLookupError: | |||
|
1263 | raise | |||
|
1264 | except LookupError: | |||
|
1265 | pass | |||
|
1266 | else: | |||
|
1267 | raise error.ProgrammingError( | |||
|
1268 | "unsupported changeid '%s' of type %s" % | |||
|
1269 | (changeid, type(changeid))) | |||
|
1270 | ||||
|
1271 | except (error.FilteredIndexError, error.FilteredLookupError): | |||
|
1272 | raise error.FilteredRepoLookupError(_("filtered revision '%s'") | |||
|
1273 | % pycompat.bytestr(changeid)) | |||
|
1274 | except IndexError: | |||
|
1275 | pass | |||
1218 | except error.WdirUnsupported: |
|
1276 | except error.WdirUnsupported: | |
1219 | return context.workingctx(self) |
|
1277 | return context.workingctx(self) | |
|
1278 | raise error.RepoLookupError( | |||
|
1279 | _("unknown revision '%s'") % changeid) | |||
1220 |
|
1280 | |||
1221 | def __contains__(self, changeid): |
|
1281 | def __contains__(self, changeid): | |
1222 | """True if the given changeid exists |
|
1282 | """True if the given changeid exists |
General Comments 0
You need to be logged in to leave comments.
Login now