Mercurial > hg
comparison mercurial/context.py @ 2956:6dddcba7596a
merge.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Fri, 18 Aug 2006 21:17:28 -0700 |
parents | 345bac2bc4ec |
children | da85145d4571 81da3c45aabd |
comparison
equal
deleted
inserted
replaced
2955:9d1c3529ebbc | 2956:6dddcba7596a |
---|---|
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 2006 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 | |
15 | 14 |
16 self._node = self._repo.lookup(self._id) | 15 self._node = self._repo.lookup(changeid) |
17 self._rev = self._repo.changelog.rev(self._node) | 16 self._rev = self._repo.changelog.rev(self._node) |
18 | 17 |
19 def changeset(self): | 18 def changeset(self): |
20 try: | 19 try: |
21 return self._changeset | 20 return self._changeset |
72 def __init__(self, repo, path, changeid=None, fileid=None): | 71 def __init__(self, repo, path, changeid=None, fileid=None): |
73 """changeid can be a changeset revision, node, or tag. | 72 """changeid can be a changeset revision, node, or tag. |
74 fileid can be a file revision or node.""" | 73 fileid can be a file revision or node.""" |
75 self._repo = repo | 74 self._repo = repo |
76 self._path = path | 75 self._path = path |
77 self._id = changeid | |
78 self._fileid = fileid | |
79 | 76 |
80 if self._id: | 77 assert changeid or fileid |
78 | |
79 if not fileid: | |
81 # if given a changeset id, go ahead and look up the file | 80 # if given a changeset id, go ahead and look up the file |
82 self._changeset = self._repo.changelog.read(self._id) | 81 self._changeid = changeid |
83 node, flag = self._repo.manifest.find(self._changeset[0], path) | 82 self._changectx = self.changectx() |
84 self._filelog = self._repo.file(self._path) | 83 self._filelog = self._repo.file(self._path) |
85 self._filenode = node | 84 self._filenode = self._changectx.filenode(self._path) |
86 elif self._fileid: | 85 else: |
87 # else be lazy | 86 # else be lazy |
88 self._filelog = self._repo.file(self._path) | 87 self._filelog = self._repo.file(self._path) |
89 self._filenode = self._filelog.lookup(self._fileid) | 88 self._filenode = self._filelog.lookup(fileid) |
89 self._changeid = self._filelog.linkrev(self._filenode) | |
90 self._filerev = self._filelog.rev(self._filenode) | 90 self._filerev = self._filelog.rev(self._filenode) |
91 | 91 |
92 def changeset(self): | 92 def changectx(self): |
93 try: | 93 try: |
94 return self._changeset | 94 return self._changectx |
95 except AttributeError: | 95 except AttributeError: |
96 self._changeset = self._repo.changelog.read(self.node()) | 96 self._changectx = changectx(self._repo, self._changeid) |
97 return self._changeset | 97 return self._changectx |
98 | 98 |
99 def filerev(self): return self._filerev | 99 def filerev(self): return self._filerev |
100 def filenode(self): return self._filenode | 100 def filenode(self): return self._filenode |
101 def filelog(self): return self._filelog | 101 def filelog(self): return self._filelog |
102 | 102 |
103 def rev(self): return self.changeset().rev() | 103 def rev(self): return self.changectx().rev() |
104 def node(self): return self.changeset().node() | 104 def node(self): return self.changectx().node() |
105 def user(self): return self.changeset().user() | 105 def user(self): return self.changectx().user() |
106 def date(self): return self.changeset().date() | 106 def date(self): return self.changectx().date() |
107 def files(self): return self.changeset().files() | 107 def files(self): return self.changectx().files() |
108 def description(self): return self.changeset().description() | 108 def description(self): return self.changectx().description() |
109 def manifest(self): return self.changeset().manifest() | 109 def manifest(self): return self.changectx().manifest() |
110 | 110 |
111 def data(self): return self._filelog.read(self._filenode) | 111 def data(self): return self._filelog.read(self._filenode) |
112 def metadata(self): return self._filelog.readmeta(self._filenode) | 112 def metadata(self): return self._filelog.readmeta(self._filenode) |
113 def renamed(self): return self._filelog.renamed(self._filenode) | 113 def renamed(self): return self._filelog.renamed(self._filenode) |
114 | 114 |