Commit Graph

1586 Commits

Author SHA1 Message Date
Jun Wu
c389ff2eb2 localrepo: rename proxycls to filteredrepo
When debugging in a Python shell, the type of "repo" is "proxycls", which
could confuse new people.

    In [1]: repo
    Out[1]: <mercurial.localrepo.proxycls at 0x7f65d4b976d0>

Let's rename it to "filteredrepo" to make it clearer.
2017-03-09 15:10:27 -08:00
Pierre-Yves David
718c1a120c vfs: use 'vfs' module directly in 'mercurial.localrepo'
Now that the 'vfs' classes moved in their own module, lets use the new module
directly. We update code iteratively to help with possible bisect needs in the
future.
2017-03-02 13:28:17 +01:00
Jun Wu
a2a0eb3ac0 localrepo: handle rename with hardlinks properly
In "aftertrans", we rename "journal.*" to "undo.*". We expect "journal.*"
files to disappear after renaming.

However, if "journal.foo" and "undo.foo" refer to a same file (hardlink),
rename may be a no-op, leaving both files on disk, according to Linux
manpage [1]:

    If oldpath and newpath are existing hard links referring to the same
    file, then rename() does nothing, and returns  a  suc‐ cess status.

The POSIX specification [2] is not very clear about what to do.

To be safe, remove "undo.*" before the rename so "journal.*" cannot be left
on disk.

[1]: http://man7.org/linux/man-pages/man2/rename.2.html
[2]: http://pubs.opengroup.org/onlinepubs/9699919799/
2017-03-02 21:49:30 -08:00
Pierre-Yves David
ded2ad613e localrepo: deprecate 'repo.opener' (API)
The "new" 'repo.vfs' attribute have been around for almost 5 years. I think we
can deprecate the old form now ;-)
2016-08-05 13:56:10 +02:00
Pierre-Yves David
232150945e localrepo: deprecated 'repo.wopener' (API)
The "new" 'repo.wvfs' attribute have been around for almost 5 years. I think we
can deprecate the old form now ;-)
2016-08-05 13:53:45 +02:00
Pierre-Yves David
ec73028c00 localrepo: add some comment about role of various vfs object
This should make things clearer for most people.
2016-08-05 13:49:05 +02:00
Dan Villiom Podlaski Christiansen
66c3976319 share: add --relative flag to store a relative path to the source
Storing a relative path the source repository is useful when exporting
repositories over the network or when they're located on external
drives where the mountpoint isn't always fixed.

Currently, Mercurial interprets paths in `.hg/shared` relative to
$PWD. I suspect this is very much unintentional, and you have to
manually edit `.hg/shared` in order to trigger this behaviour.

However, on the off chance that someone might rely on it, I added a
new capability called 'relshared'. In addition, this makes earlier
versions of Mercurial fail with a graceful error.

I should note that I haven't tested this patch on Windows.
2017-02-13 14:05:24 +01:00
Pierre-Yves David
86873414c1 color: initialize color for the localrepo ui
The 'ui' object dedicated to a 'localrepo' is independent from the one available
in dispatch (and 'uisetup'). In addition, it is created from the 'baseui'
(apparently for good reason). As a result, we need to run the color setup on
it after the local repository config is read.

This was overlooked when the rest of the initialization changed but did not
had impact yet because all setup is still global. We fix it before it is too
late.
2017-02-25 18:34:01 +01:00
FUJIWARA Katsunori
397d5cb0d7 localrepo: check HG_PENDING strictly
Before this patch, checking HG_PENDING for changelog in localrepo.py
might cause unintentional reading unrelated '00changelog.i.a' in,
because HG_PENDING is checked by str.startswith().

An external hook spawned by inner repository in nested ones satisfies
this condition.

This patch uses txnutil.mayhavepending() to check HG_PENDING strictly.

BTW, this patch may cause failure of bisect in the repository of
Mercurial itself, if examination at bisecting assumes that an external
hook can see all pending changes while nested transactions across
repositories.

This invisibility issue will be fixed by subsequent patch, which
allows HG_PENDING to refer multiple repositories.
2017-02-21 01:21:00 +09:00
Yuya Nishihara
8e1d6228ac scmutil: proxy revrange() through repo to break import cycles
This was one of the hardest import cycles as scmutil is widely used and
revset functions are likely to depend on a variety of modules.

