/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
1
# Copyright (C) 2008 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
0.200.140 by Jelmer Vernooij
Support negotiating with remote git repository and receiving pack.
17
from bzrlib.errors import InvalidRevisionId
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
18
from bzrlib.repository import InterRepository
0.200.140 by Jelmer Vernooij
Support negotiating with remote git repository and receiving pack.
19
from bzrlib.trace import info
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
20
0.200.141 by Jelmer Vernooij
Separate out local and remote fetching.
21
from bzrlib.plugins.git.repository import LocalGitRepository, GitRepository, GitFormat
22
from bzrlib.plugins.git.remote import RemoteGitRepository
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
23
0.200.140 by Jelmer Vernooij
Support negotiating with remote git repository and receiving pack.
24
from cStringIO import StringIO
25
26
27
class BzrFetchGraphWalker(object):
28
29
    def __init__(self, repository, mapping):
30
        self.repository = repository
31
        self.mapping = mapping
32
        self.done = set()
33
        self.heads = set(repository.all_revision_ids())
34
        self.parents = {}
35
36
    def ack(self, sha):
37
        revid = self.mapping.revision_id_foreign_to_bzr(sha)
38
        self.remove(revid)
39
40
    def remove(self, revid):
41
        self.done.add(revid)
42
        if ref in self.heads:
43
            self.heads.remove(revid)
44
        if revid in self.parents:
45
            for p in self.parents[revid]:
46
                self.remove(p)
47
48
    def next(self):
49
        while self.heads:
50
            ret = self.heads.pop()
51
            ps = self.repository.get_parent_map([ret])[ret]
52
            self.parents[ret] = ps
53
            self.heads.update([p for p in ps if not p in self.done])
54
            try:
55
                self.done.add(ret)
56
                return self.mapping.revision_id_bzr_to_foreign(ret)
57
            except InvalidRevisionId:
58
                pass
59
        return None
60
61
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
62
def import_git_object(repo, object):
63
    raise NotImplementedError(import_git_object)
0.200.141 by Jelmer Vernooij
Separate out local and remote fetching.
64
65
66
class InterGitRepository(InterRepository):
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
67
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
68
    _matching_repo_format = GitFormat()
69
70
    @staticmethod
71
    def _get_repo_format_to_test():
72
        return None
73
0.200.135 by Jelmer Vernooij
Add stub for fetching data.
74
    def copy_content(self, revision_id=None, pb=None):
75
        """See InterRepository.copy_content."""
76
        self.fetch(revision_id, pb, find_ghosts=False)
77
78
    def fetch(self, revision_id=None, pb=None, find_ghosts=False, 
79
              mapping=None):
0.200.141 by Jelmer Vernooij
Separate out local and remote fetching.
80
        if mapping is None:
81
            mapping = self.source.get_mapping()
0.200.140 by Jelmer Vernooij
Support negotiating with remote git repository and receiving pack.
82
        def progress(text):
83
            if pb is not None:
84
                pb.note("git: %s" % text)
85
            else:
86
                info("git: %s" % text)
0.200.141 by Jelmer Vernooij
Separate out local and remote fetching.
87
        def determine_wants(heads):
88
            if revision_id is None:
89
                ret = heads.values()
90
            else:
91
                ret = [mapping.revision_id_bzr_to_foreign(revision_id)]
92
            return [rev for rev in ret if not self.target.has_revision(mapping.revision_id_foreign_to_bzr(revision_id))]
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
93
        graph_walker = BzrFetchGraphWalker(self.target, mapping)
0.200.141 by Jelmer Vernooij
Separate out local and remote fetching.
94
        self.target.lock_write()
95
        try:
0.200.143 by Jelmer Vernooij
Reoncile InterGitRepository objects.
96
            for o in self.source.fetch_objects(determine_wants, graph_walker, progress):
97
                import_git_object(o)
0.200.141 by Jelmer Vernooij
Separate out local and remote fetching.
98
        finally:
99
            self.target.unlock()
100
101
    @staticmethod
102
    def is_compatible(source, target):
103
        """Be compatible with GitRepository."""
104
        # FIXME: Also check target uses VersionedFile
105
        return isinstance(source, LocalGitRepository) and target.supports_rich_root()