subrepo: make "_sanitize()" work

"_sanitize()" was introduced by 224e96078708 on "stable" branch, but
it has done nothing for sanitizing since 224e96078708.

"_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".

--HG--
branch : stable
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.

--HG--
branch : stable
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.

--HG--
branch : stable
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.

--HG--
branch : stable
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 fccd350acf79.

This patch introduces "pathutil.normasprefix" to normalize specified
path in the specific way for problematic encodings without regression
around issue3033.

--HG--
branch : stable
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.

--HG--
branch : stable
tests: fix cut and paste error on encoding alignment test

--HG--
branch : stable
bookmarks: properly align multi-byte characters

--HG--
branch : stable
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.

--HG--
branch : stable
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 750c7c14a637

--HG--
branch : stable
exchange: propagate arguments to the _getbundleextrapart function

The arguments was wrongly propagated (again).

This a backport of 0055b5b3eb9c

--HG--
branch : stable
exchange: fix bad indentation

Those two lines where double indented for no good reasons.

This is backport of 71931b789424.

--HG--
branch : stable
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 ab5040cd5749.

--HG--
branch : stable