Commit Graph

34737 Commits

Author SHA1 Message Date
Mark Thomas
107956c510 merge: check created file dirs for path conflicts only once (issue5716)
In large repositories, updates involving the creation of many files check the
same directories repeatedly in the wctx manifest.  Move these checks out to a
separate loop to avoid repeated checks hitting the manifest.

Differential Revision: https://phab.mercurial-scm.org/D1226
2017-11-24 12:53:58 -08:00
Mark Thomas
2f4962c2a4 merge: cache unknown dir checks (issue5716)
As mentioned in D1222, the recent pathconflicts change regresses update
performance in large repositories when many files are being updated.

To mitigate this, we introduce two caches of directories that have
already found to be either:

  - unknown directories, but which are not aliased by files and
    so don't need to be checked if they are files again; and

  - missing directores, which cannot cause path conflicts, and
    cannot contain a file that causes a path conflict.

When checking the paths of a file, testing against this caches means we can
skip tests that involve touching the filesystem.

Differential Revision: https://phab.mercurial-scm.org/D1224
2017-11-24 12:53:58 -08:00
Yuya Nishihara
5ff5d9b38c dispatch: add HGPLAIN=+strictflags to restrict early parsing of global options
If this feature is enabled, early options are parsed using the global options
table. As the parser stops processing options when non/unknown option is
encountered, it won't mistakenly take an option value as a new early option.
Still "--" can be injected to terminate the parsing (e.g. "hg -R -- log"), I
think it's unlikely to lead to an RCE.

To minimize a risk of this change, new fancyopts.earlygetopt() path is enabled
only when +strictflags is set. Also the strict parser doesn't support '--repo',
a short for '--repository' yet. This limitation will be removed later.

As this feature is backward incompatible, I decided to add a new opt-in
mechanism to HGPLAIN. I'm not pretty sure if this is the right choice, but
I'm thinking of adding +feature/-feature syntax to HGPLAIN. Alternatively,
we could add a new environment variable. Any bikeshedding is welcome.

Note that HGPLAIN=+strictflags doesn't work correctly in chg session since
command arguments are pre-processed in C. This wouldn't be easily fixed.
2017-11-23 22:17:03 +09:00
Yuya Nishihara
b0d1fec38b fancyopts: add early-options parser compatible with getopt()
The next patch will add a flag for strict parsing of early options, where
we'll have to parse all early options at once instead of processing them
one-by-one by dispatch._earlygetopt(). That's why I decided to hook
fancyopts().

All dispatch._early*opt() functions is planned to be replaced with this
function. But in this stable series, only the strict mode will be handled
by fancyopts.earlygetopt().
2017-11-23 22:04:53 +09:00
Matt Harbison
c1ef7c5a7a largefiles: pay attention to dropped standin files when updating largefiles
Previously, the largefile for a dropped standin would be deleted here, and then
restored from the cache.  This had the effect of clobbering uncommitted changes
if a revert caused the file to be forgotten, which is not what happens with a
normal file.  Now the removal and update is skipped for dropped largefiles, and
the corresponding standin is deleted from disk.

This was noticed when working on issue5738 because the forgotten standin files
were left behind, and that changes the behavior of the next rename to that
directory.  My first attempt was to cleanup the standins before calling this.
That failed, because this function deletes the largefile if the corresponding
standin is missing.

This function is called by the revert command, merge (and therefore update), and
patch, via the scmutil.marktouched() override.  So it should be pretty narrow in
scope.

I didn't mark issue5738 as fixed because the move related issues can still
happen if the main tree and the .hglf subtree get out of sync somehow.  I don't
see an easy fix for that, but that should be an edge case.  If whoever queues
this thinks it is good enough to close out the bug and can cram it into the
summary, go for it.
2017-11-12 23:45:14 -05:00
Matt Harbison
9d58e7d4a4 test-largefiles: demonstrate problems with renaming and reverting a directory
These things were uncovered looking at issue5738.

First, if the destination directory exists under .hglf, the source is moved
under the destination instead of renaming the last component for `hg mv srcdir
dstdir`.  This is extra confusing, because it occurs even if the user visible
destination (i.e. the path _not_ under .hglf) does not exist.

