Commit Graph

29282 Commits

Author SHA1 Message Date
Yuya Nishihara
348d73cc98 error: make HintException a mix-in class not derived from BaseException (API)
HintException is unrelated to the hierarchy of errors. It is an implementation
detail whether a class inherits from HintException or not, a sort of "private
inheritance" in C++.

New Hint isn't an exception class, which prevents catching error by its type:

    try:
        dosomething()
    except error.Hint:
        pass

Unfortunately, this passes on PyPy 5.3.1, but not on Python 2, and raises more
detailed TypeError on Python 3.
2016-07-09 14:28:30 +09:00
Gregory Szorc
8417644a05 sslutil: move context options flags to _hostsettings
Again, moving configuration determination to a single location.
2016-07-06 22:53:22 -07:00
Gregory Szorc
8d840bafa6 sslutil: move protocol determination to _hostsettings
Most of the logic for configuring TLS is now in this function.
Let's move protocol determination code there as well.
2016-07-06 22:47:24 -07:00
Durham Goode
3d4a2a798a share: don't recreate the source repo each time
Previously, every time you asked for the source repo of a shared working copy it
would recreate the repo object, which required calling reposetup. With certain
extension enabled, this can be quite expensive, and it can happen many times
(for instance, share attaches a post transaction hook to update bookmarks that
triggers this).

The fix is to just cache the repo object instead of constantly recreating it.
2016-07-11 13:40:02 -07:00
Maciej Fijalkowski
b3d62e8a18 setup: prepare for future cffi modules by adding placeholder in setup 2016-07-11 10:44:18 +02:00
Martijn Pieters
70f47c8885 journal: add support for seaching by pattern
If a pattern is used, include the entry name in the output, to make it clear
what name was matched.
2016-07-08 16:48:38 +01:00
Martijn Pieters
a0e514f821 journal: add share extension support
Rather than put everything into one journal file, split entries up in *shared*
and *local* entries. Working copy changes are local to a specific working copy,
so should remain local only. Other entries are shared with the source if so
configured when the share was created.

When unsharing, any shared journale entries are copied across.
2016-07-11 14:45:41 +01:00
Martijn Pieters
c699263458 journal: add dirstate tracking
Note that now the default action for `hg journal` is to list the working copy
history, not all bookmarks. In its place is the `--all` switch which lists all
name changes recorded, including the name for which the change was recorded on
each line.

