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

  • Committer: Aaron Bentley
  • Date: 2007-12-30 06:58:28 UTC
  • mto: (0.200.48 bzr-git.pull)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: aaron.bentley@utoronto.ca-20071230065828-w87ointcehj6fuft
Make checkouts work

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.lazy_import import lazy_import
23
20
from bzrlib import (
24
21
    bzrdir,
27
24
    )
28
25
 
29
26
lazy_import(globals(), """
30
 
from bzrlib.lockable_files import TransportLock
31
27
from bzrlib.plugins.git import (
32
28
    errors,
33
 
    branch,
34
 
    repository,
35
 
    workingtree,
 
29
    git_branch,
 
30
    git_repository,
36
31
    )
37
32
""")
38
33
 
39
34
 
40
 
 
41
35
class GitLock(object):
42
36
    """A lock that thunks through to Git."""
43
37
 
44
 
    def lock_write(self, token=None):
 
38
    def lock_write(self):
45
39
        pass
46
40
 
47
41
    def lock_read(self):
50
44
    def unlock(self):
51
45
        pass
52
46
 
53
 
    def peek(self):
54
 
        pass
55
 
 
56
47
 
57
48
class GitLockableFiles(lockable_files.LockableFiles):
58
49
    """Git specific lockable files abstraction."""
67
58
class GitDir(bzrdir.BzrDir):
68
59
    """An adapter to the '.git' dir used by git."""
69
60
 
70
 
    _gitrepository_class = repository.GitRepository
 
61
    _gitrepository_class = git_repository.GitRepository
71
62
 
72
 
    def __init__(self, transport, lockfiles, gitrepo, format):
 
63
    def __init__(self, transport, lockfiles, format):
73
64
        self._format = format
74
65
        self.root_transport = transport
75
 
        self._git = gitrepo
76
 
        if gitrepo.bare:
77
 
            self.transport = transport
78
 
        else:
79
 
            self.transport = transport.clone('.git')
 
66
        self.transport = transport.clone('.git')
80
67
        self._lockfiles = lockfiles
81
68
 
82
69
    def get_branch_transport(self, branch_format):
93
80
        return True
94
81
 
95
82
    def open_branch(self, ignored=None):
96
 
        """'create' a branch for this dir."""
97
 
        repo = self.open_repository()
98
 
        if repo._git.heads == []:
99
 
            head = None
100
 
        else:
101
 
            head = repo._git.head()
102
 
        return branch.GitBranch(self, repo, head, 
103
 
                                    self.root_transport.base, self._lockfiles)
 
83
        """'crate' a branch for this dir."""
 
84
        return git_branch.GitBranch(self, self._lockfiles)
104
85
 
105
86
    def open_repository(self, shared=False):
106
87
        """'open' a repository for this dir."""
107
88
        return self._gitrepository_class(self, self._lockfiles)
108
89
 
109
90
    def open_workingtree(self, recommend_upgrade=True):
110
 
        if self._git.bare:
111
 
            loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
112
 
            raise errors.bzr_errors.NoWorkingTree(loc)
113
 
        else:
114
 
            return workingtree.GitWorkingTree(self, self.open_repository(), 
115
 
                                                  self.open_branch())
116
 
 
117
 
    def cloning_metadir(self, stacked=False):
118
 
        if stacked:
119
 
            return bzrlib.bzrdir.format_registry.make_bzrdir("pack-0.92")
120
 
        else:
121
 
            return bzrlib.bzrdir.format_registry.make_bzrdir("1.6")
122
 
 
123
 
    def create_repository(self, shared=False):
124
 
        return self.open_repository()
 
91
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
 
92
        raise errors.bzr_errors.NoWorkingTree(loc)
 
93
 
 
94
    def cloning_metadir(self):
 
95
        return bzrdir.BzrDirFormat.get_default_format()
125
96
 
126
97
 
127
98
class GitBzrDirFormat(bzrdir.BzrDirFormat):
128
99
    """The .git directory control format."""
129
100
 
130
101
    _gitdir_class = GitDir
131
 
    _lock_class = TransportLock
132
102
 
133
103
    @classmethod
134
104
    def _known_formats(self):
135
105
        return set([GitBzrDirFormat()])
136
106
 
137
 
    def open(self, transport, _found=None):
 
107
    def open(self, transport, _create=False, _found=None):
138
108
        """Open this directory.
139
109
 
 
110
        :param _create: create the git dir on the fly. private to GitDirFormat.
140
111
        """
141
 
        from bzrlib.plugins.git import git
142
112
        # we dont grok readonly - git isn't integrated with transport.
143
113
        url = transport.base
144
114
        if url.startswith('readonly+'):
145
115
            url = url[len('readonly+'):]
146
 
 
147
 
        try:
148
 
            gitrepo = git.repo.Repo(transport.local_abspath("."))
149
 
        except errors.bzr_errors.NotLocalUrl:
 
116
        if not transport.has('.git'):
150
117
            raise errors.bzr_errors.NotBranchError(path=transport.base)
151
118
        lockfiles = GitLockableFiles(GitLock())
152
 
        return self._gitdir_class(transport, lockfiles, gitrepo, self)
 
119
        return self._gitdir_class(transport, lockfiles, self)
153
120
 
154
121
    @classmethod
155
122
    def probe_transport(klass, transport):
167
134
            raise errors.bzr_errors.NotBranchError(path=transport.base)
168
135
        raise errors.bzr_errors.NotBranchError(path=transport.base)
169
136
 
170
 
    def get_format_description(self):
171
 
        return "Local Git Repository"
172
 
 
173
 
    def get_format_string(self):
174
 
        return "Local Git Repository"
175
 
 
176
 
    def initialize_on_transport(self, transport):
177
 
        from bzrlib.transport.local import LocalTransport
178
 
        from bzrlib.plugins.git import git
179
 
 
180
 
        if not isinstance(transport, LocalTransport):
181
 
            raise NotImplementedError(self.initialize, 
182
 
                "Can't create Git Repositories/branches on "
183
 
                "non-local transports")
184
 
 
185
 
        git.repo.Repo.create(transport.local_abspath(".")) 
186
 
        return self.open(transport)
187
 
 
188
137
 
189
138
bzrdir.BzrDirFormat.register_control_format(GitBzrDirFormat)