/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 branch.py

More formatting fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""An adapter between a Git Branch and a Bazaar Branch"""
19
19
 
 
20
from dulwich.objects import (
 
21
    Commit,
 
22
    Tag,
 
23
    )
 
24
 
20
25
from bzrlib import (
21
26
    branch,
22
27
    config,
24
29
    revision,
25
30
    tag,
26
31
    )
27
 
from bzrlib.decorators import needs_read_lock
28
 
from bzrlib.trace import mutter
29
 
 
30
 
from bzrlib.plugins.git.foreign import ForeignBranch
31
 
from bzrlib.plugins.git.errors import LightWeightCheckoutsNotSupported
32
 
 
33
 
from dulwich.objects import (
34
 
        Commit,
35
 
        Tag,
36
 
        )
37
 
 
38
 
class GitTagDict(tag.BasicTags):
 
32
from bzrlib.decorators import (
 
33
    needs_read_lock,
 
34
    )
 
35
from bzrlib.trace import (
 
36
    mutter,
 
37
    )
 
38
 
 
39
from bzrlib.plugins.git.foreign import (
 
40
    ForeignBranch,
 
41
    )
 
42
from bzrlib.plugins.git.errors import (
 
43
    LightWeightCheckoutsNotSupported,
 
44
    )
 
45
 
 
46
 
 
47
class LocalGitTagDict(tag.BasicTags):
 
48
    """Dictionary with tags in a local repository."""
39
49
 
40
50
    def __init__(self, branch):
41
51
        self.branch = branch
49
59
                v = obj.object[1]
50
60
                obj = self.repository._git.get_object(v)
51
61
            if not isinstance(obj, Commit):
52
 
                mutter("Tag %s points at object %r that is not a commit, ignoring", k, obj)
 
62
                mutter("Tag %s points at object %r that is not a commit, "
 
63
                       "ignoring", k, obj)
53
64
                continue
54
65
            ret[k] = self.branch.mapping.revision_id_foreign_to_bzr(v)
55
66
        return ret
66
77
        # do not provide a BranchDataConfig
67
78
        self.option_sources = self.option_sources[0], self.option_sources[2]
68
79
 
69
 
    def set_user_option(self, name, value, store=config.STORE_BRANCH, warn_masked=False):
 
80
    def set_user_option(self, name, value, store=config.STORE_BRANCH,
 
81
            warn_masked=False):
70
82
        """Force local to True"""
71
 
        config.BranchConfig.set_user_option(self, name, value, store=config.STORE_LOCATION, warn_masked=warn_masked)
 
83
        config.BranchConfig.set_user_option(self, name, value,
 
84
            store=config.STORE_LOCATION, warn_masked=warn_masked)
72
85
 
73
86
 
74
87
class GitBranchFormat(branch.BranchFormat):
83
96
        if getattr(branch.repository, "get_refs", None) is not None:
84
97
            from bzrlib.plugins.git.remote import RemoteGitTagDict
85
98
            return RemoteGitTagDict(branch)
86
 
        return GitTagDict(branch)
 
99
        else:
 
100
            return LocalGitTagDict(branch)
87
101
 
88
102
 
89
103
class GitBranch(ForeignBranch):
104
118
            stop_revision = source.last_revision()
105
119
        # FIXME: Check for diverged branches
106
120
        revidmap = self.repository.dfetch(source.repository, stop_revision)
107
 
        self.head, self.mapping = self.mapping.revision_id_bzr_to_foreign(revidmap[stop_revision])
 
121
        self.head, self.mapping = self.mapping.revision_id_bzr_to_foreign(
 
122
            revidmap[stop_revision])
108
123
        return revidmap
109
124
 
110
125
    def lock_write(self):
132
147
 
133
148
 
134
149
class LocalGitBranch(GitBranch):
 
150
    """A local Git branch."""
135
151
 
136
152
    @needs_read_lock
137
153
    def last_revision(self):
140
156
            return revision.NULL_REVISION
141
157
        return self.mapping.revision_id_foreign_to_bzr(self.head)
142
158
 
143
 
    def create_checkout(self, to_location, revision_id=None, 
144
 
                        lightweight=False, accelerator_tree=None, hardlink=False):
 
159
    def create_checkout(self, to_location, revision_id=None, lightweight=False,
 
160
        accelerator_tree=None, hardlink=False):
145
161
        if lightweight:
146
162
            raise LightWeightCheckoutsNotSupported()
147
 
        return self._create_heavyweight_checkout(to_location, revision_id, hardlink)
 
163
        return self._create_heavyweight_checkout(to_location, revision_id,
 
164
            hardlink)
148
165
 
149
166
    def _create_heavyweight_checkout(self, to_location, revision_id=None, 
150
167
                                     hardlink=False):
167
184
    def _gen_revision_history(self):
168
185
        if self.head is None:
169
186
            return []
170
 
        ret = list(self.repository.iter_reverse_revision_history(self.last_revision()))
 
187
        ret = list(self.repository.iter_reverse_revision_history(
 
188
            self.last_revision()))
171
189
        ret.reverse()
172
190
        return ret
173
191
 
189
207
 
190
208
 
191
209
class InterGitGenericBranch(branch.InterBranch):
 
210
    """InterBranch implementation that pulls from Git into bzr."""
192
211
 
193
212
    @classmethod
194
213
    def is_compatible(self, source, target):
206
225
                raise BzrError("No such remote branch '%s', found: %r" % (
207
226
                    self.source.name, heads.keys()))
208
227
            head = heads[self.source.name]
209
 
            self._last_revid = self.source.mapping.revision_id_foreign_to_bzr(head)
 
228
            self._last_revid = self.source.mapping.revision_id_foreign_to_bzr(
 
229
                head)
210
230
            if self.target.repository.has_revision(self._last_revid):
211
231
                return []
212
232
            return [head]