[PATCH 01 of 41] basefilectx: add an empty class that will be used as a parent of file contexts

Sean Farley sean.michael.farley at gmail.com
Mon Aug 12 11:26:57 CDT 2013


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1376165426 18000
#      Sat Aug 10 15:10:26 2013 -0500
# Node ID c19f46b904b99937a9391f4f98f01f3b7aee3ba9
# Parent  103edf3ed79e1885fbcf7832c236eb8c8b6a0c89
basefilectx: add an empty class that will be used as a parent of file contexts

Similar to the refactoring of context, we split common logic from filectx to a
parent class called basefilectx that will be inherited by filectx,
workingfilectx, and memfilectx. This will allow a clear disinction of all the
file contexts:

- filectx: read-only access to a filerevision that is already present in the repo,
- workingfilectx: a filecontext that represents files from the working directory,
- memfilectx: a filecontext that represents files in-memory

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -407,11 +407,21 @@
                 # specified pattern is a directory
                 continue
             if match.bad(fn, _('no such file in rev %s') % self) and match(fn):
                 yield fn
 
-class filectx(object):
+class basefilectx(object):
+    """A filecontext object represents the common logic for its children:
+    filectx: read-only access to a filerevision that is already present
+             in the repo,
+    workingfilectx: a filecontext that represents files from the working
+                    directory,
+    memfilectx: a filecontext that represents files in-memory."""
+    def __new__(cls, repo, path, *args, **kwargs):
+        return super(basefilectx, cls).__new__(cls)
+
+class filectx(basefilectx):
     """A filecontext object makes access to data related to a particular
        filerevision convenient."""
     def __init__(self, repo, path, changeid=None, fileid=None,
                  filelog=None, changectx=None):
         """changeid can be a changeset revision, node, or tag.


More information about the Mercurial-devel mailing list