Mercurial > hg
annotate mercurial/context.py @ 13955:86b5cc1e8be8 stable
help config: explain that config files do not exist by default
Inspired by critique given on StackOverflow where a user writes:
I can have a good guess at what "%USERPROFILE%" might signify but
none of the files listed in the "hg help config" output exist after
running the installer. Previous experience would suggest that
missing files mean something somewhere has gone seriously wrong.
http://stackoverflow.com/questions/2329023/2351139#2351139
author | Martin Geisler <mg@lazybytes.net> |
---|---|
date | Mon, 18 Apr 2011 13:57:22 +0200 |
parents | 7ab85fec60c3 |
children | 653121e6941f |
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 # |
4635
63b9d2deed48
Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4417
diff
changeset
|
3 # Copyright 2006, 2007 Matt Mackall <mpm@selenic.com> |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
7 |
6763
403682f1c678
context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents:
6762
diff
changeset
|
8 from node import nullid, nullrev, short, hex |
3891 | 9 from i18n import _ |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
10 import ancestor, bdiff, error, util, subrepo, patch, encoding |
11303
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
11 import os, errno, stat |
3122
da85145d4571
filectx: add rename traversal for parents()
Matt Mackall <mpm@selenic.com>
parents:
2859
diff
changeset
|
12 |
8207
dd8d5be57d65
util: take propertycache from context.py
Matt Mackall <mpm@selenic.com>
parents:
8157
diff
changeset
|
13 propertycache = util.propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
14 |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
15 class changectx(object): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
16 """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
|
17 changeset convenient.""" |
6741
5918e2b79859
context: simplify changeid logic
Matt Mackall <mpm@selenic.com>
parents:
6737
diff
changeset
|
18 def __init__(self, repo, changeid=''): |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
19 """changeid is a revision number, node, or tag""" |
6741
5918e2b79859
context: simplify changeid logic
Matt Mackall <mpm@selenic.com>
parents:
6737
diff
changeset
|
20 if changeid == '': |
5918e2b79859
context: simplify changeid logic
Matt Mackall <mpm@selenic.com>
parents:
6737
diff
changeset
|
21 changeid = '.' |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
22 self._repo = repo |
7367
ad0eb8762458
context: special-case changectx setup for integer changeid
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
23 if isinstance(changeid, (long, int)): |
ad0eb8762458
context: special-case changectx setup for integer changeid
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
24 self._rev = changeid |
ad0eb8762458
context: special-case changectx setup for integer changeid
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
25 self._node = self._repo.changelog.node(changeid) |
ad0eb8762458
context: special-case changectx setup for integer changeid
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
26 else: |
ad0eb8762458
context: special-case changectx setup for integer changeid
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
27 self._node = self._repo.lookup(changeid) |
ad0eb8762458
context: special-case changectx setup for integer changeid
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
28 self._rev = self._repo.changelog.rev(self._node) |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
29 |
3166
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3165
diff
changeset
|
30 def __str__(self): |
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3165
diff
changeset
|
31 return short(self.node()) |
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3165
diff
changeset
|
32 |
6763
403682f1c678
context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents:
6762
diff
changeset
|
33 def __int__(self): |
403682f1c678
context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents:
6762
diff
changeset
|
34 return self.rev() |
403682f1c678
context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents:
6762
diff
changeset
|
35 |
3151
6719b3dd7d50
context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents:
3150
diff
changeset
|
36 def __repr__(self): |
3216
d865390c1781
context: simplify repr methods
Matt Mackall <mpm@selenic.com>
parents:
3215
diff
changeset
|
37 return "<changectx %s>" % str(self) |
3151
6719b3dd7d50
context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents:
3150
diff
changeset
|
38 |
6469
fb502719c75c
python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents:
6286
diff
changeset
|
39 def __hash__(self): |
fb502719c75c
python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents:
6286
diff
changeset
|
40 try: |
fb502719c75c
python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents:
6286
diff
changeset
|
41 return hash(self._rev) |
fb502719c75c
python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents:
6286
diff
changeset
|
42 except AttributeError: |
fb502719c75c
python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents:
6286
diff
changeset
|
43 return id(self) |
fb502719c75c
python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents:
6286
diff
changeset
|
44 |
3165
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3152
diff
changeset
|
45 def __eq__(self, other): |
3715
6cb3aca69cdc
Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents:
3712
diff
changeset
|
46 try: |
6cb3aca69cdc
Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents:
3712
diff
changeset
|
47 return self._rev == other._rev |
6cb3aca69cdc
Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents:
3712
diff
changeset
|
48 except AttributeError: |
6cb3aca69cdc
Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents:
3712
diff
changeset
|
49 return False |
3165
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3152
diff
changeset
|
50 |
4748
8808ea7da86b
merge: make test for fast-forward merge stricter (issue619)
Matt Mackall <mpm@selenic.com>
parents:
4663
diff
changeset
|
51 def __ne__(self, other): |
8808ea7da86b
merge: make test for fast-forward merge stricter (issue619)
Matt Mackall <mpm@selenic.com>
parents:
4663
diff
changeset
|
52 return not (self == other) |
8808ea7da86b
merge: make test for fast-forward merge stricter (issue619)
Matt Mackall <mpm@selenic.com>
parents:
4663
diff
changeset
|
53 |
3168
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3166
diff
changeset
|
54 def __nonzero__(self): |
3578
3b4e00cba57a
Define and use nullrev (revision of nullid) instead of -1.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3454
diff
changeset
|
55 return self._rev != nullrev |
3168
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3166
diff
changeset
|
56 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
57 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
58 def _changeset(self): |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
59 return self._repo.changelog.read(self.node()) |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
60 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
61 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
62 def _manifest(self): |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
63 return self._repo.manifest.read(self._changeset[0]) |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
64 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
65 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
66 def _manifestdelta(self): |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
67 return self._repo.manifest.readdelta(self._changeset[0]) |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
68 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
69 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
70 def _parents(self): |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
71 p = self._repo.changelog.parentrevs(self._rev) |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
72 if p[1] == nullrev: |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
73 p = p[:-1] |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
74 return [changectx(self._repo, x) for x in p] |
3215
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
75 |
8812
859f841937d0
subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
8717
diff
changeset
|
76 @propertycache |
859f841937d0
subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
8717
diff
changeset
|
77 def substate(self): |
11775
a8614c5a5e9a
subrepos: support remapping of .hgsub source paths
Martin Geisler <mg@lazybytes.net>
parents:
11703
diff
changeset
|
78 return subrepo.state(self, self._repo.ui) |
8812
859f841937d0
subrepo: introduce basic state parsing
Matt Mackall <mpm@selenic.com>
parents:
8717
diff
changeset
|
79 |
4909
1fd7a99d98f6
context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents:
4889
diff
changeset
|
80 def __contains__(self, key): |
1fd7a99d98f6
context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents:
4889
diff
changeset
|
81 return key in self._manifest |
1fd7a99d98f6
context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents:
4889
diff
changeset
|
82 |
1fd7a99d98f6
context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents:
4889
diff
changeset
|
83 def __getitem__(self, key): |
1fd7a99d98f6
context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents:
4889
diff
changeset
|
84 return self.filectx(key) |
1fd7a99d98f6
context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents:
4889
diff
changeset
|
85 |
1fd7a99d98f6
context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents:
4889
diff
changeset
|
86 def __iter__(self): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
8207
diff
changeset
|
87 for f in sorted(self._manifest): |
5485
8c0756f7b18b
Fix context iterator.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5439
diff
changeset
|
88 yield f |
4909
1fd7a99d98f6
context: add __contains__, __getitem__, and __iter__
Matt Mackall <mpm@selenic.com>
parents:
4889
diff
changeset
|
89 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
90 def changeset(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
91 return self._changeset |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
92 def manifest(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
93 return self._manifest |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
94 def manifestnode(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
95 return self._changeset[0] |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
96 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
97 def rev(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
98 return self._rev |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
99 def node(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
100 return self._node |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
101 def hex(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
102 return hex(self._node) |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
103 def user(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
104 return self._changeset[1] |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
105 def date(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
106 return self._changeset[2] |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
107 def files(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
108 return self._changeset[3] |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
109 def description(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
110 return self._changeset[4] |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
111 def branch(self): |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
112 return encoding.tolocal(self._changeset[5].get("branch")) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
113 def extra(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
114 return self._changeset[5] |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
115 def tags(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
116 return self._repo.nodetags(self._node) |
13384
caa561759538
context: add method to return all bookmarks pointing to a node
David Soria Parra <dsp@php.net>
parents:
13235
diff
changeset
|
117 def bookmarks(self): |
caa561759538
context: add method to return all bookmarks pointing to a node
David Soria Parra <dsp@php.net>
parents:
13235
diff
changeset
|
118 return self._repo.nodebookmarks(self._node) |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
119 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
120 def parents(self): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
121 """return contexts for each parent changeset""" |
6742
2d54e7c1e69d
context: clean up parents()
Matt Mackall <mpm@selenic.com>
parents:
6741
diff
changeset
|
122 return self._parents |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
123 |
8406
6ad1f72bdf34
context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents:
8401
diff
changeset
|
124 def p1(self): |
6ad1f72bdf34
context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents:
8401
diff
changeset
|
125 return self._parents[0] |
6ad1f72bdf34
context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents:
8401
diff
changeset
|
126 |
6ad1f72bdf34
context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents:
8401
diff
changeset
|
127 def p2(self): |
6ad1f72bdf34
context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents:
8401
diff
changeset
|
128 if len(self._parents) == 2: |
6ad1f72bdf34
context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents:
8401
diff
changeset
|
129 return self._parents[1] |
6ad1f72bdf34
context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents:
8401
diff
changeset
|
130 return changectx(self._repo, -1) |
6ad1f72bdf34
context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents:
8401
diff
changeset
|
131 |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
132 def children(self): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
133 """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
|
134 c = self._repo.changelog.children(self._node) |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3578
diff
changeset
|
135 return [changectx(self._repo, x) for x in c] |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
136 |
6876 | 137 def ancestors(self): |
138 for a in self._repo.changelog.ancestors(self._rev): | |
139 yield changectx(self._repo, a) | |
140 | |
141 def descendants(self): | |
142 for d in self._repo.changelog.descendants(self._rev): | |
143 yield changectx(self._repo, d) | |
144 | |
5389
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
145 def _fileinfo(self, path): |
3336
e44eadc92ec4
context: check self.__dict__ instead of using hasattr
Brendan Cully <brendan@kublai.com>
parents:
3313
diff
changeset
|
146 if '_manifest' in self.__dict__: |
3242
1539f788e913
Make changectx.filenode raise repo.LookupError on failure
Brendan Cully <brendan@kublai.com>
parents:
3241
diff
changeset
|
147 try: |
5389
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
148 return self._manifest[path], self._manifest.flags(path) |
3242
1539f788e913
Make changectx.filenode raise repo.LookupError on failure
Brendan Cully <brendan@kublai.com>
parents:
3241
diff
changeset
|
149 except KeyError: |
7633 | 150 raise error.LookupError(self._node, path, |
151 _('not found in manifest')) | |
3337
b02e60097bbe
changectx: search manifest delta for filenode
Brendan Cully <brendan@kublai.com>
parents:
3336
diff
changeset
|
152 if '_manifestdelta' in self.__dict__ or path in self.files(): |
b02e60097bbe
changectx: search manifest delta for filenode
Brendan Cully <brendan@kublai.com>
parents:
3336
diff
changeset
|
153 if path in self._manifestdelta: |
5389
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
154 return self._manifestdelta[path], self._manifestdelta.flags(path) |
3215
931288cf58a7
contexts: use __getattr__ rather than try/except in changectx
Matt Mackall <mpm@selenic.com>
parents:
3214
diff
changeset
|
155 node, flag = self._repo.manifest.find(self._changeset[0], path) |
3242
1539f788e913
Make changectx.filenode raise repo.LookupError on failure
Brendan Cully <brendan@kublai.com>
parents:
3241
diff
changeset
|
156 if not node: |
7633 | 157 raise error.LookupError(self._node, path, |
158 _('not found in manifest')) | |
3242
1539f788e913
Make changectx.filenode raise repo.LookupError on failure
Brendan Cully <brendan@kublai.com>
parents:
3241
diff
changeset
|
159 |
5389
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
160 return node, flag |
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
161 |
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
162 def filenode(self, path): |
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
163 return self._fileinfo(path)[0] |
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
164 |
6743 | 165 def flags(self, path): |
5389
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
166 try: |
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
167 return self._fileinfo(path)[1] |
7633 | 168 except error.LookupError: |
5389
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
169 return '' |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
170 |
3966
b4eaa68dea1b
context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3965
diff
changeset
|
171 def filectx(self, path, fileid=None, filelog=None): |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
172 """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
|
173 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
|
174 fileid = self.filenode(path) |
3966
b4eaa68dea1b
context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3965
diff
changeset
|
175 return filectx(self._repo, path, fileid=fileid, |
b4eaa68dea1b
context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3965
diff
changeset
|
176 changectx=self, filelog=filelog) |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
177 |
3125
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3124
diff
changeset
|
178 def ancestor(self, c2): |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3124
diff
changeset
|
179 """ |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3124
diff
changeset
|
180 return the ancestor context of self and c2 |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3124
diff
changeset
|
181 """ |
9843
d1043c2ffe6c
merge: fix changectx.ancestor(workingctx) (issue1327)
Matt Mackall <mpm@selenic.com>
parents:
9751
diff
changeset
|
182 # deal with workingctxs |
d1043c2ffe6c
merge: fix changectx.ancestor(workingctx) (issue1327)
Matt Mackall <mpm@selenic.com>
parents:
9751
diff
changeset
|
183 n2 = c2._node |
13031
3da456d0c885
code style: prefer 'is' and 'is not' tests with singletons
Martin Geisler <mg@aragost.com>
parents:
13001
diff
changeset
|
184 if n2 is None: |
9843
d1043c2ffe6c
merge: fix changectx.ancestor(workingctx) (issue1327)
Matt Mackall <mpm@selenic.com>
parents:
9751
diff
changeset
|
185 n2 = c2._parents[0]._node |
d1043c2ffe6c
merge: fix changectx.ancestor(workingctx) (issue1327)
Matt Mackall <mpm@selenic.com>
parents:
9751
diff
changeset
|
186 n = self._repo.changelog.ancestor(self._node, n2) |
3125
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3124
diff
changeset
|
187 return changectx(self._repo, n) |
02b22fefc01f
changectx: add ancestor function
Matt Mackall <mpm@selenic.com>
parents:
3124
diff
changeset
|
188 |
6764 | 189 def walk(self, match): |
8380
a00a4db76a15
context: replace pseudo-set by real set
Simon Heimberg <simohe@besonet.ch>
parents:
8312
diff
changeset
|
190 fset = set(match.files()) |
6764 | 191 # for dirstate.walk, files=['.'] means "walk the whole tree". |
192 # follow that here, too | |
8380
a00a4db76a15
context: replace pseudo-set by real set
Simon Heimberg <simohe@besonet.ch>
parents:
8312
diff
changeset
|
193 fset.discard('.') |
6764 | 194 for fn in self: |
8380
a00a4db76a15
context: replace pseudo-set by real set
Simon Heimberg <simohe@besonet.ch>
parents:
8312
diff
changeset
|
195 for ffn in fset: |
6764 | 196 # match if the file is the exact name or a directory |
197 if ffn == fn or fn.startswith("%s/" % ffn): | |
8380
a00a4db76a15
context: replace pseudo-set by real set
Simon Heimberg <simohe@besonet.ch>
parents:
8312
diff
changeset
|
198 fset.remove(ffn) |
6764 | 199 break |
200 if match(fn): | |
201 yield fn | |
8380
a00a4db76a15
context: replace pseudo-set by real set
Simon Heimberg <simohe@besonet.ch>
parents:
8312
diff
changeset
|
202 for fn in sorted(fset): |
12067
a4fbbe0fbc38
Lowercase error messages
Martin Geisler <mg@lazybytes.net>
parents:
12030
diff
changeset
|
203 if match.bad(fn, _('no such file in rev %s') % self) and match(fn): |
6764 | 204 yield fn |
205 | |
8813
db3c1ab0e632
commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents:
8812
diff
changeset
|
206 def sub(self, path): |
db3c1ab0e632
commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents:
8812
diff
changeset
|
207 return subrepo.subrepo(self, path) |
db3c1ab0e632
commit: recurse into subrepositories
Matt Mackall <mpm@selenic.com>
parents:
8812
diff
changeset
|
208 |
11106
213ca9ffcddb
changectx: change diff() to accept keyword opts
Steve Borho <steve@borho.org>
parents:
11105
diff
changeset
|
209 def diff(self, ctx2=None, match=None, **opts): |
11097
9651fa5a3cbf
context: add a changectx.diff() convenience function
Steve Borho <steve@borho.org>
parents:
10969
diff
changeset
|
210 """Returns a diff generator for the given contexts and matcher""" |
9651fa5a3cbf
context: add a changectx.diff() convenience function
Steve Borho <steve@borho.org>
parents:
10969
diff
changeset
|
211 if ctx2 is None: |
9651fa5a3cbf
context: add a changectx.diff() convenience function
Steve Borho <steve@borho.org>
parents:
10969
diff
changeset
|
212 ctx2 = self.p1() |
9651fa5a3cbf
context: add a changectx.diff() convenience function
Steve Borho <steve@borho.org>
parents:
10969
diff
changeset
|
213 if ctx2 is not None and not isinstance(ctx2, changectx): |
9651fa5a3cbf
context: add a changectx.diff() convenience function
Steve Borho <steve@borho.org>
parents:
10969
diff
changeset
|
214 ctx2 = self._repo[ctx2] |
11105
6f4543842795
changectx: use repo.ui diffopts, allow argument override
Steve Borho <steve@borho.org>
parents:
11101
diff
changeset
|
215 diffopts = patch.diffopts(self._repo.ui, opts) |
6f4543842795
changectx: use repo.ui diffopts, allow argument override
Steve Borho <steve@borho.org>
parents:
11101
diff
changeset
|
216 return patch.diff(self._repo, ctx2.node(), self.node(), |
6f4543842795
changectx: use repo.ui diffopts, allow argument override
Steve Borho <steve@borho.org>
parents:
11101
diff
changeset
|
217 match=match, opts=diffopts) |
11097
9651fa5a3cbf
context: add a changectx.diff() convenience function
Steve Borho <steve@borho.org>
parents:
10969
diff
changeset
|
218 |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
219 class filectx(object): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
220 """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
|
221 filerevision convenient.""" |
3214
696c656202a0
context: make filectx remember changectx in changectx.filectx
Matt Mackall <mpm@selenic.com>
parents:
3213
diff
changeset
|
222 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
|
223 filelog=None, changectx=None): |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
224 """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
|
225 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
|
226 self._repo = repo |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
227 self._path = path |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
228 |
3964
2308c39b9521
make it possible to use changectx to create a filectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3962
diff
changeset
|
229 assert (changeid is not None |
2308c39b9521
make it possible to use changectx to create a filectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3962
diff
changeset
|
230 or fileid is not None |
9024
10532b29cdee
context: improve arg-checking assert.
Greg Ward <greg@gerg.ca>
parents:
8813
diff
changeset
|
231 or changectx is not None), \ |
10532b29cdee
context: improve arg-checking assert.
Greg Ward <greg@gerg.ca>
parents:
8813
diff
changeset
|
232 ("bad args: changeid=%r, fileid=%r, changectx=%r" |
10532b29cdee
context: improve arg-checking assert.
Greg Ward <greg@gerg.ca>
parents:
8813
diff
changeset
|
233 % (changeid, fileid, changectx)) |
2643
f23973ea3107
fix filectxt to really work
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2629
diff
changeset
|
234 |
3124
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
235 if filelog: |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
236 self._filelog = filelog |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
237 |
5810
124577de40a7
context: preserve changeset in filectx if we have one
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
238 if changeid is not None: |
124577de40a7
context: preserve changeset in filectx if we have one
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
239 self._changeid = changeid |
124577de40a7
context: preserve changeset in filectx if we have one
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
240 if changectx is not None: |
124577de40a7
context: preserve changeset in filectx if we have one
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
241 self._changectx = changectx |
124577de40a7
context: preserve changeset in filectx if we have one
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
242 if fileid is not None: |
3213 | 243 self._fileid = fileid |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
244 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
245 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
246 def _changectx(self): |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
247 return changectx(self._repo, self._changeid) |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
248 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
249 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
250 def _filelog(self): |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
251 return self._repo.file(self._path) |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
252 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
253 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
254 def _changeid(self): |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
255 if '_changectx' in self.__dict__: |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
256 return self._changectx.rev() |
3144
8342ad5abe0b
Make filectx lazier - some users never use filenode
Brendan Cully <brendan@kublai.com>
parents:
3143
diff
changeset
|
257 else: |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
258 return self._filelog.linkrev(self._filerev) |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
259 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
260 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
261 def _filenode(self): |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
262 if '_fileid' in self.__dict__: |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
263 return self._filelog.lookup(self._fileid) |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
264 else: |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
265 return self._changectx.filenode(self._path) |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
266 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
267 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
268 def _filerev(self): |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
269 return self._filelog.rev(self._filenode) |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
270 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
271 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
272 def _repopath(self): |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
273 return self._path |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
274 |
3168
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3166
diff
changeset
|
275 def __nonzero__(self): |
3712
1bd70d40ec57
context: None is not a valid filenode (revert from 23ede9e7ad4d)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3673
diff
changeset
|
276 try: |
7874
d812029cda85
cleanup: drop variables for unused return values
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7633
diff
changeset
|
277 self._filenode |
3712
1bd70d40ec57
context: None is not a valid filenode (revert from 23ede9e7ad4d)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3673
diff
changeset
|
278 return True |
7633 | 279 except error.LookupError: |
3712
1bd70d40ec57
context: None is not a valid filenode (revert from 23ede9e7ad4d)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3673
diff
changeset
|
280 # file is missing |
1bd70d40ec57
context: None is not a valid filenode (revert from 23ede9e7ad4d)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3673
diff
changeset
|
281 return False |
3168
05c588e1803d
context: add __nonzero__ methods
Matt Mackall <mpm@selenic.com>
parents:
3166
diff
changeset
|
282 |
3166
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3165
diff
changeset
|
283 def __str__(self): |
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3165
diff
changeset
|
284 return "%s@%s" % (self.path(), short(self.node())) |
ebdb3f616bc0
Add str methods to contexts
Matt Mackall <mpm@selenic.com>
parents:
3165
diff
changeset
|
285 |
3151
6719b3dd7d50
context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents:
3150
diff
changeset
|
286 def __repr__(self): |
3216
d865390c1781
context: simplify repr methods
Matt Mackall <mpm@selenic.com>
parents:
3215
diff
changeset
|
287 return "<filectx %s>" % str(self) |
3151
6719b3dd7d50
context: add __repr__ methods
Matt Mackall <mpm@selenic.com>
parents:
3150
diff
changeset
|
288 |
6469
fb502719c75c
python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents:
6286
diff
changeset
|
289 def __hash__(self): |
fb502719c75c
python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents:
6286
diff
changeset
|
290 try: |
10942
6f26ce7ae175
filectx: _fileid isn't normalized, use _filenode instead
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10927
diff
changeset
|
291 return hash((self._path, self._filenode)) |
6469
fb502719c75c
python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents:
6286
diff
changeset
|
292 except AttributeError: |
fb502719c75c
python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents:
6286
diff
changeset
|
293 return id(self) |
fb502719c75c
python 2.6 compatibility: add __hash__ to classes that have __eq__
Paul Moore <p.f.moore@gmail.com>
parents:
6286
diff
changeset
|
294 |
3165
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3152
diff
changeset
|
295 def __eq__(self, other): |
3715
6cb3aca69cdc
Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents:
3712
diff
changeset
|
296 try: |
6cb3aca69cdc
Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents:
3712
diff
changeset
|
297 return (self._path == other._path |
10942
6f26ce7ae175
filectx: _fileid isn't normalized, use _filenode instead
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10927
diff
changeset
|
298 and self._filenode == other._filenode) |
3715
6cb3aca69cdc
Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents:
3712
diff
changeset
|
299 except AttributeError: |
6cb3aca69cdc
Make context __eq__ handle arbitrary RHS values
Brendan Cully <brendan@kublai.com>
parents:
3712
diff
changeset
|
300 return False |
3165
e78185746554
Add equality operators to changectx and filectx
Matt Mackall <mpm@selenic.com>
parents:
3152
diff
changeset
|
301 |
4748
8808ea7da86b
merge: make test for fast-forward merge stricter (issue619)
Matt Mackall <mpm@selenic.com>
parents:
4663
diff
changeset
|
302 def __ne__(self, other): |
8808ea7da86b
merge: make test for fast-forward merge stricter (issue619)
Matt Mackall <mpm@selenic.com>
parents:
4663
diff
changeset
|
303 return not (self == other) |
8808ea7da86b
merge: make test for fast-forward merge stricter (issue619)
Matt Mackall <mpm@selenic.com>
parents:
4663
diff
changeset
|
304 |
3207
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3172
diff
changeset
|
305 def filectx(self, fileid): |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3172
diff
changeset
|
306 '''opens an arbitrary revision of the file without |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3172
diff
changeset
|
307 opening a new filelog''' |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3172
diff
changeset
|
308 return filectx(self._repo, self._path, fileid=fileid, |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3172
diff
changeset
|
309 filelog=self._filelog) |
0790dce2f3a8
Add lookup method to filectx
Brendan Cully <brendan@kublai.com>
parents:
3172
diff
changeset
|
310 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
311 def filerev(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
312 return self._filerev |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
313 def filenode(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
314 return self._filenode |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
315 def flags(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
316 return self._changectx.flags(self._path) |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
317 def filelog(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
318 return self._filelog |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
319 |
3150
a5e4c8172ace
filectx: lazy linkrev usage
Matt Mackall <mpm@selenic.com>
parents:
3149
diff
changeset
|
320 def rev(self): |
3336
e44eadc92ec4
context: check self.__dict__ instead of using hasattr
Brendan Cully <brendan@kublai.com>
parents:
3313
diff
changeset
|
321 if '_changectx' in self.__dict__: |
3150
a5e4c8172ace
filectx: lazy linkrev usage
Matt Mackall <mpm@selenic.com>
parents:
3149
diff
changeset
|
322 return self._changectx.rev() |
5810
124577de40a7
context: preserve changeset in filectx if we have one
Maxim Dounin <mdounin@mdounin.ru>
parents:
5760
diff
changeset
|
323 if '_changeid' in self.__dict__: |
6210
942287cb1f57
Removed trailing spaces from everything except test output
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5813
diff
changeset
|
324 return self._changectx.rev() |
7361
9fe97eea5510
linkrev: take a revision number rather than a hash
Matt Mackall <mpm@selenic.com>
parents:
7077
diff
changeset
|
325 return self._filelog.linkrev(self._filerev) |
3150
a5e4c8172ace
filectx: lazy linkrev usage
Matt Mackall <mpm@selenic.com>
parents:
3149
diff
changeset
|
326 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
327 def linkrev(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
328 return self._filelog.linkrev(self._filerev) |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
329 def node(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
330 return self._changectx.node() |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
331 def hex(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
332 return hex(self.node()) |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
333 def user(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
334 return self._changectx.user() |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
335 def date(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
336 return self._changectx.date() |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
337 def files(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
338 return self._changectx.files() |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
339 def description(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
340 return self._changectx.description() |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
341 def branch(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
342 return self._changectx.branch() |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
343 def extra(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
344 return self._changectx.extra() |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
345 def manifest(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
346 return self._changectx.manifest() |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
347 def changectx(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
348 return self._changectx |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
349 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
350 def data(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
351 return self._filelog.read(self._filenode) |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
352 def path(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
353 return self._path |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
354 def size(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
355 return self._filelog.size(self._filerev) |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
356 |
11702
eb07fbc21e9c
filectx: use cmp(self, fctx) instead of cmp(self, text)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11605
diff
changeset
|
357 def cmp(self, fctx): |
eb07fbc21e9c
filectx: use cmp(self, fctx) instead of cmp(self, text)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11605
diff
changeset
|
358 """compare with other file context |
11539
a463e3c50212
cmp: document the fact that we return True if content is different
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11538
diff
changeset
|
359 |
11702
eb07fbc21e9c
filectx: use cmp(self, fctx) instead of cmp(self, text)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11605
diff
changeset
|
360 returns True if different than fctx. |
11539
a463e3c50212
cmp: document the fact that we return True if content is different
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11538
diff
changeset
|
361 """ |
12731
95514b58709d
context: narrow down filter special case in filectx.cmp()
Christian Ebert <blacktrash@gmx.net>
parents:
12709
diff
changeset
|
362 if (fctx._filerev is None and self._repo._encodefilterpats |
95514b58709d
context: narrow down filter special case in filectx.cmp()
Christian Ebert <blacktrash@gmx.net>
parents:
12709
diff
changeset
|
363 or self.size() == fctx.size()): |
95514b58709d
context: narrow down filter special case in filectx.cmp()
Christian Ebert <blacktrash@gmx.net>
parents:
12709
diff
changeset
|
364 return self._filelog.cmp(self._filenode, fctx.data()) |
12709
4147a292c508
filectx: use ctx.size comparisons to speed up ctx.cmp
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12361
diff
changeset
|
365 |
12731
95514b58709d
context: narrow down filter special case in filectx.cmp()
Christian Ebert <blacktrash@gmx.net>
parents:
12709
diff
changeset
|
366 return True |
3310
0e370798eebf
context: add cmp for filectxs
Matt Mackall <mpm@selenic.com>
parents:
3302
diff
changeset
|
367 |
5811
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
368 def renamed(self): |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
369 """check if file was actually renamed in this changeset revision |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
370 |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
371 If rename logged in file revision, we report copy for changeset only |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
372 if file revisions linkrev points back to the changeset in question |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
373 or both changeset parents contain different file revisions. |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
374 """ |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
375 |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
376 renamed = self._filelog.renamed(self._filenode) |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
377 if not renamed: |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
378 return renamed |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
379 |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
380 if self.rev() == self.linkrev(): |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
381 return renamed |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
382 |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
383 name = self.path() |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
384 fnode = self._filenode |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
385 for p in self._changectx.parents(): |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
386 try: |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
387 if fnode == p.filenode(name): |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
388 return None |
7633 | 389 except error.LookupError: |
5811
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
390 pass |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
391 return renamed |
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
392 |
2563
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
393 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
|
394 p = self._path |
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
395 fl = self._filelog |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3578
diff
changeset
|
396 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
|
397 |
5813
3ef279074c77
context: fix filectx.parents() bug introduced when editing 180a3eee4b75
Patrick Mezard <pmezard@gmail.com>
parents:
5811
diff
changeset
|
398 r = self._filelog.renamed(self._filenode) |
3122
da85145d4571
filectx: add rename traversal for parents()
Matt Mackall <mpm@selenic.com>
parents:
2859
diff
changeset
|
399 if r: |
3124
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
400 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
|
401 |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3578
diff
changeset
|
402 return [filectx(self._repo, p, fileid=n, filelog=l) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
403 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
|
404 |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
405 def children(self): |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
406 # hard for renames |
482c524dd9ab
Add context.py: changeset and file revision contexts
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
407 c = self._filelog.children(self._filenode) |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3578
diff
changeset
|
408 return [filectx(self._repo, self._path, fileid=x, |
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3578
diff
changeset
|
409 filelog=self._filelog) for x in c] |
2566
d8560b458f76
Convert hg annotate to context api
Matt Mackall <mpm@selenic.com>
parents:
2563
diff
changeset
|
410 |
4856
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
411 def annotate(self, follow=False, linenumber=None): |
3172
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
412 '''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
|
413 in the file, where ctx is the filectx of the node where |
4856
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
414 that line was last changed. |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
415 This returns tuples of ((ctx, linenumber), line) for each line, |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
416 if "linenumber" parameter is NOT "None". |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
417 In such tuples, linenumber means one at the first appearance |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
418 in the managed file. |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
419 To reduce annotation cost, |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
420 this returns fixed value(False is used) as linenumber, |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
421 if "linenumber" parameter is "False".''' |
3172
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
422 |
4856
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
423 def decorate_compat(text, rev): |
3172
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
424 return ([rev] * len(text.splitlines()), text) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
425 |
4856
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
426 def without_linenumber(text, rev): |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
427 return ([(rev, False)] * len(text.splitlines()), text) |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
428 |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
429 def with_linenumber(text, rev): |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
430 size = len(text.splitlines()) |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
431 return ([(rev, i) for i in xrange(1, size + 1)], text) |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
432 |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
433 decorate = (((linenumber is None) and decorate_compat) or |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
434 (linenumber and with_linenumber) or |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
435 without_linenumber) |
e45c5120ca27
Allow filectx.annotate to return the line number of first appearance.
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
4748
diff
changeset
|
436 |
3172
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
437 def pair(parent, child): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
438 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
|
439 child[0][b1:b2] = parent[0][a1:a2] |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
440 return child |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
441 |
9097
431462bd8478
fix memory usage of revlog caches by limiting cache size [issue1639]
Matt Mackall <mpm@selenic.com>
parents:
8813
diff
changeset
|
442 getlog = util.lrucachefunc(lambda x: self._repo.file(x)) |
3172
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
443 def getctx(path, fileid): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
444 log = path == self._path and self._filelog or getlog(path) |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
445 return filectx(self._repo, path, fileid=fileid, filelog=log) |
9097
431462bd8478
fix memory usage of revlog caches by limiting cache size [issue1639]
Matt Mackall <mpm@selenic.com>
parents:
8813
diff
changeset
|
446 getctx = util.lrucachefunc(getctx) |
3172
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
447 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
448 def parents(f): |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
449 # we want to reuse filectx objects as much as possible |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
450 p = f._path |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
451 if f._filerev is None: # working dir |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3578
diff
changeset
|
452 pl = [(n.path(), n.filerev()) for n in f.parents()] |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
453 else: |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3578
diff
changeset
|
454 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
|
455 |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
456 if follow: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
457 r = f.renamed() |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
458 if r: |
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
459 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
|
460 |
3578
3b4e00cba57a
Define and use nullrev (revision of nullid) instead of -1.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3454
diff
changeset
|
461 return [getctx(p, n) for p, n in pl if n != nullrev] |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
462 |
3404
1a437b0f4902
Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents:
3403
diff
changeset
|
463 # use linkrev to find the first changeset where self appeared |
5811
180a3eee4b75
Fix copies reporting in log and convert.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5810
diff
changeset
|
464 if self.rev() != self.linkrev(): |
3404
1a437b0f4902
Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents:
3403
diff
changeset
|
465 base = self.filectx(self.filerev()) |
1a437b0f4902
Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents:
3403
diff
changeset
|
466 else: |
1a437b0f4902
Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents:
3403
diff
changeset
|
467 base = self |
1a437b0f4902
Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents:
3403
diff
changeset
|
468 |
13552
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
469 # This algorithm would prefer to be recursive, but Python is a |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
470 # bit recursion-hostile. Instead we do an iterative |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
471 # depth-first search. |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
472 |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
473 visit = [base] |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
474 hist = {} |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
475 pcache = {} |
3404
1a437b0f4902
Fix annotate where linkrev != rev without exporting linkrev
Brendan Cully <brendan@kublai.com>
parents:
3403
diff
changeset
|
476 needed = {base: 1} |
3172
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
477 while visit: |
13552
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
478 f = visit[-1] |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
479 if f not in pcache: |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
480 pcache[f] = parents(f) |
3172
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
481 |
13552
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
482 ready = True |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
483 pl = pcache[f] |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
484 for p in pl: |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
485 if p not in hist: |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
486 ready = False |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
487 visit.append(p) |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
488 needed[p] = needed.get(p, 0) + 1 |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
489 if ready: |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
490 visit.pop() |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
491 curr = decorate(f.data(), f) |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
492 for p in pl: |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
493 curr = pair(hist[p], curr) |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
494 if needed[p] == 1: |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
495 del hist[p] |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
496 else: |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
497 needed[p] -= 1 |
6762 | 498 |
13552
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
499 hist[f] = curr |
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
500 pcache[f] = [] |
3172
5c93dd0ae413
Refactor annotate copy support.
Brendan Cully <brendan@kublai.com>
parents:
3152
diff
changeset
|
501 |
13552
7ab85fec60c3
ancestor: rewrite to deal with crossed linkrevs (issue2682)
Matt Mackall <mpm@selenic.com>
parents:
13481
diff
changeset
|
502 return zip(hist[base][0], hist[base][1].splitlines(True)) |
3124
4d021b91cb26
filectx: allow passing filelog in init to avoid opening new filelogs
Matt Mackall <mpm@selenic.com>
parents:
3123
diff
changeset
|
503 |
11453
2ee26044d846
context: allow passing the common cset ancestor to fctx.ancestor
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
11303
diff
changeset
|
504 def ancestor(self, fc2, actx=None): |
3126
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
505 """ |
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
506 find the common ancestor file context, if any, of self, and fc2 |
11453
2ee26044d846
context: allow passing the common cset ancestor to fctx.ancestor
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
11303
diff
changeset
|
507 |
2ee26044d846
context: allow passing the common cset ancestor to fctx.ancestor
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
11303
diff
changeset
|
508 If actx is given, it must be the changectx of the common ancestor |
2ee26044d846
context: allow passing the common cset ancestor to fctx.ancestor
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
11303
diff
changeset
|
509 of self's and fc2's respective changesets. |
3126
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
510 """ |
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
511 |
11453
2ee26044d846
context: allow passing the common cset ancestor to fctx.ancestor
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
11303
diff
changeset
|
512 if actx is None: |
2ee26044d846
context: allow passing the common cset ancestor to fctx.ancestor
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
11303
diff
changeset
|
513 actx = self.changectx().ancestor(fc2.changectx()) |
9751
f8ca4035a949
filectx: shortcut unrelated files in ancestor() (issue1327)
Matt Mackall <mpm@selenic.com>
parents:
9750
diff
changeset
|
514 |
f8ca4035a949
filectx: shortcut unrelated files in ancestor() (issue1327)
Matt Mackall <mpm@selenic.com>
parents:
9750
diff
changeset
|
515 # the trivial case: changesets are unrelated, files must be too |
f8ca4035a949
filectx: shortcut unrelated files in ancestor() (issue1327)
Matt Mackall <mpm@selenic.com>
parents:
9750
diff
changeset
|
516 if not actx: |
f8ca4035a949
filectx: shortcut unrelated files in ancestor() (issue1327)
Matt Mackall <mpm@selenic.com>
parents:
9750
diff
changeset
|
517 return None |
f8ca4035a949
filectx: shortcut unrelated files in ancestor() (issue1327)
Matt Mackall <mpm@selenic.com>
parents:
9750
diff
changeset
|
518 |
f8ca4035a949
filectx: shortcut unrelated files in ancestor() (issue1327)
Matt Mackall <mpm@selenic.com>
parents:
9750
diff
changeset
|
519 # the easy case: no (relevant) renames |
f8ca4035a949
filectx: shortcut unrelated files in ancestor() (issue1327)
Matt Mackall <mpm@selenic.com>
parents:
9750
diff
changeset
|
520 if fc2.path() == self.path() and self.path() in actx: |
9750
f153af9580fe
merge: first part of fix for issue1327
Matt Mackall <mpm@selenic.com>
parents:
9547
diff
changeset
|
521 return actx[self.path()] |
3135
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
522 acache = {} |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
523 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
524 # 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
|
525 for c in (self, fc2): |
8527
f9a80054dd3c
use 'x is None' instead of 'x == None'
Martin Geisler <mg@lazybytes.net>
parents:
8413
diff
changeset
|
526 if c._filerev is None: |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3578
diff
changeset
|
527 pl = [(n.path(), n.filenode()) for n in c.parents()] |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
528 acache[(c._path, None)] = pl |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
529 |
6286
90a4329a6b4a
filectx.ancestor: use fctx._repopath to cache filelogs (issue1035)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
6228
diff
changeset
|
530 flcache = {self._repopath:self._filelog, fc2._repopath:fc2._filelog} |
3135
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
531 def parents(vertex): |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
532 if vertex in acache: |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
533 return acache[vertex] |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
534 f, n = vertex |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
535 if f not in flcache: |
3126
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
536 flcache[f] = self._repo.file(f) |
3135
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
537 fl = flcache[f] |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3578
diff
changeset
|
538 pl = [(f, p) for p in fl.parents(n) if p != nullid] |
3135
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
539 re = fl.renamed(n) |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
540 if re: |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
541 pl.append(re) |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3578
diff
changeset
|
542 acache[vertex] = pl |
3135
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
543 return pl |
3126
4bf2e895cf86
filectx: add rename-aware ancestor algorithm
Matt Mackall <mpm@selenic.com>
parents:
3125
diff
changeset
|
544 |
3135
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
545 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
|
546 v = ancestor.ancestor(a, b, parents) |
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
547 if v: |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3578
diff
changeset
|
548 f, n = v |
3135
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
549 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
|
550 |
3135
b1db258e875c
Abstract ancestor algorithm into generic function
Matt Mackall <mpm@selenic.com>
parents:
3134
diff
changeset
|
551 return None |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
552 |
10262
eb243551cbd8
copies: speed up copy detection
Matt Mackall <mpm@selenic.com>
parents:
9843
diff
changeset
|
553 def ancestors(self): |
13481
4eb1e9d6a7c9
context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents:
13476
diff
changeset
|
554 visit = {} |
4eb1e9d6a7c9
context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents:
13476
diff
changeset
|
555 c = self |
4eb1e9d6a7c9
context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents:
13476
diff
changeset
|
556 while True: |
4eb1e9d6a7c9
context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents:
13476
diff
changeset
|
557 for parent in c.parents(): |
4eb1e9d6a7c9
context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents:
13476
diff
changeset
|
558 visit[(parent.rev(), parent.node())] = parent |
4eb1e9d6a7c9
context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents:
13476
diff
changeset
|
559 if not visit: |
4eb1e9d6a7c9
context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents:
13476
diff
changeset
|
560 break |
4eb1e9d6a7c9
context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents:
13476
diff
changeset
|
561 c = visit.pop(max(visit)) |
4eb1e9d6a7c9
context: be even more careful about result order in ancestors() (issue2642)
Matt Mackall <mpm@selenic.com>
parents:
13476
diff
changeset
|
562 yield c |
10262
eb243551cbd8
copies: speed up copy detection
Matt Mackall <mpm@selenic.com>
parents:
9843
diff
changeset
|
563 |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
564 class workingctx(changectx): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
565 """A workingctx object makes access to data related to |
6705
fec6bc978843
context: let workingctx parents be overriden
Patrick Mezard <pmezard@gmail.com>
parents:
6685
diff
changeset
|
566 the current working directory convenient. |
6709
f84f507c53d3
context: let workingctx.date(), .user() and description() be overriden
Patrick Mezard <pmezard@gmail.com>
parents:
6708
diff
changeset
|
567 date - any valid date string or (unixtime, offset), or None. |
f84f507c53d3
context: let workingctx.date(), .user() and description() be overriden
Patrick Mezard <pmezard@gmail.com>
parents:
6708
diff
changeset
|
568 user - username string, or None. |
6708
7566f00a3979
localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6707
diff
changeset
|
569 extra - a dictionary of extra values, or None. |
6707
02bad34230a2
localrepo: hide commit() file selection behind workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6705
diff
changeset
|
570 changes - a list of file lists as returned by localrepo.status() |
02bad34230a2
localrepo: hide commit() file selection behind workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6705
diff
changeset
|
571 or None to use the repository status. |
6705
fec6bc978843
context: let workingctx parents be overriden
Patrick Mezard <pmezard@gmail.com>
parents:
6685
diff
changeset
|
572 """ |
10969
ca052b484e56
context: remove parents parameter to workingctx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10942
diff
changeset
|
573 def __init__(self, repo, text="", user=None, date=None, extra=None, |
ca052b484e56
context: remove parents parameter to workingctx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10942
diff
changeset
|
574 changes=None): |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
575 self._repo = repo |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
576 self._rev = None |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
577 self._node = None |
6709
f84f507c53d3
context: let workingctx.date(), .user() and description() be overriden
Patrick Mezard <pmezard@gmail.com>
parents:
6708
diff
changeset
|
578 self._text = text |
6718
4386a7706828
Fix commit date (issue1193)
Christian Ebert <blacktrash@gmx.net>
parents:
6715
diff
changeset
|
579 if date: |
6709
f84f507c53d3
context: let workingctx.date(), .user() and description() be overriden
Patrick Mezard <pmezard@gmail.com>
parents:
6708
diff
changeset
|
580 self._date = util.parsedate(date) |
6817 | 581 if user: |
582 self._user = user | |
6707
02bad34230a2
localrepo: hide commit() file selection behind workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6705
diff
changeset
|
583 if changes: |
11101
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
584 self._status = list(changes[:4]) |
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
585 self._unknown = changes[4] |
11099
a68bd3b7c040
workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents:
11098
diff
changeset
|
586 self._ignored = changes[5] |
a68bd3b7c040
workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents:
11098
diff
changeset
|
587 self._clean = changes[6] |
a68bd3b7c040
workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents:
11098
diff
changeset
|
588 else: |
11101
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
589 self._unknown = None |
11099
a68bd3b7c040
workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents:
11098
diff
changeset
|
590 self._ignored = None |
a68bd3b7c040
workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents:
11098
diff
changeset
|
591 self._clean = None |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
592 |
6708
7566f00a3979
localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6707
diff
changeset
|
593 self._extra = {} |
7566f00a3979
localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6707
diff
changeset
|
594 if extra: |
7566f00a3979
localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6707
diff
changeset
|
595 self._extra = extra.copy() |
7566f00a3979
localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6707
diff
changeset
|
596 if 'branch' not in self._extra: |
7566f00a3979
localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6707
diff
changeset
|
597 try: |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
598 branch = encoding.fromlocal(self._repo.dirstate.branch()) |
6708
7566f00a3979
localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6707
diff
changeset
|
599 except UnicodeDecodeError: |
7566f00a3979
localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6707
diff
changeset
|
600 raise util.Abort(_('branch name not in UTF-8!')) |
7566f00a3979
localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6707
diff
changeset
|
601 self._extra['branch'] = branch |
7566f00a3979
localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6707
diff
changeset
|
602 if self._extra['branch'] == '': |
7566f00a3979
localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6707
diff
changeset
|
603 self._extra['branch'] = 'default' |
7566f00a3979
localrepo: let commit() get extra data from workingctx
Patrick Mezard <pmezard@gmail.com>
parents:
6707
diff
changeset
|
604 |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
605 def __str__(self): |
3313
6c68bc1e7873
context: change workingctx str() from . to <node>+
Matt Mackall <mpm@selenic.com>
parents:
3310
diff
changeset
|
606 return str(self._parents[0]) + "+" |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
607 |
12947
4832717aed98
context: add __repr__ methods to workingfilectx and workingctx
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12731
diff
changeset
|
608 def __repr__(self): |
4832717aed98
context: add __repr__ methods to workingfilectx and workingctx
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12731
diff
changeset
|
609 return "<workingctx %s>" % str(self) |
4832717aed98
context: add __repr__ methods to workingfilectx and workingctx
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12731
diff
changeset
|
610 |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
611 def __nonzero__(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
612 return True |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
613 |
6771
f5d7cfcbb4d3
workingctx: add __contains__ method
Matt Mackall <mpm@selenic.com>
parents:
6764
diff
changeset
|
614 def __contains__(self, key): |
8061
26316dda374f
context: fix workingctx.__contains__
Patrick Mezard <pmezard@gmail.com>
parents:
7633
diff
changeset
|
615 return self._repo.dirstate[key] not in "?r" |
6771
f5d7cfcbb4d3
workingctx: add __contains__ method
Matt Mackall <mpm@selenic.com>
parents:
6764
diff
changeset
|
616 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
617 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
618 def _manifest(self): |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
619 """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
|
620 |
11101
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
621 if self._unknown is None: |
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
622 self.status(unknown=True) |
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
623 |
3218
8d4855fd9d7b
merge: use new working context object in update
Matt Mackall <mpm@selenic.com>
parents:
3217
diff
changeset
|
624 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
|
625 copied = self._repo.dirstate.copies() |
10921
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
626 if len(self._parents) > 1: |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
627 man2 = self.p2().manifest() |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
628 def getman(f): |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
629 if f in man: |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
630 return man |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
631 return man2 |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
632 else: |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
633 getman = lambda f: man |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
634 def cf(f): |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
635 f = copied.get(f, f) |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
636 return getman(f).flags(f) |
6743 | 637 ff = self._repo.dirstate.flagfunc(cf) |
11101
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
638 modified, added, removed, deleted = self._status |
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
639 unknown = self._unknown |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3578
diff
changeset
|
640 for i, l in (("a", added), ("m", modified), ("u", unknown)): |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
641 for f in l: |
10921
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
642 orig = copied.get(f, f) |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
643 man[f] = getman(orig).get(orig, nullid) + i |
3823
676b75547d13
context: don't spuriously raise abort when a file goes missing.
Matt Mackall <mpm@selenic.com>
parents:
3715
diff
changeset
|
644 try: |
6743 | 645 man.set(f, ff(f)) |
3823
676b75547d13
context: don't spuriously raise abort when a file goes missing.
Matt Mackall <mpm@selenic.com>
parents:
3715
diff
changeset
|
646 except OSError: |
676b75547d13
context: don't spuriously raise abort when a file goes missing.
Matt Mackall <mpm@selenic.com>
parents:
3715
diff
changeset
|
647 pass |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
648 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
649 for f in deleted + removed: |
3325
50a18815e3f0
Revert changeset c67920d78248.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents:
3313
diff
changeset
|
650 if f in man: |
50a18815e3f0
Revert changeset c67920d78248.
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents:
3313
diff
changeset
|
651 del man[f] |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
652 |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
653 return man |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
654 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
655 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
656 def _status(self): |
11101
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
657 return self._repo.status()[:4] |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
658 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
659 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
660 def _user(self): |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
661 return self._repo.ui.username() |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
662 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
663 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
664 def _date(self): |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
665 return util.makedate() |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
666 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
667 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
668 def _parents(self): |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
669 p = self._repo.dirstate.parents() |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
670 if p[1] == nullid: |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
671 p = p[:-1] |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
672 self._parents = [changectx(self._repo, x) for x in p] |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
673 return self._parents |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
674 |
11098
380ab78dbd69
workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents:
11097
diff
changeset
|
675 def status(self, ignored=False, clean=False, unknown=False): |
380ab78dbd69
workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents:
11097
diff
changeset
|
676 """Explicit status query |
380ab78dbd69
workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents:
11097
diff
changeset
|
677 Unless this method is used to query the working copy status, the |
380ab78dbd69
workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents:
11097
diff
changeset
|
678 _status property will implicitly read the status using its default |
380ab78dbd69
workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents:
11097
diff
changeset
|
679 arguments.""" |
11099
a68bd3b7c040
workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents:
11098
diff
changeset
|
680 stat = self._repo.status(ignored=ignored, clean=clean, unknown=unknown) |
11101
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
681 self._unknown = self._ignored = self._clean = None |
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
682 if unknown: |
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
683 self._unknown = stat[4] |
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
684 if ignored: |
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
685 self._ignored = stat[5] |
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
686 if clean: |
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
687 self._clean = stat[6] |
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
688 self._status = stat[:4] |
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
689 return stat |
11098
380ab78dbd69
workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents:
11097
diff
changeset
|
690 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
691 def manifest(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
692 return self._manifest |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
693 def user(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
694 return self._user or self._repo.ui.username() |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
695 def date(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
696 return self._date |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
697 def description(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
698 return self._text |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
699 def files(self): |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
8207
diff
changeset
|
700 return sorted(self._status[0] + self._status[1] + self._status[2]) |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
701 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
702 def modified(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
703 return self._status[0] |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
704 def added(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
705 return self._status[1] |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
706 def removed(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
707 return self._status[2] |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
708 def deleted(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
709 return self._status[3] |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
710 def unknown(self): |
11101
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
711 assert self._unknown is not None # must call status first |
502474839293
context: only scan unknowns when needed
Matt Mackall <mpm@selenic.com>
parents:
11100
diff
changeset
|
712 return self._unknown |
11098
380ab78dbd69
workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents:
11097
diff
changeset
|
713 def ignored(self): |
11100
83968ae4aaf2
context: use asserts for ignored and clean exceptions
Matt Mackall <mpm@selenic.com>
parents:
11099
diff
changeset
|
714 assert self._ignored is not None # must call status first |
11099
a68bd3b7c040
workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents:
11098
diff
changeset
|
715 return self._ignored |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
716 def clean(self): |
11100
83968ae4aaf2
context: use asserts for ignored and clean exceptions
Matt Mackall <mpm@selenic.com>
parents:
11099
diff
changeset
|
717 assert self._clean is not None # must call status first |
11099
a68bd3b7c040
workingctx: use member variables to store ignored and clean
Steve Borho <steve@borho.org>
parents:
11098
diff
changeset
|
718 return self._clean |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
719 def branch(self): |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
720 return encoding.tolocal(self._extra['branch']) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
721 def extra(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
722 return self._extra |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
723 |
4663 | 724 def tags(self): |
725 t = [] | |
13412
58c497d0e44d
remove unnecessary list comprehensions
Martin Geisler <mg@aragost.com>
parents:
13384
diff
changeset
|
726 for p in self.parents(): |
58c497d0e44d
remove unnecessary list comprehensions
Martin Geisler <mg@aragost.com>
parents:
13384
diff
changeset
|
727 t.extend(p.tags()) |
4663 | 728 return t |
729 | |
13476
b85a09f368bd
workingctx: overload bookmarks() to return parents' bookmarks
Kevin Bullock <kbullock@ringworld.org>
parents:
13468
diff
changeset
|
730 def bookmarks(self): |
b85a09f368bd
workingctx: overload bookmarks() to return parents' bookmarks
Kevin Bullock <kbullock@ringworld.org>
parents:
13468
diff
changeset
|
731 b = [] |
b85a09f368bd
workingctx: overload bookmarks() to return parents' bookmarks
Kevin Bullock <kbullock@ringworld.org>
parents:
13468
diff
changeset
|
732 for p in self.parents(): |
b85a09f368bd
workingctx: overload bookmarks() to return parents' bookmarks
Kevin Bullock <kbullock@ringworld.org>
parents:
13468
diff
changeset
|
733 b.extend(p.bookmarks()) |
b85a09f368bd
workingctx: overload bookmarks() to return parents' bookmarks
Kevin Bullock <kbullock@ringworld.org>
parents:
13468
diff
changeset
|
734 return b |
b85a09f368bd
workingctx: overload bookmarks() to return parents' bookmarks
Kevin Bullock <kbullock@ringworld.org>
parents:
13468
diff
changeset
|
735 |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
736 def children(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
737 return [] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
738 |
6743 | 739 def flags(self, path): |
5389
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
740 if '_manifest' in self.__dict__: |
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
741 try: |
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
742 return self._manifest.flags(path) |
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
743 except KeyError: |
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
744 return '' |
5760
0145f9afb0e7
Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
5558
diff
changeset
|
745 |
5407
d7e7902bb190
Fix workingctx exec/link bit of copies on non-supporting systems
Patrick Mezard <pmezard@gmail.com>
parents:
5399
diff
changeset
|
746 orig = self._repo.dirstate.copies().get(path, path) |
5389
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
747 |
10921
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
748 def findflag(ctx): |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
749 mnode = ctx.changeset()[0] |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
750 node, flag = self._repo.manifest.find(mnode, orig) |
11143
e0a0af140f2e
context: fallback function should not return None
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10942
diff
changeset
|
751 ff = self._repo.dirstate.flagfunc(lambda x: flag or '') |
10921
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
752 try: |
10927
c1d375e93ee8
context: fix bug introduced in fb89cd21a7a0, path should be used
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10921
diff
changeset
|
753 return ff(path) |
10921
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
754 except OSError: |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
755 pass |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
756 |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
757 flag = findflag(self._parents[0]) |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
758 if flag is None and len(self.parents()) > 1: |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
759 flag = findflag(self._parents[1]) |
fb89cd21a7a0
workingctx: correctly compute the flag for noexec filesystems+merge
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
760 if flag is None or self._repo.dirstate[path] == 'r': |
5389
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
761 return '' |
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
762 return flag |
26c060922085
context: add fileflags() to avoid rebuilding manifests
Patrick Mezard <pmezard@gmail.com>
parents:
4909
diff
changeset
|
763 |
3966
b4eaa68dea1b
context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3965
diff
changeset
|
764 def filectx(self, path, filelog=None): |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
765 """get a file context from the working directory""" |
3966
b4eaa68dea1b
context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3965
diff
changeset
|
766 return workingfilectx(self._repo, path, workingctx=self, |
b4eaa68dea1b
context: create a filectxt with filelog reuse
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3965
diff
changeset
|
767 filelog=filelog) |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
768 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
769 def ancestor(self, c2): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
770 """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
|
771 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
|
772 |
6764 | 773 def walk(self, match): |
10176
24ce8f0c0a39
dirstate: don't check state of subrepo directories
Augie Fackler <durin42@gmail.com>
parents:
9974
diff
changeset
|
774 return sorted(self._repo.dirstate.walk(match, self.substate.keys(), |
24ce8f0c0a39
dirstate: don't check state of subrepo directories
Augie Fackler <durin42@gmail.com>
parents:
9974
diff
changeset
|
775 True, False)) |
6764 | 776 |
8717
e8de59577257
context: add a dirty method to detect modified contexts
Matt Mackall <mpm@selenic.com>
parents:
8528
diff
changeset
|
777 def dirty(self, missing=False): |
e8de59577257
context: add a dirty method to detect modified contexts
Matt Mackall <mpm@selenic.com>
parents:
8528
diff
changeset
|
778 "check whether a working directory is modified" |
11110
22f5ad0b5857
subrepo: dirtiness checks should iterate over subrepos
Edouard Gomez <ed.gomez@free.fr>
parents:
11106
diff
changeset
|
779 # check subrepos first |
22f5ad0b5857
subrepo: dirtiness checks should iterate over subrepos
Edouard Gomez <ed.gomez@free.fr>
parents:
11106
diff
changeset
|
780 for s in self.substate: |
22f5ad0b5857
subrepo: dirtiness checks should iterate over subrepos
Edouard Gomez <ed.gomez@free.fr>
parents:
11106
diff
changeset
|
781 if self.sub(s).dirty(): |
22f5ad0b5857
subrepo: dirtiness checks should iterate over subrepos
Edouard Gomez <ed.gomez@free.fr>
parents:
11106
diff
changeset
|
782 return True |
22f5ad0b5857
subrepo: dirtiness checks should iterate over subrepos
Edouard Gomez <ed.gomez@free.fr>
parents:
11106
diff
changeset
|
783 # check current working dir |
8717
e8de59577257
context: add a dirty method to detect modified contexts
Matt Mackall <mpm@selenic.com>
parents:
8528
diff
changeset
|
784 return (self.p2() or self.branch() != self.p1().branch() or |
e8de59577257
context: add a dirty method to detect modified contexts
Matt Mackall <mpm@selenic.com>
parents:
8528
diff
changeset
|
785 self.modified() or self.added() or self.removed() or |
e8de59577257
context: add a dirty method to detect modified contexts
Matt Mackall <mpm@selenic.com>
parents:
8528
diff
changeset
|
786 (missing and self.deleted())) |
e8de59577257
context: add a dirty method to detect modified contexts
Matt Mackall <mpm@selenic.com>
parents:
8528
diff
changeset
|
787 |
12270
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12070
diff
changeset
|
788 def add(self, list, prefix=""): |
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12070
diff
changeset
|
789 join = lambda f: os.path.join(prefix, f) |
11303
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
790 wlock = self._repo.wlock() |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
791 ui, ds = self._repo.ui, self._repo.dirstate |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
792 try: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
793 rejected = [] |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
794 for f in list: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
795 p = self._repo.wjoin(f) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
796 try: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
797 st = os.lstat(p) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
798 except: |
12270
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12070
diff
changeset
|
799 ui.warn(_("%s does not exist!\n") % join(f)) |
11303
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
800 rejected.append(f) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
801 continue |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
802 if st.st_size > 10000000: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
803 ui.warn(_("%s: up to %d MB of RAM may be required " |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
804 "to manage this file\n" |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
805 "(use 'hg revert %s' to cancel the " |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
806 "pending addition)\n") |
12270
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12070
diff
changeset
|
807 % (f, 3 * st.st_size // 1000000, join(f))) |
11303
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
808 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)): |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
809 ui.warn(_("%s not added: only files and symlinks " |
12270
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12070
diff
changeset
|
810 "supported currently\n") % join(f)) |
11303
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
811 rejected.append(p) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
812 elif ds[f] in 'amn': |
12270
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12070
diff
changeset
|
813 ui.warn(_("%s already tracked!\n") % join(f)) |
11303
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
814 elif ds[f] == 'r': |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
815 ds.normallookup(f) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
816 else: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
817 ds.add(f) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
818 return rejected |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
819 finally: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
820 wlock.release() |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
821 |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
822 def forget(self, list): |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
823 wlock = self._repo.wlock() |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
824 try: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
825 for f in list: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
826 if self._repo.dirstate[f] != 'a': |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
827 self._repo.ui.warn(_("%s not added!\n") % f) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
828 else: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
829 self._repo.dirstate.forget(f) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
830 finally: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
831 wlock.release() |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
832 |
12999
acd69df118ab
context: walk both parents for workingctx.ancestors()
Matt Mackall <mpm@selenic.com>
parents:
12731
diff
changeset
|
833 def ancestors(self): |
acd69df118ab
context: walk both parents for workingctx.ancestors()
Matt Mackall <mpm@selenic.com>
parents:
12731
diff
changeset
|
834 for a in self._repo.changelog.ancestors( |
acd69df118ab
context: walk both parents for workingctx.ancestors()
Matt Mackall <mpm@selenic.com>
parents:
12731
diff
changeset
|
835 *[p.rev() for p in self._parents]): |
acd69df118ab
context: walk both parents for workingctx.ancestors()
Matt Mackall <mpm@selenic.com>
parents:
12731
diff
changeset
|
836 yield changectx(self._repo, a) |
acd69df118ab
context: walk both parents for workingctx.ancestors()
Matt Mackall <mpm@selenic.com>
parents:
12731
diff
changeset
|
837 |
11303
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
838 def remove(self, list, unlink=False): |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
839 if unlink: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
840 for f in list: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
841 try: |
13235
6bf39d88c857
rename util.unlink to unlinkpath
Adrian Buehlmann <adrian@cadifra.com>
parents:
13047
diff
changeset
|
842 util.unlinkpath(self._repo.wjoin(f)) |
11303
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
843 except OSError, inst: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
844 if inst.errno != errno.ENOENT: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
845 raise |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
846 wlock = self._repo.wlock() |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
847 try: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
848 for f in list: |
12344
b6173aee4a47
Use lexists() instead of exists() where appropriate
Patrick Mezard <pmezard@gmail.com>
parents:
12067
diff
changeset
|
849 if unlink and os.path.lexists(self._repo.wjoin(f)): |
11303
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
850 self._repo.ui.warn(_("%s still exists!\n") % f) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
851 elif self._repo.dirstate[f] == 'a': |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
852 self._repo.dirstate.forget(f) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
853 elif f not in self._repo.dirstate: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
854 self._repo.ui.warn(_("%s not tracked!\n") % f) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
855 else: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
856 self._repo.dirstate.remove(f) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
857 finally: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
858 wlock.release() |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
859 |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
860 def undelete(self, list): |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
861 pctxs = self.parents() |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
862 wlock = self._repo.wlock() |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
863 try: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
864 for f in list: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
865 if self._repo.dirstate[f] != 'r': |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
866 self._repo.ui.warn(_("%s not removed!\n") % f) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
867 else: |
12360
4ae3e5dffa60
context: fix filectx.undelete() (issue2388)
Patrick Mezard <pmezard@gmail.com>
parents:
12344
diff
changeset
|
868 fctx = f in pctxs[0] and pctxs[0][f] or pctxs[1][f] |
11303
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
869 t = fctx.data() |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
870 self._repo.wwrite(f, t, fctx.flags()) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
871 self._repo.dirstate.normal(f) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
872 finally: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
873 wlock.release() |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
874 |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
875 def copy(self, source, dest): |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
876 p = self._repo.wjoin(dest) |
12344
b6173aee4a47
Use lexists() instead of exists() where appropriate
Patrick Mezard <pmezard@gmail.com>
parents:
12067
diff
changeset
|
877 if not os.path.lexists(p): |
11303
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
878 self._repo.ui.warn(_("%s does not exist!\n") % dest) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
879 elif not (os.path.isfile(p) or os.path.islink(p)): |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
880 self._repo.ui.warn(_("copy failed: %s is not a file or a " |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
881 "symbolic link\n") % dest) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
882 else: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
883 wlock = self._repo.wlock() |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
884 try: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
885 if self._repo.dirstate[dest] in '?r': |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
886 self._repo.dirstate.add(dest) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
887 self._repo.dirstate.copy(source, dest) |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
888 finally: |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
889 wlock.release() |
a1aad8333864
move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
11151
diff
changeset
|
890 |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
891 class workingfilectx(filectx): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
892 """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
|
893 file in the working directory convenient.""" |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
894 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
|
895 """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
|
896 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
|
897 self._repo = repo |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
898 self._path = path |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
899 self._changeid = None |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
900 self._filerev = self._filenode = None |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
901 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
902 if filelog: |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
903 self._filelog = filelog |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
904 if workingctx: |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
905 self._changectx = workingctx |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
906 |
8157
77c5877a668c
context: use Python 2.4 decorator syntax
Martin Geisler <mg@lazybytes.net>
parents:
8151
diff
changeset
|
907 @propertycache |
7368
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
908 def _changectx(self): |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
909 return workingctx(self._repo) |
595ba2537d4f
context: use descriptors to speed up lazy attributes
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7367
diff
changeset
|
910 |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
911 def __nonzero__(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
912 return True |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
913 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
914 def __str__(self): |
3313
6c68bc1e7873
context: change workingctx str() from . to <node>+
Matt Mackall <mpm@selenic.com>
parents:
3310
diff
changeset
|
915 return "%s@%s" % (self.path(), self._changectx) |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
916 |
12947
4832717aed98
context: add __repr__ methods to workingfilectx and workingctx
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12731
diff
changeset
|
917 def __repr__(self): |
4832717aed98
context: add __repr__ methods to workingfilectx and workingctx
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12731
diff
changeset
|
918 return "<workingfilectx %s>" % str(self) |
4832717aed98
context: add __repr__ methods to workingfilectx and workingctx
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12731
diff
changeset
|
919 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
920 def data(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
921 return self._repo.wread(self._path) |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
922 def renamed(self): |
8528
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
923 rp = self._repo.dirstate.copied(self._path) |
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
924 if not rp: |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
925 return None |
3965
2e5161335e65
context: fix a bug in workingfilectx.renamed
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3964
diff
changeset
|
926 return rp, self._changectx._parents[0]._manifest.get(rp, nullid) |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
927 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
928 def parents(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
929 '''return parent filectxs, following copies if necessary''' |
8528
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
930 def filenode(ctx, path): |
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
931 return ctx._manifest.get(path, nullid) |
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
932 |
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
933 path = self._path |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
934 fl = self._filelog |
8528
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
935 pcl = self._changectx._parents |
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
936 renamed = self.renamed() |
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
937 |
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
938 if renamed: |
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
939 pl = [renamed + (None,)] |
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
940 else: |
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
941 pl = [(path, filenode(pcl[0], path), fl)] |
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
942 |
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
943 for pc in pcl[1:]: |
4ddffb793d18
workingfilectx: always use the same filelog, even for renames
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
8527
diff
changeset
|
944 pl.append((path, filenode(pc, path), fl)) |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
945 |
3673
eb0b4a2d70a9
white space and line break cleanups
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3578
diff
changeset
|
946 return [filectx(self._repo, p, fileid=n, filelog=l) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
947 for p, n, l in pl if n != nullid] |
3217
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
948 |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
949 def children(self): |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
950 return [] |
6d98149d70fe
contexts: add working dir and working file contexts
Matt Mackall <mpm@selenic.com>
parents:
3216
diff
changeset
|
951 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
952 def size(self): |
11605
ce95d8b87d22
context: use os.lstat instead of os.stat to fetch file size
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11539
diff
changeset
|
953 return os.lstat(self._repo.wjoin(self._path)).st_size |
3962
2b8825c94c5a
add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3961
diff
changeset
|
954 def date(self): |
2b8825c94c5a
add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3961
diff
changeset
|
955 t, tz = self._changectx.date() |
2b8825c94c5a
add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3961
diff
changeset
|
956 try: |
4117
eb0967c6e77b
Use only integer part of mtime in workingfilectx.date(), fixes test-context.py
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4110
diff
changeset
|
957 return (int(os.lstat(self._repo.wjoin(self._path)).st_mtime), tz) |
3962
2b8825c94c5a
add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3961
diff
changeset
|
958 except OSError, err: |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
959 if err.errno != errno.ENOENT: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
960 raise |
3962
2b8825c94c5a
add date attribute to workingfilectx
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
3961
diff
changeset
|
961 return (t, tz) |
3310
0e370798eebf
context: add cmp for filectxs
Matt Mackall <mpm@selenic.com>
parents:
3302
diff
changeset
|
962 |
11702
eb07fbc21e9c
filectx: use cmp(self, fctx) instead of cmp(self, text)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11605
diff
changeset
|
963 def cmp(self, fctx): |
eb07fbc21e9c
filectx: use cmp(self, fctx) instead of cmp(self, text)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11605
diff
changeset
|
964 """compare with other file context |
11539
a463e3c50212
cmp: document the fact that we return True if content is different
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11538
diff
changeset
|
965 |
11702
eb07fbc21e9c
filectx: use cmp(self, fctx) instead of cmp(self, text)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11605
diff
changeset
|
966 returns True if different than fctx. |
11539
a463e3c50212
cmp: document the fact that we return True if content is different
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11538
diff
changeset
|
967 """ |
11703
55a2af02e45c
context: reuse filecontext.cmp in workingfilecontext.cmp
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11702
diff
changeset
|
968 # fctx should be a filectx (not a wfctx) |
55a2af02e45c
context: reuse filecontext.cmp in workingfilecontext.cmp
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11702
diff
changeset
|
969 # invert comparison to reuse the same code path |
55a2af02e45c
context: reuse filecontext.cmp in workingfilecontext.cmp
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11702
diff
changeset
|
970 return fctx.cmp(self) |
6715
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
971 |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
972 class memctx(object): |
7077
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
973 """Use memctx to perform in-memory commits via localrepo.commitctx(). |
6715
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
974 |
7077
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
975 Revision information is supplied at initialization time while |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
976 related files data and is made available through a callback |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
977 mechanism. 'repo' is the current localrepo, 'parents' is a |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
978 sequence of two parent revisions identifiers (pass None for every |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
979 missing parent), 'text' is the commit message and 'files' lists |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
980 names of files touched by the revision (normalized and relative to |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
981 repository root). |
6715
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
982 |
7077
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
983 filectxfn(repo, memctx, path) is a callable receiving the |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
984 repository, the current memctx object and the normalized path of |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
985 requested file, relative to repository root. It is fired by the |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
986 commit function for every file in 'files', but calls order is |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
987 undefined. If the file is available in the revision being |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
988 committed (updated or added), filectxfn returns a memfilectx |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
989 object. If the file was removed, filectxfn raises an |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
990 IOError. Moved files are represented by marking the source file |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
991 removed and the new file added with copy information (see |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
992 memfilectx). |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
993 |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
994 user receives the committer name and defaults to current |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
995 repository username, date is the commit date in any format |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
996 supported by util.parsedate() and defaults to current date, extra |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
997 is a dictionary of metadata or is left empty. |
6715
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
998 """ |
6721
521c6c6f3b9b
kill some trailing spaces
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6718
diff
changeset
|
999 def __init__(self, repo, parents, text, files, filectxfn, user=None, |
6715
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1000 date=None, extra=None): |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1001 self._repo = repo |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1002 self._rev = None |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1003 self._node = None |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1004 self._text = text |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1005 self._date = date and util.parsedate(date) or util.makedate() |
6809
89ec85aa6cc3
context: trigger missing username warning only when necessary
Patrick Mezard <pmezard@gmail.com>
parents:
6772
diff
changeset
|
1006 self._user = user |
6715
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1007 parents = [(p or nullid) for p in parents] |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1008 p1, p2 = parents |
6747
f6c00b17387c
use repo[changeid] to get a changectx
Matt Mackall <mpm@selenic.com>
parents:
6744
diff
changeset
|
1009 self._parents = [changectx(self._repo, p) for p in (p1, p2)] |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
8207
diff
changeset
|
1010 files = sorted(set(files)) |
6715
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1011 self._status = [files, [], [], [], []] |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1012 self._filectxfn = filectxfn |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1013 |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1014 self._extra = extra and extra.copy() or {} |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1015 if 'branch' not in self._extra: |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1016 self._extra['branch'] = 'default' |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1017 elif self._extra.get('branch') == '': |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1018 self._extra['branch'] = 'default' |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1019 |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1020 def __str__(self): |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1021 return str(self._parents[0]) + "+" |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1022 |
6763
403682f1c678
context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents:
6762
diff
changeset
|
1023 def __int__(self): |
403682f1c678
context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents:
6762
diff
changeset
|
1024 return self._rev |
403682f1c678
context: add __int__ and hex methods
Matt Mackall <mpm@selenic.com>
parents:
6762
diff
changeset
|
1025 |
6715
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1026 def __nonzero__(self): |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1027 return True |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1028 |
8401
ca7dc47eecc6
filecommit: swallow some bits from _commitctx, add _
Matt Mackall <mpm@selenic.com>
parents:
8380
diff
changeset
|
1029 def __getitem__(self, key): |
ca7dc47eecc6
filecommit: swallow some bits from _commitctx, add _
Matt Mackall <mpm@selenic.com>
parents:
8380
diff
changeset
|
1030 return self.filectx(key) |
ca7dc47eecc6
filecommit: swallow some bits from _commitctx, add _
Matt Mackall <mpm@selenic.com>
parents:
8380
diff
changeset
|
1031 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1032 def p1(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1033 return self._parents[0] |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1034 def p2(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1035 return self._parents[1] |
8406
6ad1f72bdf34
context: add p1 and p2 methods
Matt Mackall <mpm@selenic.com>
parents:
8401
diff
changeset
|
1036 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1037 def user(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1038 return self._user or self._repo.ui.username() |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1039 def date(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1040 return self._date |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1041 def description(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1042 return self._text |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1043 def files(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1044 return self.modified() |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1045 def modified(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1046 return self._status[0] |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1047 def added(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1048 return self._status[1] |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1049 def removed(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1050 return self._status[2] |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1051 def deleted(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1052 return self._status[3] |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1053 def unknown(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1054 return self._status[4] |
11098
380ab78dbd69
workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents:
11097
diff
changeset
|
1055 def ignored(self): |
380ab78dbd69
workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents:
11097
diff
changeset
|
1056 return self._status[5] |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1057 def clean(self): |
11098
380ab78dbd69
workingctx: add explicit status method, add ignored and fix clean
Steve Borho <steve@borho.org>
parents:
11097
diff
changeset
|
1058 return self._status[6] |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1059 def branch(self): |
13047
6c375e07d673
branch: operate on branch names in local string space where possible
Matt Mackall <mpm@selenic.com>
parents:
13031
diff
changeset
|
1060 return encoding.tolocal(self._extra['branch']) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1061 def extra(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1062 return self._extra |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1063 def flags(self, f): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1064 return self[f].flags() |
6715
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1065 |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1066 def parents(self): |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1067 """return contexts for each parent changeset""" |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1068 return self._parents |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1069 |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1070 def filectx(self, path, filelog=None): |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1071 """get a file context from the working directory""" |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1072 return self._filectxfn(self._repo, self, path) |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1073 |
11151
c5c190822501
slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents:
11144
diff
changeset
|
1074 def commit(self): |
c5c190822501
slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents:
11144
diff
changeset
|
1075 """commit context to the repo""" |
c5c190822501
slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents:
11144
diff
changeset
|
1076 return self._repo.commitctx(self) |
c5c190822501
slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents:
11144
diff
changeset
|
1077 |
6715
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1078 class memfilectx(object): |
7077
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
1079 """memfilectx represents an in-memory file to commit. |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
1080 |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
1081 See memctx for more details. |
6715
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1082 """ |
11151
c5c190822501
slightly improve memctx api
Alexander Solovyov <piranha@piranha.org.ua>
parents:
11144
diff
changeset
|
1083 def __init__(self, path, data, islink=False, isexec=False, copied=None): |
7077
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
1084 """ |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
1085 path is the normalized file path relative to repository root. |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
1086 data is the file content as a string. |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
1087 islink is True if the file is a symbolic link. |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
1088 isexec is True if the file is executable. |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
1089 copied is the source file path if current file was copied in the |
ccbd39cad3c3
context: improve memctx documentation
Patrick Mezard <pmezard@gmail.com>
parents:
7008
diff
changeset
|
1090 revision being committed, or None.""" |
6715
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1091 self._path = path |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1092 self._data = data |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1093 self._flags = (islink and 'l' or '') + (isexec and 'x' or '') |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1094 self._copied = None |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1095 if copied: |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1096 self._copied = (copied, nullid) |
a3c41abfa828
context: add memctx for memory commits
Patrick Mezard <pmezard@gmail.com>
parents:
6709
diff
changeset
|
1097 |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1098 def __nonzero__(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1099 return True |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1100 def __str__(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1101 return "%s@%s" % (self.path(), self._changectx) |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1102 def path(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1103 return self._path |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1104 def data(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1105 return self._data |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1106 def flags(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1107 return self._flags |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1108 def isexec(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1109 return 'x' in self._flags |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1110 def islink(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1111 return 'l' in self._flags |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1112 def renamed(self): |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
1113 return self._copied |