42
40
self.store = self.repository._git.object_store
44
42
def find_last_change_revision(self, path, commit_id):
45
if not isinstance(path, bytes):
47
43
commit = self.store[commit_id]
48
44
target_mode, target_sha = tree_lookup_path(self.store.__getitem__,
51
47
target_mode = stat.S_IFDIR
52
48
if target_mode is None:
53
raise AssertionError("sha %r for %r in %r" %
54
(target_sha, path, commit_id))
49
raise AssertionError("sha %r for %r in %r" % (target_sha, path, commit_id))
56
51
parent_commits = []
57
52
for parent_commit in [self.store[c] for c in commit.parents]:
59
54
mode, sha = tree_lookup_path(self.store.__getitem__,
60
parent_commit.tree, path)
55
parent_commit.tree, path)
61
56
except (NotTreeError, KeyError):
64
59
parent_commits.append(parent_commit)
66
61
mode = stat.S_IFDIR
67
62
# Candidate found iff, mode or text changed,
68
63
# or is a directory that didn't previously exist.
69
64
if mode != target_mode or (
70
not stat.S_ISDIR(target_mode) and sha != target_sha):
71
return (path, commit.id)
65
not stat.S_ISDIR(target_mode) and sha != target_sha):
66
return (path, commit.id)
72
67
if parent_commits == []:
74
69
commit = parent_commits[0]
82
77
self.store = self.change_scanner.repository._git.object_store
84
79
def _get_parents(self, file_id, text_revision):
85
commit_id, mapping = (
86
self.change_scanner.repository.lookup_bzr_revision_id(
80
commit_id, mapping = self.change_scanner.repository.lookup_bzr_revision_id(
89
path = encode_git_path(mapping.parse_file_id(file_id))
83
path = mapping.parse_file_id(file_id)
91
85
raise KeyError(file_id)
93
87
for commit_parent in self.store[commit_id].parents:
95
(path, text_parent) = (
96
self.change_scanner.find_last_change_revision(
89
(path, text_parent) = self.change_scanner.find_last_change_revision(path, commit_parent)
100
92
if text_parent not in text_parents:
101
93
text_parents.append(text_parent)
104
self.change_scanner.repository.lookup_foreign_revision_id(p))
105
for p in text_parents])
94
return tuple([(file_id,
95
self.change_scanner.repository.lookup_foreign_revision_id(p)) for p
107
98
def get_parent_map(self, keys):
111
102
if text_revision == NULL_REVISION:
114
if not isinstance(file_id, bytes):
115
raise TypeError(file_id)
116
if not isinstance(text_revision, bytes):
117
raise TypeError(text_revision)
119
106
ret[key] = self._get_parents(file_id, text_revision)