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

Fix compatibility with bzr 2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
            raise bzr_errors.BzrError("can't specify both ref and branch")
83
83
        if ref is not None:
84
84
            return ref
 
85
        segment_parameters = getattr(
 
86
            self.user_transport, "get_segment_parameters", lambda: {})()
 
87
        ref = segment_parameters.get("ref")
 
88
        if ref is not None:
 
89
            return urlutils.unescape(ref)
85
90
        if branch is None and getattr(self, "_get_selected_branch", False):
86
91
            branch = self._get_selected_branch()
87
92
        if branch is not None:
88
93
            from bzrlib.plugins.git.refs import branch_name_to_ref
89
 
            return branch_name_to_ref(branch, None)
90
 
        segment_parameters = getattr(
91
 
            self.user_transport, "get_segment_parameters", lambda: {})()
92
 
        ref = segment_parameters.get("ref")
93
 
        if ref is not None:
94
 
            ref = urlutils.unescape(ref)
95
 
        return ref
 
94
            return branch_name_to_ref(branch)
 
95
        return None
96
96
 
97
97
    def get_config(self):
98
98
        return GitDirConfig()
222
222
 
223
223
    def initialize_on_transport(self, transport):
224
224
        from bzrlib.plugins.git.transportgit import TransportRepo
225
 
        TransportRepo.init(transport, bare=self.bare)
 
225
        repo = TransportRepo.init(transport, bare=self.bare)
 
226
        del repo.refs["HEAD"]
226
227
        return self.open(transport)
227
228
 
228
229
    def initialize_on_transport_ex(self, transport, use_existing_dir=False,
316
317
            return refcontents[len(SYMREF):].rstrip("\n")
317
318
        return None
318
319
 
319
 
    def set_branch_reference(self, name, target):
 
320
    def set_branch_reference(self, target, name=None):
 
321
        if self.control_transport.base != target.bzrdir.control_transport.base:
 
322
            raise bzr_errors.IncompatibleFormat(target._format, self._format)
320
323
        ref = self._get_selected_ref(name)
321
324
        if ref is None:
322
325
            ref = "HEAD"
323
 
        if not getattr(target, "ref", None):
324
 
            raise bzr_errors.BzrError("Can only set symrefs to Git refs")
325
326
        self._git.refs.set_symbolic_ref(ref, target.ref)
326
327
 
327
328
    def get_branch_reference(self, name=None):
385
386
    def destroy_branch(self, name=None):
386
387
        refname = self._get_selected_ref(name)
387
388
        if refname is None:
388
 
            refname = "refs/heads/master"
 
389
            refname = "HEAD"
389
390
        try:
390
391
            del self._git.refs[refname]
391
392
        except KeyError:
451
452
                      append_revisions_only=None, ref=None):
452
453
        refname = self._get_selected_ref(name, ref)
453
454
        from dulwich.protocol import ZERO_SHA
454
 
        # FIXME: This is a bit awkward. Perhaps we should have a
455
 
        # a separate method for changing the default branch?
456
455
        if refname is None:
457
 
            refname = "refs/heads/master"
458
 
            set_head = True
459
 
        else:
460
 
            set_head = False
461
 
 
 
456
            refname = "HEAD"
462
457
        if refname in self._git.refs:
463
 
            raise bzr_errors.AlreadyBranchError(self.base)
 
458
            raise bzr_errors.AlreadyBranchError(self.user_url)
464
459
        self._git.refs[refname] = ZERO_SHA
465
 
        if set_head:
466
 
            self._git.refs.set_symbolic_ref("HEAD", refname)
467
460
        branch = self.open_branch(name)
468
461
        if append_revisions_only:
469
462
            branch.set_append_revisions_only(append_revisions_only)