Locking is switched to using a dedicated lock to avoid issues with the dirstate
being written during wlock unlocking (you can't re-lock during that process).
2016-07-11 13:39:24 +01:00
Matt Mackall
242c882fcb merge with stable 2016-07-11 08:54:13 -05:00
Gregory Szorc
0786299e33 sslutil: try to find CA certficates in well-known locations
Many Linux distros and other Nixen have CA certificates in well-defined
locations. Rather than potentially fail to load any CA certificates at
all (which will always result in a certificate verification failure),
we scan for paths to known CA certificate files and load one if seen.
Because a proper Mercurial install will have the path to the CA
certificate file defined at install time, we print a warning that
the install isn't proper and provide a URL with instructions to
correct things.

We only perform path-based fallback on Pythons that don't know
how to call into OpenSSL to load the default verify locations. This
is because we trust that Python/OpenSSL is properly configured
and knows better than Mercurial. So this new code effectively only
runs on Python <2.7.9 (technically Pythons without the modern ssl
module).
2016-07-06 21:16:00 -07:00
Gregory Szorc
0ede6720a7 sslutil: issue warning when unable to load certificates on OS X
Previously, failure to load system certificates on OS X would lead
to a certificate verify failure and that's it. We now print a warning
message with a URL that will contain information on how to configure
certificates on OS X.

As the inline comment states, there is room to improve here. I think
we could try harder to detect Homebrew and MacPorts installed
certificate files, for example. It's worth noting that Homebrew's
openssl package uses `security find-certificate -a -p` during package
installation to export the system keychain root CAs to
etc/openssl/cert.pem. This is something we could consider adding
to setup.py. We could also encourage packagers to do this. For now,
I'd just like to get this warning (which matches Windows behavior)
landed. We should have time to improve things before release.
2016-07-06 20:46:05 -07:00
Gregory Szorc
4e0e490a01 sslutil: don't access message attribute in exception (issue5285)
I should have ran the entire test suite on Python 2.6. Since the
hostname matching tests are implemented in Python (not .t tests),
it didn't uncover this warning. I'm not sure why - warnings should
be printed regardless. This is possibly a bug in the test runner.
But that's for another day...
2016-07-02 09:41:40 -07:00
Matt Mackall
154cf91894 Added signature for changeset af6493fe34d9 2016-07-01 15:12:33 -05:00
skarlage
643208895a revert: don't backup if no files reverted in interactive mode (issue4793)
When reverting interactively, we always backup files before prompting the user
to find out if they actually want to revert them. This can create spurious
*.orig files if a user enters an interactive revert session and then doesn't
revert any files. Instead, we should only backup files that are actually being
touched.
2016-06-30 08:38:19 -07:00
FUJIWARA Katsunori
6fdee58a92 perf: define command annotation locally for Mercurial earlier than 3.1
Before this patch, using cmdutil.command() for "@command" annotation
prevents perf.py from being loaded by Mercurial earlier than 1.9 (or
d4096ee63f8e), because cmdutil.command() isn't available in such
Mercurial, even though there are some code paths for Mercurial earlier
than 1.9.

For example, setting "_prereadsize" attribute in perfindex() and
perfnodelookup() is effective only with hg earlier than 1.8 (or
1299f0c14572).

In addition to it, "norepo" option of command annotation has been
available since 3.1 (or 9cbb59f03d57), and this is another blocker for
loading perf.py with earlier Mercurial.

  ============ ============ ======
               command of
  hg version   cmdutil      norepo
  ============ ============ ======
  3.1 or later      o         o
  1.9 or later      o         x
  earlier           x         x
  ============ ============ ======

This patch defines "command()" for annotation locally as below:

  - define wrapper of existing cmdutil.command(), if cmdutil.command()
    doesn't support "norepo"
    (for Mercurial earlier than 3.1)

  - define full command() locally with minimum function, if
    cmdutil.command() isn't available at runtime
    (for Mercurial earlier than 1.9)

This patch also defines parsealiases() locally without examining
whether it is available or not, because it is small enough to define
locally.
2016-07-05 07:25:51 +09:00
FUJIWARA Katsunori
a838d26c49 perf: avoid using formatteropts for Mercurial earlier than 3.2
Before this patch, referring commands.formatteropts prevents perf.py
from being loaded by Mercurial earlier than 3.2 (or 44a82ed65df7),
because it isn't available in such Mercurial, even though formatting
itself has been available since 2.2 (or 045c8375c770).

In addition to it, there are some code paths for Mercurial earlier
than 3.2. For example, setting "_prereadsize" attribute in perfindex()
and perfnodelookup() is effective only with hg earlier than 1.8 (or
1299f0c14572).

This patch uses empty option list as formatteropts, if it isn't
available in commands module at runtime.

Disabling -T/--template option for earlier Mercurial should be
reasonable, because:

  - since 0c03b2a1206a, -T/--template for formatter has been available
  - since 44a82ed65df7, commands.formatteropts has been available
  - the latter revision is direct child of the former
2016-07-05 07:25:51 +09:00
FUJIWARA Katsunori
4875ebeb0e perf: use locally defined revlog option list for Mercurial earlier than 3.7
Before this patch, referring commands.debugrevlogopts prevents perf.py
from being loaded by Mercurial earlier than 3.7 (or 1a89336e03aa),
because it isn't available in such Mercurial, even though
cmdutil.openrevlog(), a user of these options, has been available
since 1.9 (or f32fd7cab084).

In addition to it, there are some code paths for Mercurial earlier
than 3.7. For example, setting "_prereadsize" attribute in perfindex()
and perfnodelookup() is effective only with hg earlier than 1.8 (or
1299f0c14572).

But just "using locally defined revlog option list" might cause
unexpected behavior at runtime. If --dir option is specified to
cmdutil.openrevlog() of Mercurial earlier than 3.5 (or e3ab0b30c05e),
it is silently ignored without any warning or so.

  ============ ============ ===== ===============
                                  debugrevlogopts
  hg version   openrevlog() --dir of commands
  ============ ============ ===== ===============
  3.7 or later     o          o         o
  3.5 or later     o          o         x
  1.9 or later     o          x         x
  earlier          x          x         x
  ============ ============ ===== ===============

Therefore, this patch does:

  - use locally defined option list, if commands.debugrevlogopts isn't
    available (for Mercurial earlier than 3.7)

  - wrap cmdutil.openrevlog(), if it is ambiguous whether
    cmdutil.openrevlog() can recognize --dir option correctly
    (for Mercurial earlier than 3.5)

    This wrapper function aborts execution, if:
    - --dir option is specified, and
    - localrepository doesn't have "dirlog" attribute, which indicates
      that localrepository has a function for '--dir'

    BTW, extensions.wrapfunction() has been available since 1.1 (or
    56ba0b824b91), and this seems old enough for "historical
    portability" of perf.py, which has been available since 1.1 (or
    bca5e7427e89).