New repo.anyrevs() does not expand user aliases by default to copy the
behavior of the existing repo.revs(). I don't want to add new function to
localrepository, but this function is quite similar to repo.revs() so it
won't increase the complexity of the localrepository class so much.
2017-02-19 20:00:18 +09:00
Yuya Nishihara
b2229f5117 revset: split language services to revsetlang module (API)
New revsetlang module hosts parser, tokenizer, and miscellaneous functions
working on parsed tree. It does not include functions for evaluation such as
getset() and match().

  2288 mercurial/revset.py
   684 mercurial/revsetlang.py
  2972 total

get*() functions are aliased since they are common in revset.py.
2017-02-19 18:19:33 +09:00
Jun Wu
1911496ecd localrepo: move extension loading to a separate method
The stateful chg plan [1] requires a special repo object, where ideally all
side effects caused by loading the repo object could be reverted by just
dropping (gabbage collect) the loaded repo object.

Currently, that is impossible because repo.__init__ calls
"extensions.loadall", which may have unpredictable side-effects that cannot
be reverted by dropping the repo object.

This patch moves "extensions.loadall" to a separate method, so chg could
subclass localrepository and make extensions loading a no-op.

[1]: mercurial-scm.org/pipermail/mercurial-devel/2017-February/092547.html
2017-02-15 19:41:14 -08:00
Stanislau Hlebik
fda8c9c688 localrepo: avoid unnecessary sorting
headrevs output already sorted, no need to sort it again.
2017-02-13 02:31:56 -08:00
Stanislau Hlebik
8671ff39e1 localrepo: cache self.changelog in local variable
Repeated self.changelog lookups can incur overhead. Let's cache it in the
separate variable.
2017-02-13 02:26:18 -08:00
Stanislau Hlebik
1ea3a2dcdf localrepo: avoid unnecessary conversion from node to rev
changelog.heads() first calls headrevs then converts them to nodes.
localrepo.heads() then sorts them using self.changelog.rev function and makes
useless conversion back to revs. Instead let's call changelog.headrevs() from
localrepo.heads(), sort the output and then convert to nodes. Because headrevs
does not support start parameter this optimization only works if start is None.
2017-02-02 02:56:38 -08:00
Gregory Szorc
765aada92f localrepo: experimental support for non-zlib revlog compression
The final part of integrating the compression manager APIs into
revlog storage is the plumbing for repositories to advertise they
are using non-zlib storage and for revlogs to instantiate a non-zlib
compression engine.

The main intent of the compression manager work was to zstd all
of the things. Adding zstd to revlogs has proved to be more involved
than other places because revlogs are... special. Very small inputs
and the use of delta chains (which are themselves a form of
compression) are a completely different use case from streaming
compression, which bundles and the wire protocol employ. I've
conducted numerous experiments with zstd in revlogs and have yet
to formalize compression settings and a storage architecture that
I'm confident I won't regret later. In other words, I'm not yet
ready to commit to a new mechanism for using zstd - or any other
compression format - in revlogs.

That being said, having some support for zstd (and other compression
formats) in revlogs in core is beneficial. It can allow others to
conduct experiments.

This patch introduces *highly experimental* support for non-zlib
compression formats in revlogs. Introduced is a config option to
control which compression engine to use. Also introduced is a namespace
of "exp-compression-*" requirements to denote support for non-zlib
compression in revlogs. I've prefixed the namespace with "exp-"
(short for "experimental") because I'm not confident of the
requirements "schema" and in no way want to give the illusion of
supporting these requirements in the future. I fully intend to drop
support for these requirements once we figure out what we're doing
with zstd in revlogs.

A good portion of the patch is teaching the requirements system
about registered compression engines and passing the requested
compression engine as an opener option so revlogs can instantiate
the proper compression engine for new operations.

That's a verbose way of saying "we can now use zstd in revlogs!"

On an `hg pull` conversion of the mozilla-unified repo with no extra
redelta settings (like aggressivemergedeltas), we can see the impact
of zstd vs zlib in revlogs:

$ hg perfrevlogchunks -c
! chunk
! wall 2.032052 comb 2.040000 user 1.990000 sys 0.050000 (best of 5)
! wall 1.866360 comb 1.860000 user 1.820000 sys 0.040000 (best of 6)