Additionally, when a largefile is forgotten via revert, any modifications end up
getting clobbered.  For normal files, the forgotten file is left unchanged, as
shown by test-import.t.  The forget command on a largefile will correctly leave
the file unmodified.
2017-11-12 00:24:38 -05:00
Matt Harbison
d913b0c5b9 tests: add globs for Windows 2017-11-11 12:37:05 -05:00
Yuya Nishihara
d46d87090c cat: record the current behavior of wildcard matches in subrepos
Mercurial subrepos support any match patterns.
2017-11-25 15:29:34 +09:00
Augie Fackler
285d5a2a3b merge with i18n 2017-11-29 17:49:08 -05:00
Matt Harbison
40cf71ae24 convert: avoid wrong lfconvert defaults by moving configitems to core
The `hg lfconvert --to-normal` command uses the convert extension internally to
work its magic, but that produced devel-warn messages if the convert extension
wasn't loaded by the user.  The test in 658e7a6d93e0 (modified here) wasn't
showing the warnings because the convert extension was loaded via $HGRCPATH.
Most of the config options default to None/False, but 'hg.usebranchnames' and
'hg.tagsbranch' are supposed to default to True and 'default' respectively.

The first iteration of this was to ui.setconfig() inside lfconvert, to force the
convert extension to load.  But there really is no precedent for doing this, and
check-config complained that 'extensions.convert' isn't documented.  Yuya
suggested this alternative.

This partially backs out 448e09d8859d.
2017-11-28 23:20:08 -05:00
Boris Feld
cf402c02f7 tr-summary: keep a weakref to the unfiltered repository
Repoview can have a different life cycle, causing issue in some corner
cases. The particular instance that revealed this comes from localpeer. The
localpeer hold a reference to the unfiltered repository, but calling 'local()'
will create an on-demand 'visible' repoview. That repoview can be garbaged
collected any time. Here is a simplified step by step reproduction::

    1) tr = peer.local().transaction('foo')
    2) tr.close()

After (1), the repoview object is garbage collected, so weakref used in (2)
point to nothing.


Thanks to Sean Farley for helping raising and debugging this issue.
2017-11-24 21:51:41 -05:00
Wagner Bruna
9766674d68 i18n-pt_BR: synchronized with f1d5a55d6a57 2017-11-21 13:50:25 -02:00
Yuya Nishihara
52b06fe73d dispatch: verify result of early command parsing
Before, early options were stripped from args, and because of this, some
kind of parsing errors weren't reported. For example,

  $ hg ci -m -Ra file

would execute "hg ci -m file" in repository "a".

This patch fixes the issue by parsing early options again by real getopt-based
parser, and verifying the results. If the early parsing appears wrong, hg just
aborts. The current error message seems not nice, and should be improved, maybe
in V2 or follow-up.

Note that this isn't a security feature because we can still do anything by
using shell aliases.
2017-11-11 12:40:13 +09:00
Yuya Nishihara
fccba4aa77 dispatch: convert non-list option parsed by _earlygetopt() to string
So we can easily compare it with the corresponding getopt() result.

There's a minor behavior change. Before, "hg --cwd ''" failed with ENOENT.
But with this patch, an empty cwd is silently ignored. "hg -R ''" has always
worked as such, so -R has no BC.
2017-11-11 17:55:15 +09:00
Yuya Nishihara
f9dd555dd4 dispatch: add option to not strip command args parsed by _earlygetopt()
This allows us to parse the original args later by full-blown getopt() in
order to verify the result of the faulty early parsing. Still we need the
'strip=True' behavior for shell aliases.

Note that this series is RFC because it seems to change too much to be
included in stable release.
2017-11-11 16:46:41 +09:00
Yuya Nishihara
333fc1d401 dispatch: fix early parsing of short option with value like -R=foo
Before, -R=foo was parsed as '-R' 'foo', which disagrees with the standard
getopt behavior.
2017-11-14 00:25:59 +09:00
Yuya Nishihara
82ae4401fe dispatch: abort if early boolean options can't be parsed
Perhaps we'll need to restrict the parsing rules of --debugger and --profile,
where this patch will help us know why the --debugger option doesn't work.

