comparison mercurial/context.py @ 19537:6e3e8575276d

basectx: add an empty class that will be used as a parent of all contexts At the moment, there is no simple way to check if an object is a context because there is no common parent class. If there were, we could use 'isinstance' everywhere. Simply having memctx inherit from workingctx or changectx would allow the use of 'isinstance' but that could lead to some confusing situations of reading the code since we have three distinct concepts of a context: - changectx represents a changeset *already* in the repo, and is therefore immutable - workingctx represents changes on disk in the working directory - memctx represents changes solely in memory which may or may not be on disk Therefore, I propose refactoring context.py to have all three contexts inherit from a parent class 'basectx'.
author Sean Farley <sean.michael.farley@gmail.com>
date Sat, 13 Jul 2013 19:59:21 -0500
parents bc82abe500a9
children 049d6b5a4a59
comparison
equal deleted inserted replaced
19536:ab3cf67740d6 19537:6e3e8575276d
14 import obsolete as obsmod 14 import obsolete as obsmod
15 import repoview 15 import repoview
16 16
17 propertycache = util.propertycache 17 propertycache = util.propertycache
18 18
19 class changectx(object): 19 class basectx(object):
20 """A basectx object represents the common logic for its children:
21 changectx: read-only context that is already present in the repo,
22 workingctx: a context that represents the working directory and can
23 be committed,
24 memctx: a context that represents changes in-memory and can also
25 be committed."""
26 def __new__(cls, repo, changeid='', *args, **kwargs):
27 return super(basectx, cls).__new__(cls)
28
29 class changectx(basectx):
20 """A changecontext object makes access to data related to a particular 30 """A changecontext object makes access to data related to a particular
21 changeset convenient.""" 31 changeset convenient. It represents a read-only context already presnt in
32 the repo."""
22 def __init__(self, repo, changeid=''): 33 def __init__(self, repo, changeid=''):
23 """changeid is a revision number, node, or tag""" 34 """changeid is a revision number, node, or tag"""
24 if changeid == '': 35 if changeid == '':
25 changeid = '.' 36 changeid = '.'
26 self._repo = repo 37 self._repo = repo