Commit Graph

27045 Commits

Author SHA1 Message Date
Gregory Szorc
0c976d1ad3 histedit: pick an appropriate base changeset by default (BC)
Previously, `hg histedit` required a revision argument specifying which
revision to use as the base for the current histedit operation. There
was an undocumented and experimental "histedit.defaultrev" option that
supported defining a single revision to be used if no argument is
passed.

Mercurial knows what changesets can be edited. And in most scenarios,
people want to edit this history of everything on the current head that
is rewritable. Making histedit do this by default and not require
an explicit argument or additional configuration is a major usability
win and will enable more people to use histedit.

This patch changes the behavior of the experimental and undocumented
"histedit.defaultrev" config option to select an appropriate base
revision by default. Comprehensive tests exercising the edge cases
in the new, somewhat complicated default revset have been added.
Surprisingly, no tests broke. I guess we were never testing the
behavior with no ANCESTOR argument (it used to fail with
"abort: histedit requires exactly one ancestor revision"). The new
behavior is much more user friendly.

The functionality for choosing the default base revision has been
moved to destutil.py, where it can easily be modified by extensions.
2015-10-24 19:56:39 +01:00
Yuya Nishihara
a588ddbc95 rebase: remove extra "if" from check of collapsing named branches 2015-12-05 23:50:13 +09:00
Yuya Nishihara
d1c7989b16 rebase: drop redundant functions to keep branch and graft source explicitly
All entries in extra dict are propagated by default since 5293d4f88aef.
2015-12-05 23:48:22 +09:00
Yuya Nishihara
2298c7a029 color: drop useless override of ui.popbuffer()
Because labels are applied at write() time since ce03e7329682,
colorui.popbuffer() is useless and it doesn't update _bufferapplylabels
correctly. Removing it should fix the problem.
2015-12-05 23:41:11 +09:00
Pierre-Yves David
7d5370f77a repoview: bypass changelog method to computed cache key
Getting the data necessary for the cache key using the changelog/revlog method
adds a significant overhead. Given how simple the underlying implementation is
and often this code is ran, it makes sense to violate layering and directly
compute the data.

Testing `hg log` on Mozilla-central, this reduce the time spent on changelog
cache validation by an extra half:

before: 12.2s of 69s
after:   6.1s of 62s

Total speed up from this patch and it's parent is 3x

(With stupid python profiler overhead)

The global speedup without profiler overhead is still there,

Before: 51s
After:  39s (-23%)
2015-12-04 14:22:15 -08:00
Pierre-Yves David
509e099539 repoview: stop recomputing cached key in all case
As explained in the comment, we were computing the key of the cache value every
time because of some obscure MQ test failure. I've dropped that code and ran the
test again that failure is gone. I assume some transaction cleanup got rid of
it.

So we are dropping that code. This provide a significant speedup.

Testing `hg log` on Mozilla-central this reduce the time spent on changelog
cache validation by a third:

before: 19.5s of 80s
after:  12.2s of 69s

(With stupid python profiler overhead)
2015-12-04 14:04:24 -08:00
Gregory Szorc
6be2ff7286 commands.debugindexdot: use cmdutil.openrevlog()
This pattern is used for all the other debug* commands that operate
on revlogs. debugindexdot is an outlier. Make it conform.
2015-12-05 21:40:38 -08:00
Gregory Szorc
68fc062c6f commands: unify argument handling for revlog debug commands
The same 3 options are used in a few locations and I'm about to
add another. Might as well consolidate the pattern.
2015-12-05 21:47:39 -08:00
Yuya Nishihara
3e4bbbe974 commit: fix rest syntax of examples
This fixes the formatting of help/commit page and silence test-gendoc.t.
2015-12-06 17:16:37 +09:00
Gregory Szorc
cf7ff66486 ui: optionally ignore sub-options from configitems()
For convenience.
2015-12-05 20:24:39 -08:00
Gregory Szorc
220a833776 ui: add method to return option and all sub-options
Apparently ":" has been blessed as a generic separator for
options and sub-options. We formalize this by introducing an API
for obtaining an option and all its sub-options.

This will be used in a subsequent patch for declaring sub-options
for [paths].
2015-12-05 20:20:57 -08:00
Martin von Zweigbergk
7a4ad651b5 revlog: don't consider nullrev when choosing delta base
In the most complex case, we try using the incoming delta base, then
we try both parents, and then we try the previous revlog entry. If
none of these result in a good delta, we natually use the null
revision as base. However, we sometimes consider the nullrev before we
have exhausted our other options. Specifically, when both parents are
null, we use the nullrev as delta base if it produces a good delta
(according to _isgooddelta()), and we fail to try the previous revlog
entry as delta base. After e60126c6093d (addrevision: use general
delta when the incoming base delta is bad, 2015-12-01), it can also
happen for non-merge commits when the incoming delta is not good.

