/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to push.py

Move push code to push.py.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Push implementation that simply prints message saying push is not supported."""
18
18
 
 
19
from bzrlib import (
 
20
    ui,
 
21
    )
19
22
from bzrlib.repository import (
20
23
    InterRepository,
21
24
    )
23
26
from bzrlib.plugins.git.errors import (
24
27
    NoPushSupport,
25
28
    )
 
29
from bzrlib.plugins.git.mapping import (
 
30
    inventory_to_tree_and_blobs,
 
31
    revision_to_commit,
 
32
    )
26
33
from bzrlib.plugins.git.repository import (
27
34
    GitRepository,
28
35
    GitRepositoryFormat,
45
52
            fetch_spec=None):
46
53
        raise NoPushSupport()
47
54
 
 
55
    def import_revision_gist(self, revid, parent_lookup):
 
56
        """Import the gist of a revision into this Git repository.
 
57
 
 
58
        """
 
59
        objects = []
 
60
        rev = self.source.get_revision(revid)
 
61
        for sha, object, path in inventory_to_tree_and_blobs(
 
62
                self.source.get_inventory(revid), self.source.texts, None):
 
63
            if path == "":
 
64
                tree_sha = sha
 
65
            objects.append((object, path))
 
66
        commit = revision_to_commit(rev, tree_sha, parent_lookup)
 
67
        objects.append((commit, None))
 
68
        self.target._git.object_store.add_objects(objects)
 
69
        return commit.sha().hexdigest()
 
70
 
 
71
    def missing_revisions(self, stop_revision=None, ghosts=False):
 
72
        if stop_revision is not None:
 
73
            ancestry = [x for x in self.source.get_ancestry(stop_revision) if x is not None]
 
74
        else:
 
75
            ancestry = self.source.all_revision_ids()
 
76
        missing = []
 
77
        graph = self.source.get_graph()
 
78
        for revid in graph.iter_topo_order(ancestry):
 
79
            if not self.target.has_revision(revid):
 
80
                missing.append(revid)
 
81
            elif not ghosts:
 
82
                break
 
83
        return missing
 
84
 
 
85
    def dfetch(self, stop_revision=None, fetch_ghosts=False):
 
86
        """Import the gist of the ancestry of a particular revision."""
 
87
        revidmap = {}
 
88
        gitidmap = {}
 
89
        def parent_lookup(revid):
 
90
            try:
 
91
                return gitidmap[revid]
 
92
            except KeyError:
 
93
                return self.target.lookup_git_revid(revid)[0]
 
94
        mapping = self.target.get_mapping()
 
95
        self.source.lock_write()
 
96
        try:
 
97
            todo = self.missing_revisions(stop_revision, ghosts=fetch_ghosts)
 
98
            pb = ui.ui_factory.nested_progress_bar()
 
99
            try:
 
100
                for i, revid in enumerate(todo):
 
101
                    pb.update("pushing revisions", i, len(todo))
 
102
                    git_commit = self.import_revision_gist(revid, parent_lookup)
 
103
                    gitidmap[revid] = git_commit
 
104
                    git_revid = mapping.revision_id_foreign_to_bzr(git_commit)
 
105
                    revidmap[revid] = git_revid
 
106
            finally:
 
107
                pb.finished()
 
108
            if revidmap != {}:
 
109
                self.source.fetch(self.target, 
 
110
                        revision_id=revidmap[stop_revision])
 
111
        finally:
 
112
            self.source.unlock()
 
113
        return revidmap
 
114
 
48
115
    @staticmethod
49
116
    def is_compatible(source, target):
50
117
        """Be compatible with GitRepository."""