tests/test-symlink-os-yes-fs-no.py
author Gregory Szorc <gregory.szorc@gmail.com>
Tue, 11 Sep 2018 19:50:07 -0700
changeset 39604 335ae4d0a552
parent 37935 630429dcc397
child 43076 2372284d9457
permissions -rw-r--r--
bundlerepo: dynamically create repository type from base repository Previously, bundlerepository inherited from localrepo.localrepository. You simply instantiated a bundlerepository and its __init__ called localrepo.localrepository.__init__. Things were simple. Unfortunately, this strategy is limiting because it assumes that the base repository is a localrepository instance. And it assumes various properties of localrepository, such as the arguments its __init__ takes. And it prevents us from changing behavior of localrepository.__init__ without also having to change derived classes. Previous and ongoing work to abstract storage revealed these limitations. This commit changes the initialization strategy of bundle repositories to dynamically create a type to represent the repository. Instead of a static type, we instantiate a new local repo instance via localrepo.instance(). We then combine its __class__ with bundlerepository to produce a new type. This ensures that no matter how localrepo.instance() decides to create a repository object, we can derive a bundle repo object from it. i.e. localrepo.instance() could return a type that isn't a localrepository and it would "just work." Well, it would "just work" if bundlerepository's custom implementations only accessed attributes in the documented repository interface. I'm pretty sure it violates the interface contract in a handful of places. But we can worry about that another day. This change gets us closer to doing more clever things around instantiating repository instances without having to worry about teaching bundlerepository about them. .. api:: ``bundlerepo.bundlerepository`` is no longer usable on its own. The class is combined with the class of the base repository it is associated with at run-time. New bundlerepository instances can be obtained by calling ``bundlerepo.instance()`` or ``bundlerepo.makebundlerepository()``. Differential Revision: https://phab.mercurial-scm.org/D4555
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28916
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     1
from __future__ import absolute_import
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     2
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     3
import os
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     4
import sys
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     5
import time
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     6
from mercurial import (
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     7
    commands,
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
     8
    hg,
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
     9
    pycompat,
28916
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
    10
    ui as uimod,
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
    11
    util,
3b453513f1fe tests: make test-symlink-os-yes-fs-no use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 18178
diff changeset
    12
)
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    13
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    14
TESTDIR = os.environ["TESTDIR"]
14116
cd3032437064 tests: move test bundles in a bundles/ subdirectory
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11769
diff changeset
    15
BUNDLEPATH = os.path.join(TESTDIR, 'bundles', 'test-no-symlinks.hg')
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    16
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    17
# only makes sense to test on os which supports symlinks
14971
0b21ae0a2366 tests: use getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents: 14553
diff changeset
    18
if not getattr(os, "symlink", False):
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    19
    sys.exit(80) # SKIPPED_STATUS defined in run-tests.py
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    20
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 30448
diff changeset
    21
u = uimod.ui.load()
17015
73d20de5f30b tests: add missing no-outer-repo requirements
Mads Kiilerich <mads@kiilerich.com>
parents: 14971
diff changeset
    22
# hide outer repo
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    23
hg.peer(u, {}, b'.', create=True)
17015
73d20de5f30b tests: add missing no-outer-repo requirements
Mads Kiilerich <mads@kiilerich.com>
parents: 14971
diff changeset
    24
37431
5ac84b20f184 tests: use unbundle in test-symlink-os-yes-fs-no.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30559
diff changeset
    25
# unbundle with symlink support
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    26
hg.peer(u, {}, b'test0', create=True)
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    27
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    28
repo = hg.repository(u, b'test0')
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    29
commands.unbundle(u, repo, pycompat.fsencode(BUNDLEPATH), update=True)
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    30
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    31
# wait a bit, or the status call wont update the dirstate
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    32
time.sleep(1)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    33
commands.status(u, repo)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    34
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    35
# now disable symlink support -- this is what os.symlink would do on a
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    36
# non-symlink file system
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    37
def symlink_failure(src, dst):
18178
6ae45c0b4625 test-symlink-os-yes-fs-no.py: clean up use of two-argument raise
Augie Fackler <raf@durin42.com>
parents: 17015
diff changeset
    38
    raise OSError(1, "Operation not permitted")
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    39
os.symlink = symlink_failure
30448
8836f13e3c5b posix: give checklink a fast path that cache the check file and is read only
Mads Kiilerich <madski@unity3d.com>
parents: 28916
diff changeset
    40
def islink_failure(path):
8836f13e3c5b posix: give checklink a fast path that cache the check file and is read only
Mads Kiilerich <madski@unity3d.com>
parents: 28916
diff changeset
    41
    return False
8836f13e3c5b posix: give checklink a fast path that cache the check file and is read only
Mads Kiilerich <madski@unity3d.com>
parents: 28916
diff changeset
    42
os.path.islink = islink_failure
6879
24fd94ed1cc0 test symlinks on symlink-capable os but non-capable filesystem (issue1149)
Dov Feldstern <dfeldstern@fastimap.com>
parents:
diff changeset
    43
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    44
# dereference links as if a Samba server has exported this to a
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    45
# Windows client
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    46
for f in b'test0/a.lnk', b'test0/d/b.lnk':
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    47
    os.unlink(f)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    48
    fp = open(f, 'wb')
14168
135e244776f0 prevent transient leaks of file handle by using new helper functions
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 14116
diff changeset
    49
    fp.write(util.readfile(f[:-4]))
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    50
    fp.close()
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    51
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    52
# reload repository
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 30448
diff changeset
    53
u = uimod.ui.load()
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    54
repo = hg.repository(u, b'test0')
11769
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    55
commands.status(u, repo)
ca6cebd8734e dirstate: ignore symlinks when fs cannot handle them (issue1888)
Martin Geisler <mg@aragost.com>
parents: 6879
diff changeset
    56
37431
5ac84b20f184 tests: use unbundle in test-symlink-os-yes-fs-no.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30559
diff changeset
    57
# try unbundling a repo which contains symlinks
30559
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 30448
diff changeset
    58
u = uimod.ui.load()
37431
5ac84b20f184 tests: use unbundle in test-symlink-os-yes-fs-no.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30559
diff changeset
    59
37935
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    60
repo = hg.repository(u, b'test1', create=True)
630429dcc397 tests: port test-symlink-os-yes-fs-no.py to Python 3
Augie Fackler <augie@google.com>
parents: 37431
diff changeset
    61
commands.unbundle(u, repo, pycompat.fsencode(BUNDLEPATH), update=True)