Mercurial > hg
comparison hgext/inotify/server.py @ 8335:713ec3f9c9de
inotify: Clarify the use of "watcher" name.
Currently, Watcher is a class in inotify.linux.watcher, but it's also a class
in inotify.server . To complicate things further more, the latter has a
'watcher' attribute, an instance of the former class.
When it comes to the 'watcher' attribute of the Server class in inotify.server,
one can get quite confused: is it a Watcher object from inotify.server, or from
inotify.linux.watcher?
Changes:
* in inotify.linux.watcher : nothing
* in inotify.server :
** Watcher class is renamed to RepoWatcher
** server.watcher is renamed to server.repowatcher
author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
---|---|
date | Mon, 04 May 2009 21:18:33 +0900 |
parents | 0695288e8c37 |
children | 114f067229bd |
comparison
equal
deleted
inserted
replaced
8334:0695288e8c37 | 8335:713ec3f9c9de |
---|---|
112 (limit, newlimit)) | 112 (limit, newlimit)) |
113 ui.warn(_('*** echo %d > %s\n') % (newlimit, path)) | 113 ui.warn(_('*** echo %d > %s\n') % (newlimit, path)) |
114 raise util.Abort(_('cannot watch %s until inotify watch limit is raised') | 114 raise util.Abort(_('cannot watch %s until inotify watch limit is raised') |
115 % repo.root) | 115 % repo.root) |
116 | 116 |
117 class Watcher(object): | 117 class RepoWatcher(object): |
118 poll_events = select.POLLIN | 118 poll_events = select.POLLIN |
119 statuskeys = 'almr!?' | 119 statuskeys = 'almr!?' |
120 | 120 |
121 def __init__(self, ui, repo, master): | 121 def __init__(self, ui, repo, master): |
122 self.ui = ui | 122 self.ui = ui |
543 self.watcher.close() | 543 self.watcher.close() |
544 | 544 |
545 class Server(object): | 545 class Server(object): |
546 poll_events = select.POLLIN | 546 poll_events = select.POLLIN |
547 | 547 |
548 def __init__(self, ui, repo, watcher, timeout): | 548 def __init__(self, ui, repo, repowatcher, timeout): |
549 self.ui = ui | 549 self.ui = ui |
550 self.repo = repo | 550 self.repo = repo |
551 self.watcher = watcher | 551 self.repowatcher = repowatcher |
552 self.timeout = timeout | 552 self.timeout = timeout |
553 self.sock = socket.socket(socket.AF_UNIX) | 553 self.sock = socket.socket(socket.AF_UNIX) |
554 self.sockpath = self.repo.join('inotify.sock') | 554 self.sockpath = self.repo.join('inotify.sock') |
555 self.realsockpath = None | 555 self.realsockpath = None |
556 try: | 556 try: |
600 | 600 |
601 states = names.pop() | 601 states = names.pop() |
602 | 602 |
603 self.ui.note(_('answering query for %r\n') % states) | 603 self.ui.note(_('answering query for %r\n') % states) |
604 | 604 |
605 if self.watcher.timeout: | 605 if self.repowatcher.timeout: |
606 # We got a query while a rescan is pending. Make sure we | 606 # We got a query while a rescan is pending. Make sure we |
607 # rescan before responding, or we could give back a wrong | 607 # rescan before responding, or we could give back a wrong |
608 # answer. | 608 # answer. |
609 self.watcher.handle_timeout() | 609 self.repowatcher.handle_timeout() |
610 | 610 |
611 if not names: | 611 if not names: |
612 def genresult(states, tree): | 612 def genresult(states, tree): |
613 for fn, state in self.watcher.walk(states, tree): | 613 for fn, state in self.repowatcher.walk(states, tree): |
614 yield fn | 614 yield fn |
615 else: | 615 else: |
616 def genresult(states, tree): | 616 def genresult(states, tree): |
617 for fn in names: | 617 for fn in names: |
618 l = self.watcher.lookup(fn, tree) | 618 l = self.repowatcher.lookup(fn, tree) |
619 try: | 619 try: |
620 if l in states: | 620 if l in states: |
621 yield fn | 621 yield fn |
622 except TypeError: | 622 except TypeError: |
623 for f, s in self.watcher.walk(states, l, fn): | 623 for f, s in self.repowatcher.walk(states, l, fn): |
624 yield f | 624 yield f |
625 | 625 |
626 results = ['\0'.join(r) for r in [ | 626 results = ['\0'.join(r) for r in [ |
627 genresult('l', self.watcher.statustrees['l']), | 627 genresult('l', self.repowatcher.statustrees['l']), |
628 genresult('m', self.watcher.statustrees['m']), | 628 genresult('m', self.repowatcher.statustrees['m']), |
629 genresult('a', self.watcher.statustrees['a']), | 629 genresult('a', self.repowatcher.statustrees['a']), |
630 genresult('r', self.watcher.statustrees['r']), | 630 genresult('r', self.repowatcher.statustrees['r']), |
631 genresult('!', self.watcher.statustrees['!']), | 631 genresult('!', self.repowatcher.statustrees['!']), |
632 '?' in states and genresult('?', self.watcher.statustrees['?']) or [], | 632 '?' in states |
633 and genresult('?', self.repowatcher.statustrees['?']) | |
634 or [], | |
633 [], | 635 [], |
634 'c' in states and genresult('n', self.watcher.tree) or [], | 636 'c' in states and genresult('n', self.repowatcher.tree) or [], |
635 ]] | 637 ]] |
636 | 638 |
637 try: | 639 try: |
638 try: | 640 try: |
639 sock.sendall(struct.pack(common.resphdrfmt, | 641 sock.sendall(struct.pack(common.resphdrfmt, |
659 class Master(object): | 661 class Master(object): |
660 def __init__(self, ui, repo, timeout=None): | 662 def __init__(self, ui, repo, timeout=None): |
661 self.ui = ui | 663 self.ui = ui |
662 self.repo = repo | 664 self.repo = repo |
663 self.poll = select.poll() | 665 self.poll = select.poll() |
664 self.watcher = Watcher(ui, repo, self) | 666 self.repowatcher = RepoWatcher(ui, repo, self) |
665 self.server = Server(ui, repo, self.watcher, timeout) | 667 self.server = Server(ui, repo, self.repowatcher, timeout) |
666 self.table = {} | 668 self.table = {} |
667 for obj in (self.watcher, self.server): | 669 for obj in (self.repowatcher, self.server): |
668 fd = obj.fileno() | 670 fd = obj.fileno() |
669 self.table[fd] = obj | 671 self.table[fd] = obj |
670 self.poll.register(fd, obj.poll_events) | 672 self.poll.register(fd, obj.poll_events) |
671 | 673 |
672 def register(self, fd, mask): | 674 def register(self, fd, mask): |
675 def shutdown(self): | 677 def shutdown(self): |
676 for obj in self.table.itervalues(): | 678 for obj in self.table.itervalues(): |
677 obj.shutdown() | 679 obj.shutdown() |
678 | 680 |
679 def run(self): | 681 def run(self): |
680 self.watcher.setup() | 682 self.repowatcher.setup() |
681 self.ui.note(_('finished setup\n')) | 683 self.ui.note(_('finished setup\n')) |
682 if os.getenv('TIME_STARTUP'): | 684 if os.getenv('TIME_STARTUP'): |
683 sys.exit(0) | 685 sys.exit(0) |
684 while True: | 686 while True: |
685 timeout = None | 687 timeout = None |
731 | 733 |
732 pid = os.fork() | 734 pid = os.fork() |
733 if pid: | 735 if pid: |
734 return pid | 736 return pid |
735 | 737 |
736 closefds([m.server.fileno(), m.watcher.fileno()]) | 738 closefds([m.server.fileno(), m.repowatcher.fileno()]) |
737 os.setsid() | 739 os.setsid() |
738 | 740 |
739 fd = os.open('/dev/null', os.O_RDONLY) | 741 fd = os.open('/dev/null', os.O_RDONLY) |
740 os.dup2(fd, 0) | 742 os.dup2(fd, 0) |
741 if fd > 0: | 743 if fd > 0: |