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

  • Committer: Jelmer Vernooij
  • Date: 2018-11-06 02:25:29 UTC
  • mto: This revision was merged to the branch mainline in revision 7150.
  • Revision ID: jelmer@jelmer.uk-20181106022529-qlctdqketvoibpvz
Simplify brz-git, drop imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from .. import (
23
23
    branch as _mod_branch,
24
 
    errors as bzr_errors,
 
24
    errors as brz_errors,
25
25
    trace,
26
26
    osutils,
27
27
    repository as _mod_repository,
63
63
        return None
64
64
 
65
65
    def set_default_stack_on(self, value):
66
 
        raise bzr_errors.BzrError("Cannot set configuration")
 
66
        raise brz_errors.BzrError("Cannot set configuration")
67
67
 
68
68
 
69
69
class GitControlDirFormat(ControlDirFormat):
127
127
 
128
128
    def _get_selected_ref(self, branch, ref=None):
129
129
        if ref is not None and branch is not None:
130
 
            raise bzr_errors.BzrError("can't specify both ref and branch")
 
130
            raise brz_errors.BzrError("can't specify both ref and branch")
131
131
        if ref is not None:
132
132
            return ref
133
133
        if branch is not None:
164
164
        # Create/update the result branch
165
165
        try:
166
166
            result = ControlDir.open_from_transport(target_transport)
167
 
        except bzr_errors.NotBranchError:
 
167
        except brz_errors.NotBranchError:
168
168
            result = cloning_format.initialize_on_transport(target_transport)
169
169
        source_branch = self.open_branch()
170
170
        source_repository = self.find_repository()
171
171
        try:
172
172
            result_repo = result.find_repository()
173
 
        except bzr_errors.NoRepositoryPresent:
 
173
        except brz_errors.NoRepositoryPresent:
174
174
            result_repo = result.create_repository()
175
175
            target_is_empty = True
176
176
        else:
234
234
            result_dir.root_transport.local_abspath('.')
235
235
            if result_dir.open_repository().make_working_trees():
236
236
                self.open_workingtree().clone(result_dir, revision_id=revision_id)
237
 
        except (bzr_errors.NoWorkingTree, bzr_errors.NotLocalUrl):
 
237
        except (brz_errors.NoWorkingTree, brz_errors.NotLocalUrl):
238
238
            pass
239
239
 
240
240
        return result_dir
300
300
        refname = self._get_selected_ref(name)
301
301
        from .branch import GitBranch
302
302
        if isinstance(source, GitBranch) and lossy:
303
 
            raise bzr_errors.LossyPushToSameVCS(source.controldir, self)
 
303
            raise brz_errors.LossyPushToSameVCS(source.controldir, self)
304
304
        target = self.open_branch(name, nascent_ok=True)
305
305
        push_result.branch_push_result = source.push(
306
306
                target, overwrite=overwrite, stop_revision=revision_id,
349
349
            return transport._redirected_to(e.source, e.target)
350
350
        gitrepo = do_catching_redirections(_open, transport, redirected)
351
351
        if not gitrepo._controltransport.has('HEAD'):
352
 
            raise bzr_errors.NotBranchError(path=transport.base)
 
352
            raise brz_errors.NotBranchError(path=transport.base)
353
353
        return LocalGitDir(transport, gitrepo, self)
354
354
 
355
355
    def get_format_description(self):
373
373
        try:
374
374
            transport = do_catching_redirections(make_directory, transport,
375
375
                redirected)
376
 
        except bzr_errors.FileExists:
 
376
        except brz_errors.FileExists:
377
377
            if not use_existing_dir:
378
378
                raise
379
 
        except bzr_errors.NoSuchFile:
 
379
        except brz_errors.NoSuchFile:
380
380
            if not create_prefix:
381
381
                raise
382
382
            transport.create_prefix()
397
397
    def supports_transport(self, transport):
398
398
        try:
399
399
            external_url = transport.external_url()
400
 
        except bzr_errors.InProcessTransport:
401
 
            raise bzr_errors.NotBranchError(path=transport.base)
 
400
        except brz_errors.InProcessTransport:
 
401
            raise brz_errors.NotBranchError(path=transport.base)
402
402
        return external_url.startswith("file:")
403
403
 
404
404
 
464
464
        else:
465
465
            try:
466
466
                target_path = target_branch.controldir.control_transport.local_abspath('.')
467
 
            except bzr_errors.NotLocalUrl:
468
 
                raise bzr_errors.IncompatibleFormat(target_branch._format, self._format)
 
467
            except brz_errors.NotLocalUrl:
 
468
                raise brz_errors.IncompatibleFormat(target_branch._format, self._format)
469
469
            # TODO(jelmer): Do some consistency checking across branches..
470
470
            self.control_transport.put_bytes('commondir', target_path.encode('utf-8'))
471
471
            # TODO(jelmer): Urgh, avoid mucking about with internals.
479
479
                break
480
480
            else:
481
481
                # Can't create a reference to something that is not a in a repository.
482
 
                raise bzr_errors.IncompatibleFormat(self.set_branch_reference, self)
 
482
                raise brz_errors.IncompatibleFormat(self.set_branch_reference, self)
483
483
            self._git.refs.set_symbolic_ref(ref, target_ref)
484
484
 
485
485
    def get_branch_reference(self, name=None):
498
498
                    params = {}
499
499
            try:
500
500
                commondir = self.control_transport.get_bytes('commondir')
501
 
            except bzr_errors.NoSuchFile:
 
501
            except brz_errors.NoSuchFile:
502
502
                base_url = self.user_url.rstrip('/')
503
503
            else:
504
504
                base_url = urlutils.local_path_to_url(commondir.decode(osutils._fs_enc)).rstrip('/.git/')+'/'
519
519
            return self.transport
520
520
        if isinstance(branch_format, LocalGitControlDirFormat):
521
521
            return self.transport
522
 
        raise bzr_errors.IncompatibleFormat(branch_format, self._format)
 
522
        raise brz_errors.IncompatibleFormat(branch_format, self._format)
523
523
 
524
524
    def get_repository_transport(self, format):
525
525
        if format is None:
526
526
            return self.transport
527
527
        if isinstance(format, LocalGitControlDirFormat):
528
528
            return self.transport
529
 
        raise bzr_errors.IncompatibleFormat(format, self._format)
 
529
        raise brz_errors.IncompatibleFormat(format, self._format)
530
530
 
531
531
    def get_workingtree_transport(self, format):
532
532
        if format is None:
533
533
            return self.transport
534
534
        if isinstance(format, LocalGitControlDirFormat):
535
535
            return self.transport
536
 
        raise bzr_errors.IncompatibleFormat(format, self._format)
 
536
        raise brz_errors.IncompatibleFormat(format, self._format)
537
537
 
538
538
    def open_branch(self, name=None, unsupported=False, ignore_fallbacks=None,
539
539
            ref=None, possible_transports=None, nascent_ok=False):
542
542
        from .branch import LocalGitBranch
543
543
        ref = self._get_selected_ref(name, ref)
544
544
        if not nascent_ok and ref not in self._git.refs:
545
 
            raise bzr_errors.NotBranchError(self.root_transport.base,
 
545
            raise brz_errors.NotBranchError(self.root_transport.base,
546
546
                    controldir=self)
547
547
        ref_chain, unused_sha = self._git.refs.follow(ref)
548
548
        if ref_chain[-1] == b'HEAD':
555
555
        refname = self._get_selected_ref(name)
556
556
        if refname == b'HEAD':
557
557
            # HEAD can't be removed
558
 
            raise bzr_errors.UnsupportedOperation(
 
558
            raise brz_errors.UnsupportedOperation(
559
559
                self.destroy_branch, self)
560
560
        try:
561
561
            del self._git.refs[refname]
562
562
        except KeyError:
563
 
            raise bzr_errors.NotBranchError(self.root_transport.base,
 
563
            raise brz_errors.NotBranchError(self.root_transport.base,
564
564
                    controldir=self)
565
565
 
566
566
    def destroy_repository(self):
567
 
        raise bzr_errors.UnsupportedOperation(self.destroy_repository, self)
 
567
        raise brz_errors.UnsupportedOperation(self.destroy_repository, self)
568
568
 
569
569
    def destroy_workingtree(self):
570
 
        raise bzr_errors.UnsupportedOperation(self.destroy_workingtree, self)
 
570
        raise brz_errors.UnsupportedOperation(self.destroy_workingtree, self)
571
571
 
572
572
    def destroy_workingtree_metadata(self):
573
 
        raise bzr_errors.UnsupportedOperation(self.destroy_workingtree_metadata, self)
 
573
        raise brz_errors.UnsupportedOperation(self.destroy_workingtree_metadata, self)
574
574
 
575
575
    def needs_format_conversion(self, format=None):
576
576
        return not isinstance(self._format, format.__class__)
578
578
    def open_repository(self):
579
579
        """'open' a repository for this dir."""
580
580
        if self.control_transport.has('commondir'):
581
 
            raise bzr_errors.NoRepositoryPresent(self)
 
581
            raise brz_errors.NoRepositoryPresent(self)
582
582
        return self._gitrepository_class(self)
583
583
 
584
584
    def has_workingtree(self):
592
592
            branch = self.open_branch(ref=b'HEAD', nascent_ok=True)
593
593
            return GitWorkingTree(self, repo, branch)
594
594
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
595
 
        raise bzr_errors.NoWorkingTree(loc)
 
595
        raise brz_errors.NoWorkingTree(loc)
596
596
 
597
597
    def create_repository(self, shared=False):
598
598
        from .repository import GitRepositoryFormat
599
599
        if shared:
600
 
            raise bzr_errors.IncompatibleFormat(GitRepositoryFormat(), self._format)
 
600
            raise brz_errors.IncompatibleFormat(GitRepositoryFormat(), self._format)
601
601
        return self.find_repository()
602
602
 
603
603
    def create_branch(self, name=None, repository=None,
604
604
                      append_revisions_only=None, ref=None):
605
605
        refname = self._get_selected_ref(name, ref)
606
606
        if refname != b'HEAD' and refname in self._git.refs:
607
 
            raise bzr_errors.AlreadyBranchError(self.user_url)
 
607
            raise brz_errors.AlreadyBranchError(self.user_url)
608
608
        repo = self.open_repository()
609
609
        if refname in self._git.refs:
610
610
            ref_chain, unused_sha = self._git.refs.follow(self._get_selected_ref(None))
629
629
    def create_workingtree(self, revision_id=None, from_branch=None,
630
630
        accelerator_tree=None, hardlink=False):
631
631
        if self._git.bare:
632
 
            raise bzr_errors.UnsupportedOperation(self.create_workingtree, self)
 
632
            raise brz_errors.UnsupportedOperation(self.create_workingtree, self)
633
633
        if from_branch is None:
634
634
            from_branch = self.open_branch(nascent_ok=True)
635
635
        if revision_id is None:
657
657
        self._mode_check_done = True
658
658
        try:
659
659
            st = self.transport.stat('.')
660
 
        except bzr_errors.TransportNotPossible:
 
660
        except brz_errors.TransportNotPossible:
661
661
            self._dir_mode = None
662
662
            self._file_mode = None
663
663
        else:
697
697
    def _find_commondir(self):
698
698
        try:
699
699
            commondir = self.control_transport.get_bytes('commondir')
700
 
        except bzr_errors.NoSuchFile:
 
700
        except brz_errors.NoSuchFile:
701
701
            return self
702
702
        else:
703
703
            commondir = commondir.rstrip(b'/.git/').decode(osutils._fs_enc)