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