Commit Graph

15101 Commits

Author SHA1 Message Date
Matt Mackall
09bfc43ef0 encoding: use getutf8char in toutf8b
This correctly avoids the ambiguity of U+FFFD already present in the
input and similar confusion by working a character at a time.
2015-11-05 17:21:43 -06:00
Matt Mackall
cc7a93dfa3 encoding: handle non-BMP characters in fromutf8b 2015-11-05 17:11:50 -06:00
Matt Mackall
001845ef91 posix: use getutf8char to handle OS X filename percent-escaping
This replaces an open-coded utf-8 parser that was ignoring subtle issues
like overlong encodings.
2015-11-05 17:09:00 -06:00
Matt Mackall
322dbe32ca encoding: add getutf8char helper
This allows us to find character boundaries in byte strings when
trying to do custom encodings.
2015-11-05 16:48:46 -06:00
Pierre-Yves David
61ac4561fd unbundle: gratuitous fix white spacing "issue"
We were missing one space on this block.
2015-11-07 16:03:09 -05:00
Durham Goode
9980cf1bdd manifest: skip fastdelta if the change is large
In large repos, the existing manifest fastdelta computation (which performs a
bisect on the raw manifest for every file that is changing), is excessively
slow. This patch makes fastdelta fallback to the normal string delta algorithm
if the number of changes is large.

On a large repo with a commit of 8000 files, this reduces the commit time by 7
seconds (fastdelta goes from 8 seconds to 1).

I tested this change by modifying the function to compare the old and the new
values and running the test suite. The only difference is that the pure
text-diff algorithm sometimes produces smaller (but functionaly identical)
deltatexts than the bisect algorithm.
2015-11-05 18:56:40 -08:00
Siddharth Agarwal
11e83e49ad merge.mergestate: update docstrings for preresolve and resolve
Add a docstring for preresolve, and update the one for resolve.
2015-11-04 23:44:51 -08:00
Anton Shestakov
001b2cf88b hgweb: remove unused colorPart() from mercurial.js
Looks like the function wasn't ever used since its introduction in
083571f47ff6, since setColor() below always used "rgb(255, 255, 255)" notation
which doesn't need hex digits.
2015-10-24 09:47:33 +01:00
Ryan McElroy
4e01fb3c0d discovery: factor out calculation of heads to not warn about
In addition to taking a step towards getting an unreasonably large function
factored into smaller, more manageable functions, this will allow extensions
such as remotenames have more control over what pushes are allowed or not.
2015-11-06 09:48:24 -08:00
Matt Mackall
61d5d53d27 merge with stable 2015-11-04 15:17:52 -06:00
Durham Goode
49c25cc444 hooks: fix hooks not firing if prechangegroup was set (issue4934)
We need to call delayupdate again after writing to the changelog.
Otherwise the prechangegroup hook consumes the delayupdate subscription and
future hooks don't see the pending changes (see issue 4934 for more details).

Adds a test that triggers the prechangegroup hook before the pretxnchangegroup
hook and verifies that the output of pretxnchangegroup doesn't change.
2015-11-03 17:13:27 -08:00
Durham Goode
8bdfd3d55c hooks: always include HG_PENDING
Previously we would only include HG_PENDING in the hook args if the
transaction's writepending() actually wrote something. This is a bad criteria,
since it's possible that a previous call to writepending() wrote stuff and the
hooks want to still see that.

The solution is to always have hooks execute within the scope of the pending
changes by always putting HG_PENDING in the environment.
2015-11-03 16:58:13 -08:00
Gregory Szorc
61b9ffeec8 wireproto: move clonebundles command from extension (issue4931)
The SSH peer class accesses wireproto.commands[cmd] as part of encoding
command arguments. Previously, the wire protocol command was defined in
the clonebundles extension. If the client didn't have this extension
enabled (which it likely doesn't since it is meant as a server-side
extension), then clients attempting to clone via ssh:// would get a
crash due to a KeyError accessing wireproto.commands['clonebundles']
when cloning from a server that is advertising clone bundles.

Moving the definition of the wire protocol command to wireproto.py makes
this problem go away.

A side effect of this code move is servers will always respond to
"clonebundles" wire protocol command requests. This should be fine: the
server will return an empty response unless a clone bundles manifest
file is present and clients shouldn't call the command unless the server
is advertising the capability, which only happens if the clonebundles
extension is enabled and the manifest file exists.
2015-11-03 12:31:33 -08:00
Yuya Nishihara
dda890d7ab templatefilters: try round-trip utf-8 conversion by json filter (issue4933)
As JSON string is known to be a unicode, we should try round-trip conversion
for localstr type. This patch tests localstr type explicitly because
encoding.fromlocal() may raise Abort for undecodable str, which is probably
not what we want. Maybe we can refactor json filter to use encoding module
more later.

