/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

  • Committer: Jelmer Vernooij
  • Date: 2009-09-10 13:13:15 UTC
  • mto: (0.200.602 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090910131315-6890xg58pl2jseml
Allow serving remote URLs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
from bzrlib.foreign import ForeignBranch
55
55
 
56
56
 
57
 
def extract_tags(refs):
 
57
def extract_tags(refs, mapping):
58
58
    ret = {}
59
59
    for k,v in refs.iteritems():
60
60
        if k.startswith("refs/tags/") and not k.endswith("^{}"):
61
61
            v = refs.get(k+"^{}", v)
62
 
            ret[k[len("refs/tags/"):]] = v
 
62
            ret[k[len("refs/tags/"):]] = mapping.revision_id_foreign_to_bzr(v)
63
63
    return ret
64
64
 
65
65
 
88
88
 
89
89
    def get_tag_dict(self):
90
90
        ret = {}
91
 
        for k,v in extract_tags(self.repository._git.get_refs()).iteritems():
92
 
            try:
93
 
                obj = self.repository._git[v]
94
 
            except KeyError:
95
 
                mutter("Tag %s points at unknown object %s, ignoring", v, obj)
96
 
                continue
 
91
        for k,v in self.repository._git.refs.as_dict("refs/tags").iteritems():
 
92
            obj = self.repository._git.get_object(v)
97
93
            while isinstance(obj, Tag):
98
94
                v = obj.object[1]
99
 
                obj = self.repository._git[v]
 
95
                obj = self.repository._git.get_object(v)
100
96
            if not isinstance(obj, Commit):
101
97
                mutter("Tag %s points at object %r that is not a commit, "
102
98
                       "ignoring", k, obj)
126
122
    def get_format_description(self):
127
123
        return 'Git Branch'
128
124
 
129
 
    def network_name(self):
130
 
        return "git"
131
 
 
132
125
    def supports_tags(self):
133
126
        return True
134
127
 
135
 
    def get_foreign_tests_branch_factory(self):
136
 
        from bzrlib.plugins.git.tests.test_branch import ForeignTestsBranchFactory
137
 
        return ForeignTestsBranchFactory()
138
 
 
139
128
    def make_tags(self, branch):
140
129
        if getattr(branch.repository, "get_refs", None) is not None:
141
130
            from bzrlib.plugins.git.remote import RemoteGitTagDict
157
146
            self.tags = DictTagDict(self, tagsdict)
158
147
        self.name = name
159
148
        self._head = None
160
 
        self.base = bzrdir.root_transport.base
 
149
        self.base = bzrdir.transport.base
161
150
 
162
151
    def _get_checkout_format(self):
163
152
        """Return the most suitable metadir for a checkout of this branch.
197
186
 
198
187
    def get_stacked_on_url(self):
199
188
        # Git doesn't do stacking (yet...)
200
 
        raise errors.UnstackableBranchFormat(self._format, self.base)
 
189
        return None
201
190
 
202
191
    def get_parent(self):
203
192
        """See Branch.get_parent()."""
231
220
        return branch.InterBranch.get(self, target)._basic_push(
232
221
            overwrite, stop_revision)
233
222
 
234
 
 
 
223
 
235
224
class LocalGitBranch(GitBranch):
236
225
    """A local Git branch."""
237
226
 
242
231
            t.ensure_base()
243
232
            format = self._get_checkout_format()
244
233
            checkout = format.initialize_on_transport(t)
245
 
            from_branch = branch.BranchReferenceFormat().initialize(checkout,
 
234
            from_branch = branch.BranchReferenceFormat().initialize(checkout, 
246
235
                self)
247
236
            tree = checkout.create_workingtree(revision_id,
248
237
                from_branch=from_branch, hardlink=hardlink)
251
240
            return self._create_heavyweight_checkout(to_location, revision_id,
252
241
            hardlink)
253
242
 
254
 
    def _create_heavyweight_checkout(self, to_location, revision_id=None,
 
243
    def _create_heavyweight_checkout(self, to_location, revision_id=None, 
255
244
                                     hardlink=False):
256
245
        """Create a new heavyweight checkout of this branch.
257
246
 
264
253
            to_location, force_new_tree=False, format=get_rich_root_format())
