hgext/largefiles/proto.py
author Pierre-Yves David <pierre-yves.david@logilab.fr>
Thu, 18 Apr 2013 15:22:24 +0200
changeset 19047 81de87f8b480
parent 19009 07e40d589b64
child 19917 cff331cbb5ee
permissions -rw-r--r--
histedit: protect against duplicated entries Before this change one would issue rules with duplicated entries. For this to happen some other changeset had to be missing to maintain the rules length.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     1
# Copyright 2011 Fog Creek Software
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     2
#
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     3
# This software may be used and distributed according to the terms of the
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     4
# GNU General Public License version 2 or any later version.
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     5
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     6
import os
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     7
import urllib2
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
     8
17192
1ac628cd7113 peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 17127
diff changeset
     9
from mercurial import error, httppeer, util, wireproto
17127
9e1616307c4c largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16594
diff changeset
    10
from mercurial.wireproto import batchable, future
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    11
from mercurial.i18n import _
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    12
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    13
import lfutil
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    14
15255
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
    15
LARGEFILES_REQUIRED_MSG = ('\nThis repository uses the largefiles extension.'
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
    16
                           '\n\nPlease enable it in your Mercurial config '
7ab05d752405 largefiles: cosmetics, whitespace, code style
Greg Ward <greg@gerg.ca>
parents: 15252
diff changeset
    17
                           'file.\n')
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    18
18922
d2c4d37f7db5 largefiles: quiet (and document) undefined name errors (issue3886)
Bryan O'Sullivan <bryano@fb.com>
parents: 18488
diff changeset
    19
# these will all be replaced by largefiles.uisetup
d2c4d37f7db5 largefiles: quiet (and document) undefined name errors (issue3886)
Bryan O'Sullivan <bryano@fb.com>
parents: 18488
diff changeset
    20
capabilitiesorig = None
d2c4d37f7db5 largefiles: quiet (and document) undefined name errors (issue3886)
Bryan O'Sullivan <bryano@fb.com>
parents: 18488
diff changeset
    21
ssholdcallstream = None
d2c4d37f7db5 largefiles: quiet (and document) undefined name errors (issue3886)
Bryan O'Sullivan <bryano@fb.com>
parents: 18488
diff changeset
    22
httpoldcallstream = None
d2c4d37f7db5 largefiles: quiet (and document) undefined name errors (issue3886)
Bryan O'Sullivan <bryano@fb.com>
parents: 18488
diff changeset
    23
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    24
def putlfile(repo, proto, sha):
15317
41f371150ccb largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15316
diff changeset
    25
    '''Put a largefile into a repository's local store and into the
41f371150ccb largefiles: make the store primary, and the user cache secondary
Benjamin Pollack <benjamin@bitquabit.com>
parents: 15316
diff changeset
    26
    user cache.'''
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    27
    proto.redirect()
15391
a5a6a9b7f3b9 largefiles: replace tempfile.NamedTemporaryFile with tempfile.mkstemp
Hao Lian <hao@fogcreek.com>
parents: 15317
diff changeset
    28
16594
5516fdf3fe24 largefiles: in putlfile, ensure tempfile's directory exists prior to creation
hlian
parents: 16247
diff changeset
    29
    path = lfutil.storepath(repo, sha)
5516fdf3fe24 largefiles: in putlfile, ensure tempfile's directory exists prior to creation
hlian
parents: 16247
diff changeset
    30
    util.makedirs(os.path.dirname(path))
5516fdf3fe24 largefiles: in putlfile, ensure tempfile's directory exists prior to creation
hlian
parents: 16247
diff changeset
    31
    tmpfp = util.atomictempfile(path, createmode=repo.store.createmode)
5516fdf3fe24 largefiles: in putlfile, ensure tempfile's directory exists prior to creation
hlian
parents: 16247
diff changeset
    32
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    33
    try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    34
        try:
15391
a5a6a9b7f3b9 largefiles: replace tempfile.NamedTemporaryFile with tempfile.mkstemp
Hao Lian <hao@fogcreek.com>
parents: 15317
diff changeset
    35
            proto.getfile(tmpfp)
16155
1b2b42e866be largefiles: respect store.createmode and avoid extra file copy
Martin Geisler <mg@aragost.com>
parents: 15778
diff changeset
    36
            tmpfp._fp.seek(0)
1b2b42e866be largefiles: respect store.createmode and avoid extra file copy
Martin Geisler <mg@aragost.com>
parents: 15778
diff changeset
    37
            if sha != lfutil.hexsha1(tmpfp._fp):
