Commit Graph

16644 Commits

Author SHA1 Message Date
Pulkit Goyal
38a359ce5c py3: conditionalize SocketServer import
The SocketServer is renamed to socketserver in python 3
2016-06-27 16:48:54 +05:30
Pulkit Goyal
fdc0861e35 py3: conditionalize xmlrpclib import
The xmlrpclib library is renamed to xmlrpc.client in python 3
2016-06-27 16:37:37 +05:30
Pulkit Goyal
5fcc6a2628 py3: conditionalize the urlparse import
The urlparse library is renamed to urllib.parse in python 3
2016-06-27 16:16:10 +05:30
Martin von Zweigbergk
5dcec73439 debug: make debug{revlog,index,data} --dir not just a flag
The directory argument (for tree manifests) should belong to to the
--dir argument. I had mistakenly made --dir a flag. One effect of this
was that I had meant for "-m" to be optional, but instead it changed
the behavior of --dir, so with "hg debugdata -m --dir dir1 0", the -m
took over and the "dir1" got treated as a revision in the root
manifest log.
2016-06-24 11:12:41 -07:00
Martin von Zweigbergk
a785632cca debugdata: disallow trailing option with -c/-m
Before this change, "hg debugdata -c 0 foo" was allowed.
2016-06-24 11:25:55 -07:00
Yuya Nishihara
7323118189 revset: get rid of redundant error checking from match()
Actually there was no additional error checking. It should be caught by
"not all(specs)".
2016-06-26 17:16:57 +09:00
Martijn Pieters
a8afdea978 share: move magic string to a constant 2016-06-24 10:32:38 +01:00
liscju
6d9c9237d1 bookmarks: allow pushing active bookmark on new remote head (issue5236)
Before 'hg push -B .' on new remote head complained with:
abort: push creates new remote head ...

It was because _nowarnheads was not expanding active bookmark
name, so it didn't add active bookmark "proper" name to no
warn heads list.
2016-05-24 23:36:27 +02:00
Laurent Charignon
94c489ecf6 strip: invalidate phase cache after stripping changeset (issue5235)
When we remove a changeset from the changelog, the phase cache must be
invalidated, otherwise it could refer to changesets that are no longer in the
repo.

To reproduce the failure, I created an extension querying the phase cache after
the strip transaction is over.

To do that, I stripped two commits with a bookmark on one of them to force
another transaction (we open a transaction for moving bookmarks)
after the strip transaction.

Without the fix in this patch, the test leads to a stacktrace showing the issue:
      repair.strip(ui, repo, revs, backup)
    File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/repair.py", line 205, in strip
      tr.close()
    File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/transaction.py", line 44, in _active
      return func(self, *args, **kwds)
    File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/transaction.py", line 490, in close
      self._postclosecallback[cat](self)
    File "$TESTTMP/crashstrip2.py", line 4, in test
      [repo.changelog.node(r) for r in repo.revs("not public()")]
    File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/changelog.py", line 337, in node
      return super(changelog, self).node(rev)
    File "/Users/lcharignon/facebook-hg-rpms/hg-crew/mercurial/revlog.py", line 377, in node
      return self.index[rev][7]
  IndexError: revlog index out of range

