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
1=== modified file 'breezy/dirty_tracker.py'
2--- breezy/dirty_tracker.py 2020-07-27 22:52:21 +0000
3+++ breezy/dirty_tracker.py 2022-01-17 02:05:14 +0000
4@@ -15,45 +15,41 @@
5 # along with this program; if not, write to the Free Software
6 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
7
8-"""Track whether a directory structure was touched since last revision.
9-"""
10-
11-from __future__ import absolute_import
12-
13-# TODO(jelmer): Add support for ignore files
14+"""Track whether a particular directory structure is dirty."""
15
16 import os
17-try:
18- from pyinotify import (
19- WatchManager,
20- IN_CREATE,
21- IN_CLOSE_WRITE,
22- IN_Q_OVERFLOW,
23- IN_DELETE,
24- IN_MOVED_TO,
25- IN_MOVED_FROM,
26- IN_ATTRIB,
27- ProcessEvent,
28- Notifier,
29- Event,
30- )
31-except ImportError as e:
32- from .errors import DependencyNotPresent
33- raise DependencyNotPresent(library='pyinotify', error=e)
34+from pyinotify import (
35+ WatchManager,
36+ IN_CREATE,
37+ IN_CLOSE_WRITE,
38+ IN_Q_OVERFLOW,
39+ IN_DELETE,
40+ IN_MOVED_TO,
41+ IN_MOVED_FROM,
42+ IN_ATTRIB,
43+ ProcessEvent,
44+ Notifier,
45+ Event,
46+)
47+from typing import Set
48+from .workingtree import WorkingTree
49
50
51 MASK = (
52- IN_CLOSE_WRITE | IN_DELETE | IN_Q_OVERFLOW | IN_MOVED_TO | IN_MOVED_FROM |
53- IN_ATTRIB)
54-
55-
56-class _Process(ProcessEvent):
57-
58- def my_init(self):
59+ IN_CLOSE_WRITE | IN_DELETE | IN_Q_OVERFLOW | IN_MOVED_TO | IN_MOVED_FROM | IN_ATTRIB
60+)
61+
62+
63+class _Process(ProcessEvent): # type: ignore
64+
65+ paths: Set[str]
66+ created: Set[str]
67+
68+ def my_init(self) -> None:
69 self.paths = set()
70 self.created = set()
71
72- def process_default(self, event):
73+ def process_default(self, event: Event) -> None:
74 path = os.path.join(event.path, event.name)
75 if event.mask & IN_CREATE:
76 self.created.add(path)
77@@ -66,43 +62,45 @@
78 class DirtyTracker(object):
79 """Track the changes to (part of) a working tree."""
80
81- def __init__(self, tree, subpath='.'):
82+ def __init__(self, tree: WorkingTree, subpath: str = ".") -> None:
83 self._tree = tree
84 self._wm = WatchManager()
85 self._process = _Process()
86 self._notifier = Notifier(self._wm, self._process)
87 self._notifier.coalesce_events(True)
88
89- def check_excluded(p):
90- return tree.is_control_filename(tree.relpath(p))
91+ def check_excluded(p: str) -> bool:
92+ return tree.is_control_filename(tree.relpath(p)) # type: ignore
93+
94 self._wdd = self._wm.add_watch(
95- tree.abspath(subpath), MASK, rec=True, auto_add=True,
96- exclude_filter=check_excluded)
97+ tree.abspath(subpath),
98+ MASK,
99+ rec=True,
100+ auto_add=True,
101+ exclude_filter=check_excluded,
102+ )
103
104- def _process_pending(self):
105+ def _process_pending(self) -> None:
106 if self._notifier.check_events(timeout=0):
107 self._notifier.read_events()
108 self._notifier.process_events()
109
110- def __del__(self):
111- self._notifier.stop()
112-
113- def mark_clean(self):
114+ def mark_clean(self) -> None:
115 """Mark the subtree as not having any changes."""
116 self._process_pending()
117 self._process.paths.clear()
118 self._process.created.clear()
119
120- def is_dirty(self):
121+ def is_dirty(self) -> bool:
122 """Check whether there are any changes."""
123 self._process_pending()
124 return bool(self._process.paths)
125
126- def paths(self):
127+ def paths(self) -> Set[str]:
128 """Return the paths that have changed."""
129 self._process_pending()
130 return self._process.paths
131
132- def relpaths(self):
133+ def relpaths(self) -> Set[str]:
134 """Return the paths relative to the tree root that changed."""
135 return set(self._tree.relpath(p) for p in self.paths())

Subscribers

People subscribed via source and target branches