15778
f15c646bffc7 largefiles: display remote errors from putlfile (issue3123) (issue3149)
Kevin Gessner <kevin@fogcreek.com>
parents: 15391
diff changeset
    38
                raise IOError(0, _('largefile contents do not match hash'))
15391
a5a6a9b7f3b9 largefiles: replace tempfile.NamedTemporaryFile with tempfile.mkstemp
Hao Lian <hao@fogcreek.com>
parents: 15317
diff changeset
    39
            tmpfp.close()
16155
1b2b42e866be largefiles: respect store.createmode and avoid extra file copy
Martin Geisler <mg@aragost.com>
parents: 15778
diff changeset
    40
            lfutil.linktousercache(repo, sha)
15391
a5a6a9b7f3b9 largefiles: replace tempfile.NamedTemporaryFile with tempfile.mkstemp
Hao Lian <hao@fogcreek.com>
parents: 15317
diff changeset
    41
        except IOError, e:
15778
f15c646bffc7 largefiles: display remote errors from putlfile (issue3123) (issue3149)
Kevin Gessner <kevin@fogcreek.com>
parents: 15391
diff changeset
    42
            repo.ui.warn(_('largefiles: failed to put %s into store: %s') %
f15c646bffc7 largefiles: display remote errors from putlfile (issue3123) (issue3149)
Kevin Gessner <kevin@fogcreek.com>
parents: 15391
diff changeset
    43
                         (sha, e.strerror))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    44
            return wireproto.pushres(1)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    45
    finally:
16155
1b2b42e866be largefiles: respect store.createmode and avoid extra file copy
Martin Geisler <mg@aragost.com>
parents: 15778
diff changeset
    46
        tmpfp.discard()
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    47
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    48
    return wireproto.pushres(0)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    49
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    50
def getlfile(repo, proto, sha):
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
    51
    '''Retrieve a largefile from the repository-local cache or system
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
    52
    cache.'''
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    53
    filename = lfutil.findfile(repo, sha)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    54
    if not filename:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    55
        raise util.Abort(_('requested largefile %s not present in cache') % sha)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    56
    f = open(filename, 'rb')
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    57
    length = os.fstat(f.fileno())[6]
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
    58
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
    59
    # Since we can't set an HTTP content-length header here, and
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
    60
    # Mercurial core provides no way to give the length of a streamres
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
    61
    # (and reading the entire file into RAM would be ill-advised), we
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
    62
    # just send the length on the first line of the response, like the
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
    63
    # ssh proto does for string responses.
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    64
    def generator():
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    65
        yield '%d\n' % length
19009
07e40d589b64 largefiles: use filechunkiter for iterating largefile when serving getlfile
Mads Kiilerich <madski@unity3d.com>
parents: 19006
diff changeset
    66
        for chunk in util.filechunkiter(f):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    67
            yield chunk
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    68
    return wireproto.streamres(generator())
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    69
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    70
def statlfile(repo, proto, sha):
18488
a977b42df8b3 largefiles: don't verify largefile hashes on servers when processing statlfile
Mads Kiilerich <madski@unity3d.com>
parents: 18298
diff changeset
    71
    '''Return '2\n' if the largefile is missing, '0\n' if it seems to be in
a977b42df8b3 largefiles: don't verify largefile hashes on servers when processing statlfile
Mads Kiilerich <madski@unity3d.com>
parents: 18298
diff changeset
    72
    good condition.
a977b42df8b3 largefiles: don't verify largefile hashes on servers when processing statlfile
Mads Kiilerich <madski@unity3d.com>
parents: 18298
diff changeset
    73
a977b42df8b3 largefiles: don't verify largefile hashes on servers when processing statlfile
Mads Kiilerich <madski@unity3d.com>
parents: 18298
diff changeset
    74
    The value 1 is reserved for mismatched checksum, but that is too expensive
a977b42df8b3 largefiles: don't verify largefile hashes on servers when processing statlfile
Mads Kiilerich <madski@unity3d.com>
parents: 18298
diff changeset
    75
    to be verified on every stat and must be caught be running 'hg verify'
a977b42df8b3 largefiles: don't verify largefile hashes on servers when processing statlfile
Mads Kiilerich <madski@unity3d.com>
parents: 18298
diff changeset
    76
    server side.'''
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    77
    filename = lfutil.findfile(repo, sha)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    78
    if not filename:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    79
        return '2\n'
18488
a977b42df8b3 largefiles: don't verify largefile hashes on servers when processing statlfile
Mads Kiilerich <madski@unity3d.com>
parents: 18298
diff changeset
    80
    return '0\n'
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    81
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    82
def wirereposetup(ui, repo):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    83
    class lfileswirerepository(repo.__class__):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    84
        def putlfile(self, sha, fd):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    85
            # unfortunately, httprepository._callpush tries to convert its
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    86
            # input file-like into a bundle before sending it, so we can't use
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    87
            # it ...
