/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

Share more code between local and remote classes, support opening remote branches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
class GitDir(bzrdir.BzrDir):
72
72
    """An adapter to the '.git' dir used by git."""
73
73
 
74
 
    def is_supported(self):
75
 
        return True
76
 
 
77
 
    def cloning_metadir(self, stacked=False):
78
 
        if stacked:
79
 
            return bzrlib.bzrdir.format_registry.make_bzrdir("pack-0.92")
80
 
        else:
81
 
            return bzrlib.bzrdir.format_registry.make_bzrdir("1.6")
82
 
 
83
 
 
84
 
class LocalGitDir(GitDir):
85
 
    """An adapter to the '.git' dir used by git."""
86
 
 
87
74
    _gitrepository_class = repository.LocalGitRepository
88
75
 
89
76
    def __init__(self, transport, lockfiles, gitrepo, format):
106
93
    get_repository_transport = get_branch_transport
107
94
    get_workingtree_transport = get_branch_transport
108
95
 
 
96
    def is_supported(self):
 
97
        return True
 
98
 
109
99
    def open_branch(self, ignored=None):
110
100
        """'create' a branch for this dir."""
111
101
        repo = self.open_repository()
112
 
        return branch.LocalGitBranch(self, repo, "HEAD", repo._git.head(), self._lockfiles)
 
102
        if repo._git.heads == []:
 
103
            head = None
 
104
        else:
 
105
            head = repo._git.head()
 
106
        return branch.LocalGitBranch(self, repo, "HEAD", head, self._lockfiles)
113
107
 
114
108
    def open_repository(self, shared=False):
115
109
        """'open' a repository for this dir."""
123
117
            return workingtree.GitWorkingTree(self, self.open_repository(), 
124
118
                                                  self.open_branch())
125
119
 
 
120
    def cloning_metadir(self, stacked=False):
 
121
        if stacked:
 
122
            return bzrlib.bzrdir.format_registry.make_bzrdir("pack-0.92")
 
123
        else:
 
124
            return bzrlib.bzrdir.format_registry.make_bzrdir("1.6")
 
125
 
126
126
    def create_repository(self, shared=False):
127
127
        return self.open_repository()
128
128
 
129
129
 
130
 
class GitBzrDirFormat(bzrdir.BzrDirFormat):
 
130
class LocalGitBzrDirFormat(bzrdir.BzrDirFormat):
 
131
    """The .git directory control format."""
 
132
 
 
133
    _gitdir_class = GitDir
131
134
    _lock_class = TransportLock
132
135
 
133
 
    def is_supported(self):
134
 
        return True
135
 
 
136
 
 
137
 
class LocalGitBzrDirFormat(GitBzrDirFormat):
138
 
    """The .git directory control format."""
139
 
 
140
 
    _gitdir_class = LocalGitDir
141
 
 
142
136
    @classmethod
143
137
    def _known_formats(self):
144
138
        return set([LocalGitBzrDirFormat()])
163
157
    @classmethod
164
158
    def probe_transport(klass, transport):
165
159
        """Our format is present if the transport ends in '.not/'."""
166
 
        from bzrlib.plugins.git import git
167
160
        # little ugly, but works
168
161
        format = klass()
169
162
        # delegate to the main opening code. This pays a double rtt cost at the
173
166
        try:
174
167
            format.open(transport)
175
168
            return format
176
 
        except git.errors.NotGitRepository, e:
 
169
        except Exception, e:
177
170
            raise errors.bzr_errors.NotBranchError(path=transport.base)
178
171
        raise errors.bzr_errors.NotBranchError(path=transport.base)
179
172
 
199
192
        return True
200
193
 
201
194
 
202
 
class RemoteGitBzrDirFormat(GitBzrDirFormat):
 
195
class RemoteGitBzrDirFormat(bzrdir.BzrDirFormat):
203
196
    """The .git directory control format."""
204
197
 
 
198
    _lock_class = TransportLock
 
199
 
205
200
    @classmethod
206
201
    def _known_formats(self):
207
202
        return set([RemoteGitBzrDirFormat()])
249
244
    def initialize_on_transport(self, transport):
250
245
        raise errors.bzr_errors.UninitializableFormat(self)
251
246
 
 
247
    def is_supported(self):
 
248
        return True