Merge lp:~jelmer/brz-git/track-store into lp:brz-git

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
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.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Rubberstamp! Proposer approves of own proposal.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tree.py'
--- tree.py 2018-03-27 03:09:48 +0000
+++ tree.py 2018-03-28 23:03:20 +0000
@@ -265,16 +265,16 @@
265265
266 def all_versioned_paths(self):266 def all_versioned_paths(self):
267 ret = set()267 ret = set()
268 todo = set([('', self.tree)])268 todo = set([(store, '', self.tree)])
269 while todo:269 while todo:
270 (path, tree_id) = todo.pop()270 (store, path, tree_id) = todo.pop()
271 if tree_id is None:271 if tree_id is None:
272 continue272 continue
273 tree = self.store[tree_id]273 tree = store[tree_id]
274 for name, mode, hexsha in tree.items():274 for name, mode, hexsha in tree.items():
275 subpath = posixpath.join(path, name)275 subpath = posixpath.join(path, name)
276 if stat.S_ISDIR(mode):276 if stat.S_ISDIR(mode):
277 todo.add((subpath, hexsha))277 todo.add((store, subpath, hexsha))
278 else:278 else:
279 ret.add(subpath)279 ret.add(subpath)
280 return ret280 return ret
@@ -302,20 +302,22 @@
302 if self.tree is None:302 if self.tree is None:
303 raise errors.NoSuchFile(path)303 raise errors.NoSuchFile(path)
304 try:304 try:
305 return tree_lookup_path(self.store.__getitem__, self.tree,305 (mode, hexsha) = tree_lookup_path(self.store.__getitem__, self.tree,
306 path.encode('utf-8'))306 path.encode('utf-8'))
307 except KeyError:307 except KeyError:
308 raise errors.NoSuchFile(self, path)308 raise errors.NoSuchFile(self, path)
309 else:
310 return (self.store, mode, hexsha)
309311
310 def is_executable(self, path, file_id=None):312 def is_executable(self, path, file_id=None):
311 (mode, hexsha) = self._lookup_path(path)313 (store, mode, hexsha) = self._lookup_path(path)
312 if mode is None:314 if mode is None:
313 # the tree root is a directory315 # the tree root is a directory
314 return False316 return False
315 return mode_is_executable(mode)317 return mode_is_executable(mode)
316318
317 def kind(self, path, file_id=None):319 def kind(self, path, file_id=None):
318 (mode, hexsha) = self._lookup_path(path)320 (store, mode, hexsha) = self._lookup_path(path)
319 if mode is None:321 if mode is None:
320 # the tree root is a directory322 # the tree root is a directory
321 return "directory"323 return "directory"
@@ -334,7 +336,7 @@
334 return336 return
335 if from_dir is None:337 if from_dir is None:
336 from_dir = u""338 from_dir = u""
337 (mode, hexsha) = self._lookup_path(from_dir)339 (store, mode, hexsha) = self._lookup_path(from_dir)
338 if mode is None: # Root340 if mode is None: # Root
339 root_ie = self._get_dir_ie(b"", None)341 root_ie = self._get_dir_ie(b"", None)
340 else:342 else:
@@ -343,16 +345,16 @@
343 if mode_kind(mode) == 'directory':345 if mode_kind(mode) == 'directory':
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)
345 else:347 else:
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"),
347 posixpath.basename(from_dir), mode, hexsha)349 posixpath.basename(from_dir), mode, hexsha)
348 if from_dir != "" or include_root:350 if from_dir != "" or include_root:
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)
350 todo = set()352 todo = set()
351 if root_ie.kind == 'directory':353 if root_ie.kind == 'directory':
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))
353 while todo:355 while todo:
354 (path, hexsha, parent_id) = todo.pop()356 (store, path, hexsha, parent_id) = todo.pop()
355 tree = self.store[hexsha]357 tree = store[hexsha]
356 for name, mode, hexsha in tree.iteritems():358 for name, mode, hexsha in tree.iteritems():
357 if self.mapping.is_special_file(name):359 if self.mapping.is_special_file(name):
358 continue360 continue
@@ -360,12 +362,12 @@
360 if stat.S_ISDIR(mode):362 if stat.S_ISDIR(mode):
361 ie = self._get_dir_ie(child_path, parent_id)363 ie = self._get_dir_ie(child_path, parent_id)
362 if recursive:364 if recursive:
363 todo.add((child_path, hexsha, ie.file_id))365 todo.add((store, child_path, hexsha, ie.file_id))
364 else:366 else:
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)
366 yield child_path.decode('utf-8'), "V", ie.kind, ie.file_id, ie368 yield child_path.decode('utf-8'), "V", ie.kind, ie.file_id, ie
367369
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):
369 if type(path) is not bytes:371 if type(path) is not bytes:
370 raise TypeError(path)372 raise TypeError(path)
371 if type(name) is not bytes:373 if type(name) is not bytes:
@@ -374,11 +376,11 @@
374 file_id = self._fileid_map.lookup_file_id(path)376 file_id = self._fileid_map.lookup_file_id(path)
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)
376 if kind == 'symlink':378 if kind == 'symlink':
377 ie.symlink_target = self.store[hexsha].data.decode('utf-8')379 ie.symlink_target = store[hexsha].data.decode('utf-8')
378 elif kind == 'tree-reference':380 elif kind == 'tree-reference':
379 ie.reference_revision = self.mapping.revision_id_foreign_to_bzr(hexsha)381 ie.reference_revision = self.mapping.revision_id_foreign_to_bzr(hexsha)
380 else:382 else:
381 data = self.store[hexsha].data383 data = store[hexsha].data
382 ie.text_sha1 = osutils.sha_string(data)384 ie.text_sha1 = osutils.sha_string(data)
383 ie.text_size = len(data)385 ie.text_size = len(data)
384 ie.executable = mode_is_executable(mode)386 ie.executable = mode_is_executable(mode)
@@ -390,14 +392,14 @@
390 posixpath.basename(path).decode("utf-8"), parent_id)392 posixpath.basename(path).decode("utf-8"), parent_id)
391393
392 def iter_child_entries(self, path, file_id=None):394 def iter_child_entries(self, path, file_id=None):
393 (mode, tree_sha) = self._lookup_path(path)395 (store, mode, tree_sha) = self._lookup_path(path)
394396
395 if not stat.S_ISDIR(mode):397 if not stat.S_ISDIR(mode):
396 return398 return
397399
398 encoded_path = path.encode('utf-8')400 encoded_path = path.encode('utf-8')
399 file_id = self.path2id(path)401 file_id = self.path2id(path)
400 tree = self.store[tree_sha]402 tree = store[tree_sha]
401 for name, mode, hexsha in tree.iteritems():403 for name, mode, hexsha in tree.iteritems():
402 if self.mapping.is_special_file(name):404 if self.mapping.is_special_file(name):
403 continue405 continue
@@ -405,7 +407,7 @@
405 if stat.S_ISDIR(mode):407 if stat.S_ISDIR(mode):
406 yield self._get_dir_ie(child_path, file_id)408 yield self._get_dir_ie(child_path, file_id)
407 else:409 else:
408 yield self._get_file_ie(child_path, name, mode, hexsha,410 yield self._get_file_ie(store, child_path, name, mode, hexsha,
409 file_id)411 file_id)
410412
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):
@@ -419,13 +421,13 @@
419 specific_files = None421 specific_files = None
420 else:422 else:
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])
422 todo = set([("", self.tree, None)])424 todo = set([(self.store, "", self.tree, None)])
423 while todo:425 while todo:
424 path, tree_sha, parent_id = todo.pop()426 store, path, tree_sha, parent_id = todo.pop()
425 ie = self._get_dir_ie(path, parent_id)427 ie = self._get_dir_ie(path, parent_id)
426 if specific_files is None or path in specific_files:428 if specific_files is None or path in specific_files:
427 yield path.decode("utf-8"), ie429 yield path.decode("utf-8"), ie
428 tree = self.store[tree_sha]430 tree = store[tree_sha]
429 for name, mode, hexsha in tree.iteritems():431 for name, mode, hexsha in tree.iteritems():
430 if self.mapping.is_special_file(name):432 if self.mapping.is_special_file(name):
431 continue433 continue
@@ -433,10 +435,10 @@
433 if stat.S_ISDIR(mode):435 if stat.S_ISDIR(mode):
434 if (specific_files is None or436 if (specific_files is None or
435 any(filter(lambda p: p.startswith(child_path), specific_files))):437 any(filter(lambda p: p.startswith(child_path), specific_files))):
436 todo.add((child_path, hexsha, ie.file_id))438 todo.add((store, child_path, hexsha, ie.file_id))
437 elif specific_files is None or child_path in specific_files:439 elif specific_files is None or child_path in specific_files:
438 yield (child_path.decode("utf-8"),440 yield (child_path.decode("utf-8"),
439 self._get_file_ie(child_path, name, mode, hexsha,441 self._get_file_ie(store, child_path, name, mode, hexsha,
440 ie.file_id))442 ie.file_id))
441443
442 def get_revision_id(self):444 def get_revision_id(self):
@@ -449,22 +451,22 @@
449 return osutils.sha_string(self.get_file_text(path, file_id))451 return osutils.sha_string(self.get_file_text(path, file_id))
450452
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):
452 (mode, hexsha) = self._lookup_path(path)454 (store, mode, hexsha) = self._lookup_path(path)
453 return ("GIT", hexsha)455 return ("GIT", hexsha)
454456
455 def get_file_text(self, path, file_id=None):457 def get_file_text(self, path, file_id=None):
456 """See RevisionTree.get_file_text."""458 """See RevisionTree.get_file_text."""
457 (mode, hexsha) = self._lookup_path(path)459 (store, mode, hexsha) = self._lookup_path(path)
458 if stat.S_ISREG(mode):460 if stat.S_ISREG(mode):
459 return self.store[hexsha].data461 return store[hexsha].data
460 else:462 else:
461 return b""463 return b""
462464
463 def get_symlink_target(self, path, file_id=None):465 def get_symlink_target(self, path, file_id=None):
464 """See RevisionTree.get_symlink_target."""466 """See RevisionTree.get_symlink_target."""
465 (mode, hexsha) = self._lookup_path(path)467 (store, mode, hexsha) = self._lookup_path(path)
466 if stat.S_ISLNK(mode):468 if stat.S_ISLNK(mode):
467 return self.store[hexsha].data.decode('utf-8')469 return store[hexsha].data.decode('utf-8')
468 else:470 else:
469 return None471 return None
470472
@@ -476,16 +478,16 @@
476 def path_content_summary(self, path):478 def path_content_summary(self, path):
477 """See Tree.path_content_summary."""479 """See Tree.path_content_summary."""
478 try:480 try:
479 (mode, hexsha) = self._lookup_path(path)481 (store, mode, hexsha) = self._lookup_path(path)
480 except errors.NoSuchFile:482 except errors.NoSuchFile:
481 return ('missing', None, None, None)483 return ('missing', None, None, None)
482 kind = mode_kind(mode)484 kind = mode_kind(mode)
483 if kind == 'file':485 if kind == 'file':
484 executable = mode_is_executable(mode)486 executable = mode_is_executable(mode)
485 contents = self.store[hexsha].data487 contents = store[hexsha].data
486 return (kind, len(contents), executable, osutils.sha_string(contents))488 return (kind, len(contents), executable, osutils.sha_string(contents))
487 elif kind == 'symlink':489 elif kind == 'symlink':
488 return (kind, None, None, self.store[hexsha].data)490 return (kind, None, None, store[hexsha].data)
489 else:491 else:
490 return (kind, None, None, None)492 return (kind, None, None, None)
491493

Subscribers

People subscribed via source and target branches

to all changes: