/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

Simply refer to bzr's docs in HACKING.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    bzrdir,
28
28
    config,
29
29
    errors,
30
 
    foreign,
31
30
    repository,
32
31
    revision,
33
32
    tag,
52
51
    NoSuchRef,
53
52
    )
54
53
 
55
 
try:
56
 
    from bzrlib.foreign import ForeignBranch
57
 
except ImportError:
58
 
    class ForeignBranch(branch.Branch):
59
 
        def __init__(self, mapping):
60
 
            self.mapping = mapping
61
 
            super(ForeignBranch, self).__init__()
 
54
from bzrlib.foreign import ForeignBranch
62
55
 
63
56
 
64
57
def extract_tags(refs, mapping):
96
89
    def get_tag_dict(self):
97
90
        ret = {}
98
91
        for k,v in self.repository._git.refs.as_dict("refs/tags").iteritems():
99
 
            obj = self.repository._git.get_object(v)
 
92
            try:
 
93
                obj = self.repository._git.get_object(v)
 
94
            except KeyError:
 
95
                mutter("Tag %s points at unknown object %s, ignoring", v, obj)
 
96
                continue
100
97
            while isinstance(obj, Tag):
101
98
                v = obj.object[1]
102
99
                obj = self.repository._git.get_object(v)
112
109
            self.branch.mapping.revision_id_bzr_to_foreign(revid)
113
110
 
114
111
 
 
112
class DictTagDict(LocalGitTagDict):
 
113
 
 
114
 
 
115
    def __init__(self, branch, tags):
 
116
        super(DictTagDict, self).__init__(branch)
 
117
        self._tags = tags
 
118
 
 
119
    def get_tag_dict(self):
 
120
        return self._tags
 
121
 
 
122
 
 
123
 
115
124
class GitBranchFormat(branch.BranchFormat):
116
125
 
117
126
    def get_format_description(self):
131
140
class GitBranch(ForeignBranch):
132
141
    """An adapter to git repositories for bzr Branch objects."""
133
142
 
134
 
    def __init__(self, bzrdir, repository, name, lockfiles):
 
143
    def __init__(self, bzrdir, repository, name, lockfiles, tagsdict=None):
135
144
        self.repository = repository
136
145
        self._format = GitBranchFormat()
137
146
        self.control_files = lockfiles
138
147
        self.bzrdir = bzrdir
139
148
        super(GitBranch, self).__init__(repository.get_mapping())
 
149
        if tagsdict is not None:
 
150
            self.tags = DictTagDict(self, tagsdict)
140
151
        self.name = name
141
152
        self._head = None
142
153
        self.base = bzrdir.transport.base
143
154
 
 
155
    def _get_checkout_format(self):
 
156
        """Return the most suitable metadir for a checkout of this branch.
 
157
        Weaves are used if this branch's repository uses weaves.
 
158
        """
 
159
        return get_rich_root_format()
 
160
 
 
161
    def get_child_submit_format(self):
 
162
        """Return the preferred format of submissions to this branch."""
 
163
        ret = self.get_config().get_user_option("child_submit_format")
 
164
        if ret is not None:
 
165
            return ret
 
166
        return "git"
 
167
 
144
168
    def _get_nick(self, local=False, possible_master_transports=None):
145
169
        """Find the nick name for this branch.
146
170
 
204
228
class LocalGitBranch(GitBranch):
205
229
    """A local Git branch."""
206
230
 
207
 
    def _get_checkout_format(self):
208
 
        """Return the most suitable metadir for a checkout of this branch.
209
 
        Weaves are used if this branch's repository uses weaves.
210
 
        """
211
 
        format = self.repository.bzrdir.checkout_metadir()
212
 
        format.set_branch_format(self._format)
213
 
        return format
214
 
 
215
231
    def create_checkout(self, to_location, revision_id=None, lightweight=False,
216
232
        accelerator_tree=None, hardlink=False):
217
233
        if lightweight:
524
540
        result = GitBranchPushResult()
525
541
        result.source_branch = self.source
526
542
        result.target_branch = self.target
527
 
        result.old_revid = self.target.last_revision()
 
543
        try:
 
544
            result.old_revid = self.target.last_revision()
 
545
        except NoSuchRef:
 
546
            result.old_revid = revision.NULL_REVISION
528
547
        if stop_revision is None:
529
548
            stop_revision = self.source.last_revision()
530
549
        # FIXME: Check for diverged branches