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