##// END OF EJS Templates
cmdutil: make in-memory changes visible to external editor (issue4378)...
cmdutil: make in-memory changes visible to external editor (issue4378) Before this patch, external editor process for the commit log can't view some in-memory changes (especially, of dirstate), because they aren't written out until the end of transaction (or wlock). This causes unexpected output of Mercurial commands spawned from that editor process. To make in-memory changes visible to external editor process, this patch does: - write (or schedule to write) in-memory dirstate changes, and - set HG_PENDING environment variable, if: - a transaction is running, and - there are in-memory changes to be visible "hg diff" spawned from external editor process for "hg qrefresh" shows: - "changes newly imported into the topmost" before 49148d7868df(*) - "all changes recorded in the topmost by refreshing" after this patch (*) 49148d7868df changed steps invoking editor process Even though backward compatibility may be broken, the latter behavior looks reasonable, because "hg diff" spawned from the editor process consistently shows "what changes new revision records" regardless of invocation context. In fact, issue4378 itself should be resolved by 800e090e9c64, which made 'repo.transaction()' write in-memory dirstate changes out explicitly before starting transaction. It also made "hg qrefresh" imply 'dirstate.write()' before external editor invocation in call chain below. - mq.queue.refresh - strip.strip - repair.strip - localrepository.transaction - dirstate.write - localrepository.commit - invoke external editor Though, this patch has '(issue4378)' in own summary line to indicate that issues like issue4378 should be fixed by this. BTW, this patch adds '-m' option to a 'hg ci --amend' execution in 'test-commit-amend.t', to avoid invoking external editor process. In this case, "unsure" states may be changed to "clean" according to timestamp or so on. These changes should be written into pending file, if external editor invocation is required, Then, writing dirstate changes out breaks stability of test, because it shows "transaction abort!/rollback completed" occasionally. Aborting after editor process invocation while commands below may cause similar instability of tests, too (AFAIK, there is no more such one, at this revision) - commit --amend - without --message/--logfile - import - without --message/--logfile, - without --no-commit, - without --bypass, - one of below, and - patch has no description text, or - with --edit - aborting at the 1st patch, which adds or removes file(s) - if it only changes existing files, status is checked only for changed files by 'scmutil.matchfiles()', and transition from "unsure" to "normal" in dirstate doesn't occur (= dirstate isn't changed, and written out) - aborting at the 2nd or later patch implies other pending changes (e.g. changelog), and always causes showing "transaction abort!/rollback completed"

File last commit:

r26691:23c0da28 default
r26750:9f9ec4ab default
Show More
clonebundles.py
140 lines | 4.8 KiB | text/x-python | PythonLexer
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
"""server side extension to advertise pre-generated bundles to seed clones.
The extension essentially serves the content of a .hg/clonebundles.manifest
file to clients that request it.
The clonebundles.manifest file contains a list of URLs and attributes. URLs
hold pre-generated bundles that a client fetches and applies. After applying
the pre-generated bundle, the client will connect back to the original server
and pull data not in the pre-generated bundle.
Manifest File Format:
The manifest file contains a newline (\n) delimited list of entries.
Each line in this file defines an available bundle. Lines have the format:
<URL> [<key>=<value]
That is, a URL followed by extra metadata describing it. Metadata keys and
values should be URL encoded.
This metadata is optional. It is up to server operators to populate this
metadata.
Keys in UPPERCASE are reserved for use by Mercurial. All non-uppercase keys
can be used by site installations.
The server operator is responsible for generating the bundle manifest file.
Metadata Attributes:
BUNDLESPEC
A "bundle specification" string that describes the type of the bundle.
These are string values that are accepted by the "--type" argument of
`hg bundle`.
The values are parsed in strict mode, which means they must be of the
"<compression>-<type>" form. See
mercurial.exchange.parsebundlespec() for more details.
Clients will automatically filter out specifications that are unknown or
unsupported so they won't attempt to download something that likely won't
apply.
The actual value doesn't impact client behavior beyond filtering:
clients will still sniff the bundle type from the header of downloaded
files.
REQUIRESNI
Whether Server Name Indication (SNI) is required to connect to the URL.
SNI allows servers to use multiple certificates on the same IP. It is
somewhat common in CDNs and other hosting providers. Older Python
versions do not support SNI. Defining this attribute enables clients
with older Python versions to filter this entry.
If this is defined, it is important to advertise a non-SNI fallback
URL or clients running old Python releases may not be able to clone
with the clonebundles facility.
Value should be "true".
"""
from mercurial.i18n import _
from mercurial.node import nullid
from mercurial import (
exchange,
extensions,
wireproto,
)
testedwith = 'internal'
def capabilities(orig, repo, proto):
caps = orig(repo, proto)
# Only advertise if a manifest exists. This does add some I/O to requests.
# But this should be cheaper than a wasted network round trip due to
# missing file.
if repo.opener.exists('clonebundles.manifest'):
caps.append('clonebundles')
return caps
@wireproto.wireprotocommand('clonebundles', '')
def bundles(repo, proto):
"""Server command for returning info for available bundles to seed clones.
Clients will parse this response and determine what bundle to fetch.
Other extensions may wrap this command to filter or dynamically emit
data depending on the request. e.g. you could advertise URLs for
the closest data center given the client's IP address.
"""
return repo.opener.tryread('clonebundles.manifest')
@exchange.getbundle2partsgenerator('clonebundlesadvertise', 0)
def advertiseclonebundlespart(bundler, repo, source, bundlecaps=None,
b2caps=None, heads=None, common=None,
cbattempted=None, **kwargs):
"""Inserts an output part to advertise clone bundles availability."""
# Allow server operators to disable this behavior.
# # experimental config: ui.clonebundleadvertise
if not repo.ui.configbool('ui', 'clonebundleadvertise', True):
return
# Only advertise if a manifest is present.
if not repo.opener.exists('clonebundles.manifest'):
return
# And when changegroup data is requested.
if not kwargs.get('cg', True):
return
# And when the client supports clone bundles.
if cbattempted is None:
return
# And when the client didn't attempt a clone bundle as part of this pull.
if cbattempted:
return
# And when a full clone is requested.
# Note: client should not send "cbattempted" for regular pulls. This check
# is defense in depth.
if common and common != [nullid]:
return
msg = _('this server supports the experimental "clone bundles" feature '
'that should enable faster and more reliable cloning\n'
'help test it by setting the "experimental.clonebundles" config '
'flag to "true"')
bundler.newpart('output', data=msg)
def extsetup(ui):
extensions.wrapfunction(wireproto, '_capabilities', capabilities)