Still "{desc|json}" can't round-trip because showdescription() modifies a
localstr object.
2015-11-04 23:48:15 +09:00
Gregory Szorc
9a4b9852b5 exchange: do not attempt clone bundle if local repo is non-empty (issue4932) 2015-11-03 12:16:54 -08:00
Siddharth Agarwal
09431ac4f3 filemerge.prompt: separate out choice selection and action
This will make future patches cleaner.
2015-11-02 12:12:24 -08:00
Matt Harbison
de09629866 scmutil: abort if an empty revision is given to revpair()
When using 'extdiff --patch' to check the changes in a rebase, 'precursors(x)'
evaluated to an empty set because I forgot the --hidden flag, so the other
revision was used as the replacement for the empty set.  The result was the
patch for the other revision was diffed against itself, and the tool saying
there were no differences.  That's misleading since the expected diff args were
silently changed, so it's better to bail out.

The other uses of scmutil.revpair() are commands.diff and commands.status, and
it doesn't make sense to allow an empty revision there either.  The code here
was suggested by Yuya Nishihara.
2015-10-31 21:45:46 -04:00
Anton Shestakov
04c432b846 hgweb: escape class keyword when used as a js object property (issue4913) 2015-10-27 12:34:05 +08:00
Siddharth Agarwal
6b30464363 hgweb.server: drop support for Python 2.4 2015-10-24 16:23:42 -07:00
Siddharth Agarwal
532b96181d util: drop Python 2.4 compat by directly importing md5 and sha1
There's been a fair amount of cruft here over the years, which we can all
just get rid of now.
2015-10-24 15:56:16 -07:00
Anton Shestakov
9b60cbd85f hgweb: replace some str.split() calls by str.partition() or str.rpartition()
Since Python 2.5 str has new methods: partition and rpartition. They are more
specialized than the usual split and rsplit, and they sometimes convey the
intent of code better and also are a bit faster (faster than split/rsplit with
maxsplit specified). Let's use them in appropriate places for a small speedup.

Example performance (partition):

$ python -m timeit 'assert "apple|orange|banana".split("|")[0] == "apple"'
1000000 loops, best of 3: 0.376 usec per loop

$ python -m timeit 'assert "apple|orange|banana".split("|", 1)[0] == "apple"'
1000000 loops, best of 3: 0.327 usec per loop

$ python -m timeit 'assert "apple|orange|banana".partition("|")[0] == "apple"'
1000000 loops, best of 3: 0.214 usec per loop

Example performance (rpartition):

$ python -m timeit 'assert "apple|orange|banana".rsplit("|")[-1] == "banana"'
1000000 loops, best of 3: 0.372 usec per loop

$ python -m timeit 'assert "apple|orange|banana".rsplit("|", 1)[-1] == "banana"'
1000000 loops, best of 3: 0.332 usec per loop

$ python -m timeit 'assert "apple|orange|banana".rpartition("|")[-1] == "banana"'
1000000 loops, best of 3: 0.219 usec per loop
2015-11-02 23:37:49 +08:00
Anton Shestakov
df6b074b5d help: replace some str.split() calls by str.partition() or str.rpartition()
Since Python 2.5 str has new methods: partition and rpartition. They are more
specialized than the usual split and rsplit, and they sometimes convey the
intent of code better and also are a bit faster (faster than split/rsplit with
maxsplit specified). Let's use them in appropriate places for a small speedup.

Example performance (partition):

$ python -m timeit 'assert "apple|orange|banana".split("|")[0] == "apple"'
1000000 loops, best of 3: 0.376 usec per loop

$ python -m timeit 'assert "apple|orange|banana".split("|", 1)[0] == "apple"'
1000000 loops, best of 3: 0.327 usec per loop

$ python -m timeit 'assert "apple|orange|banana".partition("|")[0] == "apple"'
1000000 loops, best of 3: 0.214 usec per loop

Example performance (rpartition):

$ python -m timeit 'assert "apple|orange|banana".rsplit("|")[-1] == "banana"'
1000000 loops, best of 3: 0.372 usec per loop

$ python -m timeit 'assert "apple|orange|banana".rsplit("|", 1)[-1] == "banana"'
1000000 loops, best of 3: 0.332 usec per loop

