Commit Graph

11491 Commits

Author SHA1 Message Date
Pierre-Yves David
1b80836a48 bundle2: support transmission of params error over the wire
We picked a null character to split each parameter during the transfer. This is
fragile if the same character is used in parameter name. However other
codes will already behave in a strange way in that case, so we are not
introducing any regression. A better format may be picked for the final
version of the protocol.
2014-05-28 15:57:23 -07:00
Pierre-Yves David
e625997ab5 bundle2: introduce a `params` attribute to BundleValueError
We'll first use it for unsupported mandatory parameters on parts.
2014-05-28 15:53:34 -07:00
Pierre-Yves David
72ac6a7248 bundle2: introduce a parttype attribute to BundleValueError
We will use the Exception for more that just unknown part type.
2014-05-28 15:51:19 -07:00
Pierre-Yves David
b5c6c1b880 bundle2: rename b2x:error:unknownpart to b2x:error:unsupportedcontent
This is a backward compatibility breakage per se. But bundle2 was explicitly
flagged as experimental, and this is one an error path anyway. So the worse
possible outcome from this change is to still have a crash but with a different
message.
2014-05-27 10:32:07 -07:00
Pierre-Yves David
d9f1652a77 bundle2: move exception classes into the error module
Exceptions should have known their place.
2014-05-28 15:31:05 -07:00
Pierre-Yves David
08bcb101f2 bundle2: rename UnknownPartError to BundleValueError
We are going to raise exceptions for a wider range of cases: unsupported
mandatory stream and part parameters.  We rename the exception with a wider
name.
2014-05-28 14:22:24 -07:00
Sean Farley
3692a2672f context: explicitly return a tuple
In the refactoring of removing localrepo.status, e283486177bd, we accidentally
changed the return type from a tuple to a list. Philosophically, this is
incorrect so we explicitly return a tuple again.
2014-05-27 17:04:48 -05:00
Pierre-Yves David
096f428e53 bundle2: expose mandatory params in a mandatorykeys attribute
We expose all keys that MUST be processed in ``part.mandatorykeys``. This makes
it much easier to access the information. Enforcement of the mandatory
parameters is coming in later changesets.
2014-05-23 20:23:54 -07:00
Pierre-Yves David
467e401b10 bundle2: use the new `part.params` dictionary
We use the new ``part.params`` dictionary to access the value of parameters instead of
creating one from the part's attributes.
2014-05-26 18:45:43 -07:00
Pierre-Yves David
75a728d5f5 bundle2: introduce a `params` dictionary on unbundled parts
This exposes all parameters the part received into a ``part.params`` dictionary.
This should be much easier to use.

This dictionary itself does not expose the mandatory or advisory aspect of
parameters, but no current users of bundle2 actually enforce any of this logic.
Coming changesets will improve this aspect.
2014-05-23 17:26:57 -07:00
Pierre-Yves David
ecdd6aaf9e bundle2: make sure unbundled part param are read-only
My old uncle Robert once trusted an API user. We never saw him again.
2014-05-23 17:17:39 -07:00
Pierre-Yves David
ee0bc34f9d bundle2: introduce an `_initparams` method
The handling of parameters will become much more sophisticated in the coming
changesets. So we extract the logic in a function to not pollute the generic
logic.
2014-05-28 10:04:02 -07:00
Pierre-Yves David
17c8c5b1eb bundle2: forbid duplicate parameter keys
No rules were specified about parameter key uniqueness. We document that keys
should be unique and document it. This opens the way to a more friendly (read
dictionary like) way to access value of parameters in the code.
2014-05-22 12:52:09 -07:00
Pierre-Yves David
7023ca67e5 bundle2: update part creators to `addparam` when relevant
In some cases, the use of ``addparam`` makes code much clearer.
2014-05-23 16:46:30 -07:00
Pierre-Yves David
76215be0d0 bundle2: introduce a `addparam` method on part
We make it easier to add new parameters after the part creation. As for the
``data`` attribute we make sure the part generation has not begun yet.
2014-05-22 11:38:40 -07:00
Pierre-Yves David
3c42f04f04 bundle2: the ability to set `data` attribute of the part is now official
We make it safe to set the data attribute after part creation. It is an allowed
operation as long as the part has not started to be generated.
2014-05-22 11:21:26 -07:00
Pierre-Yves David
2ece793be7 bundle2: introduce a ReadOnlyPartError exception
As we will introduce functions to alter already created parts, we need a proper
exception to raise when code tries to alter a part that cannot be altered anymore.
2014-05-24 16:08:05 -07:00
Pierre-Yves David
4248dc3512 bundle2: warn about error during initialization in `newpart` docstring
As we are moving toward being able to alter a part after its creation, we need
to make the implication of the part being already part of the bundle2 clear.
2014-05-23 16:20:30 -07:00
Pierre-Yves David
3b20774c58 bundle2: track life cycle of parts
We introduce a ``_generated`` attribute on parts. Coming changesets will
make it easier to update a part's contents after its creation. We need a way to track
if the part is still open to modification or if it is currently being generated
and should not be touched anymore.

