Commit Graph

144 Commits

Author SHA1 Message Date
Pierre-Yves David
c5425dd70d bundlerepo: properly extract compressed changegroup from bundle2
Before this bundle repository were unable to work with compressed
bundle2. We use the same approach as with bundle1, we extract the
changegroup in uncompressed form into a temporary file.
2015-10-19 16:01:55 +02:00
Pierre-Yves David
a23eeef4af bundlerepo: uncompress changegroup in bundle1 case only
Uncompressing bundle2 needs to be handled differently.
2015-10-19 18:04:08 +02:00
Pierre-Yves David
d47e68c4cf bundlerepo: move temp-bundle writing logic into a closure
We will reuse this logic for bundle2
2015-10-19 17:58:04 +02:00
Pierre-Yves David
30913031d4 error: get Abort from 'error' instead of 'util'
The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be
confused about that and gives all the credit to 'util' instead of the
hardworking 'error'. In a spirit of equity, we break the cycle of injustice and
give back to 'error' the respect it deserves. And screw that 'util' poser.

For great justice.
2015-10-08 12:55:45 -07:00
Pierre-Yves David
3ff87b1cf4 incoming: request a bundle2 when possible (BC)
Incoming was using bundle1 in all cases, as bundle1 is restricted to
changegroup1 and does not support general delta, this can lead to significant
CPU overhead if the server is using general delta storage. We now properly
request and store a bundle2 to disk.

If the server include any output or error in the bundle, they will be stored on
disk and replayed when the bundle is read. As 'hg incoming' is going to read the
bundle right away, we call that 'good' enough and go back to the bigger plan of
having general delta on by default.

This was tracked as 4864
2015-10-05 00:23:20 -07:00
Pierre-Yves David
1bff95dea7 bundlerepo: indent some code to prepare next patch
We are about to add a new condition. Code is indented in a separated patch for
readability.
2015-10-05 00:18:11 -07:00
Durham Goode
291911d02c bundlerepo: let bundle repo look in the _mancache
When looking up a base revision, we were ignoring the contents that were already
available in the manifest's _mancache. This patch allows us to use that data
instead of reading from the revlog.

This is useful in our pushrebase extension (which allows rebasing on the server
side during a push) because it allows us to prefetch the bundle base manifest
before aquiring the repo lock (1 second saving), which means doing less work inside the lock,
which means a 20% higher commit rate.
2015-09-28 10:27:36 -07:00
Gregory Szorc
e1217593c5 bundlerepo: use absolute_import 2015-08-08 00:36:35 -07:00
Matt Mackall
7c02d2b4b4 bundlerepo: mark internal-only config variable 2015-06-25 17:43:24 -05:00
Martin von Zweigbergk
6b05ffe8de bundlerepo: remove unused 'repo' parameter
Revision d6a8b4e28635 (filelog: add file function to open other
filelogs, 2011-05-10) added a _file() method to revlog, which also
required a 'repo' parameter to be added to bundlefilelog's
constructor. The _file() method was then removed in 55fa3c487b0f
(filelog: remove unused _file method, 2015-01-22), which made the
constructor parameter unused, so let's remove that too.
2015-05-03 14:18:32 -07:00
Yuya Nishihara
dcadb4da71 bundlerepo: disable filtering of changelog while constructing revision text
This avoids the following error that happened if base revision of bundle file
was hidden. bundlerevlog needs it to construct revision texts from bundle
content as revlog.revision() does.

  File "mercurial/context.py", line 485, in _changeset
    return self._repo.changelog.read(self.rev())
  File "mercurial/changelog.py", line 319, in read
    text = self.revision(node)
  File "mercurial/bundlerepo.py", line 124, in revision
    text = self.baserevision(iterrev)
  File "mercurial/bundlerepo.py", line 160, in baserevision
    return changelog.changelog.revision(self, nodeorrev)
  File "mercurial/revlog.py", line 1041, in revision
    node = self.node(rev)
  File "mercurial/changelog.py", line 211, in node
    raise error.FilteredIndexError(rev)
  mercurial.error.FilteredIndexError: 1
2015-04-29 19:47:37 +09:00
FUJIWARA Katsunori
8019b19ea2 bundlerepo: use pathutil.normasprefix to ensure os.sep at the end of cwd
Since Python 2.7.9, "os.path.join(path, '')" doesn't add "os.sep" at
the end of UNC path (see issue4557 for detail).

