##// END OF EJS Templates
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall -
r3215:931288cf default
parent child Browse files
Show More
@@ -44,26 +44,25 b' class changectx(object):'
44 def __nonzero__(self):
44 def __nonzero__(self):
45 return self._rev != -1
45 return self._rev != -1
46
46
47 def changeset(self):
47 def __getattr__(self, name):
48 try:
48 if name == '_changeset':
49 return self._changeset
50 except AttributeError:
51 self._changeset = self._repo.changelog.read(self.node())
49 self._changeset = self._repo.changelog.read(self.node())
52 return self._changeset
50 return self._changeset
53
51 elif name == '_manifest':
54 def manifest(self):
52 self._manifest = self._repo.manifest.read(self._changeset[0])
55 try:
56 return self._manifest
53 return self._manifest
57 except AttributeError:
54 else:
58 self._manifest = self._repo.manifest.read(self.changeset()[0])
55 raise AttributeError, name
59 return self._manifest
56
57 def changeset(self): return self._changeset
58 def manifest(self): return self._manifest
60
59
61 def rev(self): return self._rev
60 def rev(self): return self._rev
62 def node(self): return self._node
61 def node(self): return self._node
63 def user(self): return self.changeset()[1]
62 def user(self): return self._changeset[1]
64 def date(self): return self.changeset()[2]
63 def date(self): return self._changeset[2]
65 def files(self): return self.changeset()[3]
64 def files(self): return self._changeset[3]
66 def description(self): return self.changeset()[4]
65 def description(self): return self._changeset[4]
67
66
68 def parents(self):
67 def parents(self):
69 """return contexts for each parent changeset"""
68 """return contexts for each parent changeset"""
@@ -76,7 +75,9 b' class changectx(object):'
76 return [ changectx(self._repo, x) for x in c ]
75 return [ changectx(self._repo, x) for x in c ]
77
76
78 def filenode(self, path):
77 def filenode(self, path):
79 node, flag = self._repo.manifest.find(self.changeset()[0], path)
78 if hasattr(self, "_manifest"):
79 return self._manifest[path]
80 node, flag = self._repo.manifest.find(self._changeset[0], path)
80 return node
81 return node
81
82
82 def filectx(self, path, fileid=None):
83 def filectx(self, path, fileid=None):
General Comments 0
You need to be logged in to leave comments. Login now