hgext/largefiles/uisetup.py
author Greg Ward <greg@gerg.ca>
Thu, 20 Oct 2011 22:24:24 -0400
branchstable
changeset 15330 1e6fcce4aab3
parent 15295 bd9405551ad4
child 15349 63455eb771af
permissions -rw-r--r--
largefiles: use smaller files in test script
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     1
# Copyright 2009-2010 Gregory P. Ward
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     2
# Copyright 2009-2010 Intelerad Medical Systems Incorporated
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     3
# Copyright 2010-2011 Fog Creek Software
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     4
# Copyright 2010-2011 Unity Technologies
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     5
#
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     6
# This software may be used and distributed according to the terms of the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     7
# GNU General Public License version 2 or any later version.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     8
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     9
'''setup for largefiles extension: uisetup'''
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    10
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    11
from mercurial import archival, cmdutil, commands, extensions, filemerge, hg, \
15188
8e115063950d largefiles: don't break existing tests (syntax error, bad imports)
Greg Ward <greg@gerg.ca>
parents: 15170
diff changeset
    12
    httprepo, localrepo, sshrepo, sshserver, util, wireproto
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    13
from mercurial.i18n import _
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    14
from mercurial.hgweb import hgweb_mod, protocol
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    15
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    16
import overrides
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    17
import proto
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    18
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    19
def uisetup(ui):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    20
    # Disable auto-status for some commands which assume that all
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    21
    # files in the result are under Mercurial's control
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    22
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    23
    entry = extensions.wrapcommand(commands.table, 'add',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    24
                                   overrides.override_add)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    25
    addopt = [('', 'large', None, _('add as largefile')),
15295
bd9405551ad4 largefiles: fix typo
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 15254
diff changeset
    26
            ('', 'lfsize', '', _('add all files above this size (in megabytes) '
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    27
                                 'as largefiles (default: 10)'))]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    28
    entry[1].extend(addopt)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    29
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    30
    entry = extensions.wrapcommand(commands.table, 'addremove',
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    31
            overrides.override_addremove)
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    32
    entry = extensions.wrapcommand(commands.table, 'remove',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    33
                                   overrides.override_remove)
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    34
    entry = extensions.wrapcommand(commands.table, 'forget',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    35
                                   overrides.override_forget)
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    36
    entry = extensions.wrapcommand(commands.table, 'status',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    37
                                   overrides.override_status)
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    38
    entry = extensions.wrapcommand(commands.table, 'log',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    39
                                   overrides.override_log)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    40
    entry = extensions.wrapcommand(commands.table, 'rollback',
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    41
                                   overrides.override_rollback)
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    42
    entry = extensions.wrapcommand(commands.table, 'verify',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    43
                                   overrides.override_verify)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    44
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    45
    verifyopt = [('', 'large', None, _('verify largefiles')),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    46
                 ('', 'lfa', None,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    47
                     _('verify all revisions of largefiles not just current')),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    48
                 ('', 'lfc', None,
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    49
                     _('verify largefile contents not just existence'))]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    50
    entry[1].extend(verifyopt)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    51
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    52
    entry = extensions.wrapcommand(commands.table, 'outgoing',
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    53
        overrides.override_outgoing)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    54
    outgoingopt = [('', 'large', None, _('display outgoing largefiles'))]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    55
    entry[1].extend(outgoingopt)
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    56
    entry = extensions.wrapcommand(commands.table, 'summary',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    57
                                   overrides.override_summary)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    58
    summaryopt = [('', 'large', None, _('display outgoing largefiles'))]
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    59
    entry[1].extend(summaryopt)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    60
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    61
    entry = extensions.wrapcommand(commands.table, 'update',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    62
                                   overrides.override_update)
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    63
    entry = extensions.wrapcommand(commands.table, 'pull',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    64
                                   overrides.override_pull)
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    65
    entry = extensions.wrapfunction(filemerge, 'filemerge',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    66
                                    overrides.override_filemerge)
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    67
    entry = extensions.wrapfunction(cmdutil, 'copy',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    68
                                    overrides.override_copy)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    69
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    70
    # Backout calls revert so we need to override both the command and the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    71
    # function
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    72
    entry = extensions.wrapcommand(commands.table, 'revert',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    73
                                   overrides.override_revert)
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    74
    entry = extensions.wrapfunction(commands, 'revert',
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15169
diff changeset
    75
                                    overrides.override_revert)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    76
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    77
    # clone uses hg._update instead of hg.update even though they are the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    78
    # same function... so wrap both of them)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    79
    extensions.wrapfunction(hg, 'update', overrides.hg_update)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    80
    extensions.wrapfunction(hg, '_update', overrides.hg_update)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    81
    extensions.wrapfunction(hg, 'clean', overrides.hg_clean)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    82
    extensions.wrapfunction(hg, 'merge', overrides.hg_merge)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    83
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    84
    extensions.wrapfunction(archival, 'archive', overrides.override_archive)