$ python -m timeit 'assert "apple|orange|banana".rpartition("|")[-1] == "banana"'
1000000 loops, best of 3: 0.219 usec per loop
2015-11-02 23:37:14 +08:00
FUJIWARA Katsunori
f850c84e84 localrepo: discard objects in _filecache at transaction failure (issue4876)
'repo.invalidate()' deletes 'filecache'-ed properties by
'filecache.__delete__()' below via 'delattr(unfiltered, k)'. But
cached objects are still kept in 'repo._filecache'.

    def __delete__(self, obj):
        try:
            del obj.__dict__[self.name]
        except KeyError:
            raise AttributeError(self.name)

If 'repo' object is reused even after failure of command execution,
referring 'filecache'-ed property may reuse one kept in
'repo._filecache', even if reloading from a file is expected.

Executing command sequence on command server is a typical case of this
situation (e0a0f9ad3e4c also tried to fix this issue). For example:

  1. start a command execution

  2. 'changelog.delayupdate()' is invoked in a transaction scope

     This replaces own 'opener' by '_divertopener()' for additional
     accessing to '00changelog.i.a' (aka "pending file").

  3. transaction is aborted, and command (1) execution is ended

     After 'repo.invalidate()' at releasing store lock, changelog
     object above (= 'opener' of it is still replaced) is deleted from
     'repo.__dict__', but still kept in 'repo._filecache'.

  4. start next command execution with same 'repo'

  5. referring 'repo.changelog' may reuse changelog object kept in
     'repo._filecache' according to timestamp of '00changelog.i'

     '00changelog.i' is truncated at transaction failure (even though
     this truncation is unintentional one, as described later), and
     'st_mtime' of it is changed. But 'st_mtime' doesn't have enough
     resolution to always detect this truncation, and invalid
     changelog object kept in 'repo._filecache' is reused
     occasionally.

     Then, "No such file or directory" error occurs for
     '00changelog.i.a', which is already removed at (3).

This patch discards objects in '_filecache' other than dirstate at
transaction failure.

Changes in 'invalidate()' can't be simplified by 'self._filecache =
{}', because 'invalidate()' should keep dirstate in 'self._filecache'

'repo.invalidate()' at "hg qpush" failure is removed in this patch,
because now it is redundant.

This patch doesn't make 'repo.invalidate()' always discard objects in
'_filecache', because 'repo.invalidate()' is invoked also at unlocking
store lock.

  - "always discard objects in filecache at unlocking" may cause
    serious performance problem for subsequent procedures at normal
    execution

  - but it is impossible to "discard objects in filecache at unlocking
    only at failure", because 'releasefn' of lock can't know whether a
    lock scope is terminated normally or not

    BTW, using "with" statement described in PEP343 for lock may
    resolve this ?

After this patch, truncation of '00changelog.i' still occurs at
transaction failure, even though newly added revisions exist only in
'00changelog.i.a' and size of '00changelog.i' isn't changed by this
truncation.

Updating 'st_mtime' of '00changelog.i' implied by this redundant
truncation also affects cache behavior as described above.

This will be fixed by dropping '00changelog.i' at aborting from the
list of files to be truncated in transaction.
2015-10-24 18:58:57 +09:00
Gábor Stefanik
9c2ffda81c demandimport: fix TypeError when importing Python regex library (issue4920) 2015-10-28 16:27:09 +01:00
Pierre-Yves David
4258ec762f uescape: also encode non-printable char under 128
We were assuming everything under 128 was printable ascii, but there are a lot
of control characters in that range that can't simply be included in json and
other targets. We forcibly encode everything under 32, because they are either
control char or oddly printable (like tab or line ending).

We also add the hypothesis-powered test that caught this.
2015-11-02 11:56:59 +00:00
Gregory Szorc
059667a51c bundle2: attribute remote failures to remote (issue4788)
Before bundle2, hook output from hook failures was prefixed with
"remote: ". Up to this point with bundle2, the output was converted to
the message to print in an Abort exception. This had 2 implications:

1) It was unclear whether an error message came from the local repo
   or the remote
2) The exit code changed from 1 to 255

This patch changes the handling of error:abort bundle2 parts during push
to prefix the error message with "remote: ". This restores the old
behavior.

We still preserve the behavior of raising an Abort during bundle2
application failure. This is a regression from pre-bundle2 because the
exit code changed.