The Firefox repo (from many months back) shrinks a tiny bit with this
patch: from 1.855GB to 1.830GB (1.4%). The hg repo itself shrinks even
less: by less than 0.1%. There may be repos that get larger instead.

This undoes the unexplained test change in e60126c6093d.
2015-12-04 17:46:56 -08:00
Martin von Zweigbergk
d9cd156585 revlog: make calls to _isgooddelta() consistent
We always want to call _isgooddelta() before accepting a delta. We
mostly call the function right after building the delta, but not
always. Instead, we have an extra call at the end of the big code
block. Let's make it consistent, so we call _isgooddelta() right after
builddelta() and exactly once per delta. That also lets us rely on
"delta is None" to mean we didn't find a good delta.
2015-12-04 17:14:14 -08:00
Martin von Zweigbergk
af588ff953 revlog: clarify which revision is added to 'tested' when using cached delta
The tested delta revisions are added to the 'tested' set. These are
the same revisions we pass to builddelta(). However, in one case, we
add builddelta(rev)[3] to the set intead of adding 'rev' itself. In
that particular case, that element is the same as the function's input
revision (because self._generaldelta is true), so the effect is the
same. Still, let's just add the function's input revision to avoid
confusing future readers.
2015-12-04 16:45:06 -08:00
Martin von Zweigbergk
0788ad5e3c revlog: remove unused variable 'chainlen' 2015-12-04 17:22:26 -08:00
Matt Harbison
378739c9cd commit: adjust the quoting in the examples to be Windows friendly
We should probably avoid strong quotes around command line args in the examples,
since cmd.exe doesn't recognize them, and it will surprise a user who cargo
cults them.  I don't see a way to make a rule for this, since strong quoting is
OK inside command line args, like within revsets.
2015-12-05 22:19:48 -05:00
Gregory Szorc
9af952ad6e wireproto: config options to disable bundle1
bundle2 is the new and preferred wire protocol format. For various
reasons, server operators may wish to force clients to use it.

One reason is performance. If a repository is stored in generaldelta,
the server must recompute deltas in order to produce the bundle1
changegroup. This can be extremely expensive. For mozilla-central,
bundle generation typically takes a few minutes. However, generating
a non-gd bundle from a generaldelta encoded mozilla-central requires
over 30 minutes of CPU! If a large repository like mozilla-central
were encoded in generaldelta and non-gd clients connected, they could
easily flood a server by cloning.

This patch gives server operators config knobs to control whether
bundle1 is allowed for push and pull operations. The default is to
support legacy bundle1 clients, making this patch backwards compatible.
2015-12-04 15:12:11 -08:00
Gregory Szorc
e4e7479111 exchange: standalone function to determine if bundle2 is requested
This will be used in a subsequent patch.
2015-12-04 13:31:01 -08:00
Gregory Szorc
49ce77c867 wireproto: add docstring for wirepeer 2015-12-04 13:15:14 -08:00
Augie Fackler
31fc3d117c commit: add some help examples (issue4963)
Includes documenting --date now, which resolves the above issue.
2015-12-04 15:24:05 -05:00
Augie Fackler
f675aea41b changegroup: restate file linknode callback using generator expressions
I think this is slightly clearer, and it nicely avoids an extra nested
function.
2015-12-04 11:39:03 -05:00
Augie Fackler
7ee8b9a4d3 changegroup: clean up file lookup function
One case is basically degenerate, so just extract it and make the
function clearer.
2015-12-04 11:38:02 -05:00
Augie Fackler
53ca8538c0 changegroup: remove one special case from lookupmflinknode
In the fastpathlinkrev case, lookupmflinknode was a very complicated
way of saying mfs.__getitem__, so let's just get that case out of our
way so it's easier to understand what's going on.
2015-12-04 10:55:46 -05:00
Augie Fackler
4e80790b8d changegroup: drop 'if True' that made the previous change clearer 2015-12-04 10:35:45 -05:00
Augie Fackler
c3a36c8116 changegroup: avoid iterating the whole manifest
The old code gathered the list of all files that changed anywhere in
history and then gathered changed file nodes by walking the entirety
of each manifest to be sent in order to gather changed file
nodes. That's going to be unfortunate for narrowhg, and it's already
inefficient for medium-to-large repositories.

