Merge lp:~jelmer/brz/nested-tree-filetimes into lp:brz/3.2

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 7572
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/nested-tree-filetimes
Merge into: lp:brz/3.2
Diff against target: 290 lines (+67/-31)
10 files modified
breezy/archive/tar.py (+1/-2)
breezy/bzr/workingtree_4.py (+3/-0)
breezy/git/annotate.py (+1/-1)
breezy/git/filegraph.py (+25/-8)
breezy/git/repository.py (+2/-4)
breezy/git/tree.py (+9/-10)
breezy/git/workingtree.py (+3/-4)
breezy/tests/per_workingtree/test_get_file_mtime.py (+21/-0)
byov.conf (+1/-1)
setup.py (+1/-1)
To merge this branch: bzr merge lp:~jelmer/brz/nested-tree-filetimes
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+413630@code.launchpad.net

Commit message

Support nested trees in Tree.get_file_mtime.

Description of the change

Support nested trees in Tree.get_file_mtime.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
lp:~jelmer/brz/nested-tree-filetimes updated
7573. By Jelmer Vernooij

install dulwich from pip.

7574. By Jelmer Vernooij

Bump dulwich.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/archive/tar.py'
2--- breezy/archive/tar.py 2020-02-18 01:57:45 +0000
3+++ breezy/archive/tar.py 2022-01-04 23:27:18 +0000
4@@ -41,7 +41,6 @@
5
6 Returns a (tarinfo, fileobj) tuple
7 """
8- file_id = getattr(entry, 'file_id', None)
9 filename = osutils.pathjoin(root, final_path)
10 item = tarfile.TarInfo(filename)
11 if force_mtime is not None:
12@@ -75,7 +74,7 @@
13 fileobj = None
14 else:
15 raise errors.BzrError("don't know how to export {%s} of kind %r"
16- % (file_id, entry.kind))
17+ % (final_path, entry.kind))
18 return (item, fileobj)
19
20
21
22=== modified file 'breezy/bzr/workingtree_4.py'
23--- breezy/bzr/workingtree_4.py 2020-11-18 02:15:43 +0000
24+++ breezy/bzr/workingtree_4.py 2022-01-04 23:27:18 +0000
25@@ -1928,6 +1928,9 @@
26 # Make sure the file exists
27 entry = self._get_entry(path=path)
28 if entry == (None, None): # do we raise?
29+ nested_tree, subpath = self.get_containing_nested_tree(path)
30+ if nested_tree is not None:
31+ return nested_tree.get_file_mtime(subpath)
32 raise errors.NoSuchFile(path)
33 parent_index = self._get_parent_index()
34 last_changed_revision = entry[1][parent_index][4]
35
36=== modified file 'breezy/git/annotate.py'
37--- breezy/git/annotate.py 2020-07-18 23:14:00 +0000
38+++ breezy/git/annotate.py 2022-01-04 23:27:18 +0000
39@@ -122,7 +122,7 @@
40 path = encode_git_path(path)
41 for commit_parent in self.store[commit_id].parents:
42 try:
43- (path, text_parent) = (
44+ (store, path, text_parent) = (
45 self.change_scanner.find_last_change_revision(
46 path, commit_parent))
47 except KeyError:
48
49=== modified file 'breezy/git/filegraph.py'
50--- breezy/git/filegraph.py 2020-07-18 23:14:00 +0000
51+++ breezy/git/filegraph.py 2022-01-04 23:27:18 +0000
52@@ -17,11 +17,17 @@
53
54 """File graph access."""
55
56+import posixpath
57 import stat
58
59 from dulwich.errors import (
60 NotTreeError,
61 )
62+try:
63+ from dulwich.objects import SubmoduleEncountered
64+except ImportError:
65+ class SubmoduleEncountered(Exception):
66+ pass
67 from dulwich.object_store import (
68 tree_lookup_path,
69 )
70@@ -44,9 +50,20 @@
71 def find_last_change_revision(self, path, commit_id):
72 if not isinstance(path, bytes):
73 raise TypeError(path)
74- commit = self.store[commit_id]
75- target_mode, target_sha = tree_lookup_path(self.store.__getitem__,
76- commit.tree, path)
77+ store = self.store
78+ while True:
79+ commit = store[commit_id]
80+ try:
81+ target_mode, target_sha = tree_lookup_path(
82+ store.__getitem__, commit.tree, path)
83+ except SubmoduleEncountered as e:
84+ revid = self.repository.lookup_foreign_revision_id(commit_id)
85+ revtree = self.repository.revision_tree(revid)
86+ store = revtree._get_submodule_store(e.path)
87+ commit_id = e.sha
88+ path = posixpath.relpath(path, e.path)
89+ else:
90+ break
91 if path == b'':
92 target_mode = stat.S_IFDIR
93 if target_mode is None:
94@@ -54,9 +71,9 @@
95 (target_sha, path, commit_id))
96 while True:
97 parent_commits = []
98- for parent_commit in [self.store[c] for c in commit.parents]:
99+ for parent_commit in [store[c] for c in commit.parents]:
100 try:
101- mode, sha = tree_lookup_path(self.store.__getitem__,
102+ mode, sha = tree_lookup_path(store.__getitem__,
103 parent_commit.tree, path)
104 except (NotTreeError, KeyError):
105 continue
106@@ -68,11 +85,11 @@
107 # or is a directory that didn't previously exist.
108 if mode != target_mode or (
109 not stat.S_ISDIR(target_mode) and sha != target_sha):
110- return (path, commit.id)
111+ return (store, path, commit.id)
112 if parent_commits == []:
113 break
114 commit = parent_commits[0]
115- return (path, commit.id)
116+ return (store, path, commit.id)
117
118
119 class GitFileParentProvider(object):
120@@ -92,7 +109,7 @@
121 text_parents = []
122 for commit_parent in self.store[commit_id].parents:
123 try:
124- (path, text_parent) = (
125+ (store, path, text_parent) = (
126 self.change_scanner.find_last_change_revision(
127 path, commit_parent))
128 except KeyError:
129
130=== modified file 'breezy/git/repository.py'
131--- breezy/git/repository.py 2021-04-03 12:58:34 +0000
132+++ breezy/git/repository.py 2022-01-04 23:27:18 +0000
133@@ -308,12 +308,10 @@
134 except ValueError:
135 raise errors.RevisionNotPresent((fileid, revid), self)
136 try:
137- obj = tree_lookup_path(
138+ mode, item_id = tree_lookup_path(
139 self._git.object_store.__getitem__, root_tree,
140 encode_git_path(path))
141- if isinstance(obj, tuple):
142- (mode, item_id) = obj
143- obj = self._git.object_store[item_id]
144+ obj = self._git.object_store[item_id]
145 except KeyError:
146 raise errors.RevisionNotPresent((fileid, revid), self)
147 else:
148
149=== modified file 'breezy/git/tree.py'
150--- breezy/git/tree.py 2021-12-09 20:50:25 +0000
151+++ breezy/git/tree.py 2022-01-04 23:27:18 +0000
152@@ -37,7 +37,6 @@
153 IndexEntry,
154 )
155 from dulwich.object_store import (
156- tree_lookup_path,
157 OverlayObjectStore,
158 )
159 from dulwich.objects import (
160@@ -369,21 +368,21 @@
161 change_scanner = self._repository._file_change_scanner
162 if self.commit_id == ZERO_SHA:
163 return NULL_REVISION
164- (unused_path, commit_id) = change_scanner.find_last_change_revision(
165+ (store, unused_path, commit_id) = change_scanner.find_last_change_revision(
166 encode_git_path(path), self.commit_id)
167- return self._repository.lookup_foreign_revision_id(
168- commit_id, self.mapping)
169+ return self.mapping.revision_id_foreign_to_bzr(commit_id)
170
171 def get_file_mtime(self, path):
172+ change_scanner = self._repository._file_change_scanner
173+ if self.commit_id == ZERO_SHA:
174+ return NULL_REVISION
175 try:
176- revid = self.get_file_revision(path)
177+ (store, unused_path, commit_id) = change_scanner.find_last_change_revision(
178+ encode_git_path(path), self.commit_id)
179 except KeyError:
180 raise errors.NoSuchFile(path)
181- try:
182- rev = self._repository.get_revision(revid)
183- except errors.NoSuchRevision:
184- raise _mod_tree.FileTimestampUnavailable(path)
185- return rev.timestamp
186+ commit = store[commit_id]
187+ return commit.commit_time
188
189 def id2path(self, file_id, recurse='down'):
190 try:
191
192=== modified file 'breezy/git/workingtree.py'
193--- breezy/git/workingtree.py 2021-05-30 17:12:41 +0000
194+++ breezy/git/workingtree.py 2022-01-04 23:27:18 +0000
195@@ -37,9 +37,6 @@
196 validate_path,
197 write_index_dict,
198 )
199-from dulwich.object_store import (
200- tree_lookup_path,
201- )
202 from dulwich.objects import (
203 S_ISGITLINK,
204 )
205@@ -75,6 +72,7 @@
206
207 from .dir import (
208 LocalGitDir,
209+ BareLocalGitControlDirFormat,
210 )
211 from .tree import (
212 MutableGitIndexTree,
213@@ -219,10 +217,11 @@
214 info = self._submodule_info()[relpath]
215 except KeyError:
216 submodule_transport = self.user_transport.clone(decode_git_path(relpath))
217+ submodule_dir = self._format._matchingcontroldir.open(submodule_transport)
218 else:
219 submodule_transport = self.control_transport.clone(
220 posixpath.join('modules', decode_git_path(info[1])))
221- submodule_dir = self._format._matchingcontroldir.open(submodule_transport)
222+ submodule_dir = BareLocalGitControlDirFormat().open(submodule_transport)
223 return Index(submodule_dir.control_transport.local_abspath('index'))
224
225 def lock_read(self):
226
227=== modified file 'breezy/tests/per_workingtree/test_get_file_mtime.py'
228--- breezy/tests/per_workingtree/test_get_file_mtime.py 2018-11-16 18:33:17 +0000
229+++ breezy/tests/per_workingtree/test_get_file_mtime.py 2022-01-04 23:27:18 +0000
230@@ -20,6 +20,7 @@
231
232 from breezy import errors
233 from breezy.tree import FileTimestampUnavailable
234+from breezy.tests import TestNotApplicable
235 from breezy.tests.per_workingtree import TestCaseWithWorkingTree
236
237
238@@ -36,6 +37,26 @@
239 tree.add(['one'])
240 return tree
241
242+ def test_get_file_mtime_nested(self):
243+ tree = self.make_basic_tree()
244+ subtree = self.make_branch_and_tree('tree/sub')
245+ self.build_tree(['tree/sub/one'])
246+ subtree.add(['one'])
247+ subtree.commit('one')
248+ try:
249+ tree.add_reference(subtree)
250+ except errors.UnsupportedOperation:
251+ raise TestNotApplicable('subtrees not supported')
252+ tree.commit('sub')
253+
254+ with tree.lock_read(), subtree.lock_read():
255+ self.assertEqual(
256+ tree.get_file_mtime('sub/one'),
257+ subtree.get_file_mtime('one'))
258+ self.assertEqual(
259+ tree.basis_tree().get_file_mtime('sub/one'),
260+ subtree.basis_tree().get_file_mtime('one'))
261+
262 def test_get_file_mtime(self):
263 tree = self.make_basic_tree()
264
265
266=== modified file 'byov.conf'
267--- byov.conf 2021-08-19 18:07:03 +0000
268+++ byov.conf 2022-01-04 23:27:18 +0000
269@@ -5,7 +5,7 @@
270 subunit.clone = (git clone https://github.com/testing-cabal/subunit.git ../subunit)
271 sphinx_epytext.install = (pip3 install sphinx_epytext)
272 flake8.install3 = (pip3 install flake8)
273-brz.extras = fastimport,launchpad,workspace,git,cext,doc
274+brz.extras = fastimport,launchpad,workspace,git,cext,doc,dulwich
275
276 [brz]
277 # because paramiko 2.0.0 is broken:
278
279=== modified file 'setup.py'
280--- setup.py 2021-11-16 11:09:01 +0000
281+++ setup.py 2022-01-04 23:27:18 +0000
282@@ -63,7 +63,7 @@
283 'patiencediff',
284 # Technically, Breezy works without these two dependencies too. But there's
285 # no way to enable them by default and let users opt out.
286- 'dulwich>=0.20.23',
287+ 'dulwich>=0.20.27',
288 ],
289 'extras_require': {
290 'cext': ['cython>=0.29'],

Subscribers

People subscribed via source and target branches