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

Start splitting up the Git{Branch,Dir,Repository} into separate modules, etc.

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
 
from bzrlib.lazy_import import lazy_import
20
19
from bzrlib import (
21
20
    bzrdir,
 
21
    errors,
22
22
    lockable_files,
23
23
    urlutils,
24
24
    )
25
25
 
26
 
lazy_import(globals(), """
27
 
from bzrlib.plugins.git import (
28
 
    errors,
 
26
from bzrlib.plugins.git.gitlib import (
29
27
    git_branch,
30
28
    git_repository,
31
29
    )
32
 
""")
33
30
 
34
31
 
35
32
class GitLock(object):
44
41
    def unlock(self):
45
42
        pass
46
43
 
47
 
    def peek(self):
48
 
        pass
49
 
 
50
44
 
51
45
class GitLockableFiles(lockable_files.LockableFiles):
52
46
    """Git specific lockable files abstraction."""
61
55
class GitDir(bzrdir.BzrDir):
62
56
    """An adapter to the '.git' dir used by git."""
63
57
 
64
 
    _gitrepository_class = git_repository.GitRepository
65
 
 
66
58
    def __init__(self, transport, lockfiles, format):
67
59
        self._format = format
68
60
        self.root_transport = transport
74
66
            return self.transport
75
67
        if isinstance(branch_format, GitBzrDirFormat):
76
68
            return self.transport
77
 
        raise errors.bzr_errors.IncompatibleFormat(branch_format, self._format)
 
69
        raise errors.IncompatibleFormat(branch_format, self._format)
78
70
 
79
71
    get_repository_transport = get_branch_transport
80
72
    get_workingtree_transport = get_branch_transport
83
75
        return True
84
76
 
85
77
    def open_branch(self, ignored=None):
86
 
        """'create' a branch for this dir."""
87
 
        repo = self.open_repository()
88
 
        if repo._git.heads == []:
89
 
            head = None
90
 
        else:
91
 
            head = repo._git.heads[0].commit.id
92
 
        return git_branch.GitBranch(self, repo, head, 
93
 
                                    self.root_transport.base, self._lockfiles)
 
78
        """'crate' a branch for this dir."""
 
79
        return git_branch.GitBranch(self, self._lockfiles)
94
80
 
95
81
    def open_repository(self, shared=False):
96
82
        """'open' a repository for this dir."""
97
 
        return self._gitrepository_class(self, self._lockfiles)
 
83
        return git_repository.GitRepository(self, self._lockfiles)
98
84
 
99
 
    def open_workingtree(self, recommend_upgrade=True):
 
85
    def open_workingtree(self):
100
86
        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()
 
87
        raise errors.NoWorkingTree(loc)
105
88
 
106
89
 
107
90
class GitBzrDirFormat(bzrdir.BzrDirFormat):
108
91
    """The .git directory control format."""
109
92
 
110
 
    _gitdir_class = GitDir
111
 
 
112
93
    @classmethod
113
94
    def _known_formats(self):
114
95
        return set([GitBzrDirFormat()])
122
103
        url = transport.base
123
104
        if url.startswith('readonly+'):
124
105
            url = url[len('readonly+'):]
 
106
        path = urlutils.local_path_from_url(url)
125
107
        if not transport.has('.git'):
126
 
            raise errors.bzr_errors.NotBranchError(path=transport.base)
 
108
            raise errors.NotBranchError(path=transport.base)
127
109
        lockfiles = GitLockableFiles(GitLock())
128
 
        return self._gitdir_class(transport, lockfiles, self)
 
110
        return GitDir(transport, lockfiles, self)
129
111
 
130
112
    @classmethod
131
113
    def probe_transport(klass, transport):
140
122
            format.open(transport)
141
123
            return format
142
124
        except Exception, e:
143
 
            raise errors.bzr_errors.NotBranchError(path=transport.base)
144
 
        raise errors.bzr_errors.NotBranchError(path=transport.base)
145
 
 
146
 
    def get_format_description(self):
147
 
        return "Local Git Repository"
 
125
            raise errors.NotBranchError(path=transport.base)
 
126
        raise errors.NotBranchError(path=transport.base)
148
127
 
149
128
 
150
129
bzrdir.BzrDirFormat.register_control_format(GitBzrDirFormat)