Merge lp:~jelmer/brz-git/track-store into lp:brz-git
- track-store
- Merge into trunk
Proposed by
Jelmer Vernooij
Status: | Merged |
---|---|
Approved by: | Jelmer Vernooij |
Approved revision: | 1906 |
Merge reported by: | The Breezy Bot |
Merged at revision: | not available |
Proposed branch: | lp:~jelmer/brz-git/track-store |
Merge into: | lp:brz-git |
Diff against target: |
213 lines (+35/-33) 1 file modified
tree.py (+35/-33) |
To merge this branch: | bzr merge lp:~jelmer/brz-git/track-store |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jelmer Vernooij | Approve | ||
Review via email: mp+342360@code.launchpad.net |
Commit message
Track store in GitRevisionTree.
Description of the change
Track store in GitRevisionTree.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'tree.py' | |||
2 | --- tree.py 2018-03-27 03:09:48 +0000 | |||
3 | +++ tree.py 2018-03-28 23:03:20 +0000 | |||
4 | @@ -265,16 +265,16 @@ | |||
5 | 265 | 265 | ||
6 | 266 | def all_versioned_paths(self): | 266 | def all_versioned_paths(self): |
7 | 267 | ret = set() | 267 | ret = set() |
9 | 268 | todo = set([('', self.tree)]) | 268 | todo = set([(store, '', self.tree)]) |
10 | 269 | while todo: | 269 | while todo: |
12 | 270 | (path, tree_id) = todo.pop() | 270 | (store, path, tree_id) = todo.pop() |
13 | 271 | if tree_id is None: | 271 | if tree_id is None: |
14 | 272 | continue | 272 | continue |
16 | 273 | tree = self.store[tree_id] | 273 | tree = store[tree_id] |
17 | 274 | for name, mode, hexsha in tree.items(): | 274 | for name, mode, hexsha in tree.items(): |
18 | 275 | subpath = posixpath.join(path, name) | 275 | subpath = posixpath.join(path, name) |
19 | 276 | if stat.S_ISDIR(mode): | 276 | if stat.S_ISDIR(mode): |
21 | 277 | todo.add((subpath, hexsha)) | 277 | todo.add((store, subpath, hexsha)) |
22 | 278 | else: | 278 | else: |
23 | 279 | ret.add(subpath) | 279 | ret.add(subpath) |
24 | 280 | return ret | 280 | return ret |
25 | @@ -302,20 +302,22 @@ | |||
26 | 302 | if self.tree is None: | 302 | if self.tree is None: |
27 | 303 | raise errors.NoSuchFile(path) | 303 | raise errors.NoSuchFile(path) |
28 | 304 | try: | 304 | try: |
30 | 305 | return tree_lookup_path(self.store.__getitem__, self.tree, | 305 | (mode, hexsha) = tree_lookup_path(self.store.__getitem__, self.tree, |
31 | 306 | path.encode('utf-8')) | 306 | path.encode('utf-8')) |
32 | 307 | except KeyError: | 307 | except KeyError: |
33 | 308 | raise errors.NoSuchFile(self, path) | 308 | raise errors.NoSuchFile(self, path) |
34 | 309 | else: | ||
35 | 310 | return (self.store, mode, hexsha) | ||
36 | 309 | 311 | ||
37 | 310 | def is_executable(self, path, file_id=None): | 312 | def is_executable(self, path, file_id=None): |
39 | 311 | (mode, hexsha) = self._lookup_path(path) | 313 | (store, mode, hexsha) = self._lookup_path(path) |
40 | 312 | if mode is None: | 314 | if mode is None: |
41 | 313 | # the tree root is a directory | 315 | # the tree root is a directory |
42 | 314 | return False | 316 | return False |
43 | 315 | return mode_is_executable(mode) | 317 | return mode_is_executable(mode) |
44 | 316 | 318 | ||
45 | 317 | def kind(self, path, file_id=None): | 319 | def kind(self, path, file_id=None): |
47 | 318 | (mode, hexsha) = self._lookup_path(path) | 320 | (store, mode, hexsha) = self._lookup_path(path) |
48 | 319 | if mode is None: | 321 | if mode is None: |
49 | 320 | # the tree root is a directory | 322 | # the tree root is a directory |
50 | 321 | return "directory" | 323 | return "directory" |
51 | @@ -334,7 +336,7 @@ | |||
52 | 334 | return | 336 | return |
53 | 335 | if from_dir is None: | 337 | if from_dir is None: |
54 | 336 | from_dir = u"" | 338 | from_dir = u"" |
56 | 337 | (mode, hexsha) = self._lookup_path(from_dir) | 339 | (store, mode, hexsha) = self._lookup_path(from_dir) |
57 | 338 | if mode is None: # Root | 340 | if mode is None: # Root |
58 | 339 | root_ie = self._get_dir_ie(b"", None) | 341 | root_ie = self._get_dir_ie(b"", None) |
59 | 340 | else: | 342 | else: |
60 | @@ -343,16 +345,16 @@ | |||
61 | 343 | if mode_kind(mode) == 'directory': | 345 | if mode_kind(mode) == 'directory': |
62 | 344 | root_ie = self._get_dir_ie(from_dir.encode("utf-8"), parent_id) | 346 | root_ie = self._get_dir_ie(from_dir.encode("utf-8"), parent_id) |
63 | 345 | else: | 347 | else: |
65 | 346 | root_ie = self._get_file_ie(from_dir.encode("utf-8"), | 348 | root_ie = self._get_file_ie(store, from_dir.encode("utf-8"), |
66 | 347 | posixpath.basename(from_dir), mode, hexsha) | 349 | posixpath.basename(from_dir), mode, hexsha) |
67 | 348 | if from_dir != "" or include_root: | 350 | if from_dir != "" or include_root: |
68 | 349 | yield (from_dir, "V", root_ie.kind, root_ie.file_id, root_ie) | 351 | yield (from_dir, "V", root_ie.kind, root_ie.file_id, root_ie) |
69 | 350 | todo = set() | 352 | todo = set() |
70 | 351 | if root_ie.kind == 'directory': | 353 | if root_ie.kind == 'directory': |
72 | 352 | todo.add((from_dir.encode("utf-8"), hexsha, root_ie.file_id)) | 354 | todo.add((store, from_dir.encode("utf-8"), hexsha, root_ie.file_id)) |
73 | 353 | while todo: | 355 | while todo: |
76 | 354 | (path, hexsha, parent_id) = todo.pop() | 356 | (store, path, hexsha, parent_id) = todo.pop() |
77 | 355 | tree = self.store[hexsha] | 357 | tree = store[hexsha] |
78 | 356 | for name, mode, hexsha in tree.iteritems(): | 358 | for name, mode, hexsha in tree.iteritems(): |
79 | 357 | if self.mapping.is_special_file(name): | 359 | if self.mapping.is_special_file(name): |
80 | 358 | continue | 360 | continue |
81 | @@ -360,12 +362,12 @@ | |||
82 | 360 | if stat.S_ISDIR(mode): | 362 | if stat.S_ISDIR(mode): |
83 | 361 | ie = self._get_dir_ie(child_path, parent_id) | 363 | ie = self._get_dir_ie(child_path, parent_id) |
84 | 362 | if recursive: | 364 | if recursive: |
86 | 363 | todo.add((child_path, hexsha, ie.file_id)) | 365 | todo.add((store, child_path, hexsha, ie.file_id)) |
87 | 364 | else: | 366 | else: |
89 | 365 | ie = self._get_file_ie(child_path, name, mode, hexsha, parent_id) | 367 | ie = self._get_file_ie(store, child_path, name, mode, hexsha, parent_id) |
90 | 366 | yield child_path.decode('utf-8'), "V", ie.kind, ie.file_id, ie | 368 | yield child_path.decode('utf-8'), "V", ie.kind, ie.file_id, ie |
91 | 367 | 369 | ||
93 | 368 | def _get_file_ie(self, path, name, mode, hexsha, parent_id): | 370 | def _get_file_ie(self, store, path, name, mode, hexsha, parent_id): |
94 | 369 | if type(path) is not bytes: | 371 | if type(path) is not bytes: |
95 | 370 | raise TypeError(path) | 372 | raise TypeError(path) |
96 | 371 | if type(name) is not bytes: | 373 | if type(name) is not bytes: |
97 | @@ -374,11 +376,11 @@ | |||
98 | 374 | file_id = self._fileid_map.lookup_file_id(path) | 376 | file_id = self._fileid_map.lookup_file_id(path) |
99 | 375 | ie = entry_factory[kind](file_id, name.decode("utf-8"), parent_id) | 377 | ie = entry_factory[kind](file_id, name.decode("utf-8"), parent_id) |
100 | 376 | if kind == 'symlink': | 378 | if kind == 'symlink': |
102 | 377 | ie.symlink_target = self.store[hexsha].data.decode('utf-8') | 379 | ie.symlink_target = store[hexsha].data.decode('utf-8') |
103 | 378 | elif kind == 'tree-reference': | 380 | elif kind == 'tree-reference': |
104 | 379 | ie.reference_revision = self.mapping.revision_id_foreign_to_bzr(hexsha) | 381 | ie.reference_revision = self.mapping.revision_id_foreign_to_bzr(hexsha) |
105 | 380 | else: | 382 | else: |
107 | 381 | data = self.store[hexsha].data | 383 | data = store[hexsha].data |
108 | 382 | ie.text_sha1 = osutils.sha_string(data) | 384 | ie.text_sha1 = osutils.sha_string(data) |
109 | 383 | ie.text_size = len(data) | 385 | ie.text_size = len(data) |
110 | 384 | ie.executable = mode_is_executable(mode) | 386 | ie.executable = mode_is_executable(mode) |
111 | @@ -390,14 +392,14 @@ | |||
112 | 390 | posixpath.basename(path).decode("utf-8"), parent_id) | 392 | posixpath.basename(path).decode("utf-8"), parent_id) |
113 | 391 | 393 | ||
114 | 392 | def iter_child_entries(self, path, file_id=None): | 394 | def iter_child_entries(self, path, file_id=None): |
116 | 393 | (mode, tree_sha) = self._lookup_path(path) | 395 | (store, mode, tree_sha) = self._lookup_path(path) |
117 | 394 | 396 | ||
118 | 395 | if not stat.S_ISDIR(mode): | 397 | if not stat.S_ISDIR(mode): |
119 | 396 | return | 398 | return |
120 | 397 | 399 | ||
121 | 398 | encoded_path = path.encode('utf-8') | 400 | encoded_path = path.encode('utf-8') |
122 | 399 | file_id = self.path2id(path) | 401 | file_id = self.path2id(path) |
124 | 400 | tree = self.store[tree_sha] | 402 | tree = store[tree_sha] |
125 | 401 | for name, mode, hexsha in tree.iteritems(): | 403 | for name, mode, hexsha in tree.iteritems(): |
126 | 402 | if self.mapping.is_special_file(name): | 404 | if self.mapping.is_special_file(name): |
127 | 403 | continue | 405 | continue |
128 | @@ -405,7 +407,7 @@ | |||
129 | 405 | if stat.S_ISDIR(mode): | 407 | if stat.S_ISDIR(mode): |
130 | 406 | yield self._get_dir_ie(child_path, file_id) | 408 | yield self._get_dir_ie(child_path, file_id) |
131 | 407 | else: | 409 | else: |
133 | 408 | yield self._get_file_ie(child_path, name, mode, hexsha, | 410 | yield self._get_file_ie(store, child_path, name, mode, hexsha, |
134 | 409 | file_id) | 411 | file_id) |
135 | 410 | 412 | ||
136 | 411 | def iter_entries_by_dir(self, specific_files=None, yield_parents=False): | 413 | def iter_entries_by_dir(self, specific_files=None, yield_parents=False): |
137 | @@ -419,13 +421,13 @@ | |||
138 | 419 | specific_files = None | 421 | specific_files = None |
139 | 420 | else: | 422 | else: |
140 | 421 | specific_files = set([p.encode('utf-8') for p in specific_files]) | 423 | specific_files = set([p.encode('utf-8') for p in specific_files]) |
142 | 422 | todo = set([("", self.tree, None)]) | 424 | todo = set([(self.store, "", self.tree, None)]) |
143 | 423 | while todo: | 425 | while todo: |
145 | 424 | path, tree_sha, parent_id = todo.pop() | 426 | store, path, tree_sha, parent_id = todo.pop() |
146 | 425 | ie = self._get_dir_ie(path, parent_id) | 427 | ie = self._get_dir_ie(path, parent_id) |
147 | 426 | if specific_files is None or path in specific_files: | 428 | if specific_files is None or path in specific_files: |
148 | 427 | yield path.decode("utf-8"), ie | 429 | yield path.decode("utf-8"), ie |
150 | 428 | tree = self.store[tree_sha] | 430 | tree = store[tree_sha] |
151 | 429 | for name, mode, hexsha in tree.iteritems(): | 431 | for name, mode, hexsha in tree.iteritems(): |
152 | 430 | if self.mapping.is_special_file(name): | 432 | if self.mapping.is_special_file(name): |
153 | 431 | continue | 433 | continue |
154 | @@ -433,10 +435,10 @@ | |||
155 | 433 | if stat.S_ISDIR(mode): | 435 | if stat.S_ISDIR(mode): |
156 | 434 | if (specific_files is None or | 436 | if (specific_files is None or |
157 | 435 | any(filter(lambda p: p.startswith(child_path), specific_files))): | 437 | any(filter(lambda p: p.startswith(child_path), specific_files))): |
159 | 436 | todo.add((child_path, hexsha, ie.file_id)) | 438 | todo.add((store, child_path, hexsha, ie.file_id)) |
160 | 437 | elif specific_files is None or child_path in specific_files: | 439 | elif specific_files is None or child_path in specific_files: |
161 | 438 | yield (child_path.decode("utf-8"), | 440 | yield (child_path.decode("utf-8"), |
163 | 439 | self._get_file_ie(child_path, name, mode, hexsha, | 441 | self._get_file_ie(store, child_path, name, mode, hexsha, |
164 | 440 | ie.file_id)) | 442 | ie.file_id)) |
165 | 441 | 443 | ||
166 | 442 | def get_revision_id(self): | 444 | def get_revision_id(self): |
167 | @@ -449,22 +451,22 @@ | |||
168 | 449 | return osutils.sha_string(self.get_file_text(path, file_id)) | 451 | return osutils.sha_string(self.get_file_text(path, file_id)) |
169 | 450 | 452 | ||
170 | 451 | def get_file_verifier(self, path, file_id=None, stat_value=None): | 453 | def get_file_verifier(self, path, file_id=None, stat_value=None): |
172 | 452 | (mode, hexsha) = self._lookup_path(path) | 454 | (store, mode, hexsha) = self._lookup_path(path) |
173 | 453 | return ("GIT", hexsha) | 455 | return ("GIT", hexsha) |
174 | 454 | 456 | ||
175 | 455 | def get_file_text(self, path, file_id=None): | 457 | def get_file_text(self, path, file_id=None): |
176 | 456 | """See RevisionTree.get_file_text.""" | 458 | """See RevisionTree.get_file_text.""" |
178 | 457 | (mode, hexsha) = self._lookup_path(path) | 459 | (store, mode, hexsha) = self._lookup_path(path) |
179 | 458 | if stat.S_ISREG(mode): | 460 | if stat.S_ISREG(mode): |
181 | 459 | return self.store[hexsha].data | 461 | return store[hexsha].data |
182 | 460 | else: | 462 | else: |
183 | 461 | return b"" | 463 | return b"" |
184 | 462 | 464 | ||
185 | 463 | def get_symlink_target(self, path, file_id=None): | 465 | def get_symlink_target(self, path, file_id=None): |
186 | 464 | """See RevisionTree.get_symlink_target.""" | 466 | """See RevisionTree.get_symlink_target.""" |
188 | 465 | (mode, hexsha) = self._lookup_path(path) | 467 | (store, mode, hexsha) = self._lookup_path(path) |
189 | 466 | if stat.S_ISLNK(mode): | 468 | if stat.S_ISLNK(mode): |
191 | 467 | return self.store[hexsha].data.decode('utf-8') | 469 | return store[hexsha].data.decode('utf-8') |
192 | 468 | else: | 470 | else: |
193 | 469 | return None | 471 | return None |
194 | 470 | 472 | ||
195 | @@ -476,16 +478,16 @@ | |||
196 | 476 | def path_content_summary(self, path): | 478 | def path_content_summary(self, path): |
197 | 477 | """See Tree.path_content_summary.""" | 479 | """See Tree.path_content_summary.""" |
198 | 478 | try: | 480 | try: |
200 | 479 | (mode, hexsha) = self._lookup_path(path) | 481 | (store, mode, hexsha) = self._lookup_path(path) |
201 | 480 | except errors.NoSuchFile: | 482 | except errors.NoSuchFile: |
202 | 481 | return ('missing', None, None, None) | 483 | return ('missing', None, None, None) |
203 | 482 | kind = mode_kind(mode) | 484 | kind = mode_kind(mode) |
204 | 483 | if kind == 'file': | 485 | if kind == 'file': |
205 | 484 | executable = mode_is_executable(mode) | 486 | executable = mode_is_executable(mode) |
207 | 485 | contents = self.store[hexsha].data | 487 | contents = store[hexsha].data |
208 | 486 | return (kind, len(contents), executable, osutils.sha_string(contents)) | 488 | return (kind, len(contents), executable, osutils.sha_string(contents)) |
209 | 487 | elif kind == 'symlink': | 489 | elif kind == 'symlink': |
211 | 488 | return (kind, None, None, self.store[hexsha].data) | 490 | return (kind, None, None, store[hexsha].data) |
212 | 489 | else: | 491 | else: |
213 | 490 | return (kind, None, None, None) | 492 | return (kind, None, None, None) |
214 | 491 | 493 |
Rubberstamp! Proposer approves of own proposal.