This makes bundlerepo incorrectly work, if:

  1. cwd is the root of UNC share (e.g. "\host\share"), and
  2. mainreporoot is near cwd (e.g. "\host\sharefoo\repo")
     - host of UNC path is same as one of cwd
     - share of UNC path starts with one of cwd
  3. "repopath" isn't specified in bundle URI
     (e.g. "bundle:bundlefile" or just "bundlefile")

For example:

  $ hg --cwd \host\share -R \host\sharefoo\repo incoming bundle

In this case:

  - os.path.join(r"\host\share", "") returns r"\host\share",
  - r"\host\sharefoo\repo".startswith(r"\host\share") returns True, then
  - r"foo\repo" is treated as repopath of bundlerepo instead of
    r"\host\sharefoo\repo"

This causes failure of combining "\host\sharefoo\repo" and bundle
file: in addition to it, "\host\share\foo\repo" may be combined with
bundle file, if it accidentally exists.

This patch uses "pathutil.normasprefix()" to ensure "os.sep" at the
end of cwd safely, even with some problematic encodings, which use
0x5c (= "os.sep" on Windows) as the tail byte of some multi-byte
characters.

BTW, normalization before "pathutil.normasprefix()" isn't needed in
this case, because "os.getcwd()" always returns normalized one.
2015-04-22 23:38:55 +09:00
Pierre-Yves David
af7d20b000 bundle2: rename format, parts and config to final names
It is finally time to freeze the bundle2 format! To do so we:
- rename HG2Y to HG20,
- drop "b2x:" prefix from all part names,
- rename capability to "bundle2-exp" to "bundle2"
- rename the hook flag from 'bundle2-exp' to 'bundle2'
2015-04-09 16:25:48 -04:00
Jordi Gutiérrez Hermoso
8eb132f5ea style: kill ersatz if-else ternary operators
Although Python supports `X = Y if COND else Z`, this was only
introduced in Python 2.5. Since we have to support Python 2.4, it was
a very common thing to write instead `X = COND and Y or Z`, which is a
bit obscure at a glance. It requires some intricate knowledge of
Python to understand how to parse these one-liners.

We change instead all of these one-liners to 4-liners. This was
executed with the following perlism:

    find -name "*.py" -exec perl -pi -e 's,(\s*)([\.\w]+) = \(?(\S+)\s+and\s+(\S*)\)?\s+or\s+(\S*)$,$1if $3:\n$1    $2 = $4\n$1else:\n$1    $2 = $5,' {} \;

I tweaked the following cases from the automatic Perl output:

    prev = (parents and parents[0]) or nullid
    port = (use_ssl and 443 or 80)
    cwd = (pats and repo.getcwd()) or ''
    rename = fctx and webutil.renamelink(fctx) or []
    ctx = fctx and fctx or ctx
    self.base = (mapfile and os.path.dirname(mapfile)) or ''

I also added some newlines wherever they seemd appropriate for readability

There are probably a few ersatz ternary operators still in the code
somewhere, lurking away from the power of a simple regex.
2015-03-13 17:00:06 -04:00
Eric Sumner
598db3e9f3 bundlerepo: basic bundle2 support
For bundlerepo to work with bundle2 files, we need to find the part that
contains the bundle's changegroup data and work with that instead of the
entire bundle.  Future work can add separate processing for other bundle2
parts.
2015-02-06 11:27:25 -08:00
Eric Sumner
caef80410d bundlerepo: keep track of the original bundle object
Bundlerepo should always close() the object that it receives from
exchange.readbundle().  When bundle2 support is added in a later diff,
self.bundle will be overwritten to be the changegroup part instead of the
entire bundle unpacker.
2015-02-05 16:03:26 -08:00
Mike Edgar
bd60d594d0 filelog: remove unused _file method 2015-01-22 11:09:34 -05:00
Eric Sumner
7cbcf9bdca changegroup.writebundle: provide ui
The next diff will add support for writing bundle2 files to writebundle, but
the bundle2 generator wants access to a ui object.  This changes the signature
and callsites to pass one in.
2015-01-15 14:39:41 -08:00
Angel Ezquerra
6e49f7def8 localrepo: remove all external users of localrepo.sopener
This change touches every module in which repository.sopener was being used, and
changes it for the equivalent repository.svfs.

It should now be possible to remove localrepo.sopener.
2015-01-11 00:25:54 +01:00
Eric Sumner
7be426bb53 incoming: handle phases the same as pull
Now that bundlerepo can move phases safely, 'hg incoming' can share its phase
handling code with pull to better reflect what would actually show up.
2014-12-18 12:33:17 -08:00
Eric Sumner
94a9b4156e bundlerepo: retract phase boundary
This patch makes bundrepo retract the phase boundary for new commits to 'draft'
status, which is consistent with the behavior of 'hg unbundle'.  The old
behavior was for commits to appear with the same phase as their nearest
ancestor in the base repository.