! chunk batch
! wall 1.877261 comb 1.870000 user 1.860000 sys 0.010000 (best of 6)
! wall 1.705410 comb 1.710000 user 1.690000 sys 0.020000 (best of 6)

$ hg perfrevlogchunks -m
! chunk
! wall 2.721427 comb 2.720000 user 2.640000 sys 0.080000 (best of 4)
! wall 2.035076 comb 2.030000 user 1.950000 sys 0.080000 (best of 5)

! chunk batch
! wall 2.614561 comb 2.620000 user 2.580000 sys 0.040000 (best of 4)
! wall 1.910252 comb 1.910000 user 1.880000 sys 0.030000 (best of 6)

$ hg perfrevlog -c -d 1
! wall 4.812885 comb 4.820000 user 4.800000 sys 0.020000 (best of 3)
! wall 4.699621 comb 4.710000 user 4.700000 sys 0.010000 (best of 3)

$ hg perfrevlog -m -d 1000
! wall 34.252800 comb 34.250000 user 33.730000 sys 0.520000 (best of 3)
! wall 24.094999 comb 24.090000 user 23.320000 sys 0.770000 (best of 3)

Only modest wins for the changelog. But manifest reading is
significantly faster. What's going on?

One reason might be data volume. zstd decompresses faster. So given
more bytes, it will put more distance between it and zlib.

Another reason is size. In the current design, zstd revlogs are
*larger*:

debugcreatestreamclonebundle (size in bytes)
zlib: 1,638,852,492
zstd: 1,680,601,332