2016-07-05 07:25:51 +09:00
FUJIWARA Katsunori
51a99ac996 perf: define util.safehasattr forcibly for Mercurial earlier than 1.9.3
Before this patch, using util.safehasattr() prevents perf.py from
being loaded by Mercurial earlier than 1.9.3 (or 36f152380d7d),
because util.safehasattr() isn't available in such Mercurial, even
though there are some code paths for Mercurial earlier than 1.9.3.

For example, setting "_prereadsize" attribute in perfindex() and
perfnodelookup() is effective only with Mercurial earlier than 1.8 (or
1299f0c14572).

This patch is a preparation for using util.safehasattr() safely in
subsequent patches.

This patch defines util.safehasattr() forcibly without examining
whether it is available or not, because:

  - examining existence of "safehasattr" safely itself needs similar logic
  - safehasattr() is small enough to define locally
2016-07-05 07:25:51 +09:00
FUJIWARA Katsunori
75253dece2 perf: add historical portability policy for future reference 2016-07-05 07:25:51 +09:00
Anton Shestakov
87dd3010a7 tests: check ETag format in test-hgweb-commands 2016-07-09 14:01:55 +08:00
Anton Shestakov
662db21d2e hgweb: emit a valid, weak ETag
Previously, ETag headers from hgweb weren't correctly formed, because rfc2616
(section 14, header definitions) requires double quotes around the content of
the header. str(web.mtime) didn't do that.

Additionally, strong ETags signify that the resource representations are
byte-for-byte identical. That is, they can be reconstructed from byte ranges if
client so wishes. Considering ETags for all hgweb pages is just mtime of
00changelog.i and doesn't consider of e.g. .hg/hgrc with description, contact
and other fields, it's clearly shouldn't be strong. The W/ prefix marks it as
weak, which still allows caching the whole served file/page, but doesn't allow
byte-range requests.
2016-07-09 03:26:24 +08:00
Gregory Szorc
38db45a34e sslutil: synchronize hostname matching logic with CPython
sslutil contains its own hostname matching logic. CPython has code
for the same intent. However, it is only available to Python 2.7.9+
(or distributions that have backported 2.7.9's ssl module
improvements).

This patch effectively imports CPython's hostname matching code
from its ssl.py into sslutil.py. The hostname matching code itself
is pretty similar. However, the DNS name matching code is much more
robust and spec conformant.

As the test changes show, this changes some behavior around
wildcard handling and IDNA matching. The new behavior allows
wildcards in the middle of words (e.g. 'f*.com' matches 'foo.com')
This is spec compliant according to RFC 6125 Section 6.5.3 item 3.

There is one test where the matcher is more strict. Before,
'*.a.com' matched '.a.com'. Now it doesn't match. Strictly speaking
this is a security vulnerability.
2016-06-26 19:34:48 -07:00
Gregory Szorc
6119f3112c tests: import CPython's hostname matching tests
CPython has a more comprehensive test suite for it's built-in hostname
matching functionality. This patch adds its tests so we can improve
our hostname matching functionality.

Many of the tests have different results from CPython. These will be
addressed in a subsequent commit.
2016-06-26 19:16:54 -07:00
Wagner Bruna
ddd16592d2 i18n-pt_BR: synchronized with fe2fb19f4279 2016-07-01 07:41:37 -03:00
Mike Miller
90a873dfc0 help: document that [subpaths] may rewrite relative paths
The subpaths substitution logic first attempts to match the absolute
repository path, then the relative subrepository path if that failed.
2016-06-16 09:15:12 -07:00
Maciej Fijalkowski
7f30335cfb policy: add cffi policy for PyPy
This adds cffi policy in the case where we don't want to use C modules,
but instead we're happy to rely on cffi (bundled with pypy)
2016-06-07 15:35:58 +02:00
Gregory Szorc
a15cc9fbbd sslutil: handle default CA certificate loading on Windows
See the inline comment for what's going on here.

There is magic built into the "ssl" module that ships with modern
CPython that knows how to load the system CA certificates on
Windows. Since we're not shipping a CA bundle with Mercurial,
if we're running on legacy CPython there's nothing we can do
to load CAs on Windows, so it makes sense to print a warning.

