14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""An adapter between a Git control dir and a Bazaar BzrDir"""
22
from bzrlib.lazy_import import lazy_import
17
"""An adapter between a Git control dir and a Bazaar BzrDir."""
23
19
from bzrlib import (
29
lazy_import(globals(), """
30
from bzrlib.lockable_files import TransportLock
26
LockWarner = getattr(lockable_files, "_LockWarner", None)
31
28
from bzrlib.plugins.git import (
39
from bzrlib.plugins.git import LocalGitBzrDirFormat
43
34
class GitLock(object):
79
77
def cloning_metadir(self, stacked=False):
80
return bzrlib.bzrdir.format_registry.make_bzrdir("1.9-rich-root")
78
return get_rich_root_format(stacked)
83
81
class LocalGitDir(GitDir):
84
82
"""An adapter to the '.git' dir used by git."""
86
_gitrepository_class = repository.LocalGitRepository
84
def _get_gitrepository_class(self):
85
from bzrlib.plugins.git.repository import LocalGitRepository
86
return LocalGitRepository
88
_gitrepository_class = property(_get_gitrepository_class)
88
90
def __init__(self, transport, lockfiles, gitrepo, format):
89
91
self._format = format
95
97
self.transport = transport.clone('.git')
96
98
self._lockfiles = lockfiles
99
self._mode_check_done = None
101
def is_control_filename(self, filename):
102
return filename == '.git' or filename.startswith('.git/')
98
104
def get_branch_transport(self, branch_format):
99
105
if branch_format is None:
100
106
return self.transport
101
107
if isinstance(branch_format, LocalGitBzrDirFormat):
102
108
return self.transport
103
raise errors.bzr_errors.IncompatibleFormat(branch_format, self._format)
109
raise bzr_errors.IncompatibleFormat(branch_format, self._format)
105
111
get_repository_transport = get_branch_transport
106
112
get_workingtree_transport = get_branch_transport
108
def open_branch(self, ignored=None):
114
def open_branch(self, ignore_fallbacks=None):
109
115
"""'create' a branch for this dir."""
110
116
repo = self.open_repository()
111
return branch.LocalGitBranch(self, repo, "HEAD", repo._git.head(), self._lockfiles)
117
from bzrlib.plugins.git.branch import LocalGitBranch
118
return LocalGitBranch(self, repo, "HEAD", self._lockfiles)
113
120
def open_repository(self, shared=False):
114
121
"""'open' a repository for this dir."""
115
122
return self._gitrepository_class(self, self._lockfiles)
117
124
def open_workingtree(self, recommend_upgrade=True):
118
if (not self._git.bare and
119
os.path.exists(os.path.join(self._git.controldir(), "index"))):
120
return workingtree.GitWorkingTree(self, self.open_repository(),
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(),
121
128
self.open_branch())
122
129
loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
123
raise errors.bzr_errors.NoWorkingTree(loc)
130
raise bzr_errors.NoWorkingTree(loc)
125
132
def create_repository(self, shared=False):
126
133
return self.open_repository()
135
def create_branch(self):
136
return self.open_branch()
138
def backup_bzrdir(self):
140
self.root_transport.copy_tree(".git", ".git.backup")
141
return (self.root_transport.abspath(".git"),
142
self.root_transport.abspath(".git.backup"))
144
raise bzr_errors.BzrError("Unable to backup bare repositories")
146
def create_workingtree(self, revision_id=None, from_branch=None,
147
accelerator_tree=None, hardlink=False):
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+')
158
return self.open_workingtree()