Timings for bundle --all on my hg repo, tested with hgperf:
Before:
! wall 23.442445 comb 23.440000 user 23.250000 sys 0.190000 (best of 3)

After:
! wall 20.272187 comb 20.270000 user 20.190000 sys 0.080000 (best of 3)
2015-12-04 10:34:58 -05:00
Augie Fackler
85e62f1eda posix: work around "posix" systems without os.link available (issue4974)
Some platforms (see bug, notably a terminal emulator on Android) ship
with os.link removed from Python to try and cater to other tools that
expect os.link to exist iff hardlinks are supported on that
platform. As a workaround for this madness, include a fallback path
for when we're on a "posix" platform but lack os.link.
2015-12-04 15:59:46 -05:00
Pierre-Yves David
4777cbdc66 pathutil: use temporary variables instead of complicated wrapping
The one-lining did not help readability, we get rid of it.
2015-12-03 13:14:20 -08:00
Pierre-Yves David
756a483011 context: use a the nofsauditor when matching file in history (issue4749)
Before this change, asking for file from history (eg: 'hg cat -r 42 foo/bar')
could fail because of the current content of the working copy (eg: current
"foo" being a symlink). As the working copy state have no influence on the
content of the history, we can safely skip these checks.

The working copy context class have a different 'match'
implementation. That implementation still use the repo.auditor will
still catch symlink traversal.

I've audited all stuff calling "match" and they all go through a ctx
in a sensible way. The most unclear case was diff which still seemed
okay. You raised my paranoid level today and I double checked through
tests. They behave properly.

The odds of someone using the wrong (matching with a changectx for
operation that will eventually touch the file system) is non-zero
because you are never sure of what people will do. But I dunno if we
can fight against that. So I would not commit to "never" for "at this
level" and "in the future" if someone write especially bad code.

However, as a last defense, the vfs itself is running path auditor in
all cases outside of .hg/. So I think anything passing the 'matcher'
for buggy reason would growl at the vfs layer.
2015-12-03 13:23:46 -08:00
Pierre-Yves David
44f90da4f8 localrepo: add a second auditor without file system check
Auditors keeps a cache of audited paths. Therefore we cannot use the same
auditor for working copy and history operation. We create a new one without
file system check for this purposes.
2015-12-03 13:22:36 -08:00
Pierre-Yves David
225db290d0 pathauditor: add a way to skip file system check
We need to be able to skip it when looking at data within the history.
Doing them in all cases leads to buggy behavior like issue4749.
2015-12-03 10:40:19 -08:00
Pierre-Yves David
6e76158146 pathauditor: move file system specific check in their own function
This will make it easy to disable that part when not relevant (eg: auditing
filename for operation in history)
2015-12-03 12:22:48 -08:00
Yuya Nishihara
758ac06b0b contrib: disable SSLv3_method() to build old Python with recent libssl
Because OpenSSL is compiled without SSLv3 support on Debian sid, Python 2.6.9
can't be built without this hack. Python 2.7 is patched appropriately, but
2.6 isn't.

http://bugs.python.org/issue22935
2015-11-07 16:31:04 +09:00
Laurent Charignon
c7dc44265f rebase: only clear rebase status after the rebase transaction has completed
In 6e6b18aab8b2, I made the mistake of moving the step "clearing the status
after a rebase" to inside the rebase transaction.
This was wrong, since we don't want to clear the status (and the rebase state)
if something went wrong during the transaction: if something goes wrong we
want to keep the rebase state to be able to abort.
It broke rebase with evolve + inhibit.
2015-12-03 08:31:20 -08:00
Gregory Szorc
f1bd627c00 mercurial: support loading modules from zipimporter
The previous refactor to module importing broke module loading when
mercurial.* modules were loaded from a zipfile (using a zipimporter).
This scenario is likely encountered when using py2exe.

Supporting zipimporter and the traditional importer side-by-side
turns out to be quite a pain. In Python 2.x, the standard, file-based
import mechanism is partially implemented in C. The sys.meta_path
and sys.path_hooks hook points exist to allow custom importers in
Python/userland. zipimport.zipimporter and our "hgimporter" class
from earlier in this patch series are 2 of these.

In a standard Python installation (no matter if running in py2exe
or similar or not), zipimport.zipimporter appears to be registered
in sys.path_hooks. This means that as each sys.path entry is
consulted, it will ask zipimporter if it supports that path and
zipimporter will be used if that entry is a zip file. In a
py2exe environment, sys.path contains an entry with the path to
the zip file containing the Python standard library along with
Mercurial's Python files.

