##// END OF EJS Templates
context.py: self.repo is not defined, change to self._repo
Benoit Boissinot -
r2627:b779319a default
parent child Browse files
Show More
@@ -1,124 +1,124 b''
1 # context.py - changeset and file context objects for mercurial
1 # context.py - changeset and file context objects for mercurial
2 #
2 #
3 # Copyright 2005 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms
5 # This software may be used and distributed according to the terms
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 class changectx(object):
8 class changectx(object):
9 """A changecontext object makes access to data related to a particular
9 """A changecontext object makes access to data related to a particular
10 changeset convenient."""
10 changeset convenient."""
11 def __init__(self, repo, changeid):
11 def __init__(self, repo, changeid):
12 """changeid is a revision number, node, or tag"""
12 """changeid is a revision number, node, or tag"""
13 self._repo = repo
13 self._repo = repo
14 self._id = changeid
14 self._id = changeid
15
15
16 self._node = self._repo.lookup(self._id)
16 self._node = self._repo.lookup(self._id)
17 self._rev = self._repo.changelog.rev(self._node)
17 self._rev = self._repo.changelog.rev(self._node)
18
18
19 def changeset(self):
19 def changeset(self):
20 try:
20 try:
21 return self._changeset
21 return self._changeset
22 except AttributeError:
22 except AttributeError:
23 self._changeset = self._repo.changelog.read(self.node())
23 self._changeset = self._repo.changelog.read(self.node())
24 return self._changeset
24 return self._changeset
25
25
26 def manifest(self):
26 def manifest(self):
27 try:
27 try:
28 return self._manifest
28 return self._manifest
29 except AttributeError:
29 except AttributeError:
30 self._manifest = self._repo.manifest.read(self.changeset()[0])
30 self._manifest = self._repo.manifest.read(self.changeset()[0])
31 return self._manifest
31 return self._manifest
32
32
33 def rev(self): return self._rev
33 def rev(self): return self._rev
34 def node(self): return self._node
34 def node(self): return self._node
35 def user(self): return self.changeset()[1]
35 def user(self): return self.changeset()[1]
36 def date(self): return self.changeset()[2]
36 def date(self): return self.changeset()[2]
37 def changedfiles(self): return self.changeset()[3]
37 def changedfiles(self): return self.changeset()[3]
38 def description(self): return self.changeset()[4]
38 def description(self): return self.changeset()[4]
39
39
40 def parents(self):
40 def parents(self):
41 """return contexts for each parent changeset"""
41 """return contexts for each parent changeset"""
42 p = self.repo.changelog.parents(self._node)
42 p = self._repo.changelog.parents(self._node)
43 return [ changectx(self._repo, x) for x in p ]
43 return [ changectx(self._repo, x) for x in p ]
44
44
45 def children(self):
45 def children(self):
46 """return contexts for each child changeset"""
46 """return contexts for each child changeset"""
47 c = self.repo.changelog.children(self._node)
47 c = self._repo.changelog.children(self._node)
48 return [ changectx(self._repo, x) for x in c ]
48 return [ changectx(self._repo, x) for x in c ]
49
49
50 def filenode(self, path):
50 def filenode(self, path):
51 node, flag = self._repo.manifest.find(self.changeset()[0], path)
51 node, flag = self._repo.manifest.find(self.changeset()[0], path)
52 return node
52 return node
53
53
54 def filectx(self, path):
54 def filectx(self, path):
55 """get a file context from this changeset"""
55 """get a file context from this changeset"""
56 return filectx(self._repo, path, fileid=self.filenode(path))
56 return filectx(self._repo, path, fileid=self.filenode(path))
57
57
58 def filectxs(self):
58 def filectxs(self):
59 """generate a file context for each file in this changeset's
59 """generate a file context for each file in this changeset's
60 manifest"""
60 manifest"""
61 mf = self.manifest()
61 mf = self.manifest()
62 m = mf.keys()
62 m = mf.keys()
63 m.sort()
63 m.sort()
64 for f in m:
64 for f in m:
65 yield self.filectx(f, fileid=mf[f])
65 yield self.filectx(f, fileid=mf[f])
66
66
67 class filectx(object):
67 class filectx(object):
68 """A filecontext object makes access to data related to a particular
68 """A filecontext object makes access to data related to a particular
69 filerevision convenient."""
69 filerevision convenient."""
70 def __init__(self, repo, path, changeid=None, fileid=None):
70 def __init__(self, repo, path, changeid=None, fileid=None):
71 """changeid can be a changeset revision, node, or tag.
71 """changeid can be a changeset revision, node, or tag.
72 fileid can be a file revision or node."""
72 fileid can be a file revision or node."""
73 self._repo = repo
73 self._repo = repo
74 self._path = path
74 self._path = path
75 self._id = changeid
75 self._id = changeid
76 self._fileid = fileid
76 self._fileid = fileid
77
77
78 if self._id:
78 if self._id:
79 # if given a changeset id, go ahead and look up the file
79 # if given a changeset id, go ahead and look up the file
80 self._changeset = changectx(repo, self._id)
80 self._changeset = changectx(self._repo, self._id)
81 node, flag = self._repo.manifest.find(self._changeset[0], path)
81 node, flag = self._repo.manifest.find(self._changeset[0], path)
82 self._node = node
82 self._node = node
83 self._filelog = self.repo.file(self._path)
83 self._filelog = self._repo.file(self._path)
84 elif self._fileid:
84 elif self._fileid:
85 # else be lazy
85 # else be lazy
86 self._filelog = self._repo.file(self._path)
86 self._filelog = self._repo.file(self._path)
87 self._filenode = self._filelog.lookup(self._fileid)
87 self._filenode = self._filelog.lookup(self._fileid)
88 self._filerev = self._filelog.rev(self._filenode)
88 self._filerev = self._filelog.rev(self._filenode)
89
89
90 def changeset(self):
90 def changeset(self):
91 try:
91 try:
92 return self._changeset
92 return self._changeset
93 except AttributeError:
93 except AttributeError:
94 self._changeset = self._repo.changelog.read(self.node())
94 self._changeset = self._repo.changelog.read(self.node())
95 return self._changeset
95 return self._changeset
96
96
97 def filerev(self): return self._filerev
97 def filerev(self): return self._filerev
98 def filenode(self): return self._filenode
98 def filenode(self): return self._filenode
99 def filelog(self): return self._filelog
99 def filelog(self): return self._filelog
100
100
101 def rev(self): return self.changeset().rev()
101 def rev(self): return self.changeset().rev()
102 def node(self): return self.changeset().node()
102 def node(self): return self.changeset().node()
103 def user(self): return self.changeset().user()
103 def user(self): return self.changeset().user()
104 def date(self): return self.changeset().date()
104 def date(self): return self.changeset().date()
105 def files(self): return self.changeset().files()
105 def files(self): return self.changeset().files()
106 def description(self): return self.changeset().description()
106 def description(self): return self.changeset().description()
107 def manifest(self): return self.changeset().manifest()
107 def manifest(self): return self.changeset().manifest()
108
108
109 def data(self): return self._filelog.read(self._filenode)
109 def data(self): return self._filelog.read(self._filenode)
110 def metadata(self): return self._filelog.readmeta(self._filenode)
110 def metadata(self): return self._filelog.readmeta(self._filenode)
111 def renamed(self): return self._filelog.renamed(self._filenode)
111 def renamed(self): return self._filelog.renamed(self._filenode)
112
112
113 def parents(self):
113 def parents(self):
114 # need to fix for renames
114 # need to fix for renames
115 p = self._filelog.parents(self._filenode)
115 p = self._filelog.parents(self._filenode)
116 return [ filectx(self._repo, self._path, fileid=x) for x in p ]
116 return [ filectx(self._repo, self._path, fileid=x) for x in p ]
117
117
118 def children(self):
118 def children(self):
119 # hard for renames
119 # hard for renames
120 c = self._filelog.children(self._filenode)
120 c = self._filelog.children(self._filenode)
121 return [ filectx(self._repo, self._path, fileid=x) for x in c ]
121 return [ filectx(self._repo, self._path, fileid=x) for x in c ]
122
122
123 def annotate(self):
123 def annotate(self):
124 return self._filelog.annotate(self._filenode)
124 return self._filelog.annotate(self._filenode)
General Comments 0
You need to be logged in to leave comments. Login now