/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

Simply refer to bzr's docs in HACKING.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""An adapter between a Git control dir and a Bazaar BzrDir."""
18
18
 
19
 
import os
20
 
 
21
 
import bzrlib
22
19
from bzrlib import (
23
20
    bzrdir,
 
21
    errors as bzr_errors,
24
22
    lockable_files,
25
23
    urlutils,
26
24
    )
29
27
 
30
28
from bzrlib.plugins.git import (
31
29
    LocalGitBzrDirFormat,
32
 
    branch,
33
 
    errors,
34
30
    get_rich_root_format,
35
 
    repository,
36
 
    workingtree,
37
31
    )
38
32
 
39
33
 
84
78
class LocalGitDir(GitDir):
85
79
    """An adapter to the '.git' dir used by git."""
86
80
 
87
 
    _gitrepository_class = repository.LocalGitRepository
 
81
    def _get_gitrepository_class(self):
 
82
        from bzrlib.plugins.git.repository import LocalGitRepository
 
83
        return LocalGitRepository
 
84
 
 
85
    _gitrepository_class = property(_get_gitrepository_class)
88
86
 
89
87
    def __init__(self, transport, lockfiles, gitrepo, format):
90
88
        self._format = format
105
103
            return self.transport
106
104
        if isinstance(branch_format, LocalGitBzrDirFormat):
107
105
            return self.transport
108
 
        raise errors.bzr_errors.IncompatibleFormat(branch_format, self._format)
 
106
        raise bzr_errors.IncompatibleFormat(branch_format, self._format)
109
107
 
110
108
    get_repository_transport = get_branch_transport
111
109
    get_workingtree_transport = get_branch_transport
113
111
    def open_branch(self, ignore_fallbacks=None):
114
112
        """'create' a branch for this dir."""
115
113
        repo = self.open_repository()
116
 
        return branch.LocalGitBranch(self, repo, "HEAD", self._lockfiles)
 
114
        from bzrlib.plugins.git.branch import LocalGitBranch
 
115
        return LocalGitBranch(self, repo, "HEAD", self._lockfiles)
117
116
 
118
117
    def open_repository(self, shared=False):
119
118
        """'open' a repository for this dir."""
120
119
        return self._gitrepository_class(self, self._lockfiles)
121
120
 
122
121
    def open_workingtree(self, recommend_upgrade=True):
123
 
        if (not self._git.bare and 
124
 
            os.path.exists(os.path.join(self._git.controldir(), "index"))):
125
 
            return workingtree.GitWorkingTree(self, self.open_repository(), 
 
122
        if not self._git.bare and self._git.has_index():
 
123
            from bzrlib.plugins.git.workingtree import GitWorkingTree
 
124
            return GitWorkingTree(self, self.open_repository(), 
126
125
                                                  self.open_branch())
127
126
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
128
 
        raise errors.bzr_errors.NoWorkingTree(loc)
 
127
        raise bzr_errors.NoWorkingTree(loc)
129
128
 
130
129
    def create_repository(self, shared=False):
131
130
        return self.open_repository()
132
131
 
133
132
    def create_branch(self):
134
133
        return self.open_branch()
 
134
 
 
135
    def backup_bzrdir(self):
 
136
        if self._git.bare:
 
137
            self.root_transport.copy_tree(".git", ".git.backup")
 
138
            return (self.root_transport.abspath(".git"),
 
139
                    self.root_transport.abspath(".git.backup"))
 
140
        else:
 
141
            raise bzr_errors.BzrError("Unable to backup bare repositories")
 
142
 
 
143
    def create_workingtree(self, revision_id=None, from_branch=None,
 
144
        accelerator_tree=None, hardlink=False):
 
145
        if self._git.bare:
 
146
            raise bzr_errors.BzrError("Can't create working tree in a bare repo")
 
147
        from dulwich.index import write_index
 
148
        from dulwich.pack import SHA1Writer
 
149
        f = open(self.transport.local_abspath("index"), 'w+')
 
150
        try:
 
151
            f = SHA1Writer(f)
 
152
            write_index(f, [])
 
153
        finally:
 
154
            f.close()
 
155
        return self.open_workingtree()