Mercurial > hg
comparison hgext/inotify/server.py @ 9349:56fb15ad8fb1
inotify: server: use wprefix everywhere, introduce prefixlen
self.wprefix = self.repo.root + '/' = self.repo.wjoin('') + '/'
Since we'll eventually get rid of self.repo, keep only the first form.
use self.prefixlen to compute only once the root prefix size.
author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
---|---|
date | Mon, 29 Jun 2009 01:05:06 +0900 |
parents | 954f7a879495 |
children | b789ea382fc0 |
comparison
equal
deleted
inserted
replaced
9348:954f7a879495 | 9349:56fb15ad8fb1 |
---|---|
310 0) | 310 0) |
311 | 311 |
312 def __init__(self, ui, repo): | 312 def __init__(self, ui, repo): |
313 self.ui = ui | 313 self.ui = ui |
314 self.repo = repo | 314 self.repo = repo |
315 self.wprefix = self.repo.wjoin('') | 315 self.wprefix = join(repo.root, '') |
316 self.prefixlen = len(self.wprefix) | |
316 try: | 317 try: |
317 self.watcher = watcher.watcher() | 318 self.watcher = watcher.watcher() |
318 except OSError, err: | 319 except OSError, err: |
319 raise util.Abort(_('inotify service not available: %s') % | 320 raise util.Abort(_('inotify service not available: %s') % |
320 err.strerror) | 321 err.strerror) |
361 def add_watch(self, path, mask): | 362 def add_watch(self, path, mask): |
362 if not path: | 363 if not path: |
363 return | 364 return |
364 if self.watcher.path(path) is None: | 365 if self.watcher.path(path) is None: |
365 if self.ui.debugflag: | 366 if self.ui.debugflag: |
366 self.ui.note(_('watching %r\n') % path[len(self.wprefix):]) | 367 self.ui.note(_('watching %r\n') % path[self.prefixlen:]) |
367 try: | 368 try: |
368 self.watcher.add(path, mask) | 369 self.watcher.add(path, mask) |
369 except OSError, err: | 370 except OSError, err: |
370 if err.errno in (errno.ENOENT, errno.ENOTDIR): | 371 if err.errno in (errno.ENOENT, errno.ENOTDIR): |
371 return | 372 return |
372 if err.errno != errno.ENOSPC: | 373 if err.errno != errno.ENOSPC: |
373 raise | 374 raise |
374 _explain_watch_limit(self.ui, self.repo) | 375 _explain_watch_limit(self.ui, self.repo) |
375 | 376 |
376 def setup(self): | 377 def setup(self): |
377 self.ui.note(_('watching directories under %r\n') % self.repo.root) | 378 self.ui.note(_('watching directories under %r\n') % self.wprefix) |
378 self.add_watch(self.repo.path, inotify.IN_DELETE) | 379 self.add_watch(self.repo.path, inotify.IN_DELETE) |
379 self.check_dirstate() | 380 self.check_dirstate() |
380 | 381 |
381 def filestatus(self, fn, st): | 382 def filestatus(self, fn, st): |
382 try: | 383 try: |
464 del self.statustrees[key].dir(root).files[fn] | 465 del self.statustrees[key].dir(root).files[fn] |
465 del self.tree.dir(root).files[fn] | 466 del self.tree.dir(root).files[fn] |
466 | 467 |
467 def scan(self, topdir=''): | 468 def scan(self, topdir=''): |
468 ds = self.repo.dirstate._map.copy() | 469 ds = self.repo.dirstate._map.copy() |
469 self.add_watch(join(self.repo.root, topdir), self.mask) | 470 self.add_watch(join(self.wprefix, topdir), self.mask) |
470 for root, dirs, files in walk(self.repo, topdir): | 471 for root, dirs, files in walk(self.repo, topdir): |
471 for d in dirs: | 472 for d in dirs: |
472 self.add_watch(join(root, d), self.mask) | 473 self.add_watch(join(root, d), self.mask) |
473 wroot = root[len(self.wprefix):] | 474 wroot = root[self.prefixlen:] |
474 for fn in files: | 475 for fn in files: |
475 wfn = join(wroot, fn) | 476 wfn = join(wroot, fn) |
476 self.updatefile(wfn, self.getstat(wfn)) | 477 self.updatefile(wfn, self.getstat(wfn)) |
477 ds.pop(wfn, None) | 478 ds.pop(wfn, None) |
478 wtopdir = topdir | 479 wtopdir = topdir |
631 if self.ui.debugflag: | 632 if self.ui.debugflag: |
632 self.ui.note(_('%s reading %d events\n') % | 633 self.ui.note(_('%s reading %d events\n') % |
633 (self.event_time(), len(events))) | 634 (self.event_time(), len(events))) |
634 for evt in events: | 635 for evt in events: |
635 assert evt.fullpath.startswith(self.wprefix) | 636 assert evt.fullpath.startswith(self.wprefix) |
636 wpath = evt.fullpath[len(self.wprefix):] | 637 wpath = evt.fullpath[self.prefixlen:] |
637 | 638 |
638 # paths have been normalized, wpath never ends with a '/' | 639 # paths have been normalized, wpath never ends with a '/' |
639 | 640 |
640 if wpath.startswith('.hg/') and evt.mask & inotify.IN_ISDIR: | 641 if wpath.startswith('.hg/') and evt.mask & inotify.IN_ISDIR: |
641 # ignore subdirectories of .hg/ (merge, patches...) | 642 # ignore subdirectories of .hg/ (merge, patches...) |
669 def debug(self): | 670 def debug(self): |
670 """ | 671 """ |
671 Returns a sorted list of relatives paths currently watched, | 672 Returns a sorted list of relatives paths currently watched, |
672 for debugging purposes. | 673 for debugging purposes. |
673 """ | 674 """ |
674 return sorted(tuple[0][len(self.wprefix):] for tuple in self.watcher) | 675 return sorted(tuple[0][self.prefixlen:] for tuple in self.watcher) |
675 | 676 |
676 class server(pollable): | 677 class server(pollable): |
677 """ | 678 """ |
678 Listens for client queries on unix socket inotify.sock | 679 Listens for client queries on unix socket inotify.sock |
679 """ | 680 """ |