Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/context.py @ 3216:5b7ed414affb
Add hg.LookupError
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Sun, 01 Oct 2006 11:58:55 -0700 |
parents | 53e843840349 |
children | dedddde58c5b |
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 # |
2858 | 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 |
3165
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
8 from demandload import * |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
9 from node import * |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
10 demandload(globals(), 'bdiff') |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
11 |
3130
da85145d4571
filectx: add rename traversal for parents()
Matt Mackall <mpm@selenic.com>
parents:
2858
diff
changeset
|
12 from node import * |
3134
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3133
diff
changeset
|
13 from demandload import demandload |
3146
e69a0cbe268e
filectx.annotate: return filectx for each line instead of rev
Brendan Cully <brendan@kublai.com>
parents:
3144
diff
changeset
|
14 demandload(globals(), "ancestor util") |
3130
da85145d4571
filectx: add rename traversal for parents()
Matt Mackall <mpm@selenic.com>
parents:
2858
diff
changeset
|
15 |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
16 class changectx(object): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
17 """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
|
18 changeset convenient.""" |
3127
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2858
diff
changeset
|
19 def __init__(self, repo, changeid=None): |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
20 """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
|
21 self._repo = repo |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
22 |
3143
db25f7b80fdb
context: handle fileid or changeid == 0
Brendan Cully <brendan@kublai.com>
parents:
3136
diff
changeset
|
23 if not changeid and changeid != 0: |
3127
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2858
diff
changeset
|
24 p1, p2 = self._repo.dirstate.parents() |
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2858
diff
changeset
|
25 self._rev = self._repo.changelog.rev(p1) |
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2858
diff
changeset
|
26 if self._rev == -1: |
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2858
diff
changeset
|
27 changeid = 'tip' |
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2858
diff
changeset
|
28 else: |
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2858
diff
changeset
|
29 self._node = p1 |
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2858
diff
changeset
|
30 return |
81da3c45aabd
Move defaultrev into changectx
Brendan Cully <brendan@kublai.com>
parents:
2858
diff
changeset
|
31 |
2652
f23973ea3107
fix filectxt to really work
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2629
diff
changeset
|
32 self._node = self._repo.lookup(changeid) |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
33 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
|
34 |
3199
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3198
diff
changeset
|
35 def __str__(self): |
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3198
diff
changeset
|
36 return short(self.node()) |
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3198
diff
changeset
|
37 |
3151
6719b3dd7d50
context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents:
3150
diff
changeset
|
38 def __repr__(self): |
6719b3dd7d50
context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents:
3150
diff
changeset
|
39 return "<changectx %s>" % short(self.node()) |
6719b3dd7d50
context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents:
3150
diff
changeset
|
40 |
3198
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3154
diff
changeset
|
41 def __eq__(self, other): |
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3154
diff
changeset
|
42 return self._rev == other._rev |
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3154
diff
changeset
|
43 |
3201
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3199
diff
changeset
|
44 def __nonzero__(self): |
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3199
diff
changeset
|
45 return self._rev != -1 |
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3199
diff
changeset
|
46 |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
47 def changeset(self): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
48 try: |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
49 return self._changeset |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
50 except AttributeError: |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
51 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
|
52 return self._changeset |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
53 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
54 def manifest(self): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
55 try: |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
56 return self._manifest |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
57 except AttributeError: |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
58 self._manifest = self._repo.manifest.read(self.changeset()[0]) |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
59 return self._manifest |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
60 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
61 def rev(self): return self._rev |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
62 def node(self): return self._node |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
63 def user(self): return self.changeset()[1] |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
64 def date(self): return self.changeset()[2] |
3130
da85145d4571
filectx: add rename traversal for parents()
Matt Mackall <mpm@selenic.com>
parents:
2858
diff
changeset
|
65 def files(self): return self.changeset()[3] |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
66 def description(self): return self.changeset()[4] |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
67 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
68 def parents(self): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
69 """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
|
70 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
|
71 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
|
72 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
73 def children(self): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
74 """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
|
75 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
|
76 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
|
77 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
78 def filenode(self, path): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
79 node, flag = self._repo.manifest.find(self.changeset()[0], path) |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
80 return node |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
81 |
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 def filectx(self, path, fileid=None): |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
83 """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
|
84 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
|
85 fileid = self.filenode(path) |
9999a796d389
context.py: filectxs was using a keyword arg, add it to filectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2627
diff
changeset
|
86 return filectx(self._repo, path, fileid=fileid) |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
87 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
88 def filectxs(self): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
89 """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
|
90 manifest""" |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
91 mf = self.manifest() |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
92 m = mf.keys() |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
93 m.sort() |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
94 for f in m: |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
95 yield self.filectx(f, fileid=mf[f]) |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
96 |
3133
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3132
diff
changeset
|
97 def ancestor(self, c2): |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3132
diff
changeset
|
98 """ |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3132
diff
changeset
|
99 return the ancestor context of self and c2 |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3132
diff
changeset
|
100 """ |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3132
diff
changeset
|
101 n = self._repo.changelog.ancestor(self._node, c2._node) |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3132
diff
changeset
|
102 return changectx(self._repo, n) |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3132
diff
changeset
|
103 |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
104 class filectx(object): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
105 """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
|
106 filerevision convenient.""" |
3132
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3131
diff
changeset
|
107 def __init__(self, repo, path, changeid=None, fileid=None, filelog=None): |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
108 """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
|
109 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
|
110 self._repo = repo |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
111 self._path = path |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
112 |
3143
db25f7b80fdb
context: handle fileid or changeid == 0
Brendan Cully <brendan@kublai.com>
parents:
3136
diff
changeset
|
113 assert changeid is not None or fileid is not None |
2652
f23973ea3107
fix filectxt to really work
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2629
diff
changeset
|
114 |
3132
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3131
diff
changeset
|
115 if filelog: |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3131
diff
changeset
|
116 self._filelog = filelog |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3131
diff
changeset
|
117 else: |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3131
diff
changeset
|
118 self._filelog = self._repo.file(self._path) |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3131
diff
changeset
|
119 |
3143
db25f7b80fdb
context: handle fileid or changeid == 0
Brendan Cully <brendan@kublai.com>
parents:
3136
diff
changeset
|
120 if fileid is None: |
2652
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: |
f23973ea3107
fix filectxt to really work
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2629
diff
changeset
|
123 self._filenode = self._filelog.lookup(fileid) |
f23973ea3107
fix filectxt to really work
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2629
diff
changeset
|
124 self._changeid = self._filelog.linkrev(self._filenode) |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
125 |
3144
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
126 def __getattr__(self, name): |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
127 if name == '_changectx': |
2652
f23973ea3107
fix filectxt to really work
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2629
diff
changeset
|
128 self._changectx = changectx(self._repo, self._changeid) |
f23973ea3107
fix filectxt to really work
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2629
diff
changeset
|
129 return self._changectx |
3144
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
130 elif name == '_filenode': |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
131 self._filenode = self._changectx.filenode(self._path) |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
132 return self._filenode |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
133 elif name == '_filerev': |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
134 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
|
135 return self._filerev |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
136 else: |
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
137 raise AttributeError, name |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
138 |
3201
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3199
diff
changeset
|
139 def __nonzero__(self): |
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3199
diff
changeset
|
140 return self._filerev != nullid |
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3199
diff
changeset
|
141 |
3199
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3198
diff
changeset
|
142 def __str__(self): |
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3198
diff
changeset
|
143 return "%s@%s" % (self.path(), short(self.node())) |
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3198
diff
changeset
|
144 |
3151
6719b3dd7d50
context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents:
3150
diff
changeset
|
145 def __repr__(self): |
3154
15d585dcdd1c
context: change filectx repr to use @
Matt Mackall <mpm@selenic.com>
parents:
3151
diff
changeset
|
146 return "<filectx %s@%s>" % (self.path(), short(self.node())) |
3151
6719b3dd7d50
context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents:
3150
diff
changeset
|
147 |
3198
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3154
diff
changeset
|
148 def __eq__(self, other): |
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3154
diff
changeset
|
149 return self._path == other._path and self._changeid == other._changeid |
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3154
diff
changeset
|
150 |
3207
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3165
diff
changeset
|
151 def filectx(self, fileid): |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3165
diff
changeset
|
152 '''opens an arbitrary revision of the file without |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3165
diff
changeset
|
153 opening a new filelog''' |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3165
diff
changeset
|
154 return filectx(self._repo, self._path, fileid=fileid, |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3165
diff
changeset
|
155 filelog=self._filelog) |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3165
diff
changeset
|
156 |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
157 def filerev(self): return self._filerev |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
158 def filenode(self): return self._filenode |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
159 def filelog(self): return self._filelog |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
160 |
3150
a5e4c8172ace
filectx: lazy linkrev usage
Matt Mackall <mpm@selenic.com>
parents:
3149
diff
changeset
|
161 def rev(self): |
a5e4c8172ace
filectx: lazy linkrev usage
Matt Mackall <mpm@selenic.com>
parents:
3149
diff
changeset
|
162 if hasattr(self, "_changectx"): |
a5e4c8172ace
filectx: lazy linkrev usage
Matt Mackall <mpm@selenic.com>
parents:
3149
diff
changeset
|
163 return self._changectx.rev() |
a5e4c8172ace
filectx: lazy linkrev usage
Matt Mackall <mpm@selenic.com>
parents:
3149
diff
changeset
|
164 return self._filelog.linkrev(self._filenode) |
a5e4c8172ace
filectx: lazy linkrev usage
Matt Mackall <mpm@selenic.com>
parents:
3149
diff
changeset
|
165 |
3144
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 def manifest(self): return self._changectx.manifest() |
3149
ff1ab08e6732
restore filectx.changectx() method
Matt Mackall <mpm@selenic.com>
parents:
3146
diff
changeset
|
172 def changectx(self): return self._changectx |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
173 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
174 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
|
175 def renamed(self): return self._filelog.renamed(self._filenode) |
3130
da85145d4571
filectx: add rename traversal for parents()
Matt Mackall <mpm@selenic.com>
parents:
2858
diff
changeset
|
176 def path(self): return self._path |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
177 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
178 def parents(self): |
3132
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3131
diff
changeset
|
179 p = self._path |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3131
diff
changeset
|
180 fl = self._filelog |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3131
diff
changeset
|
181 pl = [ (p, n, fl) for n in self._filelog.parents(self._filenode) ] |
3131
4ea58eb3f0c9
filelog: make metadata method private
Matt Mackall <mpm@selenic.com>
parents:
3130
diff
changeset
|
182 |
3132
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3131
diff
changeset
|
183 r = self.renamed() |
3130
da85145d4571
filectx: add rename traversal for parents()
Matt Mackall <mpm@selenic.com>
parents:
2858
diff
changeset
|
184 if r: |
3132
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3131
diff
changeset
|
185 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:
3131
diff
changeset
|
186 |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3131
diff
changeset
|
187 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:
3131
diff
changeset
|
188 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
|
189 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
190 def children(self): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
191 # hard for renames |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
192 c = self._filelog.children(self._filenode) |
3132
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3131
diff
changeset
|
193 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:
3131
diff
changeset
|
194 filelog=self._filelog) for x in c ] |
2566
d8560b458f76
Convert hg annotate to context api
Matt Mackall <mpm@selenic.com>
parents:
2563
diff
changeset
|
195 |
3165
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
196 def annotate(self, follow=False): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
197 '''returns a list of tuples of (ctx, line) for each line |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
198 in the file, where ctx is the filectx of the node where |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
199 that line was last changed''' |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
200 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
201 def decorate(text, rev): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
202 return ([rev] * len(text.splitlines()), text) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
203 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
204 def pair(parent, child): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
205 for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
206 child[0][b1:b2] = parent[0][a1:a2] |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
207 return child |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
208 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
209 getlog = util.cachefunc(lambda x: self._repo.file(x)) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
210 def getctx(path, fileid): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
211 log = path == self._path and self._filelog or getlog(path) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
212 return filectx(self._repo, path, fileid=fileid, filelog=log) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
213 getctx = util.cachefunc(getctx) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
214 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
215 def parents(f): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
216 # we want to reuse filectx objects as much as possible |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
217 p = f._path |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
218 pl = [ (p, f._filelog.rev(n)) for n in f._filelog.parents(f._filenode) ] |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
219 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
220 if follow: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
221 r = f.renamed() |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
222 if r: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
223 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
|
224 |
3165
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
225 return [ getctx(p, n) for p, n in pl if n != -1 ] |
3215
53e843840349
Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3209
diff
changeset
|
226 |
3165
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
227 # find all ancestors |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
228 needed = {self: 1} |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
229 visit = [self] |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
230 files = [self._path] |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
231 while visit: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
232 f = visit.pop(0) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
233 for p in parents(f): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
234 if p not in needed: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
235 needed[p] = 1 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
236 visit.append(p) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
237 if p._path not in files: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
238 files.append(p._path) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
239 else: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
240 # count how many times we'll use this |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
241 needed[p] += 1 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
242 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
243 # sort by revision (per file) which is a topological order |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
244 visit = [] |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
245 files.reverse() |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
246 for f in files: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
247 fn = [(n._filerev, n) for n in needed.keys() if n._path == f] |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
248 fn.sort() |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
249 visit.extend(fn) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
250 hist = {} |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
251 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
252 for r, f in visit: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
253 curr = decorate(f.data(), f) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
254 for p in parents(f): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
255 if p != nullid: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
256 curr = pair(hist[p], curr) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
257 # trim the history of unneeded revs |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
258 needed[p] -= 1 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
259 if not needed[p]: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
260 del hist[p] |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
261 hist[f] = curr |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
262 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3154
diff
changeset
|
263 return zip(hist[f][0], hist[f][1].splitlines(1)) |
3132
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3131
diff
changeset
|
264 |
3134
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3133
diff
changeset
|
265 def ancestor(self, fc2): |
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3133
diff
changeset
|
266 """ |
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3133
diff
changeset
|
267 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:
3133
diff
changeset
|
268 """ |
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3133
diff
changeset
|
269 |
3136
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
270 acache = {} |
3134
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3133
diff
changeset
|
271 flcache = {self._path:self._filelog, fc2._path:fc2._filelog} |
3136
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
272 def parents(vertex): |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
273 if vertex in acache: |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
274 return acache[vertex] |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
275 f, n = vertex |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
276 if f not in flcache: |
3134
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3133
diff
changeset
|
277 flcache[f] = self._repo.file(f) |
3136
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
278 fl = flcache[f] |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
279 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:
3135
diff
changeset
|
280 re = fl.renamed(n) |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
281 if re: |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
282 pl.append(re) |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
283 acache[vertex]=pl |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
284 return pl |
3134
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3133
diff
changeset
|
285 |
3136
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
286 a, b = (self._path, self._filenode), (fc2._path, fc2._filenode) |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
287 v = ancestor.ancestor(a, b, parents) |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
288 if v: |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
289 f,n = v |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
290 return filectx(self._repo, f, fileid=n, filelog=flcache[f]) |
3134
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3133
diff
changeset
|
291 |
3136
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3135
diff
changeset
|
292 return None |