def main(): ui = uimod.ui() checkobject(badpeer()) checkobject(httppeer.httppeer(ui, "http://localhost")) checkobject(localrepo.localpeer(dummyrepo())) checkobject(testingsshpeer(ui, "ssh://localhost/foo")) checkobject(bundlerepo.bundlepeer(dummyrepo()))
def testInlineRepack(self): """Verify that when fetchpacks is enabled, and the number of packfiles is over DEFAULTCACHESIZE, the refresh operation will trigger a repack, reducing the number of packfiles in the store. """ packdir = self.makeTempDir() numpacks = 20 revisionsperpack = 100 for i in range(numpacks): chain = [] revision = (str(i), self.getFakeHash(), nullid, b"content") for _ in range(revisionsperpack): chain.append(revision) revision = (str(i), self.getFakeHash(), revision[1], self.getFakeHash()) self.createPack(chain, packdir) packreader = self.datapackreader class testdatapackstore(datapackstore): DEFAULTCACHESIZE = numpacks / 2 def getpack(self, path): return packreader(path) store = testdatapackstore(uimod.ui(), packdir, True) # The first refresh should populate all the packfiles. store.refresh() self.assertEqual(len(store.packs), testdatapackstore.DEFAULTCACHESIZE) # Each packfile is made up of 2 files: the data, and the index self.assertEqual(len(os.listdir(packdir)), numpacks * 2) store.markforrefresh() # The second one should repack all the packfiles into one. store.fetchpacksenabled = True store.refresh() self.assertEqual(len(store.packs), 1) # There should only be 2 files: the packfile, and the index self.assertEqual(len(os.listdir(packdir)), 2)
def testPacksCache(self): """Test that we remember the most recent packs while fetching the delta chain.""" packdir = self.makeTempDir() deltachains = [] numpacks = 200 revisionsperpack = 100 for i in range(numpacks): chain = [] revision = (str(i), self.getFakeHash(), nullid, "content") for _ in range(revisionsperpack): chain.append(revision) revision = (str(i), self.getFakeHash(), revision[1], self.getFakeHash()) self.createPack(chain, packdir) deltachains.append(chain) class testdatapackstore(datapackstore): # Ensures that we are not keeping everything in the cache. DEFAULTCACHESIZE = numpacks / 2 store = testdatapackstore(uimod.ui(), packdir) random.shuffle(deltachains) for randomchain in deltachains: revision = random.choice(randomchain) chain = store.getdeltachain(revision[0], revision[1]) mostrecentpack = next(iter(store.packs), None) self.assertEquals( mostrecentpack.getdeltachain(revision[0], revision[1]), chain ) self.assertEquals(randomchain.index(revision) + 1, len(chain))
def setUp(self): # create a test repo location. self.tmpdir = tempfile.mkdtemp("hg-git_url-test") commands.init(ui.ui(), self.tmpdir) repo = hg.repository(ui.ui(), self.tmpdir) self.handler = GitHandler(repo, ui.ui())
#!/usr/bin/env python # Portions Copyright (c) Facebook, Inc. and its affiliates. # # This software may be used and distributed according to the terms of the # GNU General Public License version 2. # Copyright Matt Mackall <*****@*****.**> and others # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. from __future__ import absolute_import, print_function import os import sys from edenscm.hgext import traceprof from edenscm.mercurial import ui as uimod if __name__ == "__main__": sys.argv = sys.argv[1:] if not sys.argv: print("usage: traceprof.py <script> <arguments...>", file=sys.stderr) sys.exit(2) sys.path.insert(0, os.path.abspath(os.path.dirname(sys.argv[0]))) u = uimod.ui() u.setconfig("traceprof", "timethreshold", 0) with traceprof.profile(u, sys.stderr): exec(open(sys.argv[0]).read())
def testCorruptPackHandling(self): """Test that the pack store deletes corrupt packs.""" packdir = self.makeTempDir() deltachains = [] numpacks = 5 revisionsperpack = 100 firstpack = None secondindex = None for i in range(numpacks): chain = [] revision = (str(i), self.getFakeHash(), nullid, b"content") for _ in range(revisionsperpack): chain.append(revision) revision = (str(i), self.getFakeHash(), revision[1], self.getFakeHash()) pack = self.createPack(chain, packdir) if firstpack is None: firstpack = pack.packpath() elif secondindex is None: secondindex = pack.indexpath() deltachains.append(chain) ui = uimod.ui() store = datapackstore(ui, packdir, True, deletecorruptpacks=True) key = (deltachains[0][0][0], deltachains[0][0][1]) # Count packs origpackcount = len(os.listdir(packdir)) # Read key store.getdelta(*key) # Corrupt the pack os.chmod(firstpack, 0o644) f = open(firstpack, "w") f.truncate(1) f.close() # Re-create the store. Otherwise the behavior is kind of "undefined" # because the size of mmap-ed memory isn't truncated automatically, # and is filled by 0. store = datapackstore(ui, packdir, True, deletecorruptpacks=True) # Look for key again try: ui.pushbuffer(error=True) delta = store.getdelta(*key) raise RuntimeError("getdelta on corrupt key should fail %s" % repr(delta)) except KeyError: pass ui.popbuffer() # Count packs newpackcount = len(os.listdir(packdir)) # Assert the corrupt pack was removed self.assertEqual(origpackcount - 2, newpackcount) # Corrupt the index os.chmod(secondindex, 0o644) f = open(secondindex, "w") f.truncate(1) f.close() # Load the packs origpackcount = len(os.listdir(packdir)) ui.pushbuffer(error=True) store = datapackstore(ui, packdir, True, deletecorruptpacks=True) # Constructing the store doesn't load the packfiles, these are loaded # on demand, and thus the detection of bad packfiles only happen then. # Let's force a refresh to make sure the bad pack files are deleted. store.refresh() ui.popbuffer() newpackcount = len(os.listdir(packdir)) # Assert the corrupt pack was removed self.assertEqual(origpackcount - 2, newpackcount)
from __future__ import absolute_import, print_function import os from edenscm.mercurial import dispatch, ui as uimod from hghave import require # ensure errors aren't buffered testui = uimod.ui() testui.pushbuffer() testui.write(("buffered\n")) testui.warn(("warning\n")) testui.write_err("error\n") print(repr(testui.popbuffer())) # test dispatch.dispatch with the same ui object hgrc = open(os.environ["HGRCPATH"], "w") hgrc.write("[extensions]\n") hgrc.write("color=\n") hgrc.close() ui_ = uimod.ui.load() ui_.setconfig("ui", "assume-tty", "True") # we're not interested in the output, so write that to devnull ui_.fout = open(os.devnull, "wb") # call some arbitrary command just so we go through # color's wrapped _runcommand twice. def runcmd():
def __init__(self): self.ui = ui.ui()
def setUp(self): self.vfs = vfs.vfs(tempfile.mkdtemp(dir=os.getcwd()), audit=False) self.ui = ui.ui()
def __init__(self): self.ui = uimod.ui()
def __init__(self): super(badpeer, self).__init__(uimod.ui(), "http://localhost") self.badattribute = True