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.338.1
by Jelmer Vernooij
Directories don't change when their contents do. |
20 |
import stat |
21 |
||
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
22 |
from dulwich.errors import ( |
23 |
NotTreeError, |
|
24 |
)
|
|
25 |
from dulwich.object_store import ( |
|
26 |
tree_lookup_path, |
|
27 |
)
|
|
28 |
||
6986.2.1
by Jelmer Vernooij
Move breezy.plugins.git to breezy.git. |
29 |
from ..revision import ( |
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
30 |
NULL_REVISION, |
31 |
)
|
|
32 |
||
7490.70.1
by Jelmer Vernooij
Add functions for encoding/decoding git paths. |
33 |
from .mapping import ( |
34 |
encode_git_path, |
|
35 |
)
|
|
36 |
||
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
37 |
|
38 |
class GitFileLastChangeScanner(object): |
|
39 |
||
40 |
def __init__(self, repository): |
|
41 |
self.repository = repository |
|
42 |
self.store = self.repository._git.object_store |
|
43 |
||
44 |
def find_last_change_revision(self, path, commit_id): |
|
7045.4.1
by Jelmer Vernooij
Some brz-git fixes. |
45 |
if not isinstance(path, bytes): |
46 |
raise TypeError(path) |
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
47 |
commit = self.store[commit_id] |
0.200.1286
by Jelmer Vernooij
Don't set vf-specific properties. |
48 |
target_mode, target_sha = tree_lookup_path(self.store.__getitem__, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
49 |
commit.tree, path) |
7045.4.1
by Jelmer Vernooij
Some brz-git fixes. |
50 |
if path == b'': |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
51 |
target_mode = stat.S_IFDIR |
0.361.1
by Jelmer Vernooij
Don't use assert. |
52 |
if target_mode is None: |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
53 |
raise AssertionError("sha %r for %r in %r" % |
54 |
(target_sha, path, commit_id)) |
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
55 |
while True: |
0.200.1757
by Jelmer Vernooij
Fix root tests. |
56 |
parent_commits = [] |
57 |
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(). |
58 |
try: |
59 |
mode, sha = tree_lookup_path(self.store.__getitem__, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
60 |
parent_commit.tree, path) |
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
61 |
except (NotTreeError, KeyError): |
62 |
continue
|
|
0.200.1757
by Jelmer Vernooij
Fix root tests. |
63 |
else: |
64 |
parent_commits.append(parent_commit) |
|
7045.4.1
by Jelmer Vernooij
Some brz-git fixes. |
65 |
if path == b'': |
0.391.7
by Jelmer Vernooij
Fix reporting of missing files in .iter_changes. |
66 |
mode = stat.S_IFDIR |
0.338.1
by Jelmer Vernooij
Directories don't change when their contents do. |
67 |
# Candidate found iff, mode or text changed,
|
68 |
# or is a directory that didn't previously exist.
|
|
69 |
if mode != target_mode or ( |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
70 |
not stat.S_ISDIR(target_mode) and sha != target_sha): |
71 |
return (path, commit.id) |
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
72 |
if parent_commits == []: |
73 |
break
|
|
74 |
commit = parent_commits[0] |
|
0.200.1757
by Jelmer Vernooij
Fix root tests. |
75 |
return (path, commit.id) |
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
76 |
|
77 |
||
78 |
class GitFileParentProvider(object): |
|
79 |
||
80 |
def __init__(self, change_scanner): |
|
81 |
self.change_scanner = change_scanner |
|
82 |
self.store = self.change_scanner.repository._git.object_store |
|
83 |
||
84 |
def _get_parents(self, file_id, text_revision): |
|
7143.15.3
by Jelmer Vernooij
Fix pep8 issues in breezy.git. |
85 |
commit_id, mapping = ( |
86 |
self.change_scanner.repository.lookup_bzr_revision_id( |
|
87 |
text_revision)) |
|
0.355.1
by Jelmer Vernooij
If file id is not valid, raise KeyError. |
88 |
try: |
7490.70.1
by Jelmer Vernooij
Add functions for encoding/decoding git paths. |
89 |
path = encode_git_path(mapping.parse_file_id(file_id)) |
0.355.1
by Jelmer Vernooij
If file id is not valid, raise KeyError. |
90 |
except ValueError: |
91 |
raise KeyError(file_id) |
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
92 |
text_parents = [] |
93 |
for commit_parent in self.store[commit_id].parents: |
|
0.200.1756
by Jelmer Vernooij
Initial work on annotate support. |
94 |
try: |
7143.15.3
by Jelmer Vernooij
Fix pep8 issues in breezy.git. |
95 |
(path, text_parent) = ( |
96 |
self.change_scanner.find_last_change_revision( |
|
7290.36.1
by Jelmer Vernooij
Fix filegraph operations on Git. |
97 |
path, commit_parent)) |
0.200.1756
by Jelmer Vernooij
Initial work on annotate support. |
98 |
except KeyError: |
99 |
continue
|
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
100 |
if text_parent not in text_parents: |
101 |
text_parents.append(text_parent) |
|
7143.15.3
by Jelmer Vernooij
Fix pep8 issues in breezy.git. |
102 |
return tuple([ |
103 |
(file_id, |
|
104 |
self.change_scanner.repository.lookup_foreign_revision_id(p)) |
|
105 |
for p in text_parents]) |
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
106 |
|
107 |
def get_parent_map(self, keys): |
|
108 |
ret = {} |
|
109 |
for key in keys: |
|
110 |
(file_id, text_revision) = key |
|
111 |
if text_revision == NULL_REVISION: |
|
0.200.1756
by Jelmer Vernooij
Initial work on annotate support. |
112 |
ret[key] = () |
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
113 |
continue
|
7045.4.2
by Jelmer Vernooij
Fix some more gitty tests. |
114 |
if not isinstance(file_id, bytes): |
115 |
raise TypeError(file_id) |
|
116 |
if not isinstance(text_revision, bytes): |
|
117 |
raise TypeError(text_revision) |
|
0.200.1283
by Jelmer Vernooij
Provide Repository.get_file_graph() and Tree.get_file_revision(). |
118 |
try: |
119 |
ret[key] = self._get_parents(file_id, text_revision) |
|
120 |
except KeyError: |
|
121 |
pass
|
|
122 |
return ret |