311
312
def path2id(self, path):
312
313
if self.mapping.is_special_file(path):
315
if not self.is_versioned(path):
314
317
return self._fileid_map.lookup_file_id(osutils.safe_unicode(path))
316
319
def all_file_ids(self):
317
return set(self._fileid_map.all_file_ids())
320
return {self.path2id(path) for path in self.all_versioned_paths()}
319
322
def all_versioned_paths(self):
321
324
todo = [(self.store, b'', self.tree)]
323
326
(store, path, tree_id) = todo.pop()
393
395
if mode is None: # Root
394
396
root_ie = self._get_dir_ie(b"", None)
396
parent_path = posixpath.dirname(from_dir.encode("utf-8"))
398
parent_path = posixpath.dirname(from_dir)
397
399
parent_id = self._fileid_map.lookup_file_id(parent_path)
398
400
if mode_kind(mode) == 'directory':
399
401
root_ie = self._get_dir_ie(from_dir.encode("utf-8"), parent_id)
401
403
root_ie = self._get_file_ie(store, from_dir.encode("utf-8"),
402
404
posixpath.basename(from_dir), mode, hexsha)
403
if from_dir != "" or include_root:
404
406
yield (from_dir, "V", root_ie.kind, root_ie.file_id, root_ie)
406
408
if root_ie.kind == 'directory':
407
todo.append((store, from_dir.encode("utf-8"), hexsha, root_ie.file_id))
409
todo.append((store, from_dir.encode("utf-8"), b"", hexsha, root_ie.file_id))
409
(store, path, hexsha, parent_id) = todo.pop()
411
(store, path, relpath, hexsha, parent_id) = todo.pop()
410
412
tree = store[hexsha]
411
413
for name, mode, hexsha in tree.iteritems():
412
414
if self.mapping.is_special_file(name):
414
416
child_path = posixpath.join(path, name)
417
child_relpath = posixpath.join(relpath, name)
415
418
if stat.S_ISDIR(mode):
416
419
ie = self._get_dir_ie(child_path, parent_id)
418
todo.append((store, child_path, hexsha, ie.file_id))
421
todo.append((store, child_path, child_relpath, hexsha, ie.file_id))
420
423
ie = self._get_file_ie(store, child_path, name, mode, hexsha, parent_id)
421
yield child_path.decode('utf-8'), "V", ie.kind, ie.file_id, ie
424
yield child_relpath.decode('utf-8'), "V", ie.kind, ie.file_id, ie
423
426
def _get_file_ie(self, store, path, name, mode, hexsha, parent_id):
424
427
if not isinstance(path, bytes):
476
479
specific_files = None
478
481
specific_files = set([p.encode('utf-8') for p in specific_files])
479
todo = [(self.store, b"", self.tree, None)]
482
todo = deque([(self.store, b"", self.tree, self.get_root_id())])
483
if specific_files is None or u"" in specific_files:
484
yield u"", self._get_dir_ie(b"", None)
481
store, path, tree_sha, parent_id = todo.pop()
482
ie = self._get_dir_ie(path, parent_id)
483
if specific_files is None or path in specific_files:
484
yield path.decode("utf-8"), ie
486
store, path, tree_sha, parent_id = todo.popleft()
485
487
tree = store[tree_sha]
486
489
for name, mode, hexsha in tree.iteritems():
487
490
if self.mapping.is_special_file(name):
489
492
child_path = posixpath.join(path, name)
493
child_path_decoded = child_path.decode('utf-8')
490
494
if stat.S_ISDIR(mode):
491
495
if (specific_files is None or
492
496
any(filter(lambda p: p.startswith(child_path), specific_files))):
493
todo.append((store, child_path, hexsha, ie.file_id))
494
elif specific_files is None or child_path in specific_files:
495
yield (child_path.decode("utf-8"),
496
self._get_file_ie(store, child_path, name, mode, hexsha,
498
(store, child_path, hexsha, self.path2id(child_path_decoded)))
499
if specific_files is None or child_path in specific_files:
500
if stat.S_ISDIR(mode):
501
yield (child_path_decoded,
502
self._get_dir_ie(child_path, parent_id))
504
yield (child_path_decoded,
505
self._get_file_ie(store, child_path, name, mode,
507
todo.extendleft(reversed(extradirs))
509
def iter_references(self):
510
if self.supports_tree_reference():
511
for path, entry in self.iter_entries_by_dir():
512
if entry.kind == 'tree-reference':
513
yield path, self.mapping.generate_file_id(b'')
499
515
def get_revision_id(self):
500
516
"""See RevisionTree.get_revision_id."""
509
525
(store, mode, hexsha) = self._lookup_path(path)
510
526
return ("GIT", hexsha)
528
def get_file_size(self, path, file_id=None):
529
(store, mode, hexsha) = self._lookup_path(path)
530
if stat.S_ISREG(mode):
531
return len(store[hexsha].data)
512
534
def get_file_text(self, path, file_id=None):
513
535
"""See RevisionTree.get_file_text."""
514
536
(store, mode, hexsha) = self._lookup_path(path)
551
573
contents = store[hexsha].data
552
574
return (kind, len(contents), executable, osutils.sha_string(contents))
553
575
elif kind == 'symlink':
554
return (kind, None, None, store[hexsha].data)
576
return (kind, None, None, store[hexsha].data.decode('utf-8'))
555
577
elif kind == 'tree-reference':
556
578
nested_repo = self._get_nested_repository(path)
557
579
return (kind, None, None,
605
627
for key, line in annotator.annotate_flat(this_key)]
606
628
return annotations
630
def _get_rules_searcher(self, default_searcher):
631
return default_searcher
633
def walkdirs(self, prefix=u""):
634
(store, mode, hexsha) = self._lookup_path(prefix)
635
todo = deque([(store, prefix.encode('utf-8'), hexsha, self.path2id(prefix))])
637
store, path, tree_sha, parent_id = todo.popleft()
638
path_decoded = path.decode('utf-8')
639
tree = store[tree_sha]
641
for name, mode, hexsha in tree.iteritems():
642
if self.mapping.is_special_file(name):
644
child_path = posixpath.join(path, name)
645
file_id = self.path2id(child_path.decode('utf-8'))
646
if stat.S_ISDIR(mode):
647
todo.append((store, child_path, hexsha, file_id))
649
(child_path.decode('utf-8'), name.decode('utf-8'),
650
mode_kind(mode), None,
651
file_id, mode_kind(mode)))
652
yield (path_decoded, parent_id), children
609
655
def tree_delta_from_git_changes(changes, mapping,
610
656
fileid_maps, specific_files=None,