/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

Basic support for opening working trees.

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 git
 
20
 
19
21
from bzrlib.lazy_import import lazy_import
20
22
from bzrlib import (
21
23
    bzrdir,
28
30
    errors,
29
31
    git_branch,
30
32
    git_repository,
 
33
    git_workingtree,
31
34
    )
32
35
""")
33
36
 
35
38
class GitLock(object):
36
39
    """A lock that thunks through to Git."""
37
40
 
38
 
    def lock_write(self):
 
41
    def lock_write(self, token=None):
39
42
        pass
40
43
 
41
44
    def lock_read(self):
44
47
    def unlock(self):
45
48
        pass
46
49
 
 
50
    def peek(self):
 
51
        pass
 
52
 
47
53
 
48
54
class GitLockableFiles(lockable_files.LockableFiles):
49
55
    """Git specific lockable files abstraction."""
60
66
 
61
67
    _gitrepository_class = git_repository.GitRepository
62
68
 
63
 
    def __init__(self, transport, lockfiles, format):
 
69
    def __init__(self, transport, lockfiles, gitrepo, format):
64
70
        self._format = format
65
71
        self.root_transport = transport
66
 
        self.transport = transport.clone('.git')
 
72
        self._git = gitrepo
 
73
        if gitrepo.bare:
 
74
            self.transport = transport
 
75
        else:
 
76
            self.transport = transport.clone('.git')
67
77
        self._lockfiles = lockfiles
68
78
 
69
79
    def get_branch_transport(self, branch_format):
80
90
        return True
81
91
 
82
92
    def open_branch(self, ignored=None):
83
 
        """'crate' a branch for this dir."""
84
 
        return git_branch.GitBranch(self, self._lockfiles)
 
93
        """'create' a branch for this dir."""
 
94
        repo = self.open_repository()
 
95
        if repo._git.heads == []:
 
96
            head = None
 
97
        else:
 
98
            head = repo._git.heads[0].commit.id
 
99
        return git_branch.GitBranch(self, repo, head, 
 
100
                                    self.root_transport.base, self._lockfiles)
85
101
 
86
102
    def open_repository(self, shared=False):
87
103
        """'open' a repository for this dir."""
88
104
        return self._gitrepository_class(self, self._lockfiles)
89
105
 
90
106
    def open_workingtree(self, recommend_upgrade=True):
91
 
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
92
 
        raise errors.bzr_errors.NoWorkingTree(loc)
 
107
        if self._git.bare:
 
108
            loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
 
109
            raise errors.bzr_errors.NoWorkingTree(loc)
 
110
        else:
 
111
            return git_workingtree.GitWorkingTree(self, self.open_repository(), 
 
112
                                                  self.open_branch())
93
113
 
94
114
    def cloning_metadir(self):
95
115
        return bzrdir.BzrDirFormat.get_default_format()
104
124
    def _known_formats(self):
105
125
        return set([GitBzrDirFormat()])
106
126
 
107
 
    def open(self, transport, _create=False, _found=None):
 
127
    def open(self, transport, _found=None):
108
128
        """Open this directory.
109
129
 
110
 
        :param _create: create the git dir on the fly. private to GitDirFormat.
111
130
        """
112
131
        # we dont grok readonly - git isn't integrated with transport.
113
132
        url = transport.base
114
133
        if url.startswith('readonly+'):
115
134
            url = url[len('readonly+'):]
116
 
        if not transport.has('.git'):
 
135
 
 
136
        try:
 
137
            gitrepo = git.repo.Repo(transport.local_abspath("."))
 
138
        except errors.bzr_errors.NotLocalUrl:
117
139
            raise errors.bzr_errors.NotBranchError(path=transport.base)
118
140
        lockfiles = GitLockableFiles(GitLock())
119
 
        return self._gitdir_class(transport, lockfiles, self)
 
141
        return self._gitdir_class(transport, lockfiles, gitrepo, self)
120
142
 
121
143
    @classmethod
122
144
    def probe_transport(klass, transport):
134
156
            raise errors.bzr_errors.NotBranchError(path=transport.base)
135
157
        raise errors.bzr_errors.NotBranchError(path=transport.base)
136
158
 
 
159
    def get_format_description(self):
 
160
        return "Local Git Repository"
 
161
 
137
162
 
138
163
bzrdir.BzrDirFormat.register_control_format(GitBzrDirFormat)