The situation was encountered in inhibit (evolve's repo) where we would crash
following the volatile set invalidation submitted by Augie in
cbc52a99d057d11790cf5011e877c6f698bf57bf. Before his patch the issue was masked
as we were not accessing the phasecache after stripping a revision.

This bug uncovered another but in histedit (see explanation in issue5235).
I changed the histedit test accordingly to avoid fixing two things at once.
2016-05-12 06:13:59 -07:00
Mateusz Kwapich
718300b2b4 localrepo: prevent executable-bit only changes from being lost on amend
If you have just executable-bit change and amend it twice it will vanish:

 * After the first amend the commit will have the proper executable bit set
   in manifest but it won't have the the file on the list of files in
   changelog.

 * The second amend will read the wrong list of files from changelog and it
   will copy the manifest entry from parent for this file.

 * Voila! The change is lost.

This change repairs the bug in localrepo causing this and adds a test for it.
2016-05-19 14:35:22 -07:00
FUJIWARA Katsunori
17fa5d0520 help: search section of help topic by translated section name correctly
Before this patch, "hg help topic.section" might show unexpected
section of help topic in some encoding.

It applies str.lower() instead of encoding.lower(str) on translated
message to search section case-insensitively, but some encoding uses
0x41(A) - 0x5a(Z) as the second or later byte of multi-byte character
(for example, ja_JP.cp932), and str.lower() causes unexpected result.

To search section of help topic by translated section name correctly,
this patch replaces str.lower() by encoding.lower(str) for both query
string (in commands.help()) and translated help text (in
minirst.getsections()).
2016-05-13 07:19:59 +09:00
FUJIWARA Katsunori
63611bb308 patch: show lower-ed translated message correctly
Before this patch, patch.filterpatch() shows meaningless translation
of help message for chunk selection in some encoding.

It applies str.lower() instead of encoding.lower(str) on translated
message, but some encoding uses 0x41(A) - 0x5a(Z) as the second or
later byte of multi-byte character (for example, ja_JP.cp932), and
str.lower() causes unexpected result.

To show lower-ed translated message correctly, this patch replaces
str.lower() by encoding.lower(str).
2016-05-13 07:19:59 +09:00
Matt Harbison
8d72832828 help: fix the display for hg help internals.revlogs (issue5227)
It previously aborted saying the help section wasn't found.  Credit to Yuya for
figuring out the fix.
2016-05-08 22:28:09 -04:00
Sean Farley
dc865d7f73 hg-ssh: copy doc string to man page
This corrects a warning from lintian that we're shipping an executable without
a man page. Since there is a doc string in the text, let's use that for the man
page.
2016-05-06 23:03:41 -07:00
Matt Mackall
8568a2cad9 progress: stop excessive clearing (issue4801)
The progress bar was being cleared on every write(), regardless of
whether it was currently displayed. This could foul up the display of
any writes that didn't include a linebreak.

In particular, the win32 mode of the color extension was turning
single prompt string writes into two writes, and the resulting
clear/write/clear/write pattern was making the prompt invisible.

We fix this by insisting that we have shown a progress bar and haven't
just cleared it (setting lastprint to 0).

Conveniently, the test suite already had instances of duplicate
clears.. that are now cleared up.
2016-05-06 17:53:06 -05:00
Pierre-Yves David
981a2cbeeb deprecation: gate deprecation warning behind devel configuration
Regular users are not supposed to be exposed to the API deprecation warnings.
We now only issue them when the developper warnings are enabled.
2016-05-05 16:29:31 +02:00
Augie Fackler
5a2af0bc22 bookmarks: properly invalidate volatile sets when writing bookmarks
This corrects a regression introduced during the 3.7 cycle, but which
went undetected due to the surviving-but-deprecated write() method on
bmstore.
2016-05-04 22:44:30 -04:00
Mike Hommey
50e9c3bb84 bundle2: properly request phases during getbundle
getbundle was requesting the "phase" namespace instead of the "phases"
namespace, which led to the client still requesting the phases
separately after getbundle finished.
2016-05-05 20:57:38 +09:00
Pierre-Yves David
da0dc4d591 destutil: add the ability to specify a search space for rebase destination
In the 'hg pull --rebase', we don't want to pick a rebase destination unrelated
to the pull, we lay down basic infrastructure to allow such restriction on
stable (before 3.8 release) in this case. See issue 5214 for details.

Actual usage and test will be in the next patch.
2016-04-30 18:41:08 +02:00
Gregory Szorc
ad77315d76 sslutil: restore old behavior not requiring a hostname argument (issue5210)
This effectively backs out changeset 60b56b3206cc.

The http library behind ui.http2=true isn't specifying the hostname.
It is the day before the expected 3.8 release and we don't want to ship
a regression.

I'll try to restore this requirement in the 3.9 release cycle as part
of planned improvements to Mercurial's SSL/TLS interactions.
2016-04-30 09:26:47 -07:00
Matt Mackall
a684f1361f repoview: ignore unwritable hidden cache
The atomictemp.close() file attempts to do a rename, which can fail.
Moving the close inside the exception handler fixes it.

This doesn't fit well with the with: pattern, as it's the finalizer
that's failing.
2016-04-28 16:26:18 -05:00
Matt Mackall
37e825cd02 tags: silence hgtagsfnodes reading failures
tryread() doesn't handle "is a directory" errors and presumably
others. We might not want to globally swallow such tryread errors, so
we replace with our own try/except handling.

An upcoming test will use directories as a portable stand-in for
various bizarre circumstances that cache read/write code should be
robust to.
2016-04-28 15:40:43 -05:00
Matt Mackall
8ad154abd6 tags: silence cache parsing errors
Follow our standard STFU cache-handling pattern
2016-04-28 15:35:54 -05:00
Sean Farley
bf3cdfa44b revsets: add docs for '%' operator 2016-04-27 14:02:18 -07:00
Adam Simpkins
49958f0c37 graft: fix printing of --continue command
Properly shell quote arguments, to avoid printing commands that won't work when
run literally.  For example, a date string with timestamp needs to be quoted:
--date '1456953053 28800'
2016-04-27 19:24:31 -07:00
Matt Harbison
3036220cae verify: don't init subrepo when missing one is referenced (issue5128) (API)
Initializing a subrepo when one doesn't exist is the right thing to do when the
parent is being updated, but in few other cases.  Unfortunately, there isn't
enough context in the subrepo module to distinguish this case.  This same issue
can be caused with other subrepo aware commands, so there is a general issue
here beyond the scope of this fix.

A simpler attempt I tried was to add an '_updating' boolean to localrepo, and
set/clear it around the call to mergemod.update() in hg.updaterepo().  That
mostly worked, but doesn't handle the case where archive will clone the subrepo
if it is missing.  (I vaguely recall that there may be other commands that will
clone if needed like this, but certainly not all do.  It seems both handy, and a
bit surprising for what should be a read only operation.  It might be nice if
all commands did this consistently, but we probably need Angel's subrepo caching
first, to not make a mess of the working directory.)

I originally handled 'Exception' in order to pick up the Aborts raised in
subrepo.state(), but this turns out to be unnecessary because that is called
once and cached by ctx.sub() when iterating the subrepos.

It was suggested in the bug discussion to skip looking at the subrepo links
unless -S is specified.  I don't really like that idea because missing a subrepo
or (less likely, but worse) a corrupt .hgsubstate is a problem of the parent
repo when checking out a revision.  The -S option seems like a better fit for
functionality that would recurse into each subrepo and do a full verification.

Ultimately, the default value for 'allowcreate' should probably be flipped, but
since the default behavior was to allow creation, this is less risky for now.
2016-04-27 22:45:52 -04:00
Gregory Szorc
b30a08bac0 exewrapper: add .dll to LoadLibrary() argument
LoadLibrary() changes behavior depending on whether the argument
passed to it contains a period. From the MSDN docs:

If no file name extension is specified in the lpFileName parameter,
the default library extension .dll is appended. However, the file name
string can include a trailing point character (.) to indicate that the
module name has no extension. When no path is specified, the function
searches for loaded modules whose base name matches the base name of
the module to be loaded. If the name matches, the load succeeds.
Otherwise, the function searches for the file.

As the subsequent patch will show, some environments on Windows
define their Python library as e.g. "libpython2.7.dll." The existing
code would pass "libpython2.7" into LoadLibrary(). It would assume
"7" was the file extension and look for a "libpython2.dll" to load.

By passing ".dll" into LoadLibrary(), we force it to search for the
exact basename we want, even if it contains a period.
2016-04-27 09:23:39 -07:00
Martin von Zweigbergk
5746133750 update: correct description of --check option
The old "update across branches if no uncommitted changes" made
it sound like updating across branches (with no uncommitted changes)
was allowed only with this option, which was not true. Also, the option
did not care whether it was linear or across branches. Instead, it
checked that there were no uncommitted changes. Let's explain what it
does instead of trying to suggest what happens without it.
2016-04-27 14:02:54 -07:00
Adam Simpkins
c92a68e75e util: fix race in makedirs()
Update makedirs() to ignore EEXIST in case someone else has already created the
directory in question.  Previously the ensuredirs() function existed, and was
nearly identical to makedirs() except that it fixed this race.  Unfortunately
ensuredirs() was only used in 3 places, and most code uses the racy makedirs()
function.  This fixes makedirs() to be non-racy, and replaces calls to
ensuredirs() with makedirs().

In particular, mercurial.scmutil.origpath() used the racy makedirs() code,
which could cause failures during "hg update" as it tried to create backup
directories.

This does slightly change the behavior of call sites using ensuredirs():
previously ensuredirs() would throw EEXIST if the path existed but was a
regular file instead of a directory.  It did this by explicitly checking
os.path.isdir() after getting EEXIST.  The makedirs() code did not do this and
swallowed all EEXIST errors.  I kept the makedirs() behavior, since it seemed
preferable to avoid the extra stat call in the common case where this directory
already exists.  If the path does happen to be a file, the caller will almost
certainly fail with an ENOTDIR error shortly afterwards anyway.  I checked
the 3 existing call sites of ensuredirs(), and this seems to be the case for
them.
2016-04-26 15:32:59 -07:00
Matt Mackall
7909072f7f bdiff: further restrain potential quadratic performance
This causes the longest_match search to limit itself to a window of
30000 lines during search (roughly 1MB), thus avoiding a full O(N*M)
search that might occur in repetitive structured inputs. For a
particular class of many MB pathological test cases, this generated
the following timings:

size    before      after
10x     1.25s       1.24s
100x    57s         33s
1000x   >8400s      400s

The times on the right quickly become much faster and appear more linear.

While windowing means deltas are no longer "optimal", the resulting
deltas were within a couple percent of expected size. While we've yet
to have a report of a file with the level of repetition necessary to
hit this case, some JSON/XML database dump scenario is fairly likely
to hit it.

This may also slightly improve the average-case performance for deltas
of large binaries.
2016-04-22 13:38:02 -05:00
Matt Mackall
7110077dec bdiff: balance recursion to avoid quadratic behavior (issue4704)
For highly structured files like JSON or XML dumps with large numbers
of duplicate lines (eg braces) and isolated matching lines, bdiff
could find large numbers of equally good spans. Because it prefers
earlier matches, this would result in pathologically unbalance
recursion that resulted in quadratic performance.

This patch makes it prefer matches closer to the middle that tend to
balance recursion. This change improves the speed of a pathological
test case from 1100s to 9s.

Included is a smaller test that has a roughly 50x safety margin on the
performance it accepts. It's likely to fail on pure builds because
difflib also has a recursion-balancing problem.
2016-04-21 22:04:11 -05:00
Matt Mackall
f33142790b bdiff: deal better with duplicate lines
The longest_match code compares all the possible positions in two
files to find the best match. Given a pair of sequences, it
effectively searches a grid like this:

  a b b b c . d e . f
  0 1 2 3 4 5 6 7 8 9
a 1 - - - - - - - - -
b - 2 1 1 - - - - - -
b - 1 3 2 - - - - - -
b - 1 2 4 - - - - - -
. - - - - - 1 - - 1 -


Here, the 4 in the middle says "the first four lines of the
file match", which it can compute be comparing the fourth lines and
then adding one to the result found when comparing the third lines in
the entry to the upper left.

We generally avoid the quadratic worst case by only looking at lines
that match, which is precomputed. We also avoid quadratic storage by
only keeping a single column vector and then keeping track of the best
match.

Unfortunately, this can get us into trouble with the sequences above.
Because we want to reuse the '3' value when calculating the '4', we
need to be careful not to overwrite it with the '2' we calculate
immediately before. If we scan left to right, top to bottom, we're
going to have a problem: we'll overwrite our 3 before we use it and
calculate a suboptimal best match.

To address this, we can either keep two column vectors and swap
between them (which significantly complicates bookkeeping), or change
our scanning order. If we instead scan from left to right, bottom to
top, we'll avoid ever overwriting values we'll need in the future.

This unfortunately needs several changes to be made simultaneously:

- change the order we build the initial hash chains for the b sequence
- change the sentinel values from INT_MAX to -1
- change the visit order in the longest_match inner loop
- add a tie-breaker preference for earlier matches

This last is needed because we previously had an implicit tie-breaker
from our visitation order that our test suite relies on. Later matches
can also trigger a bug in the normalization code in diff().
2016-04-21 21:05:26 -05:00
Matt Mackall
01fb35972f bdiff: fix latent normalization bug
This bug is hidden by the current bias towards matches at the
beginning of the file. When this bias is tweaked later to address
recursion balancing, the normalization code could cause the next block
to shrink to a negative length, thus creating invalid delta chunks. We
add checks here to disallow that.

This bug requires test cases that are an awkwardly large size for the test
suite, but is very rapidly picked up by the included torture tester.
2016-04-21 21:53:18 -05:00
Matt Mackall
771a9f0eac bdiff: fold in shift calculation in normalize
This just makes the code harder to read without any performance
advantage. We're going to make the check here more complex, let's make
it simpler first.
2016-04-21 21:46:31 -05:00
Matt Mackall
6ac425cfc0 bdiff: unify duplicate normalize loops
We're about to make the while loop check more complicated, so let's simplify
first.
2016-04-21 21:37:13 -05:00
Gregory Szorc
c98d59c36a branchmap: remove unused exception variable 2016-03-12 16:08:19 -08:00
Henrik Stuart
40c8c53428 patch: allow copy information to be passed in
When displaying patches from graphical tools where you can browse through
individual files, with diff being called separately on each, recomputing the
limits of file copy history can become rather expensive on large repositories.
Instead, we can compute it once and pass it in for subsequent calls.
2016-06-27 12:11:18 +02:00
Gregory Szorc
aa5486b692 revset: implement match() in terms of matchany()
match() is the special case of a single element list being passed
to matchany() with the additional error checking that the revset
spec is defined. Change the implementation to remove the redundant
code and have match() call matchany().
2016-06-25 19:10:46 -07:00
Gregory Szorc
159c164568 scmutil: improve documentation of revset APIs
I can never remember the differences between the various revset
APIs. I can never remember that scmutil.revrange() is the one I
want to use from user-facing commands.

Add some documentation to clarify this.

While we're here, the argument name for revrange() is changed to
"specs" because that's what it actually is.
2016-06-25 19:12:20 -07:00
Gregory Szorc
fac475dd90 mdiff: remove use of __slots__
The use of __slots__ was added way back in 2006 in ce444c810fcf.
__slots__ isn't necessary for this class.
2016-06-25 13:52:46 -07:00
Gregory Szorc
9d12ac43cc i18n: use unicode literal
Other parts of this expression are already using unicode literals.
We need this to make Python 3 happy and to avoid an implicit
conversion in Python 2.
2016-06-25 17:40:53 -07:00
Gregory Szorc
54aabad0ba pycompat: add HTTPPasswordMgrWithDefaultRealm to Python 3 block
Looks like we missed this in 46280bc1ec69.
2016-06-25 17:22:06 -07:00
Gregory Szorc
9c6bc630a3 ui: path option to declare which revisions to push by default
Now that we have a mechanism for declaring path sub-options, we can
start to pile on features!

Many power users have expressed frustration that bare `hg push`
attempts to push all local revisions to the remote. This patch
introduces the "pushrev" path sub-option to control which revisions
are pushed when no "-r" argument is specified.

The value of this sub-option is a revset, naturally.

A future feature addition could potentially introduce a "pushnames"
sub-options that declares the list of names (branches, bookmarks,
topics, etc) to push by default. The entire "what to push by default"
feature should probably be considered before this patch lands.
2016-06-26 07:59:02 -07:00
Gregory Szorc
bbde62ff9f ui: don't fixup [paths] sub-options
As part of developing a subsequent patch I discovered that sub-option
values like "." were getting converted to paths. This is because the
[paths] section is treated specially during config loading.

This patch prevents post-processing sub-options from the [paths]
section.
2016-06-25 18:35:14 -07:00
Gregory Szorc
aa33fbc73f sslutil: abort when unable to verify peer connection (BC)
Previously, when we connected to a server and were unable to verify
its certificate against a trusted certificate authority we would
issue a warning and continue to connect. This is obviously not
great behavior because the x509 certificate model is based upon
trust of specific CAs. Failure to enforce that trust erodes security.
This behavior was defined several years ago when Python did not
support loading the system trusted CA store (Python 2.7.9's
backports of Python 3's improvements to the "ssl" module enabled
this).

This commit changes behavior when connecting to abort if the peer
certificate can't be validated. With an empty/default Mercurial
configuration, the peer certificate can be validated if Python is
able to load the system trusted CA store. Environments able to load
the system trusted CA store include:

* Python 2.7.9+ on most platforms and installations
* Python 2.7 distributions with a modern ssl module (e.g. RHEL7's
  patched 2.7.5 package)
* Python shipped on OS X

Environments unable to load the system trusted CA store include:

* Python 2.6
* Python 2.7 on many existing Linux installs (because they don't
  ship 2.7.9+ or haven't backported modern ssl module)
* Python 2.7.9+ on some installs where Python is unable to locate
  the system CA store (this is hopefully rare)

Users of these Pythongs will need to configure Mercurial to load the
system CA store using web.cacerts. This should ideally be performed
by packagers (by setting web.cacerts in the global/system hgrc file).
Where Mercurial packagers aren't setting this, the linked URL in the
new abort message can contain instructions for users.

In the future, we may want to add more code for finding the system
CA store. For example, many Linux distributions have the CA store
at well-known locations (such as /etc/ssl/certs/ca-certificates.crt
in the case of Ubuntu). This will enable CA loading to "just work"
on more Python configurations and will be best for our users since
they won't have to change anything after upgrading to a Mercurial
with this patch.

We may also want to consider distributing a trusted CA store with
Mercurial. Although we should think long and hard about that because
most systems have a global CA store and Mercurial should almost
certainly use the same store used by everything else on the system.
2016-06-25 07:26:43 -07:00
Gregory Szorc
a838b9492a sslutil: remove out of place comment
This comment likely got orphaned as a result of refactoring in this
file. It isn't providing any useful value. So delete it.
2016-06-25 07:32:02 -07:00
Martin von Zweigbergk
59e258644a revset: make head() honor order of subset
The ordering of 'x & head()' was broken in 329d82866742 (revset:
improve head revset performance, 2014-03-13). Presumably due to other
optimizations since then, undoing that change to fix the order does
not slow down the simple case of "hg log -r 'head()'" mentioned in
that commit. I see a small slowdown from ~0.16s to about ~0.19s with
'not 0 & head()', but I'd say it's worth it for the correct output.
2016-06-23 12:37:09 -07:00
Martin von Zweigbergk
f44cccc475 revsets: use itervalues() where only values are needed
I don't think there will be a noticeable speedup, but it removes an
unused variable.
2016-06-23 13:08:10 -07:00
Martin von Zweigbergk
792eb4d1ec revsets: passing a set to baseset() is not wrong
Since 303be3afebae (revset: force ascending order for baseset
initialized from a set, 2016-04-04), it is safe to pass a revset to a
baseset.
2016-06-23 12:39:05 -07:00
Pierre-Yves David
c915441bc6 pyflakes: use pycompat.pickles to prevent error
The pyflakes in my test box complain about pickle in pycompat.

  mercurial/pycompat.py:17: 'pickle' imported but unused
2016-06-24 02:04:43 +02:00
FUJIWARA Katsunori
f46b49a0e3 check-code: detect "missing _() in ui message" more exactly
Before this patch, "missing _() in ui message" rule overlooks
translatable message, which starts with other than alphabet.

To detect "missing _() in ui message" more exactly, this patch
improves the regexp with assumptions below.

  - sequence consisting of below might precede "translatable message"
    in same string token

    - formatting string, which starts with '%'
    - escaped character, which starts with 'b' (as replacement of '\\'), or
    - characters other than '%', 'b' and 'x' (as replacement of alphabet)

  - any string tokens might precede a string token, which contains
    "translatable message"

This patch builds an input file, which is used to examine "missing _()
in ui message" detection, before '"$check_code" stringjoin.py' in
test-contrib-check-code.t, because this reduces amount of change churn
in subsequent patch.

This patch also applies "()" instead of "_()" on messages below to
hide false-positives:

  - messages for ui.debug() or debug commands/tools
    - contrib/debugshell.py
    - hgext/win32mbcs.py (ui.write() is used, though)
    - mercurial/commands.py
      - _debugchangegroup
      - debugindex
      - debuglocks
      - debugrevlog
      - debugrevspec
      - debugtemplate

  - untranslatable messages
    - doc/gendoc.py (ReST specific text)
    - hgext/hgk.py (permission string)
    - hgext/keyword.py (text written into configuration file)
    - mercurial/cmdutil.py (formatting strings for JSON)
2016-06-21 00:50:39 +09:00
Jun Wu
03c27804a3 revlog: add a fast path for "ambiguous identifier"
Before fd1bb7c, if the C index.partialmatch raises RevlogError, the Python
code raises "ambiguous identifier" error immediately, which is efficient.

fd1bb7c took hidden revisions into consideration and forced the slow path
enumerating the changelog to double-check hidden revisions. But it's not
necessary if we know the revlog has no hidden revisions.

This patch adds back the fast path for unfiltered revlogs.
2016-06-22 21:30:49 +01:00
Martijn Pieters
5b87e45011 atomictempfile: add context manager support
Close the file (moving it in place) on clean context exit, discard when there
has been an exception.
2016-06-23 18:21:25 +01:00
Martijn Pieters
0b92f0a888 atomictempfile: add read to the supported file operations 2016-06-23 18:20:58 +01:00
liscju
c7ec9d159e i18n: translate abort messages
I found a few places where message given to abort is
not translated, I don't find any reason to not translate
them.
2016-06-14 11:53:55 +02:00
Denis Laxalde
2acd032eb6 hgweb: display blamed revision once per block in annotate view
I.e. when a revision blames a block of source lines, only display the
revision link on the first line of the block (this is identified by the
"blockhead" key in annotate context).

This addresses item "Visual grouping of changesets" of the blame improvements
plan (https://www.mercurial-scm.org/wiki/BlamePlan) which states: "Typically
there are block of lines all attributed to the same revision. Instead of
rendering the revision/changeset for every line, we could only render it once
per block."
2016-06-07 12:10:01 +02:00
Denis Laxalde
c4ddd5ce73 hgweb: highlight data of the current revision in annotate view
* Distinguish the /annotate/<revision>/<file>#<linenumber> link when it would
  lead to the current page (i.e. <revision> is the current revision) (style it
  gray and undecorated). This indicates more clearly that this is a "dead-end"
  in blame navigation.

* Display lines changed in current revision in green.
2016-06-02 16:26:50 +02:00
liscju
ccdb8ddd17 pull: add help information about pulling active bookmark 2016-06-20 23:24:55 +02:00
Laura Médioni
077969174b templates: add support for search webcommand in json style 2016-06-10 10:31:42 +02:00
Laura Médioni
d95b4f5e78 templates: add support for summary webcommand in json style
Change summary webcommand to yield each element of the shortlog instead of the
entire list.

This makes generated json more readable since each entry can be formatted
separately, instead of returning all the shortlog content in a single string.
2016-06-06 15:14:11 +02:00
Laura Médioni
ed3df019a8 templates: add support for filerevision webcommand in json style 2016-06-03 12:32:42 +02:00
Laura Médioni
f9a14da931 templates: add support for filelog webcommand in json style
Modify changelistentry structure to also deliver phase and branch data and use
either 'parents' or 'allparents' depending on what is defined in the view, in
order to reuse it in filelog structure.
2016-06-03 11:28:22 +02:00
liscju
1ab6bdda49 largefiles: make cloning not ask two times about password (issue4883)
Before this commit url.opener overwritten stored password
for connection with given url/user even when
new password for given connection was not filled. This
commit makes opener overwrites saved authentication only
when it contains password.
2016-06-09 12:41:57 +02:00
liscju
ade9d0fabe url: remember http password database in ui object
This makes http password database stored in ui object.
It allows reusing authentication information when we
use this database for creating password manager for
the new connection.
2016-06-09 11:41:36 +02:00
liscju
caed6f4913 url: extract password database from password manager
So far password manager was keeping authentication information so opening
new connection and creating new password manager made all saved authentication
information lost.

This commit separates password manager and password database to make it
possible to reuse saved authentication information.

This commit violates code checker because it adds add_password method (name
with underscore) to passwordmgr object to provide method required by urllib2.
2016-06-05 23:36:23 +02:00
liscju
767e27633e bookmarks: add 'hg pull -B .' for pulling the active bookmark (issue5258) 2016-06-01 22:58:57 +02:00
FUJIWARA Katsunori
84bc1a274c demandimport: delay loading for "from a import b" with absolute_import
Before this patch, "from a import b" doesn't delay loading module "b",
if absolute_import is enabled, even though "from . import b" does.

For example:

  - it is assumed that extension X has "from P import M" for module M
    under package P with absolute_import feature

  - if importing module M is already delayed before loading extension
    X, loading module M in extension X is delayed until actually
    referring

    util, cmdutil, scmutil or so of Mercurial itself should be
    imported by "from . import M" style before loading extension X

  - otherwise, module M is loaded immediately at loading extension X,
    even if extension X itself isn't used at that "hg" command invocation

    Some minor modules (e.g. filemerge or so) of Mercurial itself
    aren't imported by "from . import M" style before loading
    extension X. And of course, external libraries aren't, too.

This might cause startup performance problem of hg command, because
many bundled extensions already enable absolute_import feature.

To delay loading module for "from a import b" with absolute_import
feature, this patch does below in "from a (or .a) import b" with
absolute_import case:

  1. import root module of "name" by system built-in __import__
     (referred as _origimport)

  2. recurse down the module chain for hierarchical "name"

     This logic can be shared with non absolute_import
     case. Therefore, this patch also centralizes it into chainmodules().

  3. and fall through to process elements in "fromlist" for the leaf
     module of "name"

     Processing elements in "fromlist" is executed in the code path
     after "if _pypy: .... else: ..." clause. Therefore, this patch
     replaces "if _pypy:" with "elif _pypy:" to share it.

At faecf59a4184 introducing original "work around" for "from a import
b" case, elements in "fromlist" were imported with "level=level". But
"level" might be grater than 1 (e.g. level=2 in "from .. import b"
case) at demandimport() invocation, and importing direct sub-module in
"fromlist" with level grater than 1 causes unexpected result.

IMHO, this seems main reason of "errors for unknown reason" described
in faecf59a4184, and we don't have to worry about it, because this
issue was already fixed by 2711f50242cf.

This is reason why this patch removes "errors for unknown reasons"
comment.
2016-06-19 02:17:33 +09:00
Martijn Pieters
d908f2c8dc scmutil: allow access to filecache descriptor on class
To make it easier to patch the wrapped function, make it possible to access the
filecache descriptor directly on the class (rather than have to use
ClassObject.__dict__['attributename']). Returning `self` when the first
argument to `__get__` is `None` makes the descriptor behave the same way
`property` objects do.
2016-06-17 20:06:09 +01:00
Martin von Zweigbergk
6612ed3d4a changegroup: don't send empty subdirectory manifest groups
When grafting/rebasing, it is common for multiple changesets to make
the same change to a subdirectory. When writing the revlog for the
directory, the revlog code already takes care of not writing the entry
again. In 3eb9fa4180d3 (changegroup: prune subdirectory dirlogs too,
2016-02-12), I added the corresponding code in changegroup (not
sending entries the client already has), but I forgot to avoid sending
the entire changegroup if no nodes remained in the pruned
set. Although that's harmless besides the wasted network traffic, the
receiving side was checking for it (copied from the changegroup code
for handling files). This resulted in the client crashing with:

  abort: received dir revlog group is empty

Fix by simply not emitting a changegroup for the directory if there
were no changes is it. This matches how files are handled.
2016-06-16 15:15:33 -07:00
FUJIWARA Katsunori
d7b7f8358b doc: describe detail about checkambig optional argument
This is followup for patches below, which add checkambig argument to
existing function.

  - 6508a36c1e44
  - ccbeace526ad
  - 936ec05504bf
  - a9a2d0013b68
2016-06-13 05:11:56 +09:00
Yuya Nishihara
bed8e170aa ui: provide official way to reset internal state per command
This will allow us to clear in-memory password storage per runcommand().

I've updated commandserver to call resetstate() of both ui and repo.ui because
they may have different states in theory.
2016-06-12 14:07:26 +09:00
Yuya Nishihara
1c12bcd4ad revset: extract function that validates sort() arguments
This function will be used in _optimize() to get rid of noop sort() call while
validating its arguments.
2016-06-11 10:17:49 +09:00
Yuya Nishihara
2ddc948200 revset: build dict of extra sort options before evaluating set
Prepares for extracting a function that only validates sort options.
2016-06-15 21:26:45 +09:00
Yuya Nishihara
1ee4615445 revset: build list of (key, reverse) pairs before sorting
Prepares for extracting a function that only validates sort options.
2016-06-11 10:15:40 +09:00
Yuya Nishihara
4659949bd1 revset: fix crash on empty sort key
Make it noop as before ddf6bfe09ab2. We could change it to an error, but
allowing empty key makes some sense for scripting that builds a key string
programmatically.
2016-06-15 20:37:24 +09:00
liscju
d19dfc8664 bookmarks: abort 'push -B .' when no active bookmark 2016-06-13 23:50:26 +02:00
FUJIWARA Katsunori
f06844e1ef transaction: avoid ambiguity of file stat at restoring from backup
In some cases below, copying from backup is used to restore original
contents of a file, which is backuped via addfilegenerator(). If
copying keeps ctime, mtime and size of a file, restoring is
overlooked, and old contents cached before restoring isn't invalidated
as expected.

  - failure of transaction (from '.hg/journal.backup.*')
  - rollback of previous transaction (from '.hg/undo.backup.*')

To avoid ambiguity of file stat at restoring, this patch invokes
util.copyfile() with checkambig=True.

This patch is a part of "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-06-13 05:11:56 +09:00
FUJIWARA Katsunori
dbfbc278c8 localrepo: make restoring from backup at rollback avoid ambiguity of file stat
Rollback of previous transaction restores contents of files below by
renaming from 'undo.*' file. If renaming keeps ctime, mtime and size
of a file, restoring is overlooked, and old contents cached before
restoring isn't invalidated as expected.

  - .hg/bookmarks
  - .hg/phaseroots

To avoid ambiguity of file stat at restoring, this patch invokes
vfs.rename() with checkambig=True.

BTW, .hg/dirstate is also restored at rollback. But it is restored by
dirstate.restorebackup(), and previous patch already made it invoke
vfs.rename() with checkambig=True.

This patch is a part of "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-06-13 05:11:56 +09:00
FUJIWARA Katsunori
19907e427c dirstate: make restoring from backup avoid ambiguity of file stat
File .hg/dirstate is restored by renaming from backup in failure
inside scopes below. If renaming keeps ctime, mtime and size of a
file, restoring is overlooked, and old contents cached before
restoring isn't invalidated as expected.

  - dirstateguard scope (from '.hg/dirstate.SUFFIX')
  - transaction scope (from '.hg/journal.dirstate')

To avoid ambiguity of file stat at restoring, this patch invokes
vfs.rename() with checkambig=True.

This patch is a part of "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-06-13 05:11:56 +09:00
Martijn Pieters
6cc53d84c9 revset: add new topographical sort
Sort revisions in reverse revision order but grouped by topographical branches.
Visualised as a graph, instead of:

  o  4
  |
  | o  3
  | |
  | o  2
  | |
  o |  1
  |/
  o  0

revisions on a 'main' branch are emitted before 'side' branches:

  o  4
  |
  o  1
  |
  | o  3
  | |
  | o  2
  |/
  o  0

where what constitutes a 'main' branch is configurable, so the sort could also
result in:

  o  3
  |
  o  2
  |
  | o  4
  | |
  | o  1
  |/
  o  0

This sort was already available as an experimental option in the graphmod
module, from which it is now removed.

This sort is best used with hg log -G:

  $ hg log -G "sort(all(), topo)"
2016-06-13 18:20:00 +01:00
Martijn Pieters
57bf8caf56 revset: move groupbranchiter over from graphmod
This move is to prepare the adaptation of this function into a toposort
predicate.
2016-06-13 18:20:00 +01:00
Martijn Pieters
ffccd3fc81 revset: record if a set is in topographical order
A later revision adds actual topographical sorting. Recording if a set is in
this order allows hg log -G to avoid re-sorting the revset.
2016-06-14 11:05:36 +01:00
Augie Fackler
493fe9d7a6 util: drop local aliases for md5, sha1, sha256, and sha512
This used to be needed to paper over hashlib not being in all Pythons
we support, but that's not a problem anymore, so we can simplify
things a little bit.
2016-06-10 00:13:23 -04:00
Augie Fackler
ad67b99d20 cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1
All versions of Python we support or hope to support make the hash
functions available in the same way under the same name, so we may as
well drop the util forwards.
2016-06-10 00:12:33 -04:00
Augie Fackler
7611181d2a pathencode: use hashlib.sha1 directly instead of indirecting through util 2016-06-10 00:25:07 -04:00
Augie Fackler
9e4f37dc8d revlog: use hashlib.sha1 directly instead of through util
Also remove module-local _sha alias, which was barely used.
2016-06-10 00:10:34 -04:00
Augie Fackler
a829db2256 store: use hashlib.sha1 directly instead of through util
Also remove module-local alias to _sha, since it's not used that much.
2016-06-10 00:10:06 -04:00
Augie Fackler
e34f1062d8 similar: delete extra newline at EOF
Spotted by my emacs config that cleans up extra whitespace.
2016-06-10 00:14:43 -04:00
Augie Fackler
5bc816d6d2 scmutil: delete extra newline at EOF
Spotted by my emacs config that cleans up extra whitespace.
2016-06-10 00:14:10 -04:00
Martijn Pieters
747bfe58fe graphmod: avoid sorting when already sorted
This is somewhat redundant now, but allows us to add a toposort that should not
be re-sorted either.
2016-06-08 16:18:43 +01:00
Gregory Szorc
7a668208b8 sslutil: per-host config option to define certificates
Recent work has introduced the [hostsecurity] config section for
defining per-host security settings. This patch builds on top
of this foundation and implements the ability to define a per-host
path to a file containing certificates used for verifying the server
certificate. It is logically a per-host web.cacerts setting.

This patch also introduces a warning when both per-host
certificates and fingerprints are defined. These are mutually
exclusive for host verification and I think the user should be
alerted when security settings are ambiguous because, well,
security is important.

Tests validating the new behavior have been added.

I decided against putting "ca" in the option name because a
non-CA certificate can be specified and used to validate the server
certificate (commonly this will be the exact public certificate
used by the server). It's worth noting that the underlying
Python API used is load_verify_locations(cafile=X) and it calls
into OpenSSL's SSL_CTX_load_verify_locations(). Even OpenSSL's
documentation seems to omit that the file can contain a non-CA
certificate if it matches the server's certificate exactly. I
thought a CA certificate was a special kind of x509 certificate.
Perhaps I'm wrong and any x509 certificate can be used as a
CA certificate [as far as OpenSSL is concerned]. In any case,
I thought it best to drop "ca" from the name because this reflects
reality.
2016-06-07 20:29:54 -07:00
Matt Mackall
3291548f1c merge with stable 2016-06-09 13:47:42 -05:00
Denis Laxalde
e785df5b6d crecord: drop unused "operation" parameter from filterpatch function 2016-06-07 11:57:11 +02:00
Denis Laxalde
259dd53d72 patch: define full messages for interactive record/revert
Followup 814eb5a11da4 to provide complete context for proper localization.

Also update cmdutil.recordfilter docstring to remove recommendation that
"operation" argument should be translated. Indeed, for record/revert, we
either go to patch.filterpatch or crecord.filterpatch (in curses mode) ; the
former now build the full ui message from the operation parameter and the
latter does not use this parameter (removing in a followup patch). For shelve,
operation is not specified and this thus falls back to "record".
2016-06-07 10:37:19 +02:00
Denis Laxalde
675f39ef38 hgweb: remove unused code in annotate web command 2016-06-01 15:16:38 +02:00
Pulkit Goyal
5f52c722cf py3: conditionalize cPickle import by adding in util
The cPickle is renamed to _pickle in python3 and this C extension is available
 in pickle which was not included in earlier versions. So imports are conditionalized
 to import cPickle in py2 and pickle in py3. Moreover the use of pickle in py2 is
 switched to cPickle as the C extension is faster. The hack is added in util.py and
the modules import util.pickle
2016-06-04 14:38:00 +05:30
Kostia Balytskyi
5501c91461 revset: make filteredset.__nonzero__ respect the order of the filteredset
This fix allows __nonzero__ to respect the direction of iteration of the
whole filteredset. Here's the case when it matters. Imagine that we have a
very large repository and we want to execute a command like:

    $ hg log --rev '(tip:0) and user(ikostia)' --limit 1

(we want to get the latest commit by me).

Mercurial will evaluate a filteredset lazy data structure, an
instance of the filteredset class, which will know that it has to iterate
in a descending order (isdescending() will return True if called). This
means that when some code iterates over the instance of this filteredset,
the 'and user(ikostia)' condition will be first checked on the latest
revision, then on the second latest and so on, allowing Mercurial to
print matches as it founds them. However, cmdutil.getgraphlogrevs
contains the following code:

    revs = _logrevs(repo, opts)
    if not revs:
        return revset.baseset(), None, None

The "not revs" expression is evaluated by calling filteredset.__nonzero__,
which in its current implementation will try to iterate the filteredset
in ascending order until it finds a revision that matches the 'and user(..'
condition. If the condition is only true on late revisions, a lot of
useless iterations will be done. These iterations could be avoided if
__nonzero__ followed the order of the filteredset, which in my opinion
is a sensible thing to do here.

The problem gets even worse when instead of 'user(ikostia)' some more
expensive check is performed, like grepping the commit diff.


I tested this fix on a very large repo where tip is my commit and my very
first commit comes fairly late in the revision history. Results of timing
of the above command on that very large repo.

-with my fix:
real    0m1.795s
user    0m1.657s
sys     0m0.135s

-without my fix:
real    1m29.245s
user    1m28.223s
sys     0m0.929s

I understand that this is a very specific kind of problem that presents
itself very rarely, only on very big repositories and with expensive
checks and so on. But I don't see any disadvantages to this kind of fix
either.
2016-06-02 22:39:01 +01:00
FUJIWARA Katsunori
37b26ec7b6 phases: make writing phaseroots file out avoid ambiguity of file stat
Cached attribute repo._phasecache uses stat of '.hg/phaseroots' file
to examine validity of cached contents. If writing '.hg/phaseroots'
file out keeps ctime, mtime and size of it, change is overlooked, and
old contents cached before change isn't invalidated as expected.

To avoid ambiguity of file stat, this patch writes '.hg/phaseroots'
file out with checkambig=True.

This patch is a part of "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-06-03 00:44:20 +09:00
FUJIWARA Katsunori
f90241706d dirstate: make writing branch file out avoid ambiguity of file stat
Cached attribute dirstate._branch uses stat of '.hg/branch' file to
examine validity of cached contents. If writing '.hg/branch' file out
keeps ctime, mtime and size of it, change is overlooked, and old
contents cached before change isn't invalidated as expected.

To avoid ambiguity of file stat, this patch writes '.hg/branch' file
out with checkambig=True.

This patch is a part of "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-06-03 00:44:20 +09:00
FUJIWARA Katsunori
00e016ed43 dirstate: make writing dirstate file out avoid ambiguity of file stat
Cached attribute repo.dirstate uses stat of '.hg/dirstate' file to
examine validity of cached contents. If writing '.hg/dirstate' file
out keeps ctime, mtime and size of it, change is overlooked, and old
contents cached before change isn't invalidated as expected.

To avoid ambiguity of file stat, this patch writes '.hg/dirstate' file
out with checkambig=True.

The former diff hunk changes the code path for "dirstate.write()", and
the latter changes the code path for "dirstate.savebackup()".

This patch is a part of "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-06-03 00:44:20 +09:00
FUJIWARA Katsunori
bb78b3c1b0 bookmarks: make writing files out avoid ambiguity of file stat
Cached attribute repo._bookmarks uses stat of '.hg/bookmarks' and
'.hg/bookmarks.current' files to examine validity of cached
contents. If writing these files out keeps ctime, mtime and size of
them, change is overlooked, and old contents cached before change
isn't invalidated as expected.

To avoid ambiguity of file stat, this patch writes '.hg/bookmarks' and
'.hg/bookmarks.current' files out with checkambig=True.

This patch is a part of "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-06-03 00:44:20 +09:00
FUJIWARA Katsunori
1d5601ef04 transaction: avoid ambiguity of file stat at closing transaction
Files below, which might be changed at closing transaction, are used
to examine validity of cached properties. If changing keeps ctime,
mtime and size of a file, change is overlooked, and old contents
cached before change isn't invalidated as expected.

  - .hg/bookmarks
  - .hg/dirstate
  - .hg/phaseroots

To avoid ambiguity of file stat, this patch writes files out with
checkambig=True at closing transaction.

checkambig becomes True only at closing (= 'not suffix'), because stat
information of '.pending' file isn't used to examine validity of
cached properties.

This patch is a part of "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-06-03 00:44:20 +09:00
FUJIWARA Katsunori
01b2069695 util: add __ne__ to filestat class for consistency
This is follow up for 41ed93728910, which introduced filestat class.
2016-06-03 00:44:20 +09:00
Pierre-Yves David
b6f7b74a14 style: remove namespace class
For better or worse, our coding do not use use class for pure namespacing. We
remove the class introduced in e0db55ecbc14.
2016-04-16 16:01:24 -07:00
Pierre-Yves David
1f0c33027d style: don't use capital letter for constant
For better or worse, our coding do not use all caps for constants. We rename
constant name introduced in e0db55ecbc14.
2016-04-16 15:59:30 -07:00
Gregory Szorc
0f55e28908 sslutil: print the fingerprint from the last hash used
Before, we would always print the unprefixed SHA-1 fingerprint when
fingerprint comparison failed. Now, we print the fingerprint of the
last hash used, including the prefix if necessary. This helps ensure
that the printed hash type matches what is in the user configuration.

There are still some cases where this can print a mismatched hash type.
e.g. if there are both SHA-1 and SHA-256 fingerprints in the config,
we could print a SHA-1 hash if it comes after the SHA-256 hash. But
I'm inclined to ignore this edge case.

While I was here, the "section" variable assignment has been moved to
just above where it is used because it is now only needed for this
error message and it makes the code easier to read.
2016-06-04 11:16:08 -07:00
Gregory Szorc
2337effc05 sslutil: make cert fingerprints messages more actionable
The previous warning and abort messages were difficult to understand.
This patch makes them slightly better.

I think there is still room to tweak the messaging. And as we adopt
new security defaults, these messages will certainly change again.
But at least this takes us a step in the right direction.

References to "section" have been removed because if no fingerprint
is defined, "section" can never be "hostfingerprints." So just print
"hostsecurity" every time.
2016-05-31 19:21:08 -07:00
Gregory Szorc
a59ed87b33 sslutil: refactor code for fingerprint matching
We didn't need to use a temporary variable to indicate success because
we just return anyway.

This refactor makes the code simpler. While we're here, we also call
into formatfingerprint() to ensure the fingerprint from the proper
hashing algorithm is logged.
2016-05-30 15:43:03 -07:00
Gregory Szorc
1a6d495880 sslutil: print SHA-256 fingerprint by default
The world is starting to move on from SHA-1. A few commits ago, we
gained the ability to define certificate fingerprints using SHA-256
and SHA-512.

Let's start printing the SHA-256 fingerprint instead of the SHA-1
fingerprint to encourage people to pin with a more secure hashing
algorithm.

There is still a bit of work to be done around the fingerprint
messaging. This will be addressed in subsequent commits.
2016-05-30 15:42:39 -07:00
Gregory Szorc
9ee23a401c sslutil: move and change warning when cert verification is disabled
A short time ago, validatesocket() didn't know the reasons why
cert verification was disabled. Multiple code paths could lead
to cert verification being disabled. e.g. --insecure and lack
of loaded CAs.

With the recent refactorings to sslutil.py, we now know the reasons
behind security settings. This means we can recognize when the user
requested security be disabled (as opposed to being unable to provide
certificate verification due to lack of CAs).

This patch moves the check for certificate verification being disabled
and changes the wording to distinguish it from other states. The
warning message is purposefully more dangerous sounding in order
to help discourage people from disabling security outright.

We may want to add a URL or hint to this message. I'm going to wait
until additional changes to security defaults before committing to
something.
2016-05-30 13:15:53 -07:00
Gregory Szorc
f84915da36 sslutil: add devel.disableloaddefaultcerts to disable CA loading
There are various tests for behavior when CA certs aren't loaded.
Previously, we would pass --insecure to disable loading of CA
certs. This has worked up to this point because the error message
for --insecure and no CAs loaded is the same. Upcoming commits will
change the error message for --insecure and will change behavior
when CAs aren't loaded.

This commit introduces the ability to disable loading of CA certs
by setting devel.disableloaddefaultcerts. This allows a testing
backdoor to disable loading of CA certs even if system/default
CA certs are available. The flag is purposefully not exposed to
end-users because there should not be a need for this in the wild:
certificate pinning and --insecure provide workarounds to disable
cert loading/validation.

Tests have been updated to use the new method. The variable used
to disable CA certs has been renamed because the method is not
OS X specific.
2016-06-01 19:57:20 -07:00
Gregory Szorc
46dd18b38d sslutil: store flag for whether cert verification is disabled
This patch effectively moves the ui.insecureconnections check to
_hostsettings(). After this patch, validatesocket() no longer uses the
ui instance for anything except writing messages.

This patch also enables us to introduce a per-host config option
for disabling certificate verification.
2016-05-30 11:20:31 -07:00
Gregory Szorc
f49cf73d42 sslutil: remove "strict" argument from validatesocket()
It was only used by mail.py as part of processing smtp.verifycert,
which was just removed.
2016-05-30 11:19:43 -07:00
Gregory Szorc
35166670e2 mail: unsupport smtp.verifycert (BC)
smtp.verifycert was accidentally broken by 799db3fe9866. And,
I believe the "loose" value has been broken for longer than that.
The current code refuses to talk to a remote server unless the
CA is trusted or the fingerprint is validated. In other words,
we lost the ability for smtp.verifycert to lower/disable security.

There are special considerations for smtp.verifycert in
sslutil.validatesocket() (the "strict" argument). This violates
the direction sslutil is evolving towards, which has all security
options determined at wrapsocket() time and a unified code path and
configs for determining security options.

Since smtp.verifycert is broken and since we'll soon have new
security defaults and new mechanisms for controlling host security,
this patch formally deprecates smtp.verifycert. With this patch,
the socket security code in mail.py now effectively mirrors code
in url.py and other places we're doing socket security.

For the record, removing smtp.verifycert because it was accidentally
broken is a poor excuse to remove it. However, I would have done this
anyway because smtp.verifycert is a one-off likely used by few people
(users of the patchbomb extension) and I don't think the existence
of this seldom-used one-off in security code can be justified,
especially when you consider that better mechanisms are right around
the corner.
2016-06-04 11:13:28 -07:00
liscju
d8406bc0f4 update: fix bare --clean to work on new branch (issue5003) (BC)
Before this commit bare update --clean on newly created branch
updates to the parent commit, even if there are later commits
on the parent commit's branch. Update to the latest head on the
parent commit's branch instead.

This seems reasonable as clean should discard uncommited changes,
branch is one of them.
2016-04-05 07:30:01 +02:00
Denis Laxalde
ae2b66dbed revert: use "discard"/"revert" verb when reverting interactively (issue5143)
Instead of "record this change to 'FILE'?" now prompt with:

* "discard this change to 'FILE'?" when reverting to the parent of working
  directory, and,
* "revert this change to 'FILE'?" otherwise.
2016-06-03 15:55:07 +02:00
timeless
3d2ce9ca5a obsolete: fix grammar 2016-05-27 05:24:45 +00:00
Mateusz Kwapich
6a0946ae30 distate: add assertions to backup functions
Those assertions will prevent the backup functions from overwriting
the dirstate file in case both: suffix and prefix are empty.

(foozy suggested making that change and I agree with him)
2016-05-26 17:36:44 -07:00
Mateusz Kwapich
3f38941482 dirstate: don't use actualfilename to name the backup file
The issue with using actualfilename is that dirstate saved during transaction
with "pending" in filename will be impossible to recover from outside of the
transaction because the recover method will be looking for the name without
"pending".
2016-05-25 16:36:16 -07:00
Gregory Szorc
5ae8d037c8 sslutil: reference appropriate config section in messaging
Error messages reference the config section defining the host
fingerprint. Now that we have multiple sections where this config
setting could live, we need to point the user at the appropriate
one.

We default to the new "hostsecurity" section. But we will still
refer them to the "hostfingerprint" section if a value is defined
there.

There are some corner cases where the messaging might be off. e.g.
they could define a SHA-1 fingerprint in both sections. IMO the
messaging needs a massive overhaul. I plan to do this as part
of future refactoring to security settings.
2016-05-28 12:58:46 -07:00
Gregory Szorc
95fda4d981 sslutil: allow fingerprints to be specified in [hostsecurity]
We introduce the [hostsecurity] config section. It holds per-host
security settings.

Currently, the section only contains a "fingerprints" option,
which behaves like [hostfingerprints] but supports specifying the
hashing algorithm.

There is still some follow-up work, such as changing some error
messages.
2016-05-28 12:37:36 -07:00
timeless
0dcdb26a9d debuginstall: expose modulepolicy
With this, you can check for pure easily:
$ HGMODULEPOLICY=py ./hg debuginstall -T "{hgmodulepolicy}"
py
2016-03-09 19:55:45 +00:00
Yuya Nishihara
e2af538ed7 revset: define table of sort() key functions
This should be more readable than big "if" branch.
2016-05-14 19:52:00 +09:00
Yuya Nishihara
9079f0d3ff revset: factor out reverse flag of sort() key
Prepares for making a table of sort keys. This assumes 'k' has at least one
character, which should be guaranteed by keys.split().
2016-05-14 19:46:18 +09:00
Gregory Szorc
c039b53ee9 sslutil: calculate host fingerprints from additional algorithms
Currently, we only support defining host fingerprints with SHA-1.
A future patch will introduce support for defining fingerprints
using other hashing algorithms. In preparation for that, we
rewrite the fingerprint verification code to support multiple
fingerprints, namely SHA-256 and SHA-512 fingerprints.

We still only display the SHA-1 fingerprint. We'll have to revisit
this code once we support defining fingerprints with other hash
functions.

As part of this, I snuck in a change to use range() instead of
xrange() because xrange() isn't necessary for such small values.
2016-05-28 11:58:28 -07:00
Gregory Szorc
a3fac9baf7 util: add sha256
Upcoming patches will teach host fingerprint checking to verify
non-SHA1 fingerprints.

Many x509 certificates these days are SHA-256. And modern browsers
often display the SHA-256 fingerprint for certificates. Since
SHA-256 fingerprints are highly visible and easy to obtain, we
want to support them for fingerprint pinning. So add SHA-256
support to util.

I did not add SHA-256 to DIGESTS and DIGESTS_BY_STRENGTH because
this will advertise the algorithm on the wire protocol. I wasn't
sure if that would be appropriate. I'm playing it safe by leaving
it out for now.
2016-05-28 12:57:28 -07:00
Gregory Szorc
e0771d90f9 sslutil: move CA file processing into _hostsettings()
The CA file processing code has been moved from _determinecertoptions
into _hostsettings(). As part of the move, the logic has been changed
slightly and the "cacerts" variable has been renamed to "cafile" to
match the argument used by SSLContext.load_verify_locations().

Since _determinecertoptions() no longer contains any meaningful
code, it has been removed.
2016-05-28 12:53:33 -07:00
Gregory Szorc
a2e2e628e9 sslutil: move SSLContext.verify_mode value into _hostsettings
_determinecertoptions() and _hostsettings() are redundant with each
other. _hostsettings() is used the flexible API we want.

We start the process of removing _determinecertoptions() by moving
some of the logic for the verify_mode value into _hostsettings().

As part of this, _determinecertoptions() now takes a settings dict
as its argument. This is technically API incompatible. But since
_determinecertoptions() came into existence a few days ago as part
of this release, I'm not flagging it as such.
2016-05-28 11:41:21 -07:00
Gregory Szorc
b5e0df781f sslutil: introduce a function for determining host-specific settings
This patch marks the beginning of a series that introduces a new,
more configurable, per-host security settings mechanism. Currently,
we have global settings (like web.cacerts and the --insecure argument).
We also have per-host settings via [hostfingerprints].

Global security settings are good for defaults, but they don't
provide the amount of control often wanted. For example, an
organization may want to require a particular CA is used for a
particular hostname.

[hostfingerprints] is nice. But it currently assumes SHA-1.
Furthermore, there is no obvious place to put additional per-host
settings.

Subsequent patches will be introducing new mechanisms for defining
security settings, some on a per-host basis. This commits starts
the transition to that world by introducing the _hostsettings
function. It takes a ui and hostname and returns a dict of security
settings. Currently, it limits itself to returning host fingerprint
info.

We foreshadow the future support of non-SHA1 hashing algorithms
for verifying the host fingerprint by making the "certfingerprints"
key a list of tuples instead of a list of hashes.

We add this dict to the hgstate property on the socket and use it
during socket validation for checking fingerprints. There should be
no change in behavior.
2016-05-28 11:12:02 -07:00
Gregory Szorc
cafe3da00a sslutil: remove sslkwargs() (API)
It is now unused.
2016-05-25 19:57:31 -07:00
Gregory Szorc
a62732cd08 url: remove use of sslkwargs 2016-05-25 19:57:02 -07:00
Gregory Szorc
5c94b9af48 mail: remove use of sslkwargs 2016-05-25 19:56:20 -07:00
Gregory Szorc
d65469e1c2 httpconnection: remove use of sslkwargs
It now does nothing.
2016-05-25 19:54:06 -07:00
Gregory Szorc
32aa8e035d sslutil: move sslkwargs logic into internal function (API)
As the previous commit documented, sslkwargs() doesn't add any
value since its return is treated as a black box and proxied
to wrapsocket().

We formalize its uselessness by moving its logic into a
new, internal function and make sslkwargs() return an empty
dict.

The certificate arguments that sslkwargs specified have been
removed from wrapsocket() because they should no longer be
set.
2016-05-25 19:52:02 -07:00
Gregory Szorc
548b4e9e2c sslutil: remove ui from sslkwargs (API)
Arguments to sslutil.wrapsocket() are partially determined by
calling sslutil.sslkwargs(). This function receives a ui and
a hostname and determines what settings, if any, need to be
applied when the socket is wrapped.

Both the ui and hostname are passed into wrapsocket(). The
other arguments to wrapsocket() provided by sslkwargs() (ca_certs
and cert_reqs) are not looked at or modified anywhere outside
of sslutil.py. So, sslkwargs() doesn't need to exist as a
separate public API called before wrapsocket().

This commit starts the process of removing external consumers of
sslkwargs() by removing the "ui" key/argument from its return.
All callers now pass the ui argument explicitly.
2016-05-25 19:43:22 -07:00
Mateusz Kwapich
c2a06fee01 dirstate: remove file from copymap on drop
As the copymap is short-lived object regenerated from dirstate on each
read this didn't affect us in any serious way. But since I've started working
on permanent storage of copymap in my experiments with sqldirstate[1] I've seen
this bug leaving the copy information in copymap after reverting the file
moves and copies.

[1] https://www.mercurial-scm.org/wiki/SQLDirstatePlan
2016-05-25 16:09:07 -07:00
FUJIWARA Katsunori
ef0b8901a2 debugignore: make messages translatable
These messages have been overlooked by check-code, because they start
with non-alphabet character ('%' or '(').

Making these messages translatable seems reasonable, because messages
for ui.note(), ui.status(), ui.progress() and descriptive messages for
ui.write() in "debug" commands are already translatable in many cases.

This is also a part of preparation for making "missing _() in ui
message" detection of check-code more exact.
2016-05-26 01:57:34 +09:00
FUJIWARA Katsunori
13e0147d50 grep: make a message translatable
This message has been overlooked by check-code, because it starts with
non-alphabet character (' ').

This is also a part of preparation for making "missing _() in ui
message" detection of check-code more exact.
2016-05-26 01:57:34 +09:00
FUJIWARA Katsunori
6c92609b0f subrepo: make a message translatable
This message has been overlooked by check-code, because it starts with
non-alphabet character ('%').

This is also a part of preparation for making "missing _() in ui
message" detection of check-code more exact.
2016-05-26 01:57:34 +09:00
FUJIWARA Katsunori
390f95833b merge: make messages translatable
These messages have been overlooked by check-code, because they start
with non-alphabet character (' ').

Making these messages translatable seems reasonable, because all other
'ui.note()'-ed messages in calculateupdates() are already
translatable.

This is also a part of preparation for making "missing _() in ui
message" detection of check-code more exact.
2016-05-26 01:57:34 +09:00
FUJIWARA Katsunori
b93088d0e1 httppeer: make a message translatable
This message has been overlooked by check-code, because it starts with
non-alphabet character ('(').

Making this message translatable seems reasonable, because exception
message below in same function is already translatable

  - 'cannot create new http repository'

This is also a part of preparation for making "missing _() in ui
message" detection of check-code more exact.
2016-05-26 01:57:34 +09:00
Martijn Pieters
4501d84df3 revset: use getargsdict for sort()
This makes it possible to use keyword arguments to specify per-sort options.
For example, a hypothetical 'first' option for the user sort could sort certain
users first with:

    sort(all(), user, user.first=mpm@selenic.com)
2016-05-23 14:09:50 -07:00
Matt Mackall
204bd1271d merge with stable 2016-05-25 15:32:35 -05:00
Augie Fackler
8945f7f25d changegroup: extract method that sorts nodes to send
The current implementation of narrowhg needs to influence the order in
which nodes are sent to the client. adgar@ and I think this is
fixable, but it's going to require pretty substantial time investment,
so in the interim we'd like to extract this method.

I think it makes the group() code a little more obvious, as it took us
a couple of tries to isolate the exact behavior we were observing.
2016-05-12 22:29:05 -04:00
Gregory Szorc
accb96048e sslutil: remove redundant check of sslsocket.cipher()
We are doing this check in both wrapsocket() and validatesocket().

The check was added to the validator in 8f98f4f9ff93 and the commit
message justifies the redundancy with a "might." The check in
wrapsocket() was added in 102733a3c3e1, which appears to be part of
the same series. I'm going to argue the redundancy isn't needed.

I choose to keep the check in wrapsocket() because it is working
around a bug in Python's wrap_socket() and I feel the check for
the bug should live next to the function call exhibiting the bug.
2016-05-15 11:50:49 -07:00
Gregory Szorc
6fd76860b1 sslutil: convert socket validation from a class to a function (API)
Now that the socket validator doesn't have any instance state,
we can make it a generic function.

The "validator" class has been converted into the "validatesocket"
function and all consumers have been updated.
2016-05-15 11:38:38 -07:00
Gregory Szorc
53550ebc63 sslutil: store and use hostname and ui in socket instance
Currently, we pass a hostname and ui to sslutil.wrap_socket()
then create a separate sslutil.validator instance also from
a hostname and ui. There is a 1:1 mapping between a wrapped
socket and a validator instance. This commit lays the groundwork
for making the validation function generic by storing the
hostname and ui instance in the state dict attached to the
socket instance and then using these variables in the
validator function.

Since the arguments to sslutil.validator.__init__ are no longer
used, we make them optional and make __init__ a no-op.
2016-05-15 11:32:11 -07:00
Gregory Szorc
286aa084ac sslutil: use a dict for hanging hg state off the wrapped socket
I plan on introducing more state on the socket instance. Instead
of using multiple variables, let's just use one to minimize risk
of name collision.
2016-05-15 11:25:07 -07:00
Gregory Szorc
c8b2685285 sslutil: require serverhostname argument (API)
All callers now specify it. So we can require it.

Requiring the argument means SNI will always work if supported
by Python.

The main reason for this change is to store state on the socket
instance to make the validation function generic. This will be
evident in subsequent commits.
2016-05-05 19:10:18 -07:00
Matt Mackall
6c6e5bfc8d annotate: optimize line counting
We used len(text.splitlines()) to count lines. This allocates, copies, and
deallocates an object for every line in a file. Instead, we use
count("\n") to count newlines and adjust based on whether there's a
trailing newline.

This improves the speed of annotating localrepo.py from 4.2 to 4.0
seconds.
2016-05-18 16:37:32 -05:00
timeless
a1cb3173a2 py3: convert to next() function
next(..) was introduced in py2.6 and .next() is not available in py3

https://docs.python.org/2/library/functions.html#next
2016-05-16 21:30:53 +00:00
timeless
db06992202 revset: rename variable to avoid shadowing with builtin next() function
https://docs.python.org/2/library/functions.html#next
2016-05-16 21:30:32 +00:00
FUJIWARA Katsunori
24a3947a41 util: make copyfile avoid ambiguity of file stat if needed
In some cases below, copying from backup is used to restore original
contents of a file. If copying keeps ctime, mtime and size of a file,
restoring is overlooked, and old contents cached before restoring
isn't invalidated as expected.

  - failure of transaction before closing (from '.hg/journal.backup.*')
  - rollback of previous transaction (from '.hg/undo.backup.*')

To avoid such problem, this patch makes copyfile() avoid ambiguity of
file stat, if needed.

Ambiguity check is executed, only if:

  - checkambig=True is specified (not all copying needs ambiguity check), and
  - destination file exists before copying

This patch also adds 'not (copystat and checkambig)' assertion,
because combination of copystat and checkambig is meaningless.

This patch is a part of preparation for "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-05-19 00:20:38 +09:00
FUJIWARA Katsunori
2d04a6969f vfs: make rename avoid ambiguity of file stat if needed
In some cases below, renaming from backup is used to restore original
contents of a file. If renaming keeps ctime, mtime and size of a file,
restoring is overlooked, and old contents cached before restoring
isn't invalidated as expected.

  - failure of transaction before closing (only from '.hg/journal.dirstate')
  - rollback of previous transaction (from '.hg/undo.*')
  - failure in dirstateguard scope (from '.hg/dirstate.SUFFIX')

To avoid such problem, this patch makes vfs.rename() avoid ambiguity
of file stat, if needed.

Ambiguity check is executed, only if:

  - checkambig=True is specified (not all renaming needs ambiguity check), and
  - destination file exists before renaming

This patch is a part of preparation for "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-05-19 00:20:38 +09:00
FUJIWARA Katsunori
da123716e7 vfs: make atomictempfile avoid ambiguity of file stat if needed
This patch is a part of preparation for "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-05-19 00:20:38 +09:00
FUJIWARA Katsunori
0242ba3045 util: make atomictempfile avoid ambiguity of file stat if needed
Ambiguity check is executed at close(), only if:

  - atomictempfile is created with checkambig=True, and
  - target file exists before renaming

This restriction avoids performance decrement by needless examination
of file stat (for example, filelog doesn't need exact cache
validation, even though it uses atomictempfile to write changes out).

See description of filestat class for detail about why the logic in
this patch works as expected.

This patch is a part of preparation for "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-05-19 00:20:38 +09:00
FUJIWARA Katsunori
70f0cd3fdd util: add filestat class to detect ambiguity of file stat
Current posix.cachestat implementation might overlook change of a
file, if changing keeps ctime, mtime and size of file. Comparison of
inode number also overlooks changing in such situation, because inode
number is rapidly reused.

Contents of a file cached before changing isn't invalidated as
expected, if change of a file is overlooked for this "ambiguity" of
file stat.

This patch adds filestat class to detect ambiguity of file stat.

This patch is a part of preparation for "Exact Cache Validation Plan":

    https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
2016-05-19 00:20:37 +09:00
timeless
bd5be422b3 debuginstall: add mercurial version 2016-05-10 22:45:45 +00:00
Pulkit Goyal
e244ccece0 py3: use setattr() to assign new class attribute
The old method produces error 'object does not supports item assignment'.
So setattr() is used to assign a new class attribute via __dict__ .
2016-05-17 05:32:36 +05:30
Mateusz Kwapich
a7e298f9a4 localrepo: use dirstate savebackup instead of handling dirstate file manually
This is one step towards having dirstate manage its own storage. It will
be useful for the implementation of sql dirstate [1].

This introduced a small test change: now we always write the dirstate before
saving backup so in some cases where dirstate file didn't exist yet
savebackup can create it.

[1] https://www.mercurial-scm.org/wiki/SQLDirstatePlan
2016-05-11 14:18:52 -07:00
Mateusz Kwapich
70cc846630 localrepo: use dirstate restorebackup instead of copying dirstate manually
This is one step towards having dirstate manage its own storage. It will
be useful for the implementation of sqldirstate [1].

I'm deleting two of the dirstate.invalidate() calls in localrepo because
restorebackup method does that for us.

[1] https://www.mercurial-scm.org/wiki/SQLDirstatePlan
2016-05-13 13:30:08 -07:00
Mateusz Kwapich
2ac744860e dirstate: add prefix and suffix arguments to backup
This would allow the code explicitly copying dirstate to use this method instead.
Use of this method will increase encapsulation (the dirstate class will be sole
owner of its on-disk storage).
2016-05-13 13:28:09 -07:00
Pierre-Yves David
3b0e4dbcf2 transaction: turn lack of locking into a hard failure (API)
We have been warning about transactions without locks for about a year (and
three releases), third party extensions had a fair grace period to fix their
code, we are moving lack of locking to a hard failure in order to protect users
against repository corruption.
2016-05-05 16:20:53 +02:00
Martijn Pieters
d3f28a7e4b graphmod: update edgemap in-place
The edgemap update was not actually propagated to future asciiedge calls;
update the edge state dictionary in-place instead.
2016-05-16 16:41:26 +01:00
Matt Mackall
a24591e84c merge with stable 2016-05-17 11:28:46 -05:00
Jun Wu
1c8f26818c hgcia: remove hgcia (BC)
As discussed at:
https://www.mercurial-scm.org/pipermail/mercurial-devel/2016-March/081018.html,
cia service is down for years. It also uses socket.setdefaulttimeout() which
will break chg. This patch removes the extension.
2016-05-12 01:03:19 +01:00
Augie Fackler
6a7aaa4bf4 wireproto: optimize handling of large batch responses
Now that batch can be used by remotefilelog, the quadratic string
copying this was doing was actually disastrous. In my local testing,
fetching a 56 meg file used to take 3 minutes, and now takes only a
few seconds.
2016-05-12 09:39:14 -04:00
Pierre-Yves David
47ac7dc0f8 cleanup: replace False identity testing with an explicit token object
The recommended way to check default value (when None is not as option) is a
token object. Identity testing to integer is less explicit and not guaranteed to
work in all implementations.
2016-05-05 19:32:51 +02:00
Pierre-Yves David
917636e516 devel: officially deprecate dirstate.write without transaction argument
When we introduce the develwarning, we did not had an official deprecation API
and infrastructure. We can now officially deprecate the old way with a version
deadline.
2016-05-11 09:31:47 +02:00
Pierre-Yves David
f6e86ab7ff devel: officially deprecate update without destination
When we introduce the develwarning, we did not had an official deprecation API
and infrastructure. We can now officially deprecate the old way with a version
deadline.
2016-05-11 09:31:47 +02:00
Pierre-Yves David
efaf172347 devel: fix a typo in a deprecation warning
Credit goes to Sean Farley for spotting it.
2016-05-11 09:34:59 +02:00
Pierre-Yves David
4bd2f39b1d devel: officially deprecate old style revset
When we introduce the develwarning, we did not had an official deprecation API
and infrastructure. We can now officially deprecate the old way with a version
deadline.
2016-05-11 09:31:47 +02:00
Yuya Nishihara
2644883398 revset: make dagrange preserve order of input set
Unlike range, dagrange has no inverted range (such as '10:0'). So there should
be no practical reason to keep dagrange as a function that forces its own
ordering.

No performance regression is spotted in contrib/base-revsets.txt.
2016-05-03 12:36:44 +09:00
Mateusz Kwapich
fc3f152c3e dirstate: make backup methods public
They are called from outside of dirstate anyway and I want the localrepo to
use them too.
2016-05-05 17:06:54 -07:00
Martijn Pieters
66e28b5732 graphmod: partial edge styling
Allow for a style to only apply to the last N lines (for positive N) or
everything but the first N lines (for negative N) of the section along the
current node. This allows for more subtle grandparent styling.

So from the default:

  $ hg log -G ...
  o    Lorem ipsum dolor sit
  :\   amet, consectetur
  : :  adipiscing elit, sed
  : :  do eiusmod tempor
  : :
  o :  incididunt ut labore
  | :  et dolore magna
  | :  aliqua. Ut enim ad
  | :  minim veniam, quis
  |/
  o  nostrud exercitation
  :  ullamco laboris nisi
  :  ut aliquip ex ea
  :  commodo consequat.
  :
  o  Duis aute irure dolor
  |  in reprehenderit in
  ~  voluptate velit esse
     cillum dolore eu

to

  $ hg log -G --config "experimental.graphstyle.grandparent=2." ...
  o    Lorem ipsum dolor sit
  |\   amet, consectetur
  | |  adipiscing elit, sed
  . .  do eiusmod tempor
  . .
  o |  incididunt ut labore
  | |  et dolore magna
  | |  aliqua. Ut enim ad
  | |  minim veniam, quis
  |/
  o  nostrud exercitation
  |  ullamco laboris nisi
  |  ut aliquip ex ea
  .  commodo consequat.
  .
  o  Duis aute irure dolor
  |  in reprehenderit in
  ~  voluptate velit esse
     cillum dolore eu

or

  $ hg log -G --config "experimental.graphstyle.grandparent=1:" ...
  o    Lorem ipsum dolor sit
  |\   amet, consectetur
  | |  adipiscing elit, sed
  | |  do eiusmod tempor
  : :
  o |  incididunt ut labore
  | |  et dolore magna
  | |  aliqua. Ut enim ad
  | |  minim veniam, quis
  |/
  o  nostrud exercitation
  |  ullamco laboris nisi
  |  ut aliquip ex ea
  |  commodo consequat.
  :
  o  Duis aute irure dolor
  |  in reprehenderit in
  ~  voluptate velit esse
     cillum dolore eu

or

  $ hg log -G --config "experimental.graphstyle.grandparent=-2!" ...
  o    Lorem ipsum dolor sit
  |\   amet, consectetur
  ! !  adipiscing elit, sed
  ! !  do eiusmod tempor
  ! !
  o |  incididunt ut labore
  | |  et dolore magna
  | |  aliqua. Ut enim ad
  | |  minim veniam, quis
  |/
  o  nostrud exercitation
  |  ullamco laboris nisi
  !  ut aliquip ex ea
  !  commodo consequat.
  !
  o  Duis aute irure dolor
  |  in reprehenderit in
  ~  voluptate velit esse
     cillum dolore eu
2016-05-04 20:11:59 +01:00
Maciej Fijalkowski
f3ac5246cf pure: write a really lazy version of pure indexObject
On PyPy this version performs reasonably well compared to C version.
Example command is "hg id" which gets faster, depending on details
of your operating system and hard drive (it's bottlenecked on stat mostly)
There is potential for improvements by storing extra as a condensed struct too.
2016-04-24 14:21:38 +03:00
Jun Wu
ad658fc71c dispatch: always load extensions before running shell aliases (issue5230)
Before this patch, we may or may not load extensions for shell aliases
depending on whether the command is abbreviated or not.

Loading extensions may have useful side effects to shell aliases. For example,
the pager extension does not work for shell aliases.

This patch removes the code checking shell aliases before loading extensions
to give the user a more consistent experience. It may hurt performance for
shell aliases a bit without chg but the correctness seems worth it. It will
also make the behavior consistent with chg since chg will always load all
extensions before running commands.
2016-05-07 14:12:23 +01:00
Augie Fackler
31c27da2fc httpclient: update to upstream revision 2995635573d2
This is mostly Python 3 compat work thanks to timeless.
2016-05-09 21:13:50 -04:00
Anton Shestakov
98e687e2c1 crecord: call prevsibling() and nextsibling() directly
The 3 classes for items used in crecord (uiheader, uihunk, uihunkline) all have
prevsibling() and nextsibling() methods. The two methods are used to get the
previous/next item of the same type of the same parent element as the current
one: when `a` is a uihunkline instance, a.nextsibling() returns the next line
in this hunk (or None, if `a` is the last line).

There are also two similar methods: previtem() and nextitem(). When called with
constrainlevel=True (the default) they simply returned the result of
prevsibling()/nextsibling(). Only when called with constrainlevel=False they
did something different: they returned previous/next item regardless of its
type (so if `a` is the last line in a hunk, a.nextitem(constrainlevel=False)
could return the next hunk or the next file -- something that is not a line).

Let's simplify this logic and make code call -sibling() methods when only
siblings are needed and -item() methods when any item would do, and then remove
the constrainlevel argument from previtem() and nextitem().
2016-05-06 19:52:21 +08:00
Jordi Gutiérrez Hermoso
dc2068ce42 dispatch: add fail-* family of hooks
The post-* family of hooks will not run in case a command fails (i.e.
raises an exception). This makes it inconvenient to hook into events
such as doing something in case of a failed push.

We catch all exceptions to run the failure hook. I am not sure if this
is too aggressive, but tests apparently pass.
2016-04-28 10:37:47 -04:00
Yuya Nishihara
d1b0332b16 revset: factor out public optimize() function from recursion
New optimize() hides internal arguments and return values. This makes it easy
to add more parameters and return values to _optimize().
2016-05-02 12:09:00 +09:00
Yuya Nishihara
f18ad29e0a revset: introduce temporary variables in optimize() where they look better 2016-05-02 12:47:09 +09:00
Yuya Nishihara
3a2b799928 revset: construct arguments of only() against matched tree
Since _isonly() knows the structure of 'revs' and 'bases', it should be
slightly easier to understand than destructuring 'ta' and 'tb'.
2016-05-02 11:50:48 +09:00
Yuya Nishihara
dff8edf1fe revset: unnest isonly() closure from optimize()
There were no variables to be captured.
2016-05-02 11:27:26 +09:00
Gregory Szorc
baf0fdcf97 sslutil: stop checking for web.cacerts=! (BC)
The previous patch stopped setting web.cacerts=! to indicate
--insecure.

That left user configs as the only source that could introduce
web.cacerts=!.

The practical impact of this patch is we no longer honor
web.cacerts=! in configs. Instead, we always treat web.cacerts
as a path. The patch is therefore technically BC. However,
since I don't believe web.cacerts=! is documented, it should be
safe to remove. 358b7bec186f (which introduced --insecure) has
no indication that web.cacerts=! is anything but an implementation
detail, reinforcing my belief it can be removed without major
debate.
2016-05-05 00:46:31 -07:00
Gregory Szorc
d5340c808d dispatch: stop setting web.cacerts=! to indicate --insecure
Consumers needing to know if --insecure was used have already
transitioned to using ui.insecureconnections. The previous
patch removed the last meaningful consumer looking for
web.cacerts=!.
2016-05-05 00:40:01 -07:00
Gregory Szorc
9295bebb69 sslutil: use CA loaded state to drive validation logic
Until now, sslkwargs may set web.cacerts=! to indicate
that system certs could not be found. This is really
obtuse because sslkwargs effectively sets state on a global
object which bypasses wrapsocket() and is later consulted
by validator.__call__. This is madness.

This patch introduces an attribute on the wrapped socket
instance indicating whether system CAs were loaded. We
can set this directly inside wrapsocket() because that
function knows everything that sslkwargs() does - and more.

With this attribute set on the socket, we refactor
validator.__call__ to use it.

Since we no longer have a need for setting web.cacerts=!
in sslkwargs, we remove that.

I think the new logic is much easier to understand and will
enable behavior to be changed more easily.
2016-05-05 00:38:18 -07:00
Gregory Szorc
7b654a4277 sslutil: handle ui.insecureconnections in validator
Right now, web.cacerts=! means one of two things:

1) Use of --insecure
2) No CAs could be found and were loaded (see sslkwargs)

This isn't very obvious and makes changing behavior of these
different scenarios independent of the other impossible.

This patch changes the validator code to explicit handle the
case of --insecure being used.

As the inline comment indicates, there is room to possibly change
messaging and logic here. For now, we are backwards compatible.
2016-05-05 00:37:28 -07:00
Gregory Szorc
efcc52cbeb sslutil: check for ui.insecureconnections in sslkwargs
The end result of this function is the same. We now have a more
explicit return branch.

We still keep the old code looking at web.cacerts=! a few lines
below because we're still setting web.cacerts=! and need to react
to the variable. This will be removed in an upcoming patch.
2016-05-05 00:35:45 -07:00
Gregory Szorc
afd3cdf559 dispatch: set ui.insecureconnections when --insecure is used 2016-05-05 00:34:22 -07:00
Gregory Szorc
df3e0225af ui: add an instance flag to hold --insecure bit
Currently, when --insecure is used we set web.cacerts=! and
socket validation takes this value into account. web.cacerts=!
is not documented AFAICT and is purely an internal implementation
detail.

Let's be more explicit about what is going on by introducing a
dedicated variable outside of the config values to track that
--insecure is used.
2016-05-05 00:33:38 -07:00
Gregory Szorc
b7af0f8d55 sslutil: make sslkwargs code even more explicit
The ways in which this code can interact with socket wrapping
and validation later are mind numbing. This patch helps make it
even more clear.

The end behavior should be identical.
2016-05-05 00:32:43 -07:00
Gregory Szorc
051832cb8b sslutil: move code examining _canloaddefaultcerts out of _defaultcacerts
Before, the return of _defaultcacerts() was 1 of 3 types. This was
difficult to read. Make it return a path or None.

We had to update hghave.py in the same patch because it was also
looking at this internal function. I wasted dozens of minutes
trying to figure out why tests were failing until I found the
code in hghave.py...
2016-05-04 23:38:34 -07:00
Gregory Szorc
8bc014a599 sslutil: further refactor sslkwargs
The logic here and what happens with web.cacerts is mind numbing.
Make the code even more explicit.
2016-05-04 23:01:49 -07:00
Gregory Szorc
4bc1239076 sslutil: document and slightly refactor sslkwargs
This will help me and any reviewers keep sane as this code
is refactored.
2016-05-05 00:31:11 -07:00
Augie Fackler
c5874833d2 localrepo: remove a couple of local type aliases
The local aliases are unused now, and were confusing mypy's type
checker.
2016-05-06 11:31:29 -04:00
Augie Fackler
1ed59ab50e cmdutil: typo fix in comment 2016-05-06 14:22:17 -04:00
Pierre-Yves David
6b9ad81f0e devel: use the new 'config' argument for the update develwarn 2016-05-08 10:43:41 +02:00
Pierre-Yves David
5d9e7dcea2 devel: use the new 'config' argument for the revset develwarn 2016-05-08 10:43:41 +02:00
Pierre-Yves David
6a42d00a81 devel: use the new 'config' argument for the dirstate develwarn 2016-05-08 10:43:41 +02:00