I don't anticipate many people will see this warning because
the official (presumed popular) Mercurial distributions on
Windows bundle Python and should be distributing a modern Python
capable of loading system CA certs.
2016-07-04 10:04:11 -07:00
Gregory Szorc
44b485439c sslutil: expand _defaultcacerts docstring to note calling assumptions
We should document this so future message additions don't seem out
of place.
2016-06-30 19:54:12 -07:00
Gregory Szorc
9907ebb10f sslutil: document the Apple OpenSSL cert trick
This is sort of documented in _plainapplypython()'s docstring. But
it helps to be explicit in security code.
2016-07-04 10:00:56 -07:00
Gregory Szorc
fcfe05c8e6 sslutil: use certificates provided by certifi if available
The "certifi" Python package provides a distribution of the
Mozilla trusted CA certificates as a Python package. If it is
present, we assume the user intends it to be used and we use
it to provide the default CA certificates when certificates
are otherwise not configured.

It's worth noting that this behavior roughly matches the popular
"requests" package, which also attempts to use "certifi" if
present.
2016-07-04 09:58:45 -07:00
Pulkit Goyal
aef2bdd39a py3: make files use absolute_import and print_function
This patch includes addition of absolute_import and print_function to the
 files where they are missing. The modern importing conventions are also followed.
2016-07-03 22:28:24 +05:30
Gregory Szorc
abc557efe8 sslutil: don't attempt to find default CA certs file when told not to
Before, devel.disableloaddefaultcerts only impacted the loading of
default certs via SSLContext. After this patch, the config option also
prevents sslutil._defaultcacerts() from being called.

This config option is meant to be used by tests to force no CA certs
to be loaded. Future patches will enable _defaultcacerts() to have
success more often. Without this change we can't reliably test the
failure to load CA certs. (This patch also likely fixes test failures
on some OS X configurations.)
2016-07-01 19:17:45 -07:00
Gregory Szorc
73bc04ad9d sslutil: pass ui to _defaultcacerts
We'll use this shortly.
2016-07-01 19:04:39 -07:00
Gregory Szorc
c6b7b46813 sslutil: change comment and logged message for found ca cert file
Future patches will change _defaultcacerts() to do something
on platforms that aren't OS X. Change the comment and logged
message to reflect the future.
2016-07-01 18:03:51 -07:00
Gregory Szorc
2121e65956 tests: better testing of loaded certificates
Tests were failing on systems like RHEL 7 where loading the system
certificates results in CA certs being reported to Python. We add
a feature that detects when we're able to load *and detect* the
loading of system certificates. We update the tests to cover the
3 scenarios:

1) system CAs are loadable and detected
2) system CAs are loadable but not detected
3) system CAs aren't loadable
2016-07-01 19:27:34 -07:00
Kostia Balytskyi
78766f7ff1 update: teach hg to override untracked dir with a tracked file on update
This is a fix to an old problem when Mercurial got confused by an
untracked folder with the same name as one of the files in a commit
hg was trying to update to. It is pretty safe to remove this folder if
it is empty. Backing up an empty folder seems to go against Mercurial's
"don't track dirs" philosophy.
2016-07-01 17:42:55 +02:00
Kostia Balytskyi
a6f612e44f rebase: move handling of obsolete commits to be a separate RR class method 2016-07-01 14:09:53 +02:00
Kostia Balytskyi
c56035ebe4 rebase: move rebase finish logic to be a method of the RR class
Rebase finish logic includes collapsing working directorystate into
a single commit, moving bookmarks, clearing status and collapsemsg files,
reporting skipped commits to the user and obsoleting precursors of the
newly created commits.
2016-07-01 14:09:53 +02:00
Kostia Balytskyi
aa32920473 rebase: move core rebase logic to be a method of the RR class 2016-07-01 14:09:53 +02:00
Kostia Balytskyi
5b06bb7da5 rebase: move local variable 'extrafn' to the RR class 2016-07-01 14:09:53 +02:00
Kostia Balytskyi
ae0baad3c5 rebase: move local variable 'currentbookmarks' to the RR class 2016-07-01 14:09:53 +02:00
Kostia Balytskyi
f2b722d727 rebase: make collapsing use explicit logic to decide on the rev to reuse
This code:

    for rev in sortedstate:
        ...
    ...
    newnode = concludenode(repo, rev, p1, rbsrt.external,
                           commitmsg=commitmsg,
                           extrafn=extrafn, editor=editor,
                           keepbranches=rbsrt.keepbranchesf,
                           date=rbsrt.date)