I haven't investigated this fully, but I reckon a significant cause of
larger revlogs is that the zstd frame/header has more bytes than
zlib's. For very small inputs or data that doesn't compress well, we'll
tend to store more uncompressed chunks than with zlib (because the
compressed size isn't smaller than original). This will make revlog
reading faster because it is doing less decompression.

Moving on to bundle performance:

$ hg bundle -a -t none-v2 (total CPU time)
zlib: 102.79s
zstd:  97.75s

So, marginal CPU decrease for reading all chunks in all revlogs
(this is somewhat disappointing).

$ hg bundle -a -t <engine>-v2 (total CPU time)
zlib: 191.59s
zstd: 115.36s

This last test effectively measures the difference between zlib->zlib
and zstd->zstd for revlogs to bundle. This is a rough approximation of
what a server does during `hg clone`.

There are some promising results for zstd. But not enough for me to
feel comfortable advertising it to users. We'll get there...
2017-01-13 20:16:56 -08:00
Pulkit Goyal
f1c1938039 py3: replace os.environ with encoding.environ (part 1 of 5)
os.environ is a dictionary which has string elements on Python 3. We have
encoding.environ which take care of all these things. This is the first patch
of 5 patch series which tend to replace the occurences of os.environ with
encoding.environ as using os.environ will result in unusual behaviour.
2016-12-18 01:34:41 +05:30
Jun Wu
f9c05a235e localrepo: use ProgrammingError
This is an example usage of ProgrammingError. Let's start migrating
RuntimeError to ProgrammingError.

The code only runs when devel.all-warnings or devel.check-locks is set, so
it does not affect the end-user experience.
2016-12-06 17:06:39 +00:00
Pulkit Goyal
6e996c4d4c localrepository: remove None as default value of path argument in __init__()
The path variable in localrepository.__init__() has a default value None. So
it gives us a option to create an object to localrespository class without
path variable. But things break if you try to do so. The second line in the
init which will be executed when we try to create a localrepository object
will call os.path.expandvars(path) which returns

TypeError: argument of type 'NoneType' is not iterable

I checked occurrences when it is called and can't find any piece of code
which calls it without path variable. Also if something is calling it, its
should break.
2016-12-04 23:22:34 +05:30
Mateusz Kwapich
529860b433 localrepo: make it possible to reuse manifest when commiting context
This makes the commit function understand the context that's reusing manifest.
2016-11-17 10:59:15 -08:00
Augie Fackler
93eca45354 localrepo: refer to checkunresolved by its new name 2016-11-21 21:32:55 -05:00
Augie Fackler
fab0872f32 localrepo: refer to dirstateguard by its new name 2016-11-21 21:06:34 -05:00
Durham Goode
d2df1b3944 manifest: delete manifest.manifest class
Now that nothing uses the primary manifest class, we can delete it.
2016-11-10 02:13:19 -08:00
Durham Goode
ae274e1c50 localrepo: delete localrepo.manifest
Now that nothing uses normal manifests, we can delete localrepo.manifest.
2016-11-10 02:13:19 -08:00
Durham Goode
6fb7c00e4d manifest: remove manifest.add and add memmfctx.write
This removes one more dependency on the manifest class by moving the write
functionality onto the memmanifestctx classes and changing the one consumer to
use the new API.

By moving the write path to a manifestctx, we now give the individual manifests
control over how they're read and serialized. This will be useful in developing
new manifest formats and storage systems.
2016-11-08 08:03:43 -08:00
Mads Kiilerich
38cb771268 spelling: fixes of non-dictionary words 2016-10-17 23:16:55 +02:00
timeless
05cf1812b9 cmdutil: refactor checkunresolved
localrepo.commit had code to check for unresolved merge conflicts,
it would be helpful for at least rebase to be able to use that
code without calling commit().
2016-11-02 18:45:53 +00:00
Durham Goode
871d515e3d manifest: make manifestlog a storecache
The old @property on manifestlog was broken. It meant that we would always
recreate the manifestlog instance, which meant the cache was never hit. Since
we'll eventually remove repo.manifest and make manifestlog the only property,
let's go ahead and make manifestlog the @storecache property, have manifestlog
own the manifest instance, and have repo.manifest refer to it via manifestlog.

This means all accesses go through repo.manifestlog, which is now invalidated
correctly.
2016-10-18 17:33:39 -07:00
Durham Goode
757b6fb5aa manifest: move manifest creation to a helper function
A future patch will be moving manifest creation to be inside manifestlog as part
of improving our cache guarantees. bundlerepo and unionrepo currently rely on
being able to hook into manifest creation, so let's temporarily move the actual
manifest creation to a helper function for them to intercept.

In the future manifest.manifest() will disappear entirely and this can
disappear.
2016-10-18 17:32:51 -07:00
Gregory Szorc
26f6f03d4c exchange: refactor APIs to obtain bundle data (API)
Currently, exchange.getbundle() returns either a cg1unpacker or a
util.chunkbuffer (in the case of bundle2). This is kinda OK, as
both expose a .read() to consumers. However, localpeer.getbundle()
has code inferring what the response type is based on arguments and
converts the util.chunkbuffer returned in the bundle2 case to a
bundle2.unbundle20 instance. This is a sign that the API for
exchange.getbundle() is not ideal because it doesn't consistently
return an "unbundler" instance.

In addition, unbundlers mask the fact that there is an underlying
generator of changegroup data. In both cg1 and bundle2, this generator
is being fed into a util.chunkbuffer so it can be re-exposed as a
file object.

util.chunkbuffer is a nice abstraction. However, it should only be
used "at the edges." This is because keeping data as a generator is
more efficient than converting it to a chunkbuffer, especially if we
convert that chunkbuffer back to a generator (as is the case in some
code paths currently).

This patch refactors exchange.getbundle() into
exchange.getbundlechunks(). The new API returns an iterator of chunks
instead of a file-like object.

Callers of exchange.getbundle() have been updated to use the new API.

There is a minor change of behavior in test-getbundle.t. This is
because `hg debuggetbundle` isn't defining bundlecaps. As a result,
a cg1 data stream and unpacker is being produced. This is getting fed
into a new bundle20 instance via bundle2.writebundle(), which uses
a backchannel mechanism between changegroup generation to add the
"nbchanges" part parameter. I never liked this backchannel mechanism
and I plan to remove it someday. `hg bundle` still produces the
"nbchanges" part parameter, so there should be no user-visible
change of behavior. I consider this "regression" a bug in
`hg debuggetbundle`. And that bug is captured by an existing
"TODO" in the code to use bundle2 capabilities.
2016-10-16 10:38:52 -07:00
timeless
38fbbc49b0 localrepo: use single quotes in use warning 2016-09-20 23:48:08 +00:00
Durham Goode
847e1dc1fe manifest: add manifestlog.add
This adds a simple add() function to manifestlog. This lets us convert more
uses of repo.manifest to use repo.manifestlog, so we can further break our
dependency on the manifest class.
2016-09-20 12:24:01 -07:00
FUJIWARA Katsunori
bd4b59b7e1 localrepo: make _refreshfilecachestats unfiltered method to refresh correctly
Before this patch, if transaction is started via "filtered repo"
object, _refreshfilecachestats() at closing transaction doesn't
refresh file stat of any @filecache properties correctly, because:

  - _refreshfilecachestats() omits refreshing file stat of a
    @filecache property, if it doesn't appear in self.__dict__

  - if transaction is started via "filtered repo",
    _refreshfilecachestats() is applied on "filtered repo"

    because repo.transaction() adds "self._refreshfilecachestats" to
    post close procedures. repo.transaction() isn't unfiltered method,
    and "self" in it means "filtered repo" in this case.

    Transactions started by explicit repo.transaction() easily causes
    this situation.

  - _refreshfilecachestats() applied on "filtered repo" omits whole
    refreshing

    because @filecache properties are stored into "unfiltered repo",
    and appear only in self.__dict__ of "unfiltered repo".

This incorrect refreshing causes unnecessary reloading from files.

To refresh file stat of @filecache properties at closing transaction
correctly, this patch makes _refreshfilecachestats() unfiltered
method.

This patch chooses making _refreshfilecachestats() unfiltered method
instead of making transaction() unfiltered method, to reduce
unexpected side effect.
2016-09-12 03:06:29 +09:00
FUJIWARA Katsunori
bda63509d4 localrepo: make invalidate avoid invalidating store inside transaction (API)
Before this patch, invalidate() discards in-memory fncache changes,
even inside transaction scope.

Such changes should be written out at closing transaction. Otherwise,
fncache might overlook newly added files. A file overlooked by
fncache isn't accessible via store vfs, even if it actually exists in
store.

On the other hand, a non-existing file in fncache is less harmful,
because fncachestore always examines whether a file actually exists or
not before access. Therefore, discarding in-memory changes can be
safely omitted.

It is typical case that repo.invalidate() in streamclone is executed
inside nested transaction.

This patch makes invalidate() avoid invalidating store inside
transaction.

This patch focuses on describing only how invalidate() changes own
behavior according to activity of transaction. Describing other detail
of invalidate() in docstr will be done in another series, which
refactors invalidate*() functions.
2016-09-12 03:06:28 +09:00
Mark Ignacio
1ca1a521d4 lock: show more detail for new-style locks in lock waiting message (issue4752)
Improve the lock waiting warning message by explicitly saying that a host and
process are holding the lock. This nudges confused new users in the direction
of investigating the other process instead of removing the lock.
2016-08-30 09:25:00 -07:00
Durham Goode
f38741166f manifest: use property instead of field for manifest revlog storage
The file caches we're using to avoid reloading the manifest from disk everytime
has an annoying bug that causes the in memory structure to not be reloaded if
the mtime and the size haven't changed. This causes a breakage in the tests
because the manifestlog is not being reloaded after a commit+strip operation in
mq (the mtime is the same because it all happens in the same second, and the
resulting size is the same because we add 1 and remove 1). The only reason this
doesn't affect the manifest itself is because we touch it so often that we
had already reloaded it after the commit, but before the strip.

Once the entire manifest has migrated to manifestlog, we can get rid of these
properties, since then the manifestlog will be touched after the commit, but
before the strip, as well.
2016-08-17 13:25:13 -07:00
Durham Goode
4c0439aa0a manifest: introduce manifestlog and manifestctx classes
This is the start of a large refactoring of the manifest class. It introduces
the new manifestlog and manifestctx classes which will represent the collection
of all manifests and individual instances, respectively.

Future patches will begin to convert usages of repo.manifest to
repo.manifestlog, adding the necessary functionality to manifestlog and instance
as they are needed.
2016-08-17 13:25:13 -07:00
Augie Fackler
aa68b8b2d6 localrepo: jettison now-unused dirlog() method from localrepo 2016-08-05 12:47:03 -04:00
Pierre-Yves David
15e8baf199 develwarn: use the lock helper in local repo
We have a helper function to know if a lock is taken. When checking lock usage
we now use it instead of manually accessing the locks.
2016-08-05 13:44:17 +02: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
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
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
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
Matt Mackall
204bd1271d merge with stable 2016-05-25 15:32:35 -05: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
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
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
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
8815201972 localrepo: jettison parents() method per deprecation policy (API) 2016-05-04 21:02:03 -04:00