Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/context.py @ 37177:fbe34945220d
context: set repo property in basectx
It seems like a good practice to call the super constructor. Let's
start by passing the repo along to basectx so it can assign it to a
private attribute. We should perhaps pass the rev and node along as
well, but that requires more work before it can be done.
Differential Revision: https://phab.mercurial-scm.org/D2970
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 29 Mar 2018 23:05:41 -0700 |
parents | bb47dc2f71a0 |
children | 97ab6f2dc3c3 |
comparison
equal
deleted
inserted
replaced
37176:bb47dc2f71a0 | 37177:fbe34945220d |
---|---|
61 workingctx: a context that represents the working directory and can | 61 workingctx: a context that represents the working directory and can |
62 be committed, | 62 be committed, |
63 memctx: a context that represents changes in-memory and can also | 63 memctx: a context that represents changes in-memory and can also |
64 be committed.""" | 64 be committed.""" |
65 | 65 |
66 def __init__(self, repo): | |
67 self._repo = repo | |
68 | |
66 def __bytes__(self): | 69 def __bytes__(self): |
67 return short(self.node()) | 70 return short(self.node()) |
68 | 71 |
69 __str__ = encoding.strmethod(__bytes__) | 72 __str__ = encoding.strmethod(__bytes__) |
70 | 73 |
404 """A changecontext object makes access to data related to a particular | 407 """A changecontext object makes access to data related to a particular |
405 changeset convenient. It represents a read-only context already present in | 408 changeset convenient. It represents a read-only context already present in |
406 the repo.""" | 409 the repo.""" |
407 def __init__(self, repo, changeid='.'): | 410 def __init__(self, repo, changeid='.'): |
408 """changeid is a revision number, node, or tag""" | 411 """changeid is a revision number, node, or tag""" |
412 super(changectx, self).__init__(repo) | |
409 | 413 |
410 if changeid == '': | 414 if changeid == '': |
411 changeid = '.' | 415 changeid = '.' |
412 self._repo = repo | |
413 | 416 |
414 try: | 417 try: |
415 if isinstance(changeid, int): | 418 if isinstance(changeid, int): |
416 self._node = repo.changelog.node(changeid) | 419 self._node = repo.changelog.node(changeid) |
417 self._rev = changeid | 420 self._rev = changeid |
1132 class committablectx(basectx): | 1135 class committablectx(basectx): |
1133 """A committablectx object provides common functionality for a context that | 1136 """A committablectx object provides common functionality for a context that |
1134 wants the ability to commit, e.g. workingctx or memctx.""" | 1137 wants the ability to commit, e.g. workingctx or memctx.""" |
1135 def __init__(self, repo, text="", user=None, date=None, extra=None, | 1138 def __init__(self, repo, text="", user=None, date=None, extra=None, |
1136 changes=None): | 1139 changes=None): |
1137 self._repo = repo | 1140 super(committablectx, self).__init__(repo) |
1138 self._rev = None | 1141 self._rev = None |
1139 self._node = None | 1142 self._node = None |
1140 self._text = text | 1143 self._text = text |
1141 if date: | 1144 if date: |
1142 self._date = dateutil.parsedate(date) | 1145 self._date = dateutil.parsedate(date) |
1816 is `False`, the file was deleted. | 1819 is `False`, the file was deleted. |
1817 """ | 1820 """ |
1818 | 1821 |
1819 def __init__(self, repo): | 1822 def __init__(self, repo): |
1820 super(overlayworkingctx, self).__init__(repo) | 1823 super(overlayworkingctx, self).__init__(repo) |
1821 self._repo = repo | |
1822 self.clean() | 1824 self.clean() |
1823 | 1825 |
1824 def setbase(self, wrappedctx): | 1826 def setbase(self, wrappedctx): |
1825 self._wrappedctx = wrappedctx | 1827 self._wrappedctx = wrappedctx |
1826 self._parents = [wrappedctx] | 1828 self._parents = [wrappedctx] |