hgext/lfs/blobstore.py
changeset 51881 d62887764687
parent 51863 f4733654f144
equal deleted inserted replaced
51880:8f3cbea2547c 51881:d62887764687
    12 import hashlib
    12 import hashlib
    13 import json
    13 import json
    14 import os
    14 import os
    15 import re
    15 import re
    16 import socket
    16 import socket
       
    17 
       
    18 from typing import (
       
    19     Optional,
       
    20 )
    17 
    21 
    18 from mercurial.i18n import _
    22 from mercurial.i18n import _
    19 from mercurial.node import hex
    23 from mercurial.node import hex
    20 
    24 
    21 from mercurial import (
    25 from mercurial import (
    40 # 64 bytes for SHA256
    44 # 64 bytes for SHA256
    41 _lfsre = re.compile(br'\A[a-f0-9]{64}\Z')
    45 _lfsre = re.compile(br'\A[a-f0-9]{64}\Z')
    42 
    46 
    43 
    47 
    44 class lfsvfs(vfsmod.vfs):
    48 class lfsvfs(vfsmod.vfs):
    45     def join(self, path):
    49     def join(self, path: Optional[bytes], *insidef: bytes) -> bytes:
    46         """split the path at first two characters, like: XX/XXXXX..."""
    50         """split the path at first two characters, like: XX/XXXXX..."""
    47         if not _lfsre.match(path):
    51         if not _lfsre.match(path):
    48             raise error.ProgrammingError(b'unexpected lfs path: %s' % path)
    52             raise error.ProgrammingError(b'unexpected lfs path: %s' % path)
    49         return super(lfsvfs, self).join(path[0:2], path[2:])
    53         return super(lfsvfs, self).join(path[0:2], path[2:], *insidef)
    50 
    54 
    51     def walk(self, path=None, onerror=None):
    55     def walk(self, path=None, onerror=None):
    52         """Yield (dirpath, [], oids) tuple for blobs under path
    56         """Yield (dirpath, [], oids) tuple for blobs under path
    53 
    57 
    54         Oids only exist in the root of this vfs, so dirpath is always ''.
    58         Oids only exist in the root of this vfs, so dirpath is always ''.
    75 
    79 
    76 class nullvfs(lfsvfs):
    80 class nullvfs(lfsvfs):
    77     def __init__(self):
    81     def __init__(self):
    78         pass
    82         pass
    79 
    83 
    80     def exists(self, oid):
    84     def exists(self, path: Optional[bytes] = None) -> bool:
    81         return False
    85         return False
    82 
    86 
    83     def read(self, oid):
    87     def read(self, oid):
    84         # store.read() calls into here if the blob doesn't exist in its
    88         # store.read() calls into here if the blob doesn't exist in its
    85         # self.vfs.  Raise the same error as a normal vfs when asked to read a
    89         # self.vfs.  Raise the same error as a normal vfs when asked to read a
    91         )
    95         )
    92 
    96 
    93     def walk(self, path=None, onerror=None):
    97     def walk(self, path=None, onerror=None):
    94         return (b'', [], [])
    98         return (b'', [], [])
    95 
    99 
    96     def write(self, oid, data):
   100     def write(self, *args, **kwargs) -> int:
    97         pass
   101         return 0
    98 
   102 
    99 
   103 
   100 class lfsuploadfile(httpconnectionmod.httpsendfile):
   104 class lfsuploadfile(httpconnectionmod.httpsendfile):
   101     """a file-like object that supports keepalive."""
   105     """a file-like object that supports keepalive."""
   102 
   106