mercurial/context.py
changeset 3219 618a7f2c1b82
parent 3217 dedddde58c5b
child 3229 f7a8228fde17
equal deleted inserted replaced
3218:5c6028778c5a 3219:618a7f2c1b82
     6 # of the GNU General Public License, incorporated herein by reference.
     6 # of the GNU General Public License, incorporated herein by reference.
     7 
     7 
     8 from node import *
     8 from node import *
     9 from i18n import gettext as _
     9 from i18n import gettext as _
    10 from demandload import demandload
    10 from demandload import demandload
    11 demandload(globals(), "ancestor bdiff repo util")
    11 demandload(globals(), "ancestor bdiff repo revlog util")
    12 
    12 
    13 class changectx(object):
    13 class changectx(object):
    14     """A changecontext object makes access to data related to a particular
    14     """A changecontext object makes access to data related to a particular
    15     changeset convenient."""
    15     changeset convenient."""
    16     def __init__(self, repo, changeid=None):
    16     def __init__(self, repo, changeid=None):
   102         return changectx(self._repo, n)
   102         return changectx(self._repo, n)
   103 
   103 
   104 class filectx(object):
   104 class filectx(object):
   105     """A filecontext object makes access to data related to a particular
   105     """A filecontext object makes access to data related to a particular
   106        filerevision convenient."""
   106        filerevision convenient."""
   107     def __init__(self, repo, path, changeid=None, fileid=None, filelog=None):
   107     def __init__(self, repo_, path, changeid=None, fileid=None, filelog=None):
   108         """changeid can be a changeset revision, node, or tag.
   108         """changeid can be a changeset revision, node, or tag.
   109            fileid can be a file revision or node."""
   109            fileid can be a file revision or node."""
   110         self._repo = repo
   110         self._repo = repo_
   111         self._path = path
   111         self._path = path
   112 
   112 
   113         assert changeid is not None or fileid is not None
   113         assert changeid is not None or fileid is not None
   114 
   114 
   115         if filelog:
   115         if filelog:
   118             self._filelog = self._repo.file(self._path)
   118             self._filelog = self._repo.file(self._path)
   119 
   119 
   120         if fileid is None:
   120         if fileid is None:
   121             self._changeid = changeid
   121             self._changeid = changeid
   122         else:
   122         else:
   123             self._filenode = self._filelog.lookup(fileid)
   123             try:
       
   124                 self._filenode = self._filelog.lookup(fileid)
       
   125             except revlog.RevlogError, inst:
       
   126                 raise repo.LookupError(str(inst))
   124             self._changeid = self._filelog.linkrev(self._filenode)
   127             self._changeid = self._filelog.linkrev(self._filenode)
   125 
   128 
   126     def __getattr__(self, name):
   129     def __getattr__(self, name):
   127         if name == '_changectx':
   130         if name == '_changectx':
   128             self._changectx = changectx(self._repo, self._changeid)
   131             self._changectx = changectx(self._repo, self._changeid)