/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

Implement to_files() for git merge directives.

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)
80
78
        return get_rich_root_format(stacked)
81
79
 
82
80
    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)
 
81
        if name is None and name != "HEAD":
 
82
            return "HEAD"
 
83
        if not "/" in name:
 
84
            return "refs/heads/%s" % name
 
85
        else:
 
86
            return name
94
87
 
95
88
 
96
89
class LocalGitDir(GitDir):
113
106
        self._lockfiles = lockfiles
114
107
        self._mode_check_done = None
115
108
 
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
109
    def is_control_filename(self, filename):
128
110
        return filename == '.git' or filename.startswith('.git/')
129
111
 
130
 
    def get_branch_transport(self, branch_format, name):
 
112
    def get_branch_transport(self, branch_format):
131
113
        if branch_format is None:
132
114
            return self.transport
133
115
        if isinstance(branch_format, LocalGitBzrDirFormat):
134
116
            return self.transport
135
117
        raise bzr_errors.IncompatibleFormat(branch_format, self._format)
136
118
 
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):
 
119
    get_repository_transport = get_branch_transport
 
120
    get_workingtree_transport = get_branch_transport
 
121
 
 
122
 
 
123
    def open_branch(self, ignore_fallbacks=None, name=None, unsupported=False):
152
124
        """'create' a branch for this dir."""
153
125
        repo = self.open_repository()
154
126
        from bzrlib.plugins.git.branch import LocalGitBranch
161
133
    def list_branches(self):
162
134
        ret = []
163
135
        for name in self._git.get_refs():
164
 
            if name.startswith("refs/heads/"):
165
 
                ret.append(self.open_branch(name=name))
 
136
            ret.append(self.open_branch(name=name))
166
137
        return ret
167
138
 
168
139
    def open_repository(self, shared=False):
172
143
    def open_workingtree(self, recommend_upgrade=True):
173
144
        if not self._git.bare:
174
145
            from dulwich.errors import NoIndexPresent
175
 
            repo = self.open_repository()
176
146
            try:
177
 
                index = repo._git.open_index()
 
147
                from bzrlib.plugins.git.workingtree import GitWorkingTree
 
148
                return GitWorkingTree(self, self.open_repository(),
 
149
                                                      self.open_branch())
178
150
            except NoIndexPresent:
179
151
                pass
180
 
            else:
181
 
                from bzrlib.plugins.git.workingtree import GitWorkingTree
182
 
                return GitWorkingTree(self, repo, self.open_branch(), index)
183
152
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
184
153
        raise bzr_errors.NoWorkingTree(loc)
185
154
 
188
157
 
189
158
    def create_branch(self, name=None):
190
159
        refname = self._branch_name_to_ref(name)
191
 
        from dulwich.protocol import ZERO_SHA
192
 
        self._git.refs[refname] = ZERO_SHA
 
160
        self._git.refs[refname] = "0" * 40
193
161
        return self.open_branch(name)
194
162
 
195
163
    def backup_bzrdir(self):