bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
1 |
# Copyright (C) 2011 Canonical Ltd
|
0.358.2
by Jelmer Vernooij
Refresh copyright headers, add my email. |
2 |
# Copyright (C) 2012-2018 Jelmer Vernooij <jelmer@jelmer.uk>
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
3 |
#
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
0.358.1
by Jelmer Vernooij
Fix FSF address. |
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
17 |
|
18 |
"""File graph access."""
|
|
19 |
||
0.200.1594
by Jelmer Vernooij
Use absolute_import everywhere. |
20 |
from __future__ import absolute_import |
21 |
||
0.338.1
by Jelmer Vernooij
Directories don't change when their contents do. |
22 |
import stat |
23 |
||
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
24 |
from dulwich.errors import ( |
25 |
NotTreeError, |
|
26 |
)
|
|
27 |
from dulwich.object_store import ( |
|
28 |
tree_lookup_path, |
|
29 |
)
|
|
30 |
||
6986.2.1
by Jelmer Vernooij
Move breezy.plugins.git to breezy.git. |
31 |
from ..revision import ( |
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
32 |
NULL_REVISION, |
33 |
)
|
|
34 |
||
35 |
||
36 |
class GitFileLastChangeScanner(object): |
|
37 |
||
38 |
def __init__(self, repository): |
|
39 |
self.repository = repository |
|
40 |
self.store = self.repository._git.object_store |
|
41 |
||
42 |
def find_last_change_revision(self, path, commit_id): |
|
7045.4.1
by Jelmer Vernooij
Some brz-git fixes. |
43 |
if not isinstance(path, bytes): |
44 |
raise TypeError(path) |
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
45 |
commit = self.store[commit_id] |
0.200.1286
by Jelmer Vernooij
Don't set vf-specific properties. |
46 |
target_mode, target_sha = tree_lookup_path(self.store.__getitem__, |
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
47 |
commit.tree, path) |
7045.4.1
by Jelmer Vernooij
Some brz-git fixes. |
48 |
if path == b'': |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
49 |
target_mode = stat.S_IFDIR |
0.361.1
by Jelmer Vernooij
Don't use assert. |
50 |
if target_mode is None: |
51 |
raise AssertionError("sha %r for %r in %r" % (target_sha, path, commit_id)) |
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
52 |
while True: |
0.200.1757
by Jelmer Vernooij
Fix root tests. |
53 |
parent_commits = [] |
54 |
for parent_commit in [self.store[c] for c in commit.parents]: |
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
55 |
try: |
56 |
mode, sha = tree_lookup_path(self.store.__getitem__, |
|
57 |
parent_commit.tree, path) |
|
58 |
except (NotTreeError, KeyError): |
|
59 |
continue
|
|
0.200.1757
by Jelmer Vernooij
Fix root tests. |
60 |
else: |
61 |
parent_commits.append(parent_commit) |
|
7045.4.1
by Jelmer Vernooij
Some brz-git fixes. |
62 |
if path == b'': |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
63 |
mode = stat.S_IFDIR |
0.338.1
by Jelmer Vernooij
Directories don't change when their contents do. |
64 |
# Candidate found iff, mode or text changed,
|
65 |
# or is a directory that didn't previously exist.
|
|
66 |
if mode != target_mode or ( |
|
67 |
not stat.S_ISDIR(target_mode) and sha != target_sha): |
|
68 |
return (path, commit.id) |
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
69 |
if parent_commits == []: |
70 |
break
|
|
71 |
commit = parent_commits[0] |
|
0.200.1757
by Jelmer Vernooij
Fix root tests. |
72 |
return (path, commit.id) |
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
73 |
|
74 |
||
75 |
class GitFileParentProvider(object): |
|
76 |
||
77 |
def __init__(self, change_scanner): |
|
78 |
self.change_scanner = change_scanner |
|
79 |
self.store = self.change_scanner.repository._git.object_store |
|
80 |
||
81 |
def _get_parents(self, file_id, text_revision): |
|
82 |
commit_id, mapping = self.change_scanner.repository.lookup_bzr_revision_id( |
|
83 |
text_revision) |
|
0.355.1
by Jelmer Vernooij
If file id is not valid, raise KeyError. |
84 |
try: |
85 |
path = mapping.parse_file_id(file_id) |
|
86 |
except ValueError: |
|
87 |
raise KeyError(file_id) |
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
88 |
text_parents = [] |
89 |
for commit_parent in self.store[commit_id].parents: |
|
0.200.1756
by Jelmer Vernooij
Initial work on annotate support. |
90 |
try: |
7045.4.1
by Jelmer Vernooij
Some brz-git fixes. |
91 |
(path, text_parent) = self.change_scanner.find_last_change_revision(path.encode('utf-8'), commit_parent) |
0.200.1756
by Jelmer Vernooij
Initial work on annotate support. |
92 |
except KeyError: |
93 |
continue
|
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
94 |
if text_parent not in text_parents: |
95 |
text_parents.append(text_parent) |
|
0.200.1324
by Jelmer Vernooij
More work on roundtripping support. |
96 |
return tuple([(file_id, |
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
97 |
self.change_scanner.repository.lookup_foreign_revision_id(p)) for p |
0.200.1324
by Jelmer Vernooij
More work on roundtripping support. |
98 |
in text_parents]) |
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
99 |
|
100 |
def get_parent_map(self, keys): |
|
101 |
ret = {} |
|
102 |
for key in keys: |
|
103 |
(file_id, text_revision) = key |
|
104 |
if text_revision == NULL_REVISION: |
|
0.200.1756
by Jelmer Vernooij
Initial work on annotate support. |
105 |
ret[key] = () |
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
106 |
continue
|
7045.4.2
by Jelmer Vernooij
Fix some more gitty tests. |
107 |
if not isinstance(file_id, bytes): |
108 |
raise TypeError(file_id) |
|
109 |
if not isinstance(text_revision, bytes): |
|
110 |
raise TypeError(text_revision) |
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
111 |
try: |
112 |
ret[key] = self._get_parents(file_id, text_revision) |
|
113 |
except KeyError: |
|
114 |
pass
|
|
115 |
return ret |