##// END OF EJS Templates
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall -
r3124:4d021b91 default
parent child Browse files
Show More
@@ -70,7 +70,7 b' class changectx(object):'
70 70 class filectx(object):
71 71 """A filecontext object makes access to data related to a particular
72 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 74 """changeid can be a changeset revision, node, or tag.
75 75 fileid can be a file revision or node."""
76 76 self._repo = repo
@@ -78,15 +78,18 b' class filectx(object):'
78 78
79 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 86 if not fileid:
82 87 # if given a changeset id, go ahead and look up the file
83 88 self._changeid = changeid
84 89 self._changectx = self.changectx()
85 self._filelog = self._repo.file(self._path)
86 90 self._filenode = self._changectx.filenode(self._path)
87 91 else:
88 # else be lazy
89 self._filelog = self._repo.file(self._path)
92 # else delay changectx creation
90 93 self._filenode = self._filelog.lookup(fileid)
91 94 self._changeid = self._filelog.linkrev(self._filenode)
92 95 self._filerev = self._filelog.rev(self._filenode)
@@ -115,17 +118,23 b' class filectx(object):'
115 118 def path(self): return self._path
116 119
117 120 def parents(self):
118 p = [ (self._path, n) for n in self._filelog.parents(self._filenode) ]
119 r = self.renamed()
121 p = self._path
122 fl = self._filelog
123 pl = [ (p, n, fl) for n in self._filelog.parents(self._filenode) ]
120 124
125 r = self.renamed()
121 126 if r:
122 p[0] = r
123 return [ filectx(self._repo, p, fileid=n) for p,n in p if n != nullid ]
127 pl[0] = (r[0], r[1], None)
128
129 return [ filectx(self._repo, p, fileid=n, filelog=l)
130 for p,n,l in pl if n != nullid ]
124 131
125 132 def children(self):
126 133 # hard for renames
127 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 138 def annotate(self):
131 139 return self._filelog.annotate(self._filenode)
140
General Comments 0
You need to be logged in to leave comments. Login now