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
 | 
2  | 
#
 | 
|
3  | 
# This program is free software; you can redistribute it and/or modify
 | 
|
4  | 
# it under the terms of the GNU General Public License as published by
 | 
|
5  | 
# the Free Software Foundation; either version 2 of the License, or
 | 
|
6  | 
# (at your option) any later version.
 | 
|
7  | 
#
 | 
|
8  | 
# This program is distributed in the hope that it will be useful,
 | 
|
9  | 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|
10  | 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|
11  | 
# GNU General Public License for more details.
 | 
|
12  | 
#
 | 
|
13  | 
# You should have received a copy of the GNU General Public License
 | 
|
14  | 
# along with this program; if not, write to the Free Software
 | 
|
15  | 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
|
16  | 
||
17  | 
"""File graph access."""
 | 
|
18  | 
||
19  | 
from dulwich.errors import (  | 
|
20  | 
NotTreeError,  | 
|
21  | 
    )
 | 
|
22  | 
from dulwich.object_store import (  | 
|
23  | 
tree_lookup_path,  | 
|
24  | 
    )
 | 
|
25  | 
||
26  | 
from bzrlib.revision import (  | 
|
27  | 
NULL_REVISION,  | 
|
28  | 
    )
 | 
|
29  | 
||
30  | 
||
31  | 
class GitFileLastChangeScanner(object):  | 
|
32  | 
||
33  | 
def __init__(self, repository):  | 
|
34  | 
self.repository = repository  | 
|
35  | 
self.store = self.repository._git.object_store  | 
|
36  | 
||
37  | 
def find_last_change_revision(self, path, commit_id):  | 
|
38  | 
commit = self.store[commit_id]  | 
|
| 
0.200.1286
by Jelmer Vernooij
 Don't set vf-specific properties.  | 
39  | 
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().  | 
40  | 
commit.tree, path)  | 
41  | 
while True:  | 
|
42  | 
parent_commits = [self.store[c] for c in commit.parents]  | 
|
43  | 
for parent_commit in parent_commits:  | 
|
44  | 
try:  | 
|
45  | 
mode, sha = tree_lookup_path(self.store.__getitem__,  | 
|
46  | 
parent_commit.tree, path)  | 
|
47  | 
except (NotTreeError, KeyError):  | 
|
48  | 
                    continue
 | 
|
49  | 
if mode != target_mode or sha != target_sha:  | 
|
50  | 
return (path, commit.id)  | 
|
51  | 
if parent_commits == []:  | 
|
52  | 
                break
 | 
|
53  | 
commit = parent_commits[0]  | 
|
54  | 
return (path, commit.id)  | 
|
55  | 
||
56  | 
||
57  | 
class GitFileParentProvider(object):  | 
|
58  | 
||
59  | 
def __init__(self, change_scanner):  | 
|
60  | 
self.change_scanner = change_scanner  | 
|
61  | 
self.store = self.change_scanner.repository._git.object_store  | 
|
62  | 
||
63  | 
def _get_parents(self, file_id, text_revision):  | 
|
64  | 
commit_id, mapping = self.change_scanner.repository.lookup_bzr_revision_id(  | 
|
65  | 
text_revision)  | 
|
66  | 
path = mapping.parse_file_id(file_id)  | 
|
67  | 
text_parents = []  | 
|
68  | 
for commit_parent in self.store[commit_id].parents:  | 
|
69  | 
(_, text_parent) = self.change_scanner.find_last_change_revision(path, commit_parent)  | 
|
70  | 
if text_parent not in text_parents:  | 
|
71  | 
text_parents.append(text_parent)  | 
|
72  | 
return [(file_id,  | 
|
73  | 
self.change_scanner.repository.lookup_foreign_revision_id(p)) for p  | 
|
74  | 
in text_parents]  | 
|
75  | 
||
76  | 
def get_parent_map(self, keys):  | 
|
77  | 
ret = {}  | 
|
78  | 
for key in keys:  | 
|
79  | 
(file_id, text_revision) = key  | 
|
80  | 
if text_revision == NULL_REVISION:  | 
|
81  | 
                continue
 | 
|
82  | 
try:  | 
|
83  | 
ret[key] = self._get_parents(file_id, text_revision)  | 
|
84  | 
except KeyError:  | 
|
85  | 
                pass
 | 
|
86  | 
return ret  |