This affects several classes of operation:

* Inspecting a bundle with the -B flag
* Treating a bundle file as a peer (old: everything public, new: everything draft)
* Incoming command (neither old or new behavior is sensible -- fixed in next patch)
2014-12-18 12:22:43 -08:00
Eric Sumner
c8d74ee479 bundlerepo: implement safe phasecache
This patch makes bundlerepo use a subclass of phasecache that will allow phase
boundaries to be moved around, but will never write them to the underlying
repository.
2014-12-18 11:38:48 -08:00
Mads Kiilerich
7f9b497a4c incoming: don't request heads that already are common
Pull would send a getbundle command where common heads were sent both as common
and head, even though there is no reason to request a common head.
The request was thus twice as big as necessary and more likely to hit HTTP
header size limits.

Instead, don't request heads that already are common.

This is fixed in bundlerepo.getremotechanges . It could perhaps also have been
fixed in discovery.findcommonincoming but that would have a bigger impact.
2014-08-15 03:24:40 +02:00
Matt Mackall
4bc583507d bundlerepo: backout 5d87516cc668
According to foozy:

This patch should be backed out, because "bundlename" and "bundle" in
this case are not relative paths to the root of repositories.

The former is specified via "hg incoming --bundle BUNDLENAME"
(relative path to cwd, or absolute one), and the latter is generated
in "changegroup.writebundle" by "tempfile.mkstemp" for internal
temporary usage (absolute path).

To be exact, the latter hunk in this patch can be applied, because
"os.join" for two absolute paths can generate correct result. But the
former hunk can't, because it may unexpected result, if specified path
is relative to cwd and cwd != root.
2014-05-30 11:53:10 -07:00
Chinmay Joshi
94883ecab3 bundlerepo: update unlink in getremotechanges to use vfs
As per WindowsUTF8 plan, unlink from getremotechanges is updated to use vfs in this change.
2014-05-27 21:56:03 +05:30
Pierre-Yves David
c9703fe999 bundle2: add a ui argument to readbundle
The bundle2 unbundler needs a ui argument. We are now passing this information
to `readbundle`.
2014-04-14 15:45:30 -04:00
Pierre-Yves David
009e9f6c33 bundle2: move readbundle into the exchange module
The `readbundle` function is going to understand the bundle2 header. We move the
function to a more suitable place before making any other changes.
2014-04-14 15:33:50 -04:00
FUJIWARA Katsunori
a40858d014 bundlerepo: treat temporarily extracted bundle file via vfs 2014-03-09 01:03:28 +09:00
Mads Kiilerich
2629efac4f config: set a 'source' in most cases where config don't come from file but code
Some extensions set configuration settings that showed up in 'hg showconfig
--debug' with 'none' as source. That was confusing.

Instead, they will now tell which extension they come from.

This change tries to be consistent and specify a source everywhere - also where
it perhaps is less relevant.
2014-03-19 02:45:14 +01:00
Wojciech Lopata
53c13cb614 bundlerevlog: extract 'baserevision' method
This makes possible to use bundlerevlog class with subclasses of revlog
that override revlog's 'revision' method. In particular this change is necessary
to implement manifest compression, as it allows extension to replace manifest
class and override 'revision' method there.
2013-08-26 16:50:31 -07:00
Simon Heimberg
9e6ca20cff repo: repo isolation, do not pass on repo.ui for creating new repos
A repo should not get the configuration from an other repo, so create it with
the global configuration in repo.baseui.
This is done too when recreating a repo. The repo configuration is reread
anyway. And now deleted repo configuration does not persist.
2012-10-10 21:55:49 +02:00
Mads Kiilerich
2aa6f19508 bundlerepo: replace basemap with the base field in the index
Bundle revisions had some info in their fake revlog intries and some info in a
dict with all the bundle revisions. This dict was used to get the stored data
and to distinguish repo revisions from bundle revisions.

Real repo revisions and bundle revisions will now be distinguished by comparing
with the tip revision of the original repo. This reintroduces something similar
to disktiprev which was unused and removed in 822a1e6e3d7b and let that replace
the O(reposize) dict.
2013-02-08 23:26:00 +01:00
Pierre-Yves David
79b2b905b4 incoming: fix incoming when a local head is remotely filtered (issue3805)
In its current state discovery may return (remotely) filtered elements
in "common". This has usually no impact as "missing" is kept clear of
filtered elements. However when the "remote" repo is a local repo (disk
accessible, and directly created in memory) the incoming code takes a
shortcut and directly uses the "remote" repo to generate the incoming
output. When some common elements are filtered this led to a crash. We
now ensure we use an unfiltered repository to generate the incoming
output. This does not change the behavior as missing is clear of
filtered revision.