As a bonus, we can now detect and crash if someone manages to write bogus code
to get a part generated twice.
2014-05-22 11:14:02 -07:00
Pierre-Yves David
121338752e bundle2: update all `addpart callers to newpart`
The new method is what we want in all current cases.
2014-05-23 15:59:19 -07:00
Pierre-Yves David
a618942ce3 bundle2: have `newpart` automatically add the part to the bundle
The created part is automatically added to the bundle as this is most certainly
the intent of the user code.
2014-05-23 15:54:18 -07:00
Pierre-Yves David
637e050d21 bundle2: add a `newpart method to bundle20`
Creating new parts is the most common operation people do when exposed to a
bundler. We create a dedicated method on the bundler object for it. This will
simplify the code and also avoid having to import the ``mercurial.bundle2``
module in multiple places.

One part creators have been updated for testing purpose.
2014-05-23 15:45:46 -07:00
Pierre-Yves David
6480c98ec3 bundle2: small doc update on the bundler
The `bundle20` class contains methods to help define the content and methods
to generate the actual stream. We add small doc headers to help distinguish
between the two.
2014-05-22 10:48:37 -07:00
Sean Farley
10c800bea9 localrepo: replace status method with a shim
The path of the righteous man is beset on all sides by the inequities of the
selfish and the tyranny of evil men. Blessed is he, who in the name of charity
and good will, shepherds the weak through the valley of darkness, for he is
truly Mercurial's keeper and the finder of robust methods. And I will strike
down upon thee with great vengeance and furious anger those who would attempt
to poison and destroy Mercurial's codebase. And you will know my name is the
Lord when I lay my vengeance upon thee.
2014-04-25 15:44:55 -05:00
Sean Farley
927e6572f4 workingctx: have status method call super instead of customized code.
The old code is unneeded now that basectx has the ability to calculate the
status between two context objects.

Now, we use the objected oriented pattern called 'super'.
2014-05-27 15:55:35 -07:00
Sean Farley
7d4925ec2b basectx: copy localrepo.status method
Now that all the pieces are in place, we copy the status method from
localrepo. In the next few patches, we will remove the old implementation.
2014-04-24 18:07:42 -05:00
Sean Farley
6a40a50483 committablectx: cache _status in _poststatus
A future patch will remove the old workingctx.status which caches the status of
the working directory, therefore we now cache this status in the poststatus
hook of committablectx.
2014-04-24 17:42:53 -05:00
Sean Farley
da54d7ddc4 committablectx: simplify caching the status
Previously, workingctx had custom variables for the unknown, ignored, and clean
list of files of status. These then got moved to committablectx and, after the
refactoring of localrepo.status, are no longer needed. We, therefore, simplify
the whole mess.

