/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

  • Committer: Jelmer Vernooij
  • Date: 2009-05-16 21:13:17 UTC
  • mto: (0.200.527 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090516211317-a0s14tsrf2qusapf
Fix tests.

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
19
22
from bzrlib import (
20
23
    bzrdir,
21
 
    errors as bzr_errors,
22
24
    lockable_files,
23
25
    urlutils,
24
26
    )
27
29
 
28
30
from bzrlib.plugins.git import (
29
31
    LocalGitBzrDirFormat,
 
32
    branch,
 
33
    errors,
30
34
    get_rich_root_format,
 
35
    repository,
 
36
    workingtree,
31
37
    )
32
38
 
33
39
 
49
55
    def validate_token(self, token):
50
56
        pass
51
57
 
52
 
    def break_lock(self):
53
 
        pass
54
 
 
55
58
 
56
59
class GitLockableFiles(lockable_files.LockableFiles):
57
60
    """Git specific lockable files abstraction."""
81
84
class LocalGitDir(GitDir):
82
85
    """An adapter to the '.git' dir used by git."""
83
86
 
84
 
    def _get_gitrepository_class(self):
85
 
        from bzrlib.plugins.git.repository import LocalGitRepository
86
 
        return LocalGitRepository
87
 
 
88
 
    _gitrepository_class = property(_get_gitrepository_class)
 
87
    _gitrepository_class = repository.LocalGitRepository
89
88
 
90
89
    def __init__(self, transport, lockfiles, gitrepo, format):
91
90
        self._format = format
106
105
            return self.transport
107
106
        if isinstance(branch_format, LocalGitBzrDirFormat):
108
107
            return self.transport
109
 
        raise bzr_errors.IncompatibleFormat(branch_format, self._format)
 
108
        raise errors.bzr_errors.IncompatibleFormat(branch_format, self._format)
110
109
 
111
110
    get_repository_transport = get_branch_transport
112
111
    get_workingtree_transport = get_branch_transport
114
113
    def open_branch(self, ignore_fallbacks=None):
115
114
        """'create' a branch for this dir."""
116
115
        repo = self.open_repository()
117
 
        from bzrlib.plugins.git.branch import LocalGitBranch
118
 
        return LocalGitBranch(self, repo, "HEAD", self._lockfiles)
 
116
        return branch.LocalGitBranch(self, repo, "HEAD", self._lockfiles)
119
117
 
120
118
    def open_repository(self, shared=False):
121
119
        """'open' a repository for this dir."""
122
120
        return self._gitrepository_class(self, self._lockfiles)
123
121
 
124
122
    def open_workingtree(self, recommend_upgrade=True):
125
 
        if not self._git.bare and self._git.has_index():
126
 
            from bzrlib.plugins.git.workingtree import GitWorkingTree
127
 
            return GitWorkingTree(self, self.open_repository(),
 
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(), 
128
126
                                                  self.open_branch())
129
127
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
130
 
        raise bzr_errors.NoWorkingTree(loc)
 
128
        raise errors.bzr_errors.NoWorkingTree(loc)
131
129
 
132
130
    def create_repository(self, shared=False):
133
131
        return self.open_repository()
134
132
 
135
133
    def create_branch(self):
136
134
        return self.open_branch()
137
 
 
138
 
    def backup_bzrdir(self):
139
 
        if self._git.bare:
140
 
            self.root_transport.copy_tree(".git", ".git.backup")
141
 
            return (self.root_transport.abspath(".git"),
142
 
                    self.root_transport.abspath(".git.backup"))
143
 
        else:
144
 
            raise bzr_errors.BzrError("Unable to backup bare repositories")
145
 
 
146
 
    def create_workingtree(self, revision_id=None, from_branch=None,
147
 
        accelerator_tree=None, hardlink=False):
148
 
        if self._git.bare:
149
 
            raise bzr_errors.BzrError("Can't create working tree in a bare repo")
150
 
        from dulwich.index import write_index
151
 
        from dulwich.pack import SHA1Writer
152
 
        f = open(self.transport.local_abspath("index"), 'w+')
153
 
        try:
154
 
            f = SHA1Writer(f)
155
 
            write_index(f, [])
156
 
        finally:
157
 
            f.close()
158
 
        return self.open_workingtree()