17192
1ac628cd7113 peer: introduce real peer classes
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 17127
diff changeset
    88
            if issubclass(self.__class__, httppeer.httppeer):
15778
f15c646bffc7 largefiles: display remote errors from putlfile (issue3123) (issue3149)
Kevin Gessner <kevin@fogcreek.com>
parents: 15391
diff changeset
    89
                res = None
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    90
                try:
15778
f15c646bffc7 largefiles: display remote errors from putlfile (issue3123) (issue3149)
Kevin Gessner <kevin@fogcreek.com>
parents: 15391
diff changeset
    91
                    res = self._call('putlfile', data=fd, sha=sha,
f15c646bffc7 largefiles: display remote errors from putlfile (issue3123) (issue3149)
Kevin Gessner <kevin@fogcreek.com>
parents: 15391
diff changeset
    92
                        headers={'content-type':'application/mercurial-0.1'})
f15c646bffc7 largefiles: display remote errors from putlfile (issue3123) (issue3149)
Kevin Gessner <kevin@fogcreek.com>
parents: 15391
diff changeset
    93
                    d, output = res.split('\n', 1)
f15c646bffc7 largefiles: display remote errors from putlfile (issue3123) (issue3149)
Kevin Gessner <kevin@fogcreek.com>
parents: 15391
diff changeset
    94
                    for l in output.splitlines(True):
f15c646bffc7 largefiles: display remote errors from putlfile (issue3123) (issue3149)
Kevin Gessner <kevin@fogcreek.com>
parents: 15391
diff changeset
    95
                        self.ui.warn(_('remote: '), l, '\n')
f15c646bffc7 largefiles: display remote errors from putlfile (issue3123) (issue3149)
Kevin Gessner <kevin@fogcreek.com>
parents: 15391
diff changeset
    96
                    return int(d)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    97
                except (ValueError, urllib2.HTTPError):
15778
f15c646bffc7 largefiles: display remote errors from putlfile (issue3123) (issue3149)
Kevin Gessner <kevin@fogcreek.com>
parents: 15391
diff changeset
    98
                    self.ui.warn(_('unexpected putlfile response: %s') % res)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
    99
                    return 1
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   100
            # ... but we can't use sshrepository._call because the data=
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   101
            # argument won't get sent, and _callpush does exactly what we want
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   102
            # in this case: send the data straight through
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   103
            else:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   104
                try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   105
                    ret, output = self._callpush("putlfile", fd, sha=sha)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   106
                    if ret == "":
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   107
                        raise error.ResponseError(_('putlfile failed:'),
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   108
                                output)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   109
                    return int(ret)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   110
                except IOError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   111
                    return 1
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   112
                except ValueError:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   113
                    raise error.ResponseError(
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   114
                        _('putlfile failed (unexpected response):'), ret)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   115
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   116
        def getlfile(self, sha):
19004
6614e5e24e66 largefiles: move protocol conversion into getlfile and make it an iterable
Mads Kiilerich <madski@unity3d.com>
parents: 18922
diff changeset
   117
            """returns an iterable with the chunks of the file with sha sha"""
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   118
            stream = self._callstream("getlfile", sha=sha)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   119
            length = stream.readline()
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   120
            try:
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   121
                length = int(length)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   122
            except ValueError:
15170
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
   123
                self._abort(error.ResponseError(_("unexpected response:"),
c1a4a3220711 largefiles: fix over-long lines
Matt Mackall <mpm@selenic.com>
parents: 15168
diff changeset
   124
                                                length))
19004
6614e5e24e66 largefiles: move protocol conversion into getlfile and make it an iterable
Mads Kiilerich <madski@unity3d.com>
parents: 18922
diff changeset
   125
19005
1b84047e7d16 largefiles: drop limitreader, use filechunkiter limit
Mads Kiilerich <madski@unity3d.com>
parents: 19004
diff changeset
   126
            # SSH streams will block if reading more than length
1b84047e7d16 largefiles: drop limitreader, use filechunkiter limit
Mads Kiilerich <madski@unity3d.com>
parents: 19004
diff changeset
   127
            for chunk in util.filechunkiter(stream, 128 * 1024, length):
19004
6614e5e24e66 largefiles: move protocol conversion into getlfile and make it an iterable
Mads Kiilerich <madski@unity3d.com>
parents: 18922
diff changeset
   128
                yield chunk