I have another series to extend this feature to --config/--cwd/-R, but even
with that, shell aliases can be used to get around the restriction.
2017-11-11 14:02:41 +09:00
Yuya Nishihara
8f01395e02 dispatch: stop parsing of early boolean option at "--" 2017-11-10 22:27:26 +09:00
Yuya Nishihara
01e537d4b9 dispatch: extract stub function to peek boolean command option
We should at least stop parsing at "--". The 'name' argument is passed for
future extension.
2017-11-10 22:22:39 +09:00
Yuya Nishihara
7137d3d976 dispatch: do not drop unpaired argument at _earlygetopt()
Before, "hg log -R" just worked.
2017-11-11 12:09:19 +09:00
Yuya Nishihara
0704342965 amend: update .hgsubstate before committing a memctx (issue5677)
This is a minimal copy of localrepo.commit(). As the current amend() function
heavily depends on the wctx API, it wasn't easy to port it to use a separate
status tuple. So for now, wctx._status is updated in-place.
2017-11-04 20:07:40 +09:00
Yuya Nishihara
f281b565b3 subrepo: extract preprocess of repo.commit() to free function
No code change other than extracting a function. Maybe we should stop mutating
the status argument, but that's out of the scope of stable changes.
2017-11-04 19:21:39 +09:00
Yuya Nishihara
ec502c74f8 tests: demonstrate that .hgsubstate isn't updated on amend
Loosely based on test-amend.t and test-subrepo.t
2017-11-04 18:54:57 +09:00
Yuya Nishihara
df1f119682 amend: do not drop missing files (issue5732)
samefile() can be wrong since wctx.manifest() does not include missing files,
whereas missing files should be preserved on commit.
2017-11-04 23:48:19 +09:00
Yuya Nishihara
e6c4026850 amend: do not take untracked files as modified or clean (issue5732)
fctx.exists() shouldn't be used here as it checks if a file physically exists,
which may disagree with the dirstate.
2017-11-04 23:45:59 +09:00
Yuya Nishihara
5ea9a0ac48 tests: add more complete test for status changes on amend
This demonstrates that missing/untracked files are handled incorrectly. The
correct outputs are suppressed by (false !), and wrong outputs are added with
(true !) instead.

The setup code is copied from test-status-rev.t.
2017-11-04 23:40:26 +09:00
Mark Thomas
ce1d136e58 scmutil: don't try to delete origbackup symlinks to directories (issue5731)
When origbackuppath is set, when looking to see if a file we are backing up
conflicts with a directory in the origbackuppath, we incorrectly match on
symlinks to directories.  This means we try to call vfs.rmtree on the
symlink, which fails.

Differential Revision: https://phab.mercurial-scm.org/D1311
2017-11-03 09:27:36 -07:00
Mark Thomas
63c7a46713 tests: add a test demonstrating issue5731
If origbackups are in use, a symlink to a valid directory is backed up, and an
update is made that attempts to backup a file or link over that symlink, we
abort with a bad error message instead of successfully updating.

Differential Revision: https://phab.mercurial-scm.org/D1310
2017-11-03 09:27:35 -07:00
Augie Fackler
ffbe6c0a13 Added signature for changeset f1d5a55d6a57 2017-11-07 13:15:35 -05:00
Augie Fackler
d0223576fe stable: merge with security patches 2017-11-07 11:22:24 -05:00
Gregory Szorc
bcd6d015d2 subrepo: use per-type config options to enable subrepos
We change subrepos.allowed from a list of allowed subrepo types to
a combination of a master switch and per-type boolean flag.

If the master switch is set, subrepos can be disabled wholesale.

If subrepos are globally enabled, then per-type options are
consulted. Mercurial repos are enabled by default. Everything else
is disabled by default.
2017-11-06 22:32:41 -08:00
Augie Fackler
68d8df395d config: add some more documentation around why svn and git subrepos are off 2017-11-06 14:56:17 -05:00
Gregory Szorc
53801830bd share: move config item declarations into core
These config items control share behavior that is implemented in core.
Since the functionality is implemented in core, extensions may
leverage it.

Mozilla has one such extension. And, it needs to access share.pool.
Before this patch, a devel warning regarding accessing an unregistered
config option would be issued unless the share extension were loaded.
Moving the registration of the config options to core fixes this.
2017-11-06 10:33:40 -08:00
Yuya Nishihara
e5730ba521 subrepo: disable git and svn subrepos by default (BC) (SEC)
We have a security issue with git subrepos. I'm not sure if svn subrepo is
vulnerable, but it seems not 100% safe to allow writing arbitrary data into
a metadata directory. So for now, only hg subrepo is enabled by default.

Maybe we should improve the help to describe why git/svn subrepos are
disabled.
2017-11-05 21:51:42 +09:00
Yuya Nishihara
9752ef714d subrepo: extend config option to disable subrepos by type (SEC)
This allows us to minimize the behavior change introduced by the next patch.

I have no idea which config style is preferred in UX POV, but I decided to
get things done.

 a) list: 'allowed = hg, git, svn'
 b) sub option: 'allowed.hg = True' or 'allowed:hg = True'
 c) per-type action: 'hg = allow', 'git = abort'
