hgext/inotify/__init__.py
changeset 6998 ddfcefab8b97
parent 6753 ed5ffb2c12f3
parent 6997 9c4e488f105e
child 7083 9dcce703edb8
equal deleted inserted replaced
6992:4e62be0208d3 6998:ddfcefab8b97
    22     if timeout:
    22     if timeout:
    23         timeout = float(timeout) * 1e3
    23         timeout = float(timeout) * 1e3
    24 
    24 
    25     class service:
    25     class service:
    26         def init(self):
    26         def init(self):
    27             self.master = server.Master(ui, repo, timeout)
    27             try:
       
    28                 self.master = server.Master(ui, repo, timeout)
       
    29             except server.AlreadyStartedException, inst:
       
    30                 raise util.Abort(str(inst))
    28 
    31 
    29         def run(self):
    32         def run(self):
    30             try:
    33             try:
    31                 self.master.run()
    34                 self.master.run()
    32             finally:
    35             finally:
    53                 if not ignored and not self.inotifyserver:
    56                 if not ignored and not self.inotifyserver:
    54                     result = client.query(ui, repo, files, match, False,
    57                     result = client.query(ui, repo, files, match, False,
    55                                           clean, unknown)
    58                                           clean, unknown)
    56                     if result is not None:
    59                     if result is not None:
    57                         return result
    60                         return result
    58             except socket.error, err:
    61             except (OSError, socket.error), err:
    59                 if err[0] == errno.ECONNREFUSED:
    62                 if err[0] == errno.ECONNREFUSED:
    60                     ui.warn(_('(found dead inotify server socket; '
    63                     ui.warn(_('(found dead inotify server socket; '
    61                                    'removing it)\n'))
    64                                    'removing it)\n'))
    62                     os.unlink(repo.join('inotify.sock'))
    65                     os.unlink(repo.join('inotify.sock'))
    63                 elif err[0] != errno.ENOENT:
    66                 if err[0] in (errno.ECONNREFUSED, errno.ENOENT) and \
    64                     raise
    67                         ui.configbool('inotify', 'autostart'):
    65                 if ui.configbool('inotify', 'autostart'):
       
    66                     query = None
    68                     query = None
    67                     ui.debug(_('(starting inotify server)\n'))
    69                     ui.debug(_('(starting inotify server)\n'))
    68                     try:
    70                     try:
    69                         server.start(ui, repo)
    71                         server.start(ui, repo)
    70                         query = client.query
    72                         query = client.query
    74                         ui.debug(str(inst))
    76                         ui.debug(str(inst))
    75                         query = client.query
    77                         query = client.query
    76                     except Exception, inst:
    78                     except Exception, inst:
    77                         ui.warn(_('could not start inotify server: '
    79                         ui.warn(_('could not start inotify server: '
    78                                        '%s\n') % inst)
    80                                        '%s\n') % inst)
    79                         ui.print_exc()
       
    80 
       
    81                     if query:
    81                     if query:
    82                         try:
    82                         try:
    83                             return query(ui, repo, files or [], match,
    83                             return query(ui, repo, files or [], match,
    84                                          ignored, clean, unknown)
    84                                          ignored, clean, unknown)
    85                         except socket.error, err:
    85                         except socket.error, err:
    86                             ui.warn(_('could not talk to new inotify '
    86                             ui.warn(_('could not talk to new inotify '
    87                                            'server: %s\n') % err[1])
    87                                            'server: %s\n') % err[-1])
    88                             ui.print_exc()
    88                 else:
       
    89                     ui.warn(_('failed to contact inotify server: %s\n')
       
    90                              % err[-1])
       
    91                 ui.print_exc()
       
    92                 # replace by old status function
       
    93                 ui.warn(_('deactivating inotify\n'))
       
    94                 self.status = super(inotifydirstate, self).status
    89 
    95 
    90             return super(inotifydirstate, self).status(
    96             return super(inotifydirstate, self).status(
    91                 match, ignored, clean, unknown)
    97                 match, ignored, clean, unknown)
    92 
    98 
    93     repo.dirstate.__class__ = inotifydirstate
    99     repo.dirstate.__class__ = inotifydirstate