The way the importer mechanism works is the first importer that
declares knowledge of a module (via find_module() returning an
object) gets to load it. Since our "hgimporter" is registered
in sys.meta_path and returns an interest in specific mercurial.*
modules, the zipimporter registered on sys.path_hooks never comes
into play for these modules. So, we need to be zipimporter aware
and call into zipimporter to load modules.

This patch teaches "hgimporter" how to call out into zipimporter
when necessary. We detect the necessity of zipimporter by looking
at the loader for the "mercurial" module. If it is a zipimporter
instance, we load via zipimporter.

The behavior of zipimporter is a bit wonky.

You appear to need separate zipimporter instances for each directory
in the zip file. I'm not sure why this is. I suspect it has
something to do with the low-level importing mechanism (implemented
in C) operating on a per-directory basis. PEP-302 makes some
references to this. I was not able to get a zipimporter to
import modules outside of its immediate directory no matter how
I specified the module name. This is why we use separate
zipimporter instances for the ".zip/mercurial" and
".zip/mercurial/pure" locations.

The zipimporter documentation for Python 2.7 explicitly states that
zipimporter does not import dynamic modules (C extensions). Yet from
a py2exe distribution on Windows - where the .pyd files are *not*
in the zip archive - zipimporter imported these dynamic modules
just fine! I'm not sure if dynamic modules can't be imported from
*inside* the zip archive or whether zipimporter looks for dynamic
modules outside the zip archive. All I know is zipimporter does
manage to import the .pyd files on Windows and this patch makes
our new importer compatible with py2exe.

In the ideal world, We'd probably reimplement or fall back to parts
of the built-in import mechanism instead of handling zipimporter
specially. After all, if we're loading Mercurial modules via
something that isn't the built-in file-based importer or zipimporter,
our custom importer will likely fail because it doesn't know how to
call into it. I'd like to think that we'll never encounter this
in the wild, but you never know. If we do encounter it, we can
come up with another solution.

It's worth nothing that Python 3 has moved a lot of the importing
code from C to Python. Python 3 gives you near total control over
the import mechanism. So in the very distant future when Mercurial
drops Python 2 support, it's likely that our custom importer code
can be refactored to something a bit saner.
2015-12-03 21:25:05 -08:00
Gregory Szorc
767a462bbd mercurial: don't load C extensions from PyPy
PyPy isn't compatible with Python C extensions.

