/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: Michael Hudson
  • Date: 2010-02-17 02:04:25 UTC
  • mto: (0.200.721 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: michael.hudson@canonical.com-20100217020425-1i19smhkatqsrg3v
this works for my tests, but i'm pretty sure it's wrong in general

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2007 Canonical Ltd
2
 
# Copyright (C) 2010 Jelmer Vernooij
3
2
#
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
22
21
    errors as bzr_errors,
23
22
    lockable_files,
24
23
    urlutils,
25
 
    version_info as bzrlib_version,
26
24
    )
27
25
 
28
26
LockWarner = getattr(lockable_files, "_LockWarner", None)
79
77
    def cloning_metadir(self, stacked=False):
80
78
        return get_rich_root_format(stacked)
81
79
 
82
 
    def _branch_name_to_ref(self, name):
83
 
        raise NotImplementedError(self._branch_name_to_ref)
84
 
 
85
 
    if bzrlib_version >= (2, 2):
86
 
        def open_branch(self, name=None, ignore_fallbacks=None,
87
 
            unsupported=False):
88
 
            return self._open_branch(name=name,
89
 
                ignore_fallbacks=ignore_fallbacks, unsupported=unsupported)
90
 
    else:
91
 
        def open_branch(self, ignore_fallbacks=None, unsupported=False):
92
 
            return self._open_branch(name=None,
93
 
                ignore_fallbacks=ignore_fallbacks, unsupported=unsupported)
94
 
 
95
80
 
96
81
class LocalGitDir(GitDir):
97
82
    """An adapter to the '.git' dir used by git."""
113
98
        self._lockfiles = lockfiles
114
99
        self._mode_check_done = None
115
100
 
116
 
    def _branch_name_to_ref(self, name):
117
 
        from bzrlib.plugins.git.refs import branch_name_to_ref
118
 
        if name in (None, "HEAD"):
119
 
            from dulwich.repo import SYMREF
120
 
            refcontents = self._git.refs.read_ref("HEAD")
121
 
            if refcontents.startswith(SYMREF):
122
 
                name = refcontents[len(SYMREF):]
123
 
            else:
124
 
                name = "HEAD"
125
 
        return branch_name_to_ref(name, "HEAD")
126
 
 
127
101
    def is_control_filename(self, filename):
128
102
        return filename == '.git' or filename.startswith('.git/')
129
103
 
130
 
    def get_branch_transport(self, branch_format, name):
 
104
    def get_branch_transport(self, branch_format):
131
105
        if branch_format is None:
132
106
            return self.transport
133
107
        if isinstance(branch_format, LocalGitBzrDirFormat):
134
108
            return self.transport
135
109
        raise bzr_errors.IncompatibleFormat(branch_format, self._format)
136
110
 
137
 
    def get_repository_transport(self, format):
138
 
        if format is None:
139
 
            return self.transport
140
 
        if isinstance(format, LocalGitBzrDirFormat):
141
 
            return self.transport
142
 
        raise bzr_errors.IncompatibleFormat(format, self._format)
143
 
 
144
 
    def get_workingtree_transport(self, format):
145
 
        if format is None:
146
 
            return self.transport
147
 
        if isinstance(format, LocalGitBzrDirFormat):
148
 
            return self.transport
149
 
        raise bzr_errors.IncompatibleFormat(format, self._format)
150
 
 
151
 
    def _open_branch(self, name=None, ignore_fallbacks=None, unsupported=False):
 
111
    get_repository_transport = get_branch_transport
 
112
    get_workingtree_transport = get_branch_transport
 
113
 
 
114
    def open_branch(self, ignore_fallbacks=None):
152
115
        """'create' a branch for this dir."""
153
116
        repo = self.open_repository()
154
117
        from bzrlib.plugins.git.branch import LocalGitBranch
155
 
        return LocalGitBranch(self, repo, self._branch_name_to_ref(name),
156
 
            self._lockfiles)
157
 
 
158
 
    def destroy_branch(self, name=None):
159
 
        del self._git.refs[self._branch_name_to_ref(name)]
160
 
 
161
 
    def list_branches(self):
162
 
        ret = []
163
 
        for name in self._git.get_refs():
164
 
            if name.startswith("refs/heads/"):
165
 
                ret.append(self.open_branch(name=name))
166
 
        return ret
 
118
        return LocalGitBranch(self, repo, "HEAD", self._lockfiles)
167
119
 
168
120
    def open_repository(self, shared=False):
169
121
        """'open' a repository for this dir."""
172
124
    def open_workingtree(self, recommend_upgrade=True):
173
125
        if not self._git.bare:
174
126
            from dulwich.errors import NoIndexPresent
175
 
            repo = self.open_repository()
176
127
            try:
177
 
                index = repo._git.open_index()
 
128
                from bzrlib.plugins.git.workingtree import GitWorkingTree
 
129
                return GitWorkingTree(self, self.open_repository(),
 
130
                                                      self.open_branch())
178
131
            except NoIndexPresent:
179
132
                pass
180
 
            else:
181
 
                from bzrlib.plugins.git.workingtree import GitWorkingTree
182
 
                return GitWorkingTree(self, repo, self.open_branch(), index)
183
133
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
184
134
        raise bzr_errors.NoWorkingTree(loc)
185
135
 
186
136
    def create_repository(self, shared=False):
187
137
        return self.open_repository()
188
138
 
189
 
    def create_branch(self, name=None):
190
 
        refname = self._branch_name_to_ref(name)
191
 
        from dulwich.protocol import ZERO_SHA
192
 
        self._git.refs[refname] = ZERO_SHA
193
 
        return self.open_branch(name)
 
139
    def create_branch(self):
 
140
        return self.open_branch()
194
141
 
195
142
    def backup_bzrdir(self):
196
143
        if self._git.bare: