Mercurial > hg
view tests/test-narrow-expanddirstate.t @ 42054:399ed3e86a49
py2exe: add workaround to allow bundling of hgext3rd.* extensions
py2exe doesn't know how to handle namespace packages *at all*, so it treats
them like normal packages. As a result, if we try and bundle hgext3rd.evolve
in a py2exe build, it won't work if we install evolve into the virtualenv. In
order to work around this, tortoisehg installs hgext3rd.evolve etc into its
staged hg directory, since it doesn't use a virtualenv. As a workaround for us,
we'll just allow any extra packages users want bundled are part of hg during
the pseudo-install phase that py2exe uses. I'm not happy about this, but it
*works*.
As a sample of how you'd make an MSI with evolve bundled:
import os
import shutil
import subprocess
import tempfile
def stage_evolve(version):
"""Stage evolve for inclusion in py2exe binary."""
with tempfile.TemporaryDirectory() as temp:
evolve = os.path.join(temp, "evolve")
subprocess.check_call([
"hg.exe",
"clone",
"https://www.mercurial-scm.org/repo/evolve/",
"--update",
version,
evolve,
])
dest = os.path.join('..', 'hgext3rd', 'evolve')
if os.path.exists(dest):
shutil.rmtree(dest)
shutil.copytree(os.path.join(evolve, "hgext3rd", "evolve"), dest)
def main():
stage_evolve('tip')
print("\0")
print("hgext3rd")
print("hgext3rd.evolve")
print("hgext3rd.evolve.hack")
print("hgext3rd.evolve.thirdparty")
if __name__ == "__main__":
main()
is a script you can pass to the wix/build.py as --extra-packages-script,
and the resulting .msi will have an hg binary with evolve baked in. users
will still need to enable evolve in their hgrc, so you'd probably also
want to bundle configs in your msi for an enterprise environment, but that's
already easy to do with the support for extra features and wxs files in the
wix build process.
Differential Revision: https://phab.mercurial-scm.org/D6189
author | Augie Fackler <augie@google.com> |
---|---|
date | Wed, 03 Apr 2019 11:46:29 -0400 |
parents | 44a51c1c8e17 |
children | 28d5e05c139a |
line wrap: on
line source
$ . "$TESTDIR/narrow-library.sh" $ hg init master $ cd master $ mkdir inside $ echo inside > inside/f1 $ mkdir outside $ echo outside > outside/f2 $ mkdir patchdir $ echo patch_this > patchdir/f3 $ hg ci -Aqm 'initial' $ cd .. $ hg clone --narrow ssh://user@dummy/master narrow --include inside requesting all changes adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files new changesets dff6a2a6d433 updating to branch default 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd narrow $ mkdir outside $ echo other_contents > outside/f2 $ hg tracked | grep outside [1] $ hg files | grep outside [1] $ hg status `hg status` did not add outside. $ hg tracked | grep outside [1] $ hg files | grep outside [1] Unfortunately this is not really a candidate for adding to narrowhg proper, since it depends on some other source for providing the manifests (when using treemanifests) and file contents. Something like a virtual filesystem and/or remotefilelog. We want to be useful when not using those systems, so we do not have this method available in narrowhg proper at the moment. $ cat > "$TESTTMP/expand_extension.py" <<EOF > import os > import sys > > from mercurial import encoding > from mercurial import extensions > from mercurial import localrepo > from mercurial import match as matchmod > from mercurial import narrowspec > from mercurial import patch > from mercurial import util as hgutil > > narrowspecexpanded = False > def expandnarrowspec(ui, repo, newincludes=None): > if not newincludes: > return > if getattr(repo, '_narrowspecexpanded', False): > return > repo._narrowspecexpanded = True > import sys > newincludes = set([newincludes]) > includes, excludes = repo.narrowpats > currentmatcher = narrowspec.match(repo.root, includes, excludes) > includes = includes | newincludes > if not repo.currenttransaction(): > ui.develwarn(b'expandnarrowspec called outside of transaction!') > repo.setnarrowpats(includes, excludes) > narrowspec.copytoworkingcopy(repo) > newmatcher = narrowspec.match(repo.root, includes, excludes) > added = matchmod.differencematcher(newmatcher, currentmatcher) > for f in repo[b'.'].manifest().walk(added): > repo.dirstate.normallookup(f) > > def reposetup(ui, repo): > class expandingrepo(repo.__class__): > def narrowmatch(self, *args, **kwargs): > with repo.wlock(), repo.lock(), repo.transaction( > b'expandnarrowspec'): > expandnarrowspec(ui, repo, > encoding.environ.get(b'DIRSTATEINCLUDES')) > return super(expandingrepo, self).narrowmatch(*args, **kwargs) > repo.__class__ = expandingrepo > > def extsetup(unused_ui): > def overridepatch(orig, ui, repo, *args, **kwargs): > with repo.wlock(): > expandnarrowspec(ui, repo, encoding.environ.get(b'PATCHINCLUDES')) > return orig(ui, repo, *args, **kwargs) > > extensions.wrapfunction(patch, b'patch', overridepatch) > EOF $ cat >> ".hg/hgrc" <<EOF > [extensions] > expand_extension = $TESTTMP/expand_extension.py > EOF Since we do not have the ability to rely on a virtual filesystem or remotefilelog in the test, we just fake it by copying the data from the 'master' repo. $ cp -a ../master/.hg/store/data/* .hg/store/data Do that for patchdir as well. $ cp -a ../master/patchdir . `hg status` will now add outside, but not patchdir. $ DIRSTATEINCLUDES=path:outside hg status M outside/f2 $ hg tracked | grep outside I path:outside $ hg files | grep outside > /dev/null $ hg tracked | grep patchdir [1] $ hg files | grep patchdir [1] Get rid of the modification to outside/f2. $ hg update -C . 1 files updated, 0 files merged, 0 files removed, 0 files unresolved This patch will not apply cleanly at the moment, so `hg import` will break $ cat > "$TESTTMP/foo.patch" <<EOF > --- patchdir/f3 > +++ patchdir/f3 > @@ -1,1 +1,1 @@ > -this should be "patch_this", but its not, so patch fails > +this text is irrelevant > EOF $ PATCHINCLUDES=path:patchdir hg import -p0 -e "$TESTTMP/foo.patch" -m ignored applying $TESTTMP/foo.patch patching file patchdir/f3 Hunk #1 FAILED at 0 1 out of 1 hunks FAILED -- saving rejects to file patchdir/f3.rej abort: patch failed to apply [255] $ hg tracked | grep patchdir [1] $ hg files | grep patchdir > /dev/null [1] Let's make it apply cleanly and see that it *did* expand properly $ cat > "$TESTTMP/foo.patch" <<EOF > --- patchdir/f3 > +++ patchdir/f3 > @@ -1,1 +1,1 @@ > -patch_this > +patched_this > EOF $ PATCHINCLUDES=path:patchdir hg import -p0 -e "$TESTTMP/foo.patch" -m message applying $TESTTMP/foo.patch $ cat patchdir/f3 patched_this $ hg tracked | grep patchdir I path:patchdir $ hg files | grep patchdir > /dev/null