265
254
        checkout = checkout_branch.bzrdir
266
255
        checkout_branch.bind(self)
267
 
        # pull up to the specified revision_id to set the initial
 
256
        # pull up to the specified revision_id to set the initial 
268
257
        # branch tip correctly, and seed it with history.
269
258
        checkout_branch.pull(self, stop_revision=revision_id)
270
259
        return checkout.create_workingtree(revision_id, hardlink=hardlink)
322
311
            if self.old_revid == self.new_revid:
323
312
                to_file.write('No revisions to pull.\n')
324
313
            else:
325
 
                to_file.write('Now on revision %d (git sha: %s).\n' %
 
314
                to_file.write('Now on revision %d (git sha: %s).\n' % 
326
315
                        (self.new_revno, self.new_git_head))
327
316
        self._show_tag_conficts(to_file)
328
317
 
351
340
    """InterBranch implementation that pulls from Git into bzr."""
352
341
 
353
342
    @classmethod
354
 
    def _get_interrepo(self, source, target):
355
 
        return repository.InterRepository.get(source.repository,
356
 
            target.repository)
357
 
 
358
 
    @classmethod
359
 
    def is_compatible(cls, source, target):
360
 
        return (isinstance(source, GitBranch) and
361
 
                not isinstance(target, GitBranch) and
362
 
                (getattr(cls._get_interrepo(source, target), "fetch_objects", None) is not None))
 
343
    def is_compatible(self, source, target):
 
344
        return (isinstance(source, GitBranch) and 
 
345
                not isinstance(target, GitBranch))
363
346
 
364
347
    def update_revisions(self, stop_revision=None, overwrite=False,
365
348
        graph=None):
366
349
        """See InterBranch.update_revisions()."""
367
 
        interrepo = self._get_interrepo(self.source, self.target)
 
350
        interrepo = repository.InterRepository.get(self.source.repository, 
 
351
            self.target.repository)
368
352
        self._head = None
369
353
        self._last_revid = None
370
354
        def determine_wants(heads):
372
356
                raise NoSuchRef(self.source.name, heads.keys())
373
357
            if stop_revision is not None:
374
358
                self._last_revid = stop_revision
375
 
                self._head, mapping = self.source.repository.lookup_bzr_revision_id(
 
359
                self._head, mapping = self.source.repository.lookup_git_revid(
376
360
                    stop_revision)
377
361
            else:
378
362
                self._head = heads[self.source.name]
417
401
            graph = self.target.repository.get_graph(self.source.repository)
418
402
            result.old_revno, result.old_revid = \
419
403
                self.target.last_revision_info()
420
 
            self.update_revisions(stop_revision, overwrite=overwrite,
 
404
            self.update_revisions(stop_revision, overwrite=overwrite, 
421
405
                graph=graph)
422
406
            result.new_git_head = self._head
423
407
            result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
442
426
        result.target_branch = self.target
443
427
        graph = self.target.repository.get_graph(self.source.repository)
444
428
        result.old_revno, result.old_revid = self.target.last_revision_info()
445
 
        self.update_revisions(stop_revision, overwrite=overwrite, graph=graph)
 
429
        self.update_revisions(stop_revision, overwrite=overwrite, 
 
430
            graph=graph)
446
431
        result.new_git_head = self._head
447
432
        result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
448
433
            overwrite)
460
445
    @classmethod
461
446
    def is_compatible(self, source, target):
462
447
        from bzrlib.plugins.git.remote import RemoteGitBranch
463
 
        return (isinstance(source, LocalGitBranch) and
 
448
        return (isinstance(source, LocalGitBranch) and 
464
449
                isinstance(target, RemoteGitBranch))
465
450
 
466
451
    def _basic_push(self, overwrite=False, stop_revision=None):
472
457
        # FIXME: Check for diverged branches
473
458
        def get_changed_refs(old_refs):
474
459
            result.old_revid = self.target.mapping.revision_id_foreign_to_bzr(old_refs.get("refs/heads/master", "0" * 40))
475
 
            refs = { "refs/heads/master": self.source.repository.lookup_bzr_revision_id(stop_revision)[0] }
 
460
            refs = { "refs/heads/master": self.source.repository.lookup_git_revid(stop_revision)[0] }
476
461
            result.new_revid = stop_revision
477
462
            for name, sha in self.source.repository._git.refs.as_dict("refs/tags").iteritems():
478
463
                refs["refs/tags/%s" % name] = sha
479
464
            return refs
480
 
        self.target.repository.send_pack(get_changed_refs,
 
465
        self.target.repository.send_pack(get_changed_refs, 
481
466
                self.source.repository._git.object_store.generate_pack_contents)
482
467
        return result
483
468
 
488
473
    @classmethod
489
474
    def is_compatible(self, source, target):
490
475
        from bzrlib.plugins.git.remote import RemoteGitBranch
491
 
        return (isinstance(source, RemoteGitBranch) and
 
476
        return (isinstance(source, RemoteGitBranch) and 
492
477
                isinstance(target, LocalGitBranch))
493
478
 
494
479
    def _basic_push(self, overwrite=False, stop_revision=None):
503
488
        return result
504
489
 
505
490
    def update_tags(self, refs):
506
 
        for name, v in extract_tags(refs).iteritems():
507
 
            revid = self.target.mapping.revision_id_foreign_to_bzr(v)
 
491
        for name, revid in extract_tags(refs, self.target.mapping).iteritems():
508
492
            self.target.tags.set_tag(name, revid)
509
493
 
510
494
    def update_refs(self, stop_revision=None):
511
 
        interrepo = repository.InterRepository.get(self.source.repository,
 
495
        interrepo = repository.InterRepository.get(self.source.repository, 
512
496
            self.target.repository)
513
497
        if stop_revision is None:
514
498
            refs = interrepo.fetch_refs(branches=["HEAD"])
517
501
            refs = interrepo.fetch_refs(revision_id=stop_revision)
518
502
        return refs, stop_revision
519
503
 
520
 
    def pull(self, stop_revision=None, overwrite=False,
 
504
    def pull(self, stop_revision=None, overwrite=False, 
521
505
        possible_transports=None, local=False):
522
506
        # This type of branch can't be bound.
523
507
        if local:
532
516
        result.new_revid = self.target.last_revision()
533
517
        return result
534
518
 
535
 
 
 
519
    
536
520
class InterToGitBranch(branch.InterBranch):
537
521
    """InterBranch implementation that pulls from Git into bzr."""
538
522
 
539
 
    @staticmethod
540
 
    def _get_branch_formats_to_test():
541
 
        return None, None
542
 
 
543
523
    @classmethod
544
524
    def is_compatible(self, source, target):
545
 
        return (not isinstance(source, GitBranch) and
 
525
        return (not isinstance(source, GitBranch) and 
546
526
                isinstance(target, GitBranch))
547
527
 
548
528
    def update_revisions(self, *args, **kwargs):
549
529
        raise NoPushSupport()
550
530
 
551
 
    def push(self, overwrite=True, stop_revision=None,
 
531
    def push(self, overwrite=True, stop_revision=None, 
552
532
             _override_hook_source_branch=None):
553
533
        raise NoPushSupport()
554
534
 
556
536
        result = GitBranchPushResult()
557
537
        result.source_branch = self.source
558
538
        result.target_branch = self.target
559
 
        try:
560
 
            result.old_revid = self.target.last_revision()
561
 
        except NoSuchRef:
562
 
            result.old_revid = revision.NULL_REVISION
 
539
        result.old_revid = self.target.last_revision()
563
540
        if stop_revision is None:
564
541
            stop_revision = self.source.last_revision()
565
542
        # FIXME: Check for diverged branches