/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: 2008-12-25 01:28:00 UTC
  • mto: (0.200.144 dulwich)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20081225012800-96iswmhsbn3wlyz6
Update copyright years.

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