annotate hglib/context.py @ 175:c16e2087660f

client: remove unused imports
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 06 Jul 2016 14:11:02 -0700
parents 6d273d0a51aa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
148
c1b966866ed7 hglib: make all imports absolute (issue4520)
Brett Cannon <brett@python.org>
parents: 142
diff changeset
1 import hglib.client # Circular dependency.
c1b966866ed7 hglib: make all imports absolute (issue4520)
Brett Cannon <brett@python.org>
parents: 142
diff changeset
2 from hglib import util, templates
110
c635e6e7054f context: raise same error when not found for all hg versions
Alexander Plavin <me@aplavin.ru>
parents: 104
diff changeset
3 from hglib.error import CommandError
153
ef8eb78fc88d hglib: don't try to use long under Python 3 (issue4520)
Brett Cannon <brett@python.org>
parents: 151
diff changeset
4 from hglib.util import b, strtobytes, integertypes
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
5
142
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
6 _nullcset = [b('-1'), b('0000000000000000000000000000000000000000'), b(''),
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
7 b(''), b(''), b(''), b('')]
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
8
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
9 class changectx(object):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
10 """A changecontext object makes access to data related to a particular
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
11 changeset convenient."""
142
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
12 def __init__(self, repo, changeid=b('')):
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
13 """changeid is a revision number, node, or tag"""
142
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
14 if changeid == b(''):
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
15 changeid = b('.')
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
16 self._repo = repo
148
c1b966866ed7 hglib: make all imports absolute (issue4520)
Brett Cannon <brett@python.org>
parents: 142
diff changeset
17 if isinstance(changeid, hglib.client.revision):
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
18 cset = changeid
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
19 elif changeid == -1:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
20 cset = _nullcset
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
21 else:
153
ef8eb78fc88d hglib: don't try to use long under Python 3 (issue4520)
Brett Cannon <brett@python.org>
parents: 151
diff changeset
22 if isinstance(changeid, integertypes):
151
b91356bf7186 hglib: use strtobytes() (issue4520)
Brett Cannon <brett@python.org>
parents: 149
diff changeset
23 changeid = b('rev(') + strtobytes(changeid) + b(')')
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
24
110
c635e6e7054f context: raise same error when not found for all hg versions
Alexander Plavin <me@aplavin.ru>
parents: 104
diff changeset
25 notfound = False
c635e6e7054f context: raise same error when not found for all hg versions
Alexander Plavin <me@aplavin.ru>
parents: 104
diff changeset
26 try:
c635e6e7054f context: raise same error when not found for all hg versions
Alexander Plavin <me@aplavin.ru>
parents: 104
diff changeset
27 cset = self._repo.log(changeid)
138
a05cdc1579df context: handle tip+1 breakage in pre-3.2 default branch
Matt Mackall <mpm@selenic.com>
parents: 137
diff changeset
28 # hg bbf4f3dfd700 gave a null result for tip+1
a05cdc1579df context: handle tip+1 breakage in pre-3.2 default branch
Matt Mackall <mpm@selenic.com>
parents: 137
diff changeset
29 if (cset and cset[0][1] == _nullcset[1]
a05cdc1579df context: handle tip+1 breakage in pre-3.2 default branch
Matt Mackall <mpm@selenic.com>
parents: 137
diff changeset
30 and cset[0][0] != _nullcset[0]):
a05cdc1579df context: handle tip+1 breakage in pre-3.2 default branch
Matt Mackall <mpm@selenic.com>
parents: 137
diff changeset
31 notfound = True
110
c635e6e7054f context: raise same error when not found for all hg versions
Alexander Plavin <me@aplavin.ru>
parents: 104
diff changeset
32 except CommandError:
c635e6e7054f context: raise same error when not found for all hg versions
Alexander Plavin <me@aplavin.ru>
parents: 104
diff changeset
33 notfound = True
c635e6e7054f context: raise same error when not found for all hg versions
Alexander Plavin <me@aplavin.ru>
parents: 104
diff changeset
34
c635e6e7054f context: raise same error when not found for all hg versions
Alexander Plavin <me@aplavin.ru>
parents: 104
diff changeset
35 if notfound or not len(cset):
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
36 raise ValueError('changeid %r not found in repo' % changeid)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
37 if len(cset) > 1:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
38 raise ValueError('changeid must yield a single changeset')
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
39 cset = cset[0]
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
40
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
41 self._rev, self._node, self._tags = cset[:3]
99
2b36619ec0a0 client: add date field to revision
Idan Kamara <idankk86@gmail.com>
parents: 94
diff changeset
42 self._branch, self._author, self._description, self._date = cset[3:]
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
43
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
44 self._rev = int(self._rev)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
45
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
46 self._tags = self._tags.split()
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
47 try:
142
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
48 self._tags.remove(b('tip'))
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
49 except ValueError:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
50 pass
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
51
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
52 self._ignored = None
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
53 self._clean = None
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
54
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
55 def __str__(self):
155
6ec4075191ce hglib: make str(hglib.context.changectx) work with Python 3 (issue4520)
Brett Cannon <brett@python.org>
parents: 153
diff changeset
56 return self._node[:12].decode('latin-1')
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
57
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
58 def __int__(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
59 return self._rev
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
60
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
61 def __repr__(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
62 return "<changectx %s>" % str(self)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
63
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
64 def __hash__(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
65 try:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
66 return hash(self._rev)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
67 except AttributeError:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
68 return id(self)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
69
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
70 def __eq__(self, other):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
71 try:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
72 return self._rev == other._rev
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
73 except AttributeError:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
74 return False
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
75
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
76 def __ne__(self, other):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
77 return not (self == other)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
78
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
79 def __nonzero__(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
80 return self._rev != -1
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
81
149
958307b30af3 hglib: add a __bool__ method where __nonzero__ is defined (issue4520)
Brett Cannon <brett@python.org>
parents: 148
diff changeset
82 def __bool__(self):
958307b30af3 hglib: add a __bool__ method where __nonzero__ is defined (issue4520)
Brett Cannon <brett@python.org>
parents: 148
diff changeset
83 return self.__nonzero__()
958307b30af3 hglib: add a __bool__ method where __nonzero__ is defined (issue4520)
Brett Cannon <brett@python.org>
parents: 148
diff changeset
84
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
85 def __contains__(self, key):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
86 return key in self._manifest
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
87
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
88 def __iter__(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
89 for f in sorted(self._manifest):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
90 yield f
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
91
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
92 @util.propertycache
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
93 def _status(self):
155
6ec4075191ce hglib: make str(hglib.context.changectx) work with Python 3 (issue4520)
Brett Cannon <brett@python.org>
parents: 153
diff changeset
94 return self._parsestatus(self._repo.status(change=strtobytes(self)))[:4]
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
95
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
96 def _parsestatus(self, stat):
142
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
97 d = dict((c, [])
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
98 for c in (b('M'), b('A'), b('R'), b('!'), b('?'), b('I'),
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
99 b('C'), b(' ')))
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
100 for k, path in stat:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
101 d[k].append(path)
142
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
102 return (d[b('M')], d[b('A')], d[b('R')], d[b('!')], d[b('?')],
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
103 d[b('I')], d[b('C')])
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
104
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
105 def status(self, ignored=False, clean=False):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
106 """Explicit status query
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
107 Unless this method is used to query the working copy status, the
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
108 _status property will implicitly read the status using its default
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
109 arguments."""
155
6ec4075191ce hglib: make str(hglib.context.changectx) work with Python 3 (issue4520)
Brett Cannon <brett@python.org>
parents: 153
diff changeset
110 stat = self._parsestatus(self._repo.status(change=strtobytes(self),
6ec4075191ce hglib: make str(hglib.context.changectx) work with Python 3 (issue4520)
Brett Cannon <brett@python.org>
parents: 153
diff changeset
111 ignored=ignored,
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
112 clean=clean))
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
113 self._unknown = self._ignored = self._clean = None
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
114 if ignored:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
115 self._ignored = stat[5]
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
116 if clean:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
117 self._clean = stat[6]
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
118 self._status = stat[:4]
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
119 return stat
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
120
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
121 def rev(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
122 return self._rev
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
123
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
124 def node(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
125 return self._node
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
126
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
127 def tags(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
128 return self._tags
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
129
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
130 def branch(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
131 return self._branch
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
132
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
133 def author(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
134 return self._author
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
135
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
136 def user(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
137 return self._author
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
138
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
139 def date(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
140 return self._date
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
141
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
142 def description(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
143 return self._description
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
144
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
145 def files(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
146 return sorted(self._status[0] + self._status[1] + self._status[2])
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
147
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
148 def modified(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
149 return self._status[0]
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
150
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
151 def added(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
152 return self._status[1]
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
153
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
154 def removed(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
155 return self._status[2]
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
156
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
157 def ignored(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
158 if self._ignored is None:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
159 self.status(ignored=True)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
160 return self._ignored
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
161
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
162 def clean(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
163 if self._clean is None:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
164 self.status(clean=True)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
165 return self._clean
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
166
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
167 @util.propertycache
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
168 def _manifest(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
169 d = {}
155
6ec4075191ce hglib: make str(hglib.context.changectx) work with Python 3 (issue4520)
Brett Cannon <brett@python.org>
parents: 153
diff changeset
170 for node, p, e, s, path in self._repo.manifest(rev=strtobytes(self)):
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
171 d[path] = node
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
172 return d
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
173
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
174 def manifest(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
175 return self._manifest
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
176
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
177 def hex(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
178 return hex(self._node)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
179
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
180 @util.propertycache
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
181 def _parents(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
182 """return contexts for each parent changeset"""
155
6ec4075191ce hglib: make str(hglib.context.changectx) work with Python 3 (issue4520)
Brett Cannon <brett@python.org>
parents: 153
diff changeset
183 par = self._repo.parents(rev=strtobytes(self))
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
184 if not par:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
185 return [changectx(self._repo, -1)]
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
186 return [changectx(self._repo, int(cset.rev)) for cset in par]
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
187
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
188 def parents(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
189 return self._parents
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
190
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
191 def p1(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
192 return self._parents[0]
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
193
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
194 def p2(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
195 if len(self._parents) == 2:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
196 return self._parents[1]
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
197 return changectx(self._repo, -1)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
198
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
199 @util.propertycache
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
200 def _bookmarks(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
201 books = [bm for bm in self._repo.bookmarks()[0] if bm[1] == self._rev]
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
202
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
203 bms = []
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
204 for name, r, n in books:
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
205 bms.append(name)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
206 return bms
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
207
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
208 def bookmarks(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
209 return self._bookmarks
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
210
124
cc7569bffb26 context: add 'hidden' method to check if the changeset is hidden
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 110
diff changeset
211 def hidden(self):
cc7569bffb26 context: add 'hidden' method to check if the changeset is hidden
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 110
diff changeset
212 """return True if the changeset is hidden, else False"""
142
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
213 return bool(self._repo.log(revrange=self._node + b(' and hidden()'),
124
cc7569bffb26 context: add 'hidden' method to check if the changeset is hidden
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 110
diff changeset
214 hidden=True))
cc7569bffb26 context: add 'hidden' method to check if the changeset is hidden
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 110
diff changeset
215
126
a7fe976b1931 context: add 'phase' getter
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 124
diff changeset
216 def phase(self):
a7fe976b1931 context: add 'phase' getter
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 124
diff changeset
217 """return the phase of the changeset (public, draft or secret)"""
156
6d273d0a51aa hglib: remove the user of str in hglib.context (issue5420)
Brett Cannon <brett@python.org>
parents: 155
diff changeset
218 return self._repo.phase(strtobytes(self._rev))[0][1]
126
a7fe976b1931 context: add 'phase' getter
Paul Tonelli <paul.tonelli@logilab.fr>
parents: 124
diff changeset
219
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
220 def children(self):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
221 """return contexts for each child changeset"""
142
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
222 for c in self._repo.log(b('children(') + self._node + b(')')):
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
223 yield changectx(self._repo, c)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
224
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
225 def ancestors(self):
142
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
226 for a in self._repo.log(b('ancestors(') + self._node + b(')')):
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
227 yield changectx(self._repo, a)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
228
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
229 def descendants(self):
142
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
230 for d in self._repo.log(b('descendants(') + self._node + b(')')):
94
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
231 yield changectx(self._repo, d)
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
232
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
233 def ancestor(self, c2):
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
234 """
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
235 return the ancestor context of self and c2
4da6bb8abfcc context: initial implementation of changectx
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
236 """
142
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
237 return changectx(self._repo,
fe74d5599539 hglib: wrap all application string literals in util.b() (issue4520)
Brett Cannon <brett@python.org>
parents: 138
diff changeset
238 b('ancestor(') + self + b(', ') + c2 + b(')'))