Because we no longer raise an Abort with the remote's message, we needed
to insert a message for the new Abort. So, I invented a new error
message for that. This is another change from pre-bundle2. However, I
like the new error message because it states unambiguously who aborted
the push failed, which I think is important for users so they can decide
what's next.
2015-10-24 00:39:22 +01:00
Yuya Nishihara
0ef9d443e7 help: mention alias and revsetalias in description of HGPLAINEXCEPT 2015-10-24 06:59:26 +01:00
Augie Fackler
8501cbfa05 debugrevlog: cope with empty revlog files
I have no idea where it came from, but my clone of Mercurial has an
empty filelog for `contrib/hgfixes/__init__.py` - it's *valid*, just
contains no nodes. Without this change, debugrevlog crashes with a
zero division error.
2015-10-23 11:04:53 -04:00
Augie Fackler
86f88ad861 merge: improve clarity of table in update docstring 2015-10-23 06:06:22 -04:00
Gregory Szorc
51ee0dd173 ui: support paths.default-push without paths.default set (issue4914)
This behavior regressed as part of the paths API refactoring. Previous
behavior was to accept "default-push" without "default" defined. Current
behavior aborts with "default repository not configured!." This patch
restores the old behavior and adds test coverage for the scenario, which
was absent before.
2015-10-22 18:59:03 +00:00
Matt Mackall
afeb6dfab1 bookmarks: don't allow pushing new head for existing mark with -B (issue4400) 2015-10-21 16:21:27 -05:00
timeless
ca55452b0c commands: fix help for debugobsolete 2015-10-20 18:46:00 -04:00
Sean Farley
68f4554f78 pull: all pass along extra opargs
Wihtout this patch, commands.pull silently drops opargs defeating the whole
purpose of the argument.
2015-10-19 15:47:40 -07:00
Sean Farley
4c9db86a8b push: all pass along opargs
Wihtout this patch, commands.push silently drops opargs defeating the whole
purpose of the argument.
2015-10-19 15:43:35 -07:00
timeless
d454b6c02e mail: drop python 2.5 self.sock.read workaround 2015-10-15 17:24:42 -04:00
timeless
803e780536 url: drop support for python2.5 2015-10-15 17:21:08 -04:00
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
2468be2e78 bundle2: make unbundle.compressed return True when compressed
We were returning 'False' in all cases, even when the bundle2 was actually
compressed.
2015-10-02 23:21:39 -07: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
0089eccb8e strip: pass source and url to bundle2 processing
Restoring from a 'bundle2' was missing this data.
2015-10-20 16:01:33 +02:00
Pierre-Yves David
5c189f7c9b unbundle: use 'url' argument with applybundle
This will let the hook get access to the 'url' value.
2015-10-20 15:56:22 +02:00
Pierre-Yves David
fb85c76c3c applybundle: take url as argument
We allow specifying the url to carry it to hooks. This gets us closer to
'bundle1.apply(...)' and will allow us to remove regressions in multiple place
where we forget to pass the url to hooks.
2015-10-20 15:55:04 +02:00
Pierre-Yves David
921847dc20 unbundle: use 'source' argument with applybundle
This will let the hook get access to the 'source' value.
2015-10-20 15:53:07 +02:00
Pierre-Yves David
737d464351 applybundle: take source as argument
We allow specifying the source to carry it to hooks. This gets us closer to
'bundle1.apply(...)' and will allow us to remove regressions in multiple places
where we forget to pass the source to hooks.
2015-10-20 15:52:42 +02:00
Pierre-Yves David
a8f2963ec8 applybundle: set 'bundle2=1' env for all transaction
This should be set for all bundle2 application, we enforce that at a low level.
This is for courtesy with hooks.
2015-10-20 15:48:24 +02:00
Pierre-Yves David
d58db8692b unbundle: use 'bundle2.applybundle'
This is one such place.
2015-10-20 15:47:20 +02:00
Pierre-Yves David
bffc6ff104 bundle2: introduce an "applybundle" function
There is a case where the intent is clear and the transaction is not optional. We
want to be able to alter that transaction in a wide and easy way. We cannot get
a unified '.apply(repo)' method for bundle1 and bundle2 yet because the api are
still a bit too far apart. But this is a good step forward to get the rc out.
2015-10-20 15:45:39 +02:00
Siddharth Agarwal
700ac1613d commands.resolve: conclude merge driver if no unresolved files are left
This can happen when either 'hg resolve --all' is called or a driver-resolved
file is explicitly requested.

This is done as part of 'hg resolve --all' so that users still have a chance to
test their changes before committing them.

The exact semantics here are still to be decided. This does not impact any
non-experimental features.

Thanks to Pierre-Yves David for some advice about this behavior in particular,
and merge drivers in general.
2015-10-15 01:31:04 -07:00
Siddharth Agarwal
2dafef1c48 commands.resolve: call driverpreprocess if we haven't run it yet
We need to be careful about allowing --mark and --unmark to keep working -- we
don't want the user to be stuck in a weird state. The exact behavior here is
still to be decided, though.
2015-10-15 01:27:06 -07:00