15169
aa262fff87ac largefile: fix up hasattr usage
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
    85
    if util.safehasattr(cmdutil, 'bailifchanged'):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    86
        extensions.wrapfunction(cmdutil, 'bailifchanged',
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    87
            overrides.override_bailifchanged)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    88
    else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    89
        extensions.wrapfunction(cmdutil, 'bail_if_changed',
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    90
            overrides.override_bailifchanged)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    91
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    92
    # create the new wireproto commands ...
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    93
    wireproto.commands['putlfile'] = (proto.putlfile, 'sha')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    94
    wireproto.commands['getlfile'] = (proto.getlfile, 'sha')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    95
    wireproto.commands['statlfile'] = (proto.statlfile, 'sha')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    96
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    97
    # ... and wrap some existing ones
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    98
    wireproto.commands['capabilities'] = (proto.capabilities, '')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    99
    wireproto.commands['heads'] = (proto.heads, '')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   100
    wireproto.commands['lheads'] = (wireproto.heads, '')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   101
15254
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
   102
    # make putlfile behave the same as push and {get,stat}lfile behave
dd03d3a9f888 largefiles: more work on cleaning up comments
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
   103
    # the same as pull w.r.t. permissions checks
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   104
    hgweb_mod.perms['putlfile'] = 'push'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   105
    hgweb_mod.perms['getlfile'] = 'pull'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   106
    hgweb_mod.perms['statlfile'] = 'pull'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   107
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   108
    # the hello wireproto command uses wireproto.capabilities, so it won't see
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   109
    # our largefiles capability unless we replace the actual function as well.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   110
    proto.capabilities_orig = wireproto.capabilities
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   111
    wireproto.capabilities = proto.capabilities
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   112
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15188
diff changeset
   113
    # these let us reject non-largefiles clients and make them display
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15188
diff changeset
   114
    # our error messages
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   115
    protocol.webproto.refuseclient = proto.webproto_refuseclient
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   116
    sshserver.sshserver.refuseclient = proto.sshproto_refuseclient
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   117
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   118
    # can't do this in reposetup because it needs to have happened before
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   119
    # wirerepo.__init__ is called
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   120
    proto.ssh_oldcallstream = sshrepo.sshrepository._callstream
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   121
    proto.http_oldcallstream = httprepo.httprepository._callstream
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   122
    sshrepo.sshrepository._callstream = proto.sshrepo_callstream
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   123
    httprepo.httprepository._callstream = proto.httprepo_callstream
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   124
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   125
    # don't die on seeing a repo with the largefiles requirement
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   126
    localrepo.localrepository.supported |= set(['largefiles'])
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   127
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   128
    # override some extensions' stuff as well
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   129
    for name, module in extensions.extensions():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   130
        if name == 'fetch':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   131
            extensions.wrapcommand(getattr(module, 'cmdtable'), 'fetch',
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   132
                overrides.override_fetch)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   133
        if name == 'purge':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   134
            extensions.wrapcommand(getattr(module, 'cmdtable'), 'purge',
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   135
                overrides.override_purge)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   136
        if name == 'rebase':
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   137
            extensions.wrapcommand(getattr(module, 'cmdtable'), 'rebase',
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   138
                overrides.override_rebase)