comparison mercurial/context.py @ 3124:4d021b91cb26

filectx: allow passing filelog in init to avoid opening new filelogs
author Matt Mackall <mpm@selenic.com>
date Sun, 17 Sep 2006 22:58:11 -0500
parents 4ea58eb3f0c9
children 02b22fefc01f
comparison
equal deleted inserted replaced
3123:4ea58eb3f0c9 3124:4d021b91cb26
68 yield self.filectx(f, fileid=mf[f]) 68 yield self.filectx(f, fileid=mf[f])
69 69
70 class filectx(object): 70 class filectx(object):
71 """A filecontext object makes access to data related to a particular 71 """A filecontext object makes access to data related to a particular
72 filerevision convenient.""" 72 filerevision convenient."""
73 def __init__(self, repo, path, changeid=None, fileid=None): 73 def __init__(self, repo, path, changeid=None, fileid=None, filelog=None):
74 """changeid can be a changeset revision, node, or tag. 74 """changeid can be a changeset revision, node, or tag.
75 fileid can be a file revision or node.""" 75 fileid can be a file revision or node."""
76 self._repo = repo 76 self._repo = repo
77 self._path = path 77 self._path = path
78 78
79 assert changeid or fileid 79 assert changeid or fileid
80 80
81 if filelog:
82 self._filelog = filelog
83 else:
84 self._filelog = self._repo.file(self._path)
85
81 if not fileid: 86 if not fileid:
82 # if given a changeset id, go ahead and look up the file 87 # if given a changeset id, go ahead and look up the file
83 self._changeid = changeid 88 self._changeid = changeid
84 self._changectx = self.changectx() 89 self._changectx = self.changectx()
85 self._filelog = self._repo.file(self._path)
86 self._filenode = self._changectx.filenode(self._path) 90 self._filenode = self._changectx.filenode(self._path)
87 else: 91 else:
88 # else be lazy 92 # else delay changectx creation
89 self._filelog = self._repo.file(self._path)
90 self._filenode = self._filelog.lookup(fileid) 93 self._filenode = self._filelog.lookup(fileid)
91 self._changeid = self._filelog.linkrev(self._filenode) 94 self._changeid = self._filelog.linkrev(self._filenode)
92 self._filerev = self._filelog.rev(self._filenode) 95 self._filerev = self._filelog.rev(self._filenode)
93 96
94 def changectx(self): 97 def changectx(self):
113 def data(self): return self._filelog.read(self._filenode) 116 def data(self): return self._filelog.read(self._filenode)
114 def renamed(self): return self._filelog.renamed(self._filenode) 117 def renamed(self): return self._filelog.renamed(self._filenode)
115 def path(self): return self._path 118 def path(self): return self._path
116 119
117 def parents(self): 120 def parents(self):
118 p = [ (self._path, n) for n in self._filelog.parents(self._filenode) ] 121 p = self._path
122 fl = self._filelog
123 pl = [ (p, n, fl) for n in self._filelog.parents(self._filenode) ]
124
119 r = self.renamed() 125 r = self.renamed()
126 if r:
127 pl[0] = (r[0], r[1], None)
120 128
121 if r: 129 return [ filectx(self._repo, p, fileid=n, filelog=l)
122 p[0] = r 130 for p,n,l in pl if n != nullid ]
123 return [ filectx(self._repo, p, fileid=n) for p,n in p if n != nullid ]
124 131
125 def children(self): 132 def children(self):
126 # hard for renames 133 # hard for renames
127 c = self._filelog.children(self._filenode) 134 c = self._filelog.children(self._filenode)
128 return [ filectx(self._repo, self._path, fileid=x) for x in c ] 135 return [ filectx(self._repo, self._path, fileid=x,
136 filelog=self._filelog) for x in c ]
129 137
130 def annotate(self): 138 def annotate(self):
131 return self._filelog.annotate(self._filenode) 139 return self._filelog.annotate(self._filenode)
140