##// END OF EJS Templates
mercurial: implement import hook for handling C/Python modules...
mercurial: implement import hook for handling C/Python modules There are a handful of modules that have both pure Python and C extension implementations. Currently, setup.py copies files from mercurial/pure/*.py to mercurial/ during the install process if C extensions are not available. This way, "import mercurial.X" will work whether C extensions are available or not. This approach has a few drawbacks. First, there aren't run-time checks verifying the C extensions are loaded when they should be. This could lead to accidental use of the slower pure Python modules. Second, the C extensions aren't compatible with PyPy and running Mercurial with PyPy requires installing Mercurial - you can't run ./hg from a source checkout. This makes developing while running PyPy somewhat difficult. This patch implements a PEP-302 import hook for finding and loading the modules with both C and Python implementations. When a module with dual implementations is requested for import, its import is handled by our import hook. The importer has a mechanism that controls what types of modules we allow to load. We call this loading behavior the "module load policy." There are 3 settings: * Only load C extensions * Only load pure Python * Try to load C and fall back to Python An environment variable allows overriding this policy at run time. This is mainly useful for developers and for performing actions against the source checkout (such as installing), which require overriding the default (strict) policy about requiring C extensions. The default mode for now is to allow both. This isn't proper and is technically backwards incompatible. However, it is necessary to implement a sane patch series that doesn't break the world during future bisections. The behavior will be corrected in future patch. We choose the main mercurial/__init__.py module for this code out of necessity: in a future world, if the custom module importer isn't registered, we'll fail to find/import certain modules when running from a pure installation. Without the magical import-time side-effects, *any* importer of mercurial.* modules would be required to call a function to register our importer. I'm not a fan of import time side effects and I initially attempted to do this. However, I was foiled by our own test harness, which has numerous `python` invoked scripts that "import mercurial" and fail because the importer isn't registered. Realizing this problem is probably present in random Python scripts that have been written over the years, I decided that sacrificing purity for backwards compatibility is necessary. Plus, if you are programming Python, "import" should probably "just work." It's worth noting that now that we have a custom module loader, it would be possible to hook up demand module proxies at this level instead of replacing __import__. We leave this work for another time, if it's even desired. This patch breaks importing in environments where Mercurial modules are loaded from a zip file (such as py2exe distributions). This will be addressed in a subsequent patch.

File last commit:

r20532:f1a3ae7c default
r27220:4374d819 default
Show More
phases.txt
94 lines | 2.8 KiB | text/plain | TextLexer
Matt Mackall
help: add phases topic
r15996 What are phases?
FUJIWARA Katsunori
doc: unify section level between help topics...
r17267 ================
Matt Mackall
help: add phases topic
r15996
Phases are a system for tracking which changesets have been or should
be shared. This helps prevent common mistakes when modifying history
(for instance, with the mq or rebase extensions).
Each changeset in a repository is in one of the following phases:
- public : changeset is visible on a public server
- draft : changeset is not yet published
- secret : changeset should not be pushed, pulled, or cloned
These phases are ordered (public < draft < secret) and no changeset
can be in a lower phase than its ancestors. For instance, if a
changeset is public, all its ancestors are also public. Lastly,
Johan Samyn
help: add verb to sentence in phases.txt
r16244 changeset phases should only be changed towards the public phase.
Matt Mackall
help: add phases topic
r15996
How are phases managed?
FUJIWARA Katsunori
doc: unify section level between help topics...
r17267 =======================
Matt Mackall
help: add phases topic
r15996
For the most part, phases should work transparently. By default, a
changeset is created in the draft phase and is moved into the public
phase when it is pushed to another repository.
Once changesets become public, extensions like mq and rebase will
refuse to operate on them to prevent creating duplicate changesets.
Phases can also be manually manipulated with the :hg:`phase` command
if needed. See :hg:`help -v phase` for examples.
Phases and servers
FUJIWARA Katsunori
doc: unify section level between help topics...
r17267 ==================
Matt Mackall
help: add phases topic
r15996
Normally, all servers are ``publishing`` by default. This means::
- all draft changesets that are pulled or cloned appear in phase
public on the client
- all draft changesets that are pushed appear as public on both
client and server
- secret changesets are neither pushed, pulled, or cloned
.. note::
Simon Heimberg
help: remove last occurrences of ".. note::" without two newlines...
r20532
Matt Mackall
help: add phases topic
r15996 Pulling a draft changeset from a publishing server does not mark it
as public on the server side due to the read-only nature of pull.
Sometimes it may be desirable to push and pull changesets in the draft
phase to share unfinished work. This can be done by setting a
repository to disable publishing in its configuration file::
[phases]
Matt Mackall
help: fix publish option spelling in phases topic
r16000 publish = False
Wagner Bruna
help/phases: remove trailing whitespace
r15998
Jordi Gutiérrez Hermoso
doc: reword "config file" to "configuration file"...
r19295 See :hg:`help config` for more information on configuration files.
Matt Mackall
help: add phases topic
r15996
.. note::
Simon Heimberg
help: remove last occurrences of ".. note::" without two newlines...
r20532
Matt Mackall
help: add phases topic
r15996 Servers running older versions of Mercurial are treated as
publishing.
Pierre-Yves David
phases: add a formal note that hash of secret changeset may leak out...
r20299 .. note::
Simon Heimberg
help: remove last occurrences of ".. note::" without two newlines...
r20532
Pierre-Yves David
phases: add a formal note that hash of secret changeset may leak out...
r20299 Changesets in secret phase are not exchanged with the server. This
applies to their content: file names, file contents, and changeset
metadata. For technical reasons, the identifier (e.g. d825e4025e39)
of the secret changeset may be communicated to the server.
Matt Mackall
help: add examples to phases topic
r16011 Examples
FUJIWARA Katsunori
doc: unify section level between help topics...
r17267 ========
Matt Mackall
help: add examples to phases topic
r16011
- list changesets in draft or secret phase::
hg log -r "not public()"
- change all secret changesets to draft::
hg phase --draft "secret()"
- forcibly move the current changeset and descendants from public to draft::
hg phase --force --draft .
- show a list of changeset revision and phase::
hg log --template "{rev} {phase}\n"
Matt Mackall
phases: add resync example to help topic
r16041 - resynchronize draft changesets relative to a remote repository::
FUJIWARA Katsunori
doc: use double quotation mark to quote arguments in examples for Windows users...
r19959 hg phase -fd "outgoing(URL)"
Matt Mackall
phases: add resync example to help topic
r16041
Matt Mackall
help: add examples to phases topic
r16011 See :hg:`help phase` for more information on manually manipulating phases.