As a bonus, we are able to remove the need for having 'assert'.
2014-04-24 17:31:20 -05:00
Sean Farley
b948452671 localrepo: remove cache code now handled by _prestatus
This patch removes the last of the 'working' variable that was sprinkled
throughout localrepo.status which paves the way for future patches to use the
object oriented design of contexts to handle calculating the status.
2014-04-23 16:08:20 -05:00
Sean Farley
c4a16ba6c8 workingctx: add note about super._prestatus calling manifest 2014-04-23 16:06:42 -05:00
Sean Farley
ff42938c33 basectx: preserve loading the cached manifest in _prestatus
This is just a copy from localrepo.status and is a small step to removing that
method entirely. The prestatus hook is only called for changectx's, thereby
ensuring that the same behavior is guaranteed.
2014-04-23 16:06:23 -05:00
Sean Farley
24d42ebd09 localrepo: use new subrev method of context.py
With the machinery in place, we use context.subrev instead of testing for a
workingctx directly. This allows more flexibility for later patches that will
add memctx to the mix.
2013-09-20 21:59:34 -05:00
Sean Farley
9882a9e5a4 committablectx: add subrev method to return None
This allows a future patch to use object oriented style to remove an if
statement in the status method.
2013-09-20 22:07:58 -05:00
Sean Farley
ede9f80137 basectx: add subrev method to return the rev of a subrepo given a subpath
This will be used in an upcoming patch to simplify the status method by
eliminating an if block.
2013-09-20 21:55:42 -05:00
Matt Mackall
95a0ecfb91 merge with stable 2014-05-27 17:41:20 -07:00
Durham Goode
e18e8b3005 bundle2: fix bundle2 pulling all revs on empty pulls
When bundle2 was enabled, if hg pull had no commits to pull, it would print
'no changes found' and then download the entire repository from the server. This
was caused by heads and common being set to None, which gets treated as
heads=cl.heads() and common=[nullid], which means download the entire repo.

Pulling bundles without a changegroup is a valid use case (like if we're just
updating bookmarks), so this modifes the bundle code to allow not adding
changegroups.

This is backport of 26ad3517a3a2.
2014-05-07 17:24:19 -07:00
Pierre-Yves David
d55202b92c exchange: fix bad indentation
Those two lines where double indented for no good reasons.

This is backport of d889859ccef0.
2014-05-07 19:26:15 -07:00
Pierre-Yves David
d4684c05ab exchange: propagate arguments to the _getbundleextrapart function
The arguments was wrongly propagated (again).

This a backport of 1c1da5990b8c
2014-05-07 19:28:17 -07:00
Durham Goode
f8ebc64925 bundle2: fix configuration name mismatch
During pulls bundle2 was checking server.bundle2, but during pushes it was
checking experimental.bundle2. This makes them both experimental.bundle2.

This is a backport of a9334b37b19a
2014-05-07 17:20:38 -07:00
Yuya Nishihara
bc04e2c6cd alias: change return code of bad definition to 255
We use 255 for general command error.

It can't raise util.Abort because help module executes badalias command to get
error message.
2014-05-17 15:14:18 +09:00
Matt Mackall
10039fb244 bookmarks: properly align multi-byte characters 2014-05-27 15:16:52 -07:00
Yuya Nishihara
2827ff321c alias: handle shlex error in command aliases
No command should fail with ValueError just because there is unparseable
alias definition.

It returns 1 like other badalias handlers, but should be changed to 255 in
a later version because we use 255 for general command error.
2014-05-17 13:06:16 +09:00
FUJIWARA Katsunori
85d651396d subrepo: normalize path in the specific way for problematic encodings
Before this patch, "reporelpath()" uses "rstrip(os.sep)" to trim
"os.sep" at the end of "parent.root" path.

But it doesn't work correctly with some problematic encodings on
Windows, because some multi-byte characters in such encodings contain
'\\' (0x5c) as the tail byte of them.

In such cases, "reporelpath()" leaves unexpected '\\' at the beginning
of the path returned to callers.

"lcalrepository.root" seems not to have tail "os.sep", because it is
always normalized by "os.path.realpath()" in "vfs.__init__()", but in
fact it has tail "os.sep", if it is a root (of the drive): path
normalization trims tail "os.sep" off "/foo/bar/", but doesn't trim
one off "/".

So, just avoiding "rstrip(os.sep)" in "reporelpath()" causes
regression around issue3033 fixed by e3dfde137fa5.

This patch introduces "pathutil.normasprefix" to normalize specified
path in the specific way for problematic encodings without regression
around issue3033.
2014-05-08 19:03:00 +09:00
FUJIWARA Katsunori
f2a51c0956 subrepo: avoid sanitizing ".hg/hgrc" in meta data area for non-hg subrepos
Before this patch, sanitizing ".hg/hgrc" scans directories and files
also in meta data area for non-hg subrepos: under ".svn" for
Subversion subrepo, for example.

This may cause not only performance impact (especially in large scale
subrepos) but also unexpected removing meta data files.

This patch avoids sanitizing ".hg/hgrc" in meta data area for non-hg
subrepos.