Now that we have proper low level filtering, incoming code needs a
deeper cleanup but it is already planned.
2013-02-06 07:55:29 +00:00
Mads Kiilerich
c5bc5634f4 bundlerepo: remove old style check of file names
The old check is no longer needed:

The checked paths will be passed on to filelog.__init__ which will prefix the
path with 'data/'. A leading '/' will thus not do any harm.

And: The paths will be used by an opener which will use a pathauditor.

And finally: The old check did not consider Windows paths and was thus
insufficient.
2013-01-16 20:52:56 +01:00
Mads Kiilerich
f6143872ae bundlerepo: use revlog._checkhash
The error message will mention datafile instead of indexfile.
2013-01-16 20:41:41 +01:00
Mads Kiilerich
979df4de21 bundlerepo: store validated deltabase rev in basemap instead of node
This avoids some lookups and aligns bundlerepo more with what revlog do.
2013-01-16 20:41:41 +01:00
Mads Kiilerich
dfcce184ad bundlerepo: use rev instead of node for iteration in revision()
Avoids some lookups and avoids using rev while iterating.
2013-01-16 20:41:41 +01:00
Mads Kiilerich
3480f8c2f3 bundlerepo: inline inbundle()
It didn't make it faster, it didn't make the code smaller, it didn't make the
code simpler.

-1 is never in basemap.
2013-01-16 20:41:41 +01:00
Mads Kiilerich
0cd92a03f7 bundlerepo: drop bundlebase wrapper function for basemap 2013-01-16 20:41:41 +01:00
Mads Kiilerich
d5bb25d87f bundlerepo: remove unused disktiprev attribute 2013-01-16 20:41:41 +01:00
Mads Kiilerich
7bc546e4e0 bundlerepo: improve performance for bundle() revset expression
Create the set of revision numbers directly instead of creating a list of nodes
first.
2013-01-16 20:41:34 +01:00
Mads Kiilerich
2539797b50 bundlerepo: fix outdated comment
Comment was made invalid by e0e9ec25a09e.
2013-01-16 20:41:32 +01:00
Pierre-Yves David
b52ac2ca01 bundlerepo: drop use of _cacheabletip
Now that bundlerepo use a read only VFS, we do not worry about what part of the
branchmap is written back to disk. Nothing is written at all.
2012-12-28 02:34:32 +01:00
Pierre-Yves David
eccc0c88c9 bundlerepo: enforce reading from core repo only
We do not want anything computed with the bundle overlay to be written back in
the repo. Such write will likely contains invalid data.

The short terms goal of this change is to drop use of `_cacheabletip` in bundle
repo.
2012-12-28 02:32:47 +01:00
Mads Kiilerich
056fcbf2bc merge with stable 2012-12-28 11:55:45 +01:00
Pierre-Yves David
62e1246b84 bundlerepo: use _cacheabletip mechanism in bundlerepo
Instead of preventing any cache write we allow writing cache for all content of
the original repo.

The motivation for this change is to drop the custom _writebranchcache of
bundlerepo to help extraction of the branchmap logic out of localrepo.
2012-12-20 12:17:44 +01:00
Mads Kiilerich
861c915f14 bundlerepo: don't return the peer without bundlerepo from getremotechanges
Problem:
getremotechanges would return the 'other' repo if nothing was incoming and
there thus wasn't any bundle to base the repo on. The 'other' could be a http
peer which only implement the functionality available over the http protocol.
Transplant could thus fail with
  TypeError: argument of type 'httppeer' is not iterable

Solution:
Return the local repo instead of the remote peer if there is no reason to place
a bundlerepo on top of the local repo.
2012-12-28 11:16:01 +01:00
Pierre-Yves David
ff24df652d clfilter: ensure that filecache on localrepo is unfiltered
All filecache usage on repo is for logic that should be unfiltered. The
caches should be common to all filtered instances, and computation must
be done unfiltered.  A dedicated storecache subclass is created for
this purpose.
2012-10-08 19:34:04 +02:00
Tomasz Kleczek
fab490ae63 bundle: add revset expression to show bundle contents (issue3487)
bundle() revset expression returns all changes that are present
in the bundle file (no matter whether they are in the repo or not).

Bundle file should be specified via -R option.
2012-10-31 16:23:23 -07:00
Sune Foldager
7045c35403 peer: introduce canpush and improve error message 2012-07-13 21:52:28 +02:00