Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/context.py @ 3241:a184cd0c2db9
Merge with upstream
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Tue, 03 Oct 2006 12:14:33 -0700 |
parents | f7a8228fde17 8d4855fd9d7b |
children | 1539f788e913 |
rev | line source |
---|---|
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
1 # context.py - changeset and file context objects for mercurial |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
2 # |
2859 | 3 # Copyright 2006 Matt Mackall <mpm@selenic.com> |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
4 # |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
7 |
3172
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
8 from node import * |
3225
dedddde58c5b
Raise LookupError in changectx.filectx if filenode can't be found
Brendan Cully <brendan@kublai.com>
parents:
3223
diff
changeset
|
9 from i18n import gettext as _ |
3126
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
10 from demandload import demandload |
3227
618a7f2c1b82
Make filectx.__init__ use LookupError
Brendan Cully <brendan@kublai.com>
parents:
3225
diff
changeset
|
11 demandload(globals(), "ancestor bdiff repo revlog util") |
3122
da85145d4571
filectx: add rename traversal for parents()
Matt Mackall <mpm@selenic.com>
parents:
2859
diff
changeset
|
12 |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
13 class changectx(object): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
14 """A changecontext object makes access to data related to a particular |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
15 changeset convenient.""" |
3132
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2859
diff
changeset
|
16 def __init__(self, repo, changeid=None): |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
17 """changeid is a revision number, node, or tag""" |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
18 self._repo = repo |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
19 |
3143
db25f7b80fdb
context: handle fileid or changeid == 0
Brendan Cully <brendan@kublai.com>
parents:
3135
diff
changeset
|
20 if not changeid and changeid != 0: |
3132
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2859
diff
changeset
|
21 p1, p2 = self._repo.dirstate.parents() |
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2859
diff
changeset
|
22 self._rev = self._repo.changelog.rev(p1) |
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2859
diff
changeset
|
23 if self._rev == -1: |
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2859
diff
changeset
|
24 changeid = 'tip' |
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2859
diff
changeset
|
25 else: |
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2859
diff
changeset
|
26 self._node = p1 |
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2859
diff
changeset
|
27 return |
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2859
diff
changeset
|
28 |
2643
f23973ea3107
fix filectxt to really work
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2629
diff
changeset
|
29 self._node = self._repo.lookup(changeid) |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
30 self._rev = self._repo.changelog.rev(self._node) |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
31 |
3166
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3165
diff
changeset
|
32 def __str__(self): |
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3165
diff
changeset
|
33 return short(self.node()) |
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3165
diff
changeset
|
34 |
3151
6719b3dd7d50
context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents:
3150
diff
changeset
|
35 def __repr__(self): |
3216
d865390c1781
context: simplify repr methods
Matt Mackall <mpm@selenic.com>
parents:
3215
diff
changeset
|
36 return "<changectx %s>" % str(self) |
3151
6719b3dd7d50
context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents:
3150
diff
changeset
|
37 |
3165
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3152
diff
changeset
|
38 def __eq__(self, other): |
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3152
diff
changeset
|
39 return self._rev == other._rev |
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3152
diff
changeset
|
40 |
3168
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3166
diff
changeset
|
41 def __nonzero__(self): |
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3166
diff
changeset
|
42 return self._rev != -1 |
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3166
diff
changeset
|
43 |
3215
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
44 def __getattr__(self, name): |
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
45 if name == '_changeset': |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
46 self._changeset = self._repo.changelog.read(self.node()) |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
47 return self._changeset |
3215
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
48 elif name == '_manifest': |
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
49 self._manifest = self._repo.manifest.read(self._changeset[0]) |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
50 return self._manifest |
3215
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
51 else: |
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
52 raise AttributeError, name |
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
53 |
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
54 def changeset(self): return self._changeset |
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
55 def manifest(self): return self._manifest |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
56 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
57 def rev(self): return self._rev |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
58 def node(self): return self._node |
3215
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
59 def user(self): return self._changeset[1] |
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
60 def date(self): return self._changeset[2] |
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
61 def files(self): return self._changeset[3] |
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
62 def description(self): return self._changeset[4] |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
63 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
64 def parents(self): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
65 """return contexts for each parent changeset""" |
2627
b779319a532b
context.py: self.repo is not defined, change to self._repo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2566
diff
changeset
|
66 p = self._repo.changelog.parents(self._node) |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
67 return [ changectx(self._repo, x) for x in p ] |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
68 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
69 def children(self): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
70 """return contexts for each child changeset""" |
2627
b779319a532b
context.py: self.repo is not defined, change to self._repo
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2566
diff
changeset
|
71 c = self._repo.changelog.children(self._node) |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
72 return [ changectx(self._repo, x) for x in c ] |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
73 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
74 def filenode(self, path): |
3215
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
75 if hasattr(self, "_manifest"): |
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
76 return self._manifest[path] |
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
77 node, flag = self._repo.manifest.find(self._changeset[0], path) |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
78 return node |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
79 |
2628
9999a796d389
context.py: filectxs was using a keyword arg, add it to filectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2627
diff
changeset
|
80 def filectx(self, path, fileid=None): |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
81 """get a file context from this changeset""" |
2628
9999a796d389
context.py: filectxs was using a keyword arg, add it to filectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2627
diff
changeset
|
82 if fileid is None: |
9999a796d389
context.py: filectxs was using a keyword arg, add it to filectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2627
diff
changeset
|
83 fileid = self.filenode(path) |
3214
696c656202a0
context: make filectx remember changectx in changectx.filectx
Matt Mackall <mpm@selenic.com>
parents:
3213
diff
changeset
|
84 return filectx(self._repo, path, fileid=fileid, changectx=self) |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
85 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
86 def filectxs(self): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
87 """generate a file context for each file in this changeset's |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
88 manifest""" |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
89 mf = self.manifest() |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
90 m = mf.keys() |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
91 m.sort() |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
92 for f in m: |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
93 yield self.filectx(f, fileid=mf[f]) |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
94 |
3125
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3124
diff
changeset
|
95 def ancestor(self, c2): |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3124
diff
changeset
|
96 """ |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3124
diff
changeset
|
97 return the ancestor context of self and c2 |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3124
diff
changeset
|
98 """ |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3124
diff
changeset
|
99 n = self._repo.changelog.ancestor(self._node, c2._node) |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3124
diff
changeset
|
100 return changectx(self._repo, n) |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3124
diff
changeset
|
101 |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
102 class filectx(object): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
103 """A filecontext object makes access to data related to a particular |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
104 filerevision convenient.""" |
3214
696c656202a0
context: make filectx remember changectx in changectx.filectx
Matt Mackall <mpm@selenic.com>
parents:
3213
diff
changeset
|
105 def __init__(self, repo, path, changeid=None, fileid=None, |
696c656202a0
context: make filectx remember changectx in changectx.filectx
Matt Mackall <mpm@selenic.com>
parents:
3213
diff
changeset
|
106 filelog=None, changectx=None): |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
107 """changeid can be a changeset revision, node, or tag. |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
108 fileid can be a file revision or node.""" |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
109 self._repo = repo |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
110 self._path = path |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
111 |
3143
db25f7b80fdb
context: handle fileid or changeid == 0
Brendan Cully <brendan@kublai.com>
parents:
3135
diff
changeset
|
112 assert changeid is not None or fileid is not None |
2643
f23973ea3107
fix filectxt to really work
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2629
diff
changeset
|
113 |
3124
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
114 if filelog: |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
115 self._filelog = filelog |
3214
696c656202a0
context: make filectx remember changectx in changectx.filectx
Matt Mackall <mpm@selenic.com>
parents:
3213
diff
changeset
|
116 if changectx: |
696c656202a0
context: make filectx remember changectx in changectx.filectx
Matt Mackall <mpm@selenic.com>
parents:
3213
diff
changeset
|
117 self._changectx = changectx |
696c656202a0
context: make filectx remember changectx in changectx.filectx
Matt Mackall <mpm@selenic.com>
parents:
3213
diff
changeset
|
118 self._changeid = changectx.node() |
3124
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
119 |
3143
db25f7b80fdb
context: handle fileid or changeid == 0
Brendan Cully <brendan@kublai.com>
parents:
3135
diff
changeset
|
120 if fileid is None: |
2643
f23973ea3107
fix filectxt to really work
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2629
diff
changeset
|
121 self._changeid = changeid |
f23973ea3107
fix filectxt to really work
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2629
diff
changeset
|
122 else: |
3213 | 123 self._fileid = fileid |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
124 |
3144
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
125 def __getattr__(self, name): |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
126 if name == '_changectx': |
2643
f23973ea3107
fix filectxt to really work
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2629
diff
changeset
|
127 self._changectx = changectx(self._repo, self._changeid) |
f23973ea3107
fix filectxt to really work
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2629
diff
changeset
|
128 return self._changectx |
3213 | 129 elif name == '_filelog': |
130 self._filelog = self._repo.file(self._path) | |
131 return self._filelog | |
132 elif name == '_changeid': | |
133 self._changeid = self._filelog.linkrev(self._filenode) | |
134 return self._changeid | |
3144
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
135 elif name == '_filenode': |
3241 | 136 try: |
137 if hasattr(self, "_fileid"): | |
138 self._filenode = self._filelog.lookup(self._fileid) | |
139 else: | |
140 self._filenode = self._changectx.filenode(self._path) | |
141 except revlog.RevlogError, inst: | |
142 raise repo.LookupError(str(inst)) | |
3144
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
143 return self._filenode |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
144 elif name == '_filerev': |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
145 self._filerev = self._filelog.rev(self._filenode) |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
146 return self._filerev |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
147 else: |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
148 raise AttributeError, name |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
149 |
3168
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3166
diff
changeset
|
150 def __nonzero__(self): |
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3166
diff
changeset
|
151 return self._filerev != nullid |
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3166
diff
changeset
|
152 |
3166
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3165
diff
changeset
|
153 def __str__(self): |
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3165
diff
changeset
|
154 return "%s@%s" % (self.path(), short(self.node())) |
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3165
diff
changeset
|
155 |
3151
6719b3dd7d50
context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents:
3150
diff
changeset
|
156 def __repr__(self): |
3216
d865390c1781
context: simplify repr methods
Matt Mackall <mpm@selenic.com>
parents:
3215
diff
changeset
|
157 return "<filectx %s>" % str(self) |
3151
6719b3dd7d50
context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents:
3150
diff
changeset
|
158 |
3165
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3152
diff
changeset
|
159 def __eq__(self, other): |
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3152
diff
changeset
|
160 return self._path == other._path and self._changeid == other._changeid |
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3152
diff
changeset
|
161 |
3207
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3172
diff
changeset
|
162 def filectx(self, fileid): |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3172
diff
changeset
|
163 '''opens an arbitrary revision of the file without |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3172
diff
changeset
|
164 opening a new filelog''' |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3172
diff
changeset
|
165 return filectx(self._repo, self._path, fileid=fileid, |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3172
diff
changeset
|
166 filelog=self._filelog) |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3172
diff
changeset
|
167 |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
168 def filerev(self): return self._filerev |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
169 def filenode(self): return self._filenode |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
170 def filelog(self): return self._filelog |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
171 |
3150
a5e4c8172ace
filectx: lazy linkrev usage
Matt Mackall <mpm@selenic.com>
parents:
3149
diff
changeset
|
172 def rev(self): |
a5e4c8172ace
filectx: lazy linkrev usage
Matt Mackall <mpm@selenic.com>
parents:
3149
diff
changeset
|
173 if hasattr(self, "_changectx"): |
a5e4c8172ace
filectx: lazy linkrev usage
Matt Mackall <mpm@selenic.com>
parents:
3149
diff
changeset
|
174 return self._changectx.rev() |
a5e4c8172ace
filectx: lazy linkrev usage
Matt Mackall <mpm@selenic.com>
parents:
3149
diff
changeset
|
175 return self._filelog.linkrev(self._filenode) |
a5e4c8172ace
filectx: lazy linkrev usage
Matt Mackall <mpm@selenic.com>
parents:
3149
diff
changeset
|
176 |
3144
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
177 def node(self): return self._changectx.node() |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
178 def user(self): return self._changectx.user() |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
179 def date(self): return self._changectx.date() |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
180 def files(self): return self._changectx.files() |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
181 def description(self): return self._changectx.description() |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
182 def manifest(self): return self._changectx.manifest() |
3149
ff1ab08e6732
restore filectx.changectx() method
Matt Mackall <mpm@selenic.com>
parents:
3146
diff
changeset
|
183 def changectx(self): return self._changectx |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
184 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
185 def data(self): return self._filelog.read(self._filenode) |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
186 def renamed(self): return self._filelog.renamed(self._filenode) |
3122
da85145d4571
filectx: add rename traversal for parents()
Matt Mackall <mpm@selenic.com>
parents:
2859
diff
changeset
|
187 def path(self): return self._path |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
188 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
189 def parents(self): |
3124
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
190 p = self._path |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
191 fl = self._filelog |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
192 pl = [ (p, n, fl) for n in self._filelog.parents(self._filenode) ] |
3123
4ea58eb3f0c9
filelog: make metadata method private
Matt Mackall <mpm@selenic.com>
parents:
3122
diff
changeset
|
193 |
3124
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
194 r = self.renamed() |
3122
da85145d4571
filectx: add rename traversal for parents()
Matt Mackall <mpm@selenic.com>
parents:
2859
diff
changeset
|
195 if r: |
3124
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
196 pl[0] = (r[0], r[1], None) |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
197 |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
198 return [ filectx(self._repo, p, fileid=n, filelog=l) |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
199 for p,n,l in pl if n != nullid ] |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
200 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
201 def children(self): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
202 # hard for renames |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
203 c = self._filelog.children(self._filenode) |
3124
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
204 return [ filectx(self._repo, self._path, fileid=x, |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
205 filelog=self._filelog) for x in c ] |
2566
d8560b458f76
Convert hg annotate to context api
Matt Mackall <mpm@selenic.com>
parents:
2563
diff
changeset
|
206 |
3172
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
207 def annotate(self, follow=False): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
208 '''returns a list of tuples of (ctx, line) for each line |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
209 in the file, where ctx is the filectx of the node where |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
210 that line was last changed''' |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
211 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
212 def decorate(text, rev): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
213 return ([rev] * len(text.splitlines()), text) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
214 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
215 def pair(parent, child): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
216 for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
217 child[0][b1:b2] = parent[0][a1:a2] |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
218 return child |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
219 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
220 getlog = util.cachefunc(lambda x: self._repo.file(x)) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
221 def getctx(path, fileid): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
222 log = path == self._path and self._filelog or getlog(path) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
223 return filectx(self._repo, path, fileid=fileid, filelog=log) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
224 getctx = util.cachefunc(getctx) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
225 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
226 def parents(f): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
227 # we want to reuse filectx objects as much as possible |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
228 p = f._path |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
229 if f._filerev is None: # working dir |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
230 pl = [ (n.path(), n.filerev()) for n in f.parents() ] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
231 else: |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
232 pl = [ (p, n) for n in f._filelog.parentrevs(f._filerev) ] |
3172
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
233 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
234 if follow: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
235 r = f.renamed() |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
236 if r: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
237 pl[0] = (r[0], getlog(r[0]).rev(r[1])) |
3146
e69a0cbe268e
filectx.annotate: return filectx for each line instead of rev
Brendan Cully <brendan@kublai.com>
parents:
3144
diff
changeset
|
238 |
3172
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
239 return [ getctx(p, n) for p, n in pl if n != -1 ] |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
240 |
3172
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
241 # find all ancestors |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
242 needed = {self: 1} |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
243 visit = [self] |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
244 files = [self._path] |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
245 while visit: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
246 f = visit.pop(0) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
247 for p in parents(f): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
248 if p not in needed: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
249 needed[p] = 1 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
250 visit.append(p) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
251 if p._path not in files: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
252 files.append(p._path) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
253 else: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
254 # count how many times we'll use this |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
255 needed[p] += 1 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
256 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
257 # sort by revision (per file) which is a topological order |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
258 visit = [] |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
259 files.reverse() |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
260 for f in files: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
261 fn = [(n._filerev, n) for n in needed.keys() if n._path == f] |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
262 fn.sort() |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
263 visit.extend(fn) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
264 hist = {} |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
265 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
266 for r, f in visit: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
267 curr = decorate(f.data(), f) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
268 for p in parents(f): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
269 if p != nullid: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
270 curr = pair(hist[p], curr) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
271 # trim the history of unneeded revs |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
272 needed[p] -= 1 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
273 if not needed[p]: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
274 del hist[p] |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
275 hist[f] = curr |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
276 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
277 return zip(hist[f][0], hist[f][1].splitlines(1)) |
3124
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
278 |
3126
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
279 def ancestor(self, fc2): |
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
280 """ |
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
281 find the common ancestor file context, if any, of self, and fc2 |
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
282 """ |
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
283 |
3135
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
284 acache = {} |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
285 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
286 # prime the ancestor cache for the working directory |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
287 for c in (self, fc2): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
288 if c._filerev == None: |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
289 pl = [ (n.path(), n.filenode()) for n in c.parents() ] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
290 acache[(c._path, None)] = pl |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
291 |
3126
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
292 flcache = {self._path:self._filelog, fc2._path:fc2._filelog} |
3135
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
293 def parents(vertex): |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
294 if vertex in acache: |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
295 return acache[vertex] |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
296 f, n = vertex |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
297 if f not in flcache: |
3126
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
298 flcache[f] = self._repo.file(f) |
3135
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
299 fl = flcache[f] |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
300 pl = [ (f,p) for p in fl.parents(n) if p != nullid ] |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
301 re = fl.renamed(n) |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
302 if re: |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
303 pl.append(re) |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
304 acache[vertex]=pl |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
305 return pl |
3126
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
306 |
3135
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
307 a, b = (self._path, self._filenode), (fc2._path, fc2._filenode) |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
308 v = ancestor.ancestor(a, b, parents) |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
309 if v: |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
310 f,n = v |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
311 return filectx(self._repo, f, fileid=n, filelog=flcache[f]) |
3126
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
312 |
3135
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
313 return None |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
314 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
315 class workingctx(changectx): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
316 """A workingctx object makes access to data related to |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
317 the current working directory convenient.""" |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
318 def __init__(self, repo): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
319 self._repo = repo |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
320 self._rev = None |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
321 self._node = None |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
322 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
323 def __str__(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
324 return "." |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
325 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
326 def __nonzero__(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
327 return True |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
328 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
329 def __getattr__(self, name): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
330 if name == '_parents': |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
331 self._parents = self._repo.parents() |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
332 return self._parents |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
333 if name == '_status': |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
334 self._status = self._repo.status() |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
335 return self._status |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
336 if name == '_manifest': |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
337 self._buildmanifest() |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
338 return self._manifest |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
339 else: |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
340 raise AttributeError, name |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
341 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
342 def _buildmanifest(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
343 """generate a manifest corresponding to the working directory""" |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
344 |
3218
8d4855fd9d7b
merge: use new working context object in update
Matt Mackall <mpm@selenic.com>
parents:
3217
diff
changeset
|
345 man = self._parents[0].manifest().copy() |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
346 copied = self._repo.dirstate.copies() |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
347 modified, added, removed, deleted, unknown = self._status[:5] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
348 for i,l in (("a", added), ("m", modified), ("u", unknown)): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
349 for f in l: |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
350 man[f] = man.get(copied.get(f, f), nullid) + i |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
351 man.set(f, util.is_exec(self._repo.wjoin(f), man.execf(f))) |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
352 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
353 for f in deleted + removed: |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
354 del man[f] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
355 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
356 self._manifest = man |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
357 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
358 def manifest(self): return self._manifest |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
359 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
360 def user(self): return self._repo.ui.username() |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
361 def date(self): return util.makedate() |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
362 def description(self): return "" |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
363 def files(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
364 f = self.modified() + self.added() + self.removed() |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
365 f.sort() |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
366 return f |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
367 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
368 def modified(self): return self._status[0] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
369 def added(self): return self._status[1] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
370 def removed(self): return self._status[2] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
371 def deleted(self): return self._status[3] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
372 def unknown(self): return self._status[4] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
373 def clean(self): return self._status[5] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
374 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
375 def parents(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
376 """return contexts for each parent changeset""" |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
377 return self._parents |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
378 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
379 def children(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
380 return [] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
381 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
382 def filectx(self, path): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
383 """get a file context from the working directory""" |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
384 return workingfilectx(self._repo, path, workingctx=self) |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
385 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
386 def ancestor(self, c2): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
387 """return the ancestor context of self and c2""" |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
388 return self._parents[0].ancestor(c2) # punt on two parents for now |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
389 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
390 class workingfilectx(filectx): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
391 """A workingfilectx object makes access to data related to a particular |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
392 file in the working directory convenient.""" |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
393 def __init__(self, repo, path, filelog=None, workingctx=None): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
394 """changeid can be a changeset revision, node, or tag. |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
395 fileid can be a file revision or node.""" |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
396 self._repo = repo |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
397 self._path = path |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
398 self._changeid = None |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
399 self._filerev = self._filenode = None |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
400 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
401 if filelog: |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
402 self._filelog = filelog |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
403 if workingctx: |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
404 self._changectx = workingctx |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
405 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
406 def __getattr__(self, name): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
407 if name == '_changectx': |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
408 self._changectx = workingctx(repo) |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
409 return self._changectx |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
410 elif name == '_repopath': |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
411 self._repopath = self._repo.dirstate.copied(p) or self._path |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
412 elif name == '_filelog': |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
413 self._filelog = self._repo.file(self._repopath) |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
414 return self._filelog |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
415 else: |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
416 raise AttributeError, name |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
417 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
418 def __nonzero__(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
419 return True |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
420 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
421 def __str__(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
422 return "%s@." % self.path() |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
423 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
424 def filectx(self, fileid): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
425 '''opens an arbitrary revision of the file without |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
426 opening a new filelog''' |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
427 return filectx(self._repo, self._repopath, fileid=fileid, |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
428 filelog=self._filelog) |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
429 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
430 def rev(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
431 if hasattr(self, "_changectx"): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
432 return self._changectx.rev() |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
433 return self._filelog.linkrev(self._filenode) |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
434 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
435 def data(self): return self._repo.wread(self._path) |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
436 def renamed(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
437 rp = self._repopath |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
438 if rp == self._path: |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
439 return None |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
440 return rp, self._workingctx._parents._manifest.get(rp, nullid) |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
441 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
442 def parents(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
443 '''return parent filectxs, following copies if necessary''' |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
444 p = self._path |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
445 rp = self._repopath |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
446 pcl = self._workingctx._parents |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
447 fl = self._filelog |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
448 pl = [ (rp, pcl[0]._manifest.get(rp, nullid), fl) ] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
449 if len(pcl) > 1: |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
450 if rp != p: |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
451 fl = None |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
452 pl.append((p, pcl[1]._manifest.get(p, nullid), fl)) |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
453 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
454 return [ filectx(self._repo, p, fileid=n, filelog=l) |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
455 for p,n,l in pl if n != nullid ] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
456 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
457 def children(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
458 return [] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
459 |