comparison mercurial/debugcommands.py @ 35562:6580cf751418

debug: add a 'debugdownload' command This command resolve and fetch and URL through the Mercurial logic. Mercurial logic add various headers (including authentication) while resolving an URL so the commands helps with building the same request Mercurial would be doing. A new test file is created because we'll add more logic regarding Mercurial download logic and it will grow to a reasonable size.
author Boris Feld <boris.feld@octobus.net>
date Fri, 15 Dec 2017 09:30:16 +0100
parents 5880318624c9
children 35fb3367f72d
comparison
equal deleted inserted replaced
35561:4c3a4bb31c0e 35562:6580cf751418
67 sslutil, 67 sslutil,
68 streamclone, 68 streamclone,
69 templater, 69 templater,
70 treediscovery, 70 treediscovery,
71 upgrade, 71 upgrade,
72 url as urlmod,
72 util, 73 util,
73 vfs as vfsmod, 74 vfs as vfsmod,
74 ) 75 )
75 76
76 release = lockmod.release 77 release = lockmod.release
783 ui.write(("remote is subset\n")) 784 ui.write(("remote is subset\n"))
784 785
785 remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, revs=None) 786 remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, revs=None)
786 localrevs = opts['rev'] 787 localrevs = opts['rev']
787 doit(localrevs, remoterevs) 788 doit(localrevs, remoterevs)
789
790 _chunksize = 4 << 10
791
792 @command('debugdownload',
793 [
794 ('o', 'output', '', _('path')),
795 ],
796 norepo=True)
797 def debugdownload(ui, url, output=None, **opts):
798 """download a resource using Mercurial logic and config
799 """
800 fh = urlmod.open(ui, url, output)
801
802 dest = ui
803 if output:
804 dest = open(output, "wb", _chunksize)
805 try:
806 data = fh.read(_chunksize)
807 while data:
808 dest.write(data)
809 data = fh.read(_chunksize)
810 finally:
811 if output:
812 dest.close()
788 813
789 @command('debugextensions', cmdutil.formatteropts, [], norepo=True) 814 @command('debugextensions', cmdutil.formatteropts, [], norepo=True)
790 def debugextensions(ui, **opts): 815 def debugextensions(ui, **opts):
791 '''show information about active extensions''' 816 '''show information about active extensions'''
792 opts = pycompat.byteskwargs(opts) 817 opts = pycompat.byteskwargs(opts)