2017-11-05 21:48:58 +09:00
Yuya Nishihara
f864544d81 subrepo: add config option to reject any subrepo operations (SEC)
This is an alternative workaround for the issue5730.

Perhaps this is the simplest way of disabling subrepo operations. It does
nothing clever, but just aborts if Mercurial starts accessing to a subrepo.

I think Greg's patch is more useful since it allows us to at least check
out the parent repository. However, that would be confusing if the default
is flipped to checkout=False and subrepos are silently ignored.

I don't like the config name 'allowed', but I couldn't get any better name.
2017-11-05 21:22:07 +09:00
Matt Harbison
2be4ce7af1 morestatus: don't crash with different drive letters for repo.root and CWD
Previously, if there were unresolved files and the CWD drive was different from
the repo drive, `hg status -v` would page the normal status, followed by the
exception header.  A stacktrace was waiting when the pager exited.  The
underlying cause was the same as 12441ef4442f.

Unfortunately, I don't see any reasonable way to write a test this [1].

[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-November/107401.html
2017-11-04 23:39:54 -04:00
Matt Harbison
212ee63a25 pathutil: add doctests for canonpath()
This is a followup to 12441ef4442f.  Since there's no way to ensure that more
drive letters than C: exist, this seems like the only way to test it.  This is
enough to catch the 12441ef4442f scenario, as well as CWD outside of the repo
when the path isn't prefixed with path/to/repo.
2017-11-03 22:22:50 -04:00
Yuya Nishihara
dac75264c0 subrepo: disallow symlink traversal across subrepo mount point (SEC)
It wasn't easy to extend the pathauditor to check symlink traversal across
subrepos because pathauditor._checkfs() rejects a directory having ".hg"
directory. That's why I added the explicit islink() check.

No idea if this patch is necessary after we've fixed the issue5730 by
splitting submerge() into planning and execution phases.
2017-11-03 20:12:50 +09:00
Yuya Nishihara
ace48cdb7b tests: show symlink traversal across subrepo mount point (SEC)
Also adds a couple of tests where the auditor does work as expected.
2017-11-03 19:17:25 +09:00
Matt Harbison
31925dd9ca share: handle --relative shares to a different drive letter gracefully
This had the same problem as 12441ef4442f.  Banning os.path.relpath() is
tempting, but the hint it provides is useful here.
2017-11-02 23:55:09 -04:00
Matt Harbison
325a0abc6e pathutil: use util.pathto() to calculate relative cwd in canonpath()
os.path.relpath() exploded if the 'root' and 'cwd' directories had different
drive letters.  I noticed this in TortoiseHg when typing a fileset into the
filter, and it kept complaining until the closing '()' was typed.  This was
reproducible on the command line with:

  $ cd /d
  $ hg -R /c/Users/Matt/Projects/hg files 'set:e'
  Traceback (most recent call last):
  ...
  File "mercurial\pathutil.pyc", line 182, in canonpath
  File "ntpath.pyc", line 529, in relpath
  ValueError: path is on drive c:, start on drive d:
2017-11-02 20:35:31 -04:00
Kevin Bullock
8f9983c9f0 Added signature for changeset bfd77d488124 2017-11-01 16:54:39 -05:00
Jun Wu
04a084983c test-dispatch: stabilize the test
When cwd is removed and `hg` is executed, some shells may run `getcwd`
before forking and executing, some may not do it, some may print a
different error message.

The test should be shell-independent so let's just avoid checking the error
message.

Differential Revision: https://phab.mercurial-scm.org/D1282
2017-11-01 14:22:26 -07:00
Kevin Bullock
0c315becfe internals: update test-help.t for config registrar copy-edit 2017-11-01 15:34:22 -05:00
Kevin Bullock
8b1854807c internals: copy-edit "register" -> "registrar" in configitem docs 2017-11-01 13:24:08 -05:00
Augie Fackler
69ce54473a merge with i18n 2017-11-01 16:07:33 -04:00
Wagner Bruna
27cee4a057 i18n-pt_BR: synchronized with cb9be6b29e0b 2017-11-01 08:31:16 -02:00
Matt Harbison
ba66d4513f help: minor copy editing for grammar 2017-10-31 23:09:29 -04:00
Yuya Nishihara
21161a9bda configitems: relax warning about unwanted default value
The original condition was a bit harsh for extension authors since third-party
extensions need to preserve compatibility with older Mercurial versions, where
no defaults would be loaded from the configtable. So let's silence the warning
if the given default value matches, which should be harmless.
2017-10-31 22:37:30 +09:00