uses 'rev' variable in 'concludenode' function invocation. It is not
explicitly assigned before, but its value comes as last value or 'rev' in
a for loop, e.g. last element in a 'sortedstate'. IMO this a bad style and it
also makes it hard to refactor the function, so it is better to explicitly
define the value passed to 'concludenode'.
2016-07-01 14:09:53 +02:00
Kostia Balytskyi
936c3aec9f rebase: move new rebase preparation to be a method of the RR class
This commit moves logic that prepares the execution of a new rebase
operation to be a method of the rebaseruntime class.
2016-07-01 14:09:53 +02:00
Kostia Balytskyi
0946a3aa1d rebase: move abort/continue prep to be a method of the RR class
This commit moves logic that prepares the execution of abort and
continue phases or rebase operation to be a method of the rebaseruntime
class.
2016-07-01 14:09:53 +02:00
Gregory Szorc
5255c3f24b hgweb: expose list of per-repo labels to templates
hgweb currently offers limited functionality for "classifying"
repositories. This patch aims to change that.

The web.labels config option list is introduced. Its values
are exposed to the "index" and "summary" templates. Custom
templates can use template features like ifcontains() to e.g.
look for the presence of a specific label and engage specific
behavior. For example, a site operator may wish to assign a
"defunct" label to a repository so the repository is prominently
marked as dead in repository indexes.
2016-06-30 18:59:53 -07:00
Sean Farley
bae0386e22 histedit: move autoverb rule to the commit it matches
Inspired by how 'git rebase -i' works, we move the autoverb to the
commit line summary that it matches. We do this by iterating over all
rules and inserting each non-autoverb line into a key in an ordered
dictionary. If we find an autoverb line later, we then search for the
matching key and append it to the list (which is the value of each key
in the dictionary). If we can't find a previous line to move to, then we
leave the rule in the same spot.

Tests have been updated but the diff looks a little messy because we
need to change one of the summary lines so that it will actually move to
a new spot. On top of that, we added -q flags to future some of the
output and needed to change the file it modified so that it wouldn't
cause a conflict.
2016-06-21 14:58:49 -07:00
Henrik Stuart
5de4cefa8f largefiles: fix support for local largefiles while using share extension
Prior to revision 149be6a0072e, largefiles were saved in the local repository,
even if it was using the share extension. After that change, all largefiles are
now stored in the shared repository. However, the backward compatibility for
existing largefiles already placed in the local repository was never tested,
and has been broken since.
2016-06-07 08:32:33 +02:00
Matt Mackall
d3fd1530f8 bdiff: remove effectively dead code
Now that we extend matches backwards in the inner loop, the final
adjustment has no effect.

(A similar extension for the forward direction is trickier and has
less benefit.)
2016-06-02 17:11:32 -05:00
Matt Mackall
18c0002f9b bdiff: extend matches across popular lines
For very large diffs that have large numbers of identical lines (JSON
dumps) that also have large blocks of identical text, bdiff could become
confused about which block matches which because it can only match
very limited regions. The result is very large diffs for small sets of edits.

The earlier recursion rebalancing fix made this behavior more frequent because
it's now more prone to match block 1 to block 2. One frequent user of
large JSON files reported being unable to pass the resulting diffs
through their code review system.

Prior to this change, bdiff would calculate the length of a match at
(i, j) as 1 + length found at (i-1, j-1). With large number of popular
(ignored) lines, this often meant matches couldn't be extended
backwards at all and thus all matching regions were very small.
Disabling the popularity threshold is not an option because it brings
back quadratic behavior.

Instead, we extend a match backwards until we either found a previously
discovered match or we find a mismatching line. This thus successfully
bridges over any popular lines inside and before a matching region.
The larger regions then significant reduce the probability of confusion.
2016-06-02 17:09:06 -05:00
Danek Duvall
fd61c5191c tests-subrepo-git: use "f" to dump pwned.txt, for portability
Rather than sometimes using a complicated shell construct to dump pwned.txt
(if it wasn't expected to exist, but might, if something were broken) or
just cat (if it was expected to exist), just use the "f" utility, which
will be consistent in its behavior across different platforms.

Also make sure that *something* gets put into pwned.txt, even if we ended
up typoing the message variable.
2016-06-02 16:18:44 -07:00