addbackup: use the vfs for the backup destination too

The backup file location was always computed using the opener, bypassing the
'location' setting. (And making the feature broken.)
addbackup: handle file in subdirectory

The current naming scheme ('journal.backups.<file>') resulted is bad directory
name when 'file' was in a subdirectory. We now extract the directory name and
create the backupfile within it.

We plan to use file in a subdirectory for cachefile.
transaction: use 'location' instead of 'vfs' in the addbackup method

This unlock the backup of file outside of store (eg: bookmarks).
transaction: use 'location' instead of 'vfs' objects for file generation

The argument is now a location name. The location must be present in the
'vfsmap' provided to the transaction at creation time.
transaction: drop special handling for phases and bookmarks generation

We are still doing double backups, but now that we have proper
location handling this is less of an issue. Dropping this simplifies
the code before we add some pending-related logic.

This also ensures we actually test the new 'location' mechanism.
merge: drop underscore prefix from _checkunknown()

The method has been called from commands.py since 3eab42088be4
(update: just merge unknown file collisions, 2012-02-09), so drop the
underscore prefix that suggests that it's private.
manifestmerge: use already existing fl2 synonym for m2.flags(f)

Probably not a noticeable performance gain, but shortens the code
slightly.
revset.only: use cl.findmissingrevs

ancestor.missingancestors is really an implementation detail.
cmdserver: use given streams as pipe channels like other commands

Because commandserver itself is an hg subcommand, it shouldn't use stdio
directly in principle.
cmdserver: postpone creation of pipe server until run()

This makes it easy to swap file descriptors while running command server.
cmdserver: protect pipe server streams against corruption caused by direct io

Because pipe-mode server uses stdio as IPC channel, other modules should not
touch stdio directly and use ui instead.  However, this strategy is brittle
because several Python functions read and write stdio implicitly.

    print 'hello'  # should use ui.write()
    # => ch = 'h', size = 1701604463 'ello', data = '\n'

This patch adds protection for such mistakes.  Both stdio files and low-level
file descriptors are redirected to /dev/null while command server uses them.
remove: recurse into subrepositories with --subrepos/-S flag

Like 'forget', git and svn subrepos are currently not supported.  Unfortunately
the name 'remove' is already used in the subrepo classes, so we break the
convention of naming the subrepo function after the command.
remove: support remove with explicit paths in subrepos
remove: avoid a bogus warning about no tracked files when removing '.'

Previously, any files relative to the root of the repo that match the -I
patterns would be deleted, but the command exited with 1 after printing a
warning:

   $ hg remove -S -I 're:.*.txt' .
   removing sub1/sub2/folder/test.txt
   removing sub1/sub2/test.txt
   not removing .: no tracked files
ancestor.lazyancestors: take parentrevs function rather than changelog

Principle of least privilege, and it also brings this in line with
missingancestors.
test-ancestor: test iteration for lazyancestors

This has some test coverage in test-revlog-ancestry.py, but not very much.
test-ancestor: define a main function

We're going to add to it in upcoming patches.
test-ancestor: use random testing for missing ancestors

We're going to make changes to the missing ancestor algorithm, and random
testing will give us much more confidence than a fixed set of tests.
ancestor.missingancestors: don't discard from basesvisit

We only actually care about whether revsvisit is empty, so we can let
basesvisit grow to arbitrary size.

It turns out that this actually helps performance. For a large repo with
hundreds of thousands of commits, hg perfrevset 'only(0, tip)' (basically the
worst case, involving a full DAG traversal) goes from 1.63 seconds to 1.50. hg
perfrevset 'only(tip, 0)' remains unchanged at 1.98 seconds.
ancestor.missingancestors: calculate start point after filtering revsvisit

Any revs that are filtered out are also in basesvisit, which means they
wouldn't be returned in the missing list anyway. There's no need to explore
such revs or their ancestors.

The 'if not revsvisit' check moves down because we can't call max() on an empty
set.