hgext/largefiles/remotestore.py
changeset 43077 687b865b95ad
parent 43076 2372284d9457
child 43105 649d3ac37a12
equal deleted inserted replaced
43076:2372284d9457 43077:687b865b95ad
    36             self._lstore = localstore.localstore(self.ui, self.repo, self.repo)
    36             self._lstore = localstore.localstore(self.ui, self.repo, self.repo)
    37 
    37 
    38     def put(self, source, hash):
    38     def put(self, source, hash):
    39         if self.sendfile(source, hash):
    39         if self.sendfile(source, hash):
    40             raise error.Abort(
    40             raise error.Abort(
    41                 _('remotestore: could not put %s to remote store %s')
    41                 _(b'remotestore: could not put %s to remote store %s')
    42                 % (source, util.hidepassword(self.url))
    42                 % (source, util.hidepassword(self.url))
    43             )
    43             )
    44         self.ui.debug(
    44         self.ui.debug(
    45             _('remotestore: put %s to remote store %s\n')
    45             _(b'remotestore: put %s to remote store %s\n')
    46             % (source, util.hidepassword(self.url))
    46             % (source, util.hidepassword(self.url))
    47         )
    47         )
    48 
    48 
    49     def exists(self, hashes):
    49     def exists(self, hashes):
    50         return dict(
    50         return dict(
    51             (h, s == 0)
    51             (h, s == 0)
    52             for (h, s) in self._stat(hashes).iteritems()  # dict-from-generator
    52             for (h, s) in self._stat(hashes).iteritems()  # dict-from-generator
    53         )
    53         )
    54 
    54 
    55     def sendfile(self, filename, hash):
    55     def sendfile(self, filename, hash):
    56         self.ui.debug('remotestore: sendfile(%s, %s)\n' % (filename, hash))
    56         self.ui.debug(b'remotestore: sendfile(%s, %s)\n' % (filename, hash))
    57         try:
    57         try:
    58             with lfutil.httpsendfile(self.ui, filename) as fd:
    58             with lfutil.httpsendfile(self.ui, filename) as fd:
    59                 return self._put(hash, fd)
    59                 return self._put(hash, fd)
    60         except IOError as e:
    60         except IOError as e:
    61             raise error.Abort(
    61             raise error.Abort(
    62                 _('remotestore: could not open file %s: %s')
    62                 _(b'remotestore: could not open file %s: %s')
    63                 % (filename, stringutil.forcebytestr(e))
    63                 % (filename, stringutil.forcebytestr(e))
    64             )
    64             )
    65 
    65 
    66     def _getfile(self, tmpfile, filename, hash):
    66     def _getfile(self, tmpfile, filename, hash):
    67         try:
    67         try:
    75         except urlerr.urlerror as e:
    75         except urlerr.urlerror as e:
    76             # This usually indicates a connection problem, so don't
    76             # This usually indicates a connection problem, so don't
    77             # keep trying with the other files... they will probably
    77             # keep trying with the other files... they will probably
    78             # all fail too.
    78             # all fail too.
    79             raise error.Abort(
    79             raise error.Abort(
    80                 '%s: %s' % (util.hidepassword(self.url), e.reason)
    80                 b'%s: %s' % (util.hidepassword(self.url), e.reason)
    81             )
    81             )
    82         except IOError as e:
    82         except IOError as e:
    83             raise basestore.StoreError(
    83             raise basestore.StoreError(
    84                 filename, hash, self.url, stringutil.forcebytestr(e)
    84                 filename, hash, self.url, stringutil.forcebytestr(e)
    85             )
    85             )
   116             else:
   116             else:
   117                 stat = stats[expectedhash]
   117                 stat = stats[expectedhash]
   118                 if stat:
   118                 if stat:
   119                     if stat == 1:
   119                     if stat == 1:
   120                         self.ui.warn(
   120                         self.ui.warn(
   121                             _('changeset %s: %s: contents differ\n')
   121                             _(b'changeset %s: %s: contents differ\n')
   122                             % (cset, filename)
   122                             % (cset, filename)
   123                         )
   123                         )
   124                         failed = True
   124                         failed = True
   125                     elif stat == 2:
   125                     elif stat == 2:
   126                         self.ui.warn(
   126                         self.ui.warn(
   127                             _('changeset %s: %s missing\n') % (cset, filename)
   127                             _(b'changeset %s: %s missing\n') % (cset, filename)
   128                         )
   128                         )
   129                         failed = True
   129                         failed = True
   130                     else:
   130                     else:
   131                         raise RuntimeError(
   131                         raise RuntimeError(
   132                             'verify failed: unexpected response '
   132                             b'verify failed: unexpected response '
   133                             'from statlfile (%r)' % stat
   133                             b'from statlfile (%r)' % stat
   134                         )
   134                         )
   135         return failed
   135         return failed
   136 
   136 
   137     def _put(self, hash, fd):
   137     def _put(self, hash, fd):
   138         '''Put file with the given hash in the remote store.'''
   138         '''Put file with the given hash in the remote store.'''
   139         raise NotImplementedError('abstract method')
   139         raise NotImplementedError(b'abstract method')
   140 
   140 
   141     def _get(self, hash):
   141     def _get(self, hash):
   142         '''Get a iterator for content with the given hash.'''
   142         '''Get a iterator for content with the given hash.'''
   143         raise NotImplementedError('abstract method')
   143         raise NotImplementedError(b'abstract method')
   144 
   144 
   145     def _stat(self, hashes):
   145     def _stat(self, hashes):
   146         '''Get information about availability of files specified by
   146         '''Get information about availability of files specified by
   147         hashes in the remote store. Return dictionary mapping hashes
   147         hashes in the remote store. Return dictionary mapping hashes
   148         to return code where 0 means that file is available, other
   148         to return code where 0 means that file is available, other
   149         values if not.'''
   149         values if not.'''
   150         raise NotImplementedError('abstract method')
   150         raise NotImplementedError(b'abstract method')