Merge lp:~jelmer/brz/dirty-tracker into lp:brz/3.2

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/dirty-tracker
Merge into: lp:brz/3.2
Diff against target: 135 lines (+42/-44)
1 file modified
breezy/dirty_tracker.py (+42/-44)
To merge this branch: bzr merge lp:~jelmer/brz/dirty-tracker
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+414214@code.launchpad.net

Commit message

Import new version of dirty_tracker from lintian-brush.

Description of the change

Update dirty_tracker.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/dirty_tracker.py'
--- breezy/dirty_tracker.py 2020-07-27 22:52:21 +0000
+++ breezy/dirty_tracker.py 2022-01-17 02:05:14 +0000
@@ -15,45 +15,41 @@
15# along with this program; if not, write to the Free Software15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA16# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717
18"""Track whether a directory structure was touched since last revision.18"""Track whether a particular directory structure is dirty."""
19"""
20
21from __future__ import absolute_import
22
23# TODO(jelmer): Add support for ignore files
2419
25import os20import os
26try:21from pyinotify import (
27 from pyinotify import (22 WatchManager,
28 WatchManager,23 IN_CREATE,
29 IN_CREATE,24 IN_CLOSE_WRITE,
30 IN_CLOSE_WRITE,25 IN_Q_OVERFLOW,
31 IN_Q_OVERFLOW,26 IN_DELETE,
32 IN_DELETE,27 IN_MOVED_TO,
33 IN_MOVED_TO,28 IN_MOVED_FROM,
34 IN_MOVED_FROM,29 IN_ATTRIB,
35 IN_ATTRIB,30 ProcessEvent,
36 ProcessEvent,31 Notifier,
37 Notifier,32 Event,
38 Event,33)
39 )34from typing import Set
40except ImportError as e:35from .workingtree import WorkingTree
41 from .errors import DependencyNotPresent
42 raise DependencyNotPresent(library='pyinotify', error=e)
4336
4437
45MASK = (38MASK = (
46 IN_CLOSE_WRITE | IN_DELETE | IN_Q_OVERFLOW | IN_MOVED_TO | IN_MOVED_FROM |39 IN_CLOSE_WRITE | IN_DELETE | IN_Q_OVERFLOW | IN_MOVED_TO | IN_MOVED_FROM | IN_ATTRIB
47 IN_ATTRIB)40)
4841
4942
50class _Process(ProcessEvent):43class _Process(ProcessEvent): # type: ignore
5144
52 def my_init(self):45 paths: Set[str]
46 created: Set[str]
47
48 def my_init(self) -> None:
53 self.paths = set()49 self.paths = set()
54 self.created = set()50 self.created = set()
5551
56 def process_default(self, event):52 def process_default(self, event: Event) -> None:
57 path = os.path.join(event.path, event.name)53 path = os.path.join(event.path, event.name)
58 if event.mask & IN_CREATE:54 if event.mask & IN_CREATE:
59 self.created.add(path)55 self.created.add(path)
@@ -66,43 +62,45 @@
66class DirtyTracker(object):62class DirtyTracker(object):
67 """Track the changes to (part of) a working tree."""63 """Track the changes to (part of) a working tree."""
6864
69 def __init__(self, tree, subpath='.'):65 def __init__(self, tree: WorkingTree, subpath: str = ".") -> None:
70 self._tree = tree66 self._tree = tree
71 self._wm = WatchManager()67 self._wm = WatchManager()
72 self._process = _Process()68 self._process = _Process()
73 self._notifier = Notifier(self._wm, self._process)69 self._notifier = Notifier(self._wm, self._process)
74 self._notifier.coalesce_events(True)70 self._notifier.coalesce_events(True)
7571
76 def check_excluded(p):72 def check_excluded(p: str) -> bool:
77 return tree.is_control_filename(tree.relpath(p))73 return tree.is_control_filename(tree.relpath(p)) # type: ignore
74
78 self._wdd = self._wm.add_watch(75 self._wdd = self._wm.add_watch(
79 tree.abspath(subpath), MASK, rec=True, auto_add=True,76 tree.abspath(subpath),
80 exclude_filter=check_excluded)77 MASK,
78 rec=True,
79 auto_add=True,
80 exclude_filter=check_excluded,
81 )
8182
82 def _process_pending(self):83 def _process_pending(self) -> None:
83 if self._notifier.check_events(timeout=0):84 if self._notifier.check_events(timeout=0):
84 self._notifier.read_events()85 self._notifier.read_events()
85 self._notifier.process_events()86 self._notifier.process_events()
8687
87 def __del__(self):88 def mark_clean(self) -> None:
88 self._notifier.stop()
89
90 def mark_clean(self):
91 """Mark the subtree as not having any changes."""89 """Mark the subtree as not having any changes."""
92 self._process_pending()90 self._process_pending()
93 self._process.paths.clear()91 self._process.paths.clear()
94 self._process.created.clear()92 self._process.created.clear()
9593
96 def is_dirty(self):94 def is_dirty(self) -> bool:
97 """Check whether there are any changes."""95 """Check whether there are any changes."""
98 self._process_pending()96 self._process_pending()
99 return bool(self._process.paths)97 return bool(self._process.paths)
10098
101 def paths(self):99 def paths(self) -> Set[str]:
102 """Return the paths that have changed."""100 """Return the paths that have changed."""
103 self._process_pending()101 self._process_pending()
104 return self._process.paths102 return self._process.paths
105103
106 def relpaths(self):104 def relpaths(self) -> Set[str]:
107 """Return the paths relative to the tree root that changed."""105 """Return the paths relative to the tree root that changed."""
108 return set(self._tree.relpath(p) for p in self.paths())106 return set(self._tree.relpath(p) for p in self.paths())

Subscribers

People subscribed via source and target branches