19006
0b3b84222a2d largefiles: getlfile must hit end of HTTP chunked streams to reuse connections
Mads Kiilerich <madski@unity3d.com>
parents: 19005
diff changeset
   129
            # HTTP streams must hit the end to process the last empty
0b3b84222a2d largefiles: getlfile must hit end of HTTP chunked streams to reuse connections
Mads Kiilerich <madski@unity3d.com>
parents: 19005
diff changeset
   130
            # chunk of Chunked-Encoding so the connection can be reused.
0b3b84222a2d largefiles: getlfile must hit end of HTTP chunked streams to reuse connections
Mads Kiilerich <madski@unity3d.com>
parents: 19005
diff changeset
   131
            if issubclass(self.__class__, httppeer.httppeer):
0b3b84222a2d largefiles: getlfile must hit end of HTTP chunked streams to reuse connections
Mads Kiilerich <madski@unity3d.com>
parents: 19005
diff changeset
   132
                chunk = stream.read(1)
0b3b84222a2d largefiles: getlfile must hit end of HTTP chunked streams to reuse connections
Mads Kiilerich <madski@unity3d.com>
parents: 19005
diff changeset
   133
                if chunk:
0b3b84222a2d largefiles: getlfile must hit end of HTTP chunked streams to reuse connections
Mads Kiilerich <madski@unity3d.com>
parents: 19005
diff changeset
   134
                    self._abort(error.ResponseError(_("unexpected response:"),
0b3b84222a2d largefiles: getlfile must hit end of HTTP chunked streams to reuse connections
Mads Kiilerich <madski@unity3d.com>
parents: 19005
diff changeset
   135
                                                    chunk))
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   136
17127
9e1616307c4c largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16594
diff changeset
   137
        @batchable
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   138
        def statlfile(self, sha):
17127
9e1616307c4c largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16594
diff changeset
   139
            f = future()
9e1616307c4c largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16594
diff changeset
   140
            result = {'sha': sha}
9e1616307c4c largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16594
diff changeset
   141
            yield result, f
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   142
            try:
17127
9e1616307c4c largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16594
diff changeset
   143
                yield int(f.value)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   144
            except (ValueError, urllib2.HTTPError):
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
   145
                # If the server returns anything but an integer followed by a
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   146
                # newline, newline, it's not speaking our language; if we get
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   147
                # an HTTP error, we can't be sure the largefile is present;
15252
6e809bb4f969 largefiles: improve comments, internal docstrings
Greg Ward <greg@gerg.ca>
parents: 15224
diff changeset
   148
                # either way, consider it missing.
17127
9e1616307c4c largefiles: batch statlfile requests when pushing a largefiles repo (issue3386)
Na'Tosha Bard <natosha@unity3d.com>
parents: 16594
diff changeset
   149
                yield 2
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   150
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   151
    repo.__class__ = lfileswirerepository
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   152
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   153
# advertise the largefiles=serve capability
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   154
def capabilities(repo, proto):
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16155
diff changeset
   155
    return capabilitiesorig(repo, proto) + ' largefiles=serve'
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   156
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   157
def heads(repo, proto):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   158
    if lfutil.islfilesrepo(repo):
15224
7c604d8c7e83 largefiles: remove pre-1.9 code from extension first bundled with 1.9
Na'Tosha Bard <natosha@unity3d.com>
parents: 15170
diff changeset
   159
        return wireproto.ooberror(LARGEFILES_REQUIRED_MSG)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   160
    return wireproto.heads(repo, proto)
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   161
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16155
diff changeset
   162
def sshrepocallstream(self, cmd, **args):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   163
    if cmd == 'heads' and self.capable('largefiles'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   164
        cmd = 'lheads'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   165
    if cmd == 'batch' and self.capable('largefiles'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   166
        args['cmds'] = args['cmds'].replace('heads ', 'lheads ')
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16155
diff changeset
   167
    return ssholdcallstream(self, cmd, **args)
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   168
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16155
diff changeset
   169
def httprepocallstream(self, cmd, **args):
15168
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   170
    if cmd == 'heads' and self.capable('largefiles'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   171
        cmd = 'lheads'
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   172
    if cmd == 'batch' and self.capable('largefiles'):
cfccd3bee7b3 hgext: add largefiles extension
various
parents:
diff changeset
   173
        args['cmds'] = args['cmds'].replace('heads ', 'lheads ')
16247
d87d9d8a8e03 largefiles: remove use of underscores that breaks coding convention
Na'Tosha Bard <natosha@unity3d.com>
parents: 16155
diff changeset
   174
    return httpoldcallstream(self, cmd, **args)