With this patch, the module load policy is automatically to "Python
only" when run under PyPy. `hg` and other Python scripts importing
mercurial.* modules will run from the source checkout or any
installation when executed with PyPy. This should enable people to
more easily experiment with PyPy and its potentially significant
performance benefits over CPython!
2015-11-24 22:21:51 -08:00
Gregory Szorc
3dd11a41cf mercurial: be more strict about loading dual implemented modules
With this change in place, we should have slightly stronger guarantees
about how modules with both Python and C implementations are loaded.
Before, our module loader's default policy looked under both mercurial/*
and mercurial/pure/* and imported whatever it found, C or pure. The fact
it looked in both locations by default was a temporary regression from
the beginning of this series.

This patch does 2 things:

1) Changes the default module load policy to only load C modules
2) Verifies that files loaded from mercurial/* are actually C modules

This 2nd behavior change makes our new module loading mechanism
stricter than from before this series. Before, it was possible to load
a .py-based module from mercurial/*. This could happen if an old
installation orphaned a file and then somehow didn't install the C
version for the new install. We now detect this odd configuration
and fall back to loading the pure Python module, assuming it is
allowed. In the case of a busted installation, we fail fast. While
we could fall back, we explicitly decide not to do this because
we don't want people accidentally not running the C modules and having
slow performance as a result.
2015-11-24 22:50:04 -08:00
Gregory Szorc
a150316d11 setup: refactor handling of modules with C/Python implementations
Previously, .py files under mercurial/pure/ were copied to mercurial/*
during installation if we were performing a pure Python installation.

Now that the new import hooks and module load policy are in place, this
hackery from the past is no longer necessary.

With this patch, we stop copying modules from mercurial/pure/* to
mercurial/*. Instead, we preserve the files at their original
hierarchy, mirroring the source repository structure.

In addition, we always install the pure modules. Before, we would only
include the pure modules in the distribution/installation if the
install-time settings requested a pure Python installation. The upside
of this change is that CPython and PyPy can run from the same Mercurial
installation, making packaging and distribution of Mercurial simpler.

The inclusion of pure Python modules in the installation sounds
risky, as it could lead to inadvertent loading of non-C modules.
This shouldn't be a problem. The default module load policy is "C
only" (or at least will be shortly) and the only way to load pure
modules from an installation is if a) pure installation was requested
b) the HGMODULELOADPOLICY overrides the requirement for C modules.

The default module load policy as defined in source is a special string
whose default value from the checkout is equivalent to the "C only"
policy (again, not exactly the state right now). For pure
installations, this default policy is not appropriate and will not
work. This patch adds support for rewriting __init__.py during
installation to reflect the module load policy that should be in
place accoding to the installation settings. For default CPython
installs, the value in the source file will change but there will
be no functional change. For pure installations, the default policy
will be set to "py," allowing them to work without having to set
environment variables.
2015-12-03 21:48:12 -08:00
Gregory Szorc
ec18b44ca2 check-seclevel: set module load policy to Python only
If we don't change this, the upcoming change to make the module
loading policy only load C modules will cause this script to fail if
run with CPython against an unbuilt source checkout.
2015-11-24 22:53:55 -08:00
Gregory Szorc
d7669a769a 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.
2015-12-03 21:37:01 -08:00
Augie Fackler
514dae67c6 changegroup: document manifest linkrev callback some more
Martin and I just got super-confused reading some code here, so I
think it's time for some more documentation.
2015-12-03 10:56:05 -05:00
Augie Fackler
aa07f6f058 changegroup: note during bundle apply if the repo was empty
An upcoming change for exchanging treemanifest data will need to
update the repository capabilities, which we should only do if the
repository was empty before we started applying this changegroup. In
the future we will probably need a strategy for upgrading to
treemanifest in requires during a pull (I'm assuming at some point
we'll make it possible to have a flag day to enable treemanifests on
an existing history.)
2015-12-02 14:32:17 -05:00
timeless
538843243e histedit: improve missing rule suggestion
include actual suggested text
2015-12-02 07:41:35 +00:00
Yuya Nishihara
10b6f5819b graphlog: make node symbol templatable by ui.graphnodetemplate option
New ui.graphnodetemplate option allows us to colorize a node symbol by phase
or branch,

  [ui]
  graphnodetemplate = {label('graphnode.{phase}', graphnode)}
  [color]
  graphnode.draft = yellow bold

or use a variety of unicode emoji characters, and so on. (You'll need less-481
to display non-BMP unicode character.)

  [ui]
  graphnodetemplate = {ifeq(obsolete, 'stable', graphnode, '\xf0\x9f\x92\xa9')}
2015-11-14 17:25:43 +09:00
Yuya Nishihara
e3b2f52bb0 templatekw: avoid slow creation of changectx objects in showgraphnode()
This mitigates the minor perf regression introduced by the previous patch.

  % hg log -G -R mozilla-central -l10000 --time > /dev/null
  (original) real 2.200 secs
  (previous) real 2.590 secs
  (this)     real 2.280 secs
2015-11-14 17:02:57 +09:00
Yuya Nishihara
f981890d2b graphlog: extract "graphnode" template keyword that represents node symbol
This provides a default node symbol. Tests will be added later.

"showparents" variable is renamed to "wpnodes" to avoid confusion with the
existing showparents() function.
2015-11-14 16:58:18 +09:00
Yuya Nishihara
78ebbc20b2 graphlog: move creation of workingdir-parent nodes to displaygraph()
Future patches will make a node symbol templatable. Because arguments of a
templatekw function are repo and ctx, "showparents" list will have to be
built from a repo object by that function.
2015-11-14 16:45:15 +09:00
Anton Shestakov
11e3a4574b builddeb: read default distribution and codename from lsb_release
This makes `make deb` place packages into a more appropriately named directory
instead of just "debian-unknown".
2015-11-25 18:07:33 +08:00
Anton Shestakov
68c6668d13 builddeb: remove unused --debbuilddir option
Looks like it was never used and after d43cf24ee602 it can be removed.
2015-11-25 15:26:03 +08:00
Anton Shestakov
b61eeae0ab builddeb: add --distid option to specify Distributor ID
This allows builddeb to handle distributions that are not Debian.

Distributor ID is reported by lsb_release --id, and in case of builddeb it's
usually Debian or Ubuntu.
2015-11-25 15:15:03 +08:00
Anton Shestakov
b5106c63ef builddeb: rename --release option to --codename
Debian and Ubuntu releases have both codenames and traditional version numbers.
An entire "branch" of releases is referred to by its codename, and version
numbers (e.g. 8.2, 14.04.3) are used to address individual releases.

Since we use codenames for building .deb packages, let's call the option and
the variable appropriately.
2015-11-25 14:59:43 +08:00