/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

Add tests for revspec.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
from bzrlib.plugins.git.errors import (
31
31
    NoPushSupport,
32
32
    )
33
 
from bzrlib.plugins.git.mapping import (
34
 
    extract_unusual_modes,
35
 
    )
36
33
from bzrlib.plugins.git.object_store import (
37
34
    BazaarObjectStore,
38
35
    )
57
54
        """
58
55
        self.source = source
59
56
        self._object_store = store
60
 
        self._revids = set()
61
 
        self._sent_shas = set()
62
57
        self._pending = []
63
58
        self.pb = pb
64
59
 
65
60
    def import_revisions(self, revids):
66
 
        self._revids.update(revids)
67
61
        for i, revid in enumerate(revids):
68
62
            if self.pb:
69
63
                self.pb.update("pushing revisions", i, len(revids))
70
64
            git_commit = self.import_revision(revid)
71
65
            yield (revid, git_commit)
72
66
 
73
 
    def need_sha(self, sha):
74
 
        if sha is None or sha in self._sent_shas:
75
 
            return False
76
 
        (type, (fileid, revid)) = self._object_store._idmap.lookup_git_sha(sha)
77
 
        assert type in ("blob", "tree")
78
 
        if revid in self._revids:
79
 
            # Not sent yet, and part of the set of revisions to send
80
 
            return True
81
 
        # Not changed in the revisions to send, so either not necessary
82
 
        # or already present remotely (as git doesn't do ghosts)
83
 
        return False
84
 
 
85
 
    def queue(self, sha, obj, path, ie=None, inv=None, unusual_modes=None):
86
 
        if obj is None:
87
 
            # Can't lazy-evaluate directories, since they might be eliminated
88
 
            if ie.kind == "directory":
89
 
                obj = self._object_store._get_ie_object(ie, inv, unusual_modes)
90
 
                if obj is None:
91
 
                    return
92
 
            else:
93
 
                obj = (ie, inv, unusual_modes)
94
 
        self._pending.append((obj, path))
95
 
        self._sent_shas.add(sha)
96
 
 
97
67
    def import_revision(self, revid):
98
68
        """Import the gist of a revision into this Git repository.
99
69
 
100
70
        """
101
 
        inv = self.source.get_inventory(revid)
 
71
        inv = self._object_store.parent_invs_cache.get_inventory(revid)
102
72
        rev = self.source.get_revision(revid)
103
 
        unusual_modes = extract_unusual_modes(rev)
104
 
        todo = [inv.root]
105
 
        tree_sha = None
106
 
        while todo:
107
 
            ie = todo.pop()
108
 
            (sha, object) = self._object_store._get_ie_object_or_sha1(ie, inv, unusual_modes)
109
 
            if ie.parent_id is None:
110
 
                tree_sha = sha
111
 
            if not self.need_sha(sha):
112
 
                continue
113
 
            self.queue(sha, object, inv.id2path(ie.file_id), ie, inv, unusual_modes)
114
 
            if ie.kind == "directory":
115
 
                todo.extend(ie.children.values())
116
 
        assert tree_sha is not None
117
 
        commit = self._object_store._get_commit(rev, tree_sha)
118
 
        self.queue(commit.id, commit, None, None)
 
73
        commit = None
 
74
        for path, obj in self._object_store._revision_to_objects(rev, inv):
 
75
            if obj._type == "commit":
 
76
                commit = obj
 
77
            self._pending.append((obj, path))
119
78
        return commit.id
120
79
 
121
80
    def __len__(self):
122
81
        return len(self._pending)
123
82
 
124
83
    def __iter__(self):
125
 
        for i, (object, path) in enumerate(self._pending):
126
 
            if self.pb:
127
 
                self.pb.update("writing pack objects", i, len(self))
128
 
            if isinstance(object, tuple):
129
 
                object = self._object_store._get_ie_object(*object)
130
 
            yield (object, path)
 
84
        return iter(self._pending)
131
85
 
132
86
 
133
87
class InterToGitRepository(InterRepository):