This patch stops checking "ignore" target at the first
(case-insensitive) appearance of it, because continuation of scanning
is meaningless in almost all cases.
2014-05-08 19:03:00 +09:00
FUJIWARA Katsunori
8aea0c13e6 subrepo: make "_sanitize()" take absolute path to the root of subrepo
Before this patch, "hg update" doesn't sanitize ".hg/hgrc" in non-hg
subrepos correctly, if "hg update" is executed not at the root of the
parent repository.

"_sanitize()" takes relative path to subrepo from the root of the
parent repository, and passes it to "os.walk()". In this case,
"os.walk()" expects CWD to be equal to the root of the parent
repository.

So, "os.walk()" can't find specified path (or may scan unexpected
path), if CWD isn't equal to the root of the parent repository.

Non-hg subrepo under nested hg-subrepos may cause same problem, too:
CWD may be equal to the root of the outer most repository, or so.

This patch makes "_sanitize()" take absolute path to the root of
subrepo to sanitize correctly in such cases.

This patch doesn't normalize the path to hostile files as the one
relative to CWD (or the root of the outer most repository), to fix the
problem in the simple way suitable for "stable".

Normalizing should be done in the future: maybe as a part of the
migration to vfs.
2014-05-08 19:03:00 +09:00
FUJIWARA Katsunori
a8f723b6c7 subrepo: invoke "_sanitize()" also after "git merge --ff"
Before this patch, sanitizing ".hg/hgrc" in git subrepo doesn't work,
when the working directory is updated by "git merge --ff".

"_sanitize()" is not invoked after checking target revision out into
the working directory in this case, even though it is invoked
indirectly via "checkout" (or "rawcheckout") in other cases.

This patch invokes "_sanitize()" explicitly also after "git merge
--ff" execution.
2014-05-08 19:03:00 +09:00
FUJIWARA Katsunori
78cdb35351 subrepo: make "_sanitize()" work
"_sanitize()" was introduced by 5131f2755f60 on "stable" branch, but
it has done nothing for sanitizing since 5131f2755f60.

"_sanitize()" assumes "Visitor" design pattern:

    "os.walk()" should invoke specified function ("v" in this case)
    for each directory elements under specified path

but "os.walk()" assumes "Iterator" design pattern:

    callers of it should drive loop to scan each directory elements
    under specified path by themselves with the returned generator
    object

Because of this mismatching, "_sanitize()" just discards the generator
object returned by "os.walk()" and does nothing for sanitizing.

This patch makes "_sanitize()" work.

This patch also changes the format of warning message to show each
unlinked files, for multiple appearances of "potentially hostile
.hg/hgrc".
2014-05-08 19:03:00 +09:00
Yuya Nishihara
c5b2af81b6 alias: fix loss of non-zero return code in command aliases
This also includes test for shell aliases.  It avoid using "false" command
because "man false" does not say "exit with 1" but "exit with a status code
indicating failure."
2014-05-17 14:43:06 +09:00
Pierre-Yves David
0203860e23 changelog: ensure changelog._delaybuf is initialized
The ``localrepo.writepending`` method is using the ``changelog._delaybuff``
attribute to know if it has anything to do. However the ``changelog._delaybuff``
is never initialised at ``__init__`` time. This can lead to crash when using
bundle2 for part that never touch the changelog.

We simply initialize it to its base value. This is scheduled for stable as it
both trivial and blocking for experimenting with bundle2.
2014-05-20 13:55:08 -07:00
Yuya Nishihara
1cdd3cec9a proxy: remove unneeded _set_hostport for compatibility with Python 2.7.7rc1
With Python 2.7.7rc1, "hg pull" through HTTP CONNECT tunnel fails due to the
removal of _set_hostport [1].

      ...
      File "mercurial/url.py", line 372, in https_open
        return self.do_open(self._makeconnection, req)
      ...
      File "mercurial/url.py", line 342, in connect
        _generic_proxytunnel(self)
      File "mercurial/url.py", line 228, in _generic_proxytunnel
        self._set_hostport(self.host, self.port)
    AttributeError: httpsconnection instance has no attribute '_set_hostport'

self._set_hostport(self.host, self.port) should be noop and can be removed
because:

 - _set_hostport() [2] was the function to parse "host:port" string and
   set them to self.host and self.port,
 - and (self.host, self.port) pair should be valid since connect() is called
   prior to _generic_proxytunnel().

 [1]: http://hg.python.org/cpython/rev/568041fd8090
 [2]: http://hg.python.org/cpython/file/3a1db0d2747e/Lib/httplib.py#l721
2014-05-22 22:05:26 +09:00