/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:
21
21
    errors as bzr_errors,
22
22
    lockable_files,
23
23
    urlutils,
24
 
    version_info as bzrlib_version,
25
24
    )
26
25
 
27
26
LockWarner = getattr(lockable_files, "_LockWarner", None)
79
78
        return get_rich_root_format(stacked)
80
79
 
81
80
    def _branch_name_to_ref(self, name):
82
 
        raise NotImplementedError(self._branch_name_to_ref)
83
 
 
84
 
    if bzrlib_version >= (2, 2):
85
 
        def open_branch(self, name=None, ignore_fallbacks=None,
86
 
            unsupported=False):
87
 
            return self._open_branch(name=name,
88
 
                ignore_fallbacks=ignore_fallbacks, unsupported=unsupported)
89
 
    else:
90
 
        def open_branch(self, ignore_fallbacks=None, unsupported=False):
91
 
            return self._open_branch(name=None,
92
 
                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
93
87
 
94
88
 
95
89
class LocalGitDir(GitDir):
112
106
        self._lockfiles = lockfiles
113
107
        self._mode_check_done = None
114
108
 
115
 
    def _branch_name_to_ref(self, name):
116
 
        from bzrlib.plugins.git.branch import branch_name_to_ref
117
 
        if name in (None, "HEAD"):
118
 
            from dulwich.repo import SYMREF
119
 
            refcontents = self._git.refs.read_ref("HEAD")
120
 
            if refcontents.startswith(SYMREF):
121
 
                name = refcontents[len(SYMREF):]
122
 
            else:
123
 
                name = "HEAD"
124
 
        return branch_name_to_ref(name, "HEAD")
125
 
 
126
109
    def is_control_filename(self, filename):
127
110
        return filename == '.git' or filename.startswith('.git/')
128
111
 
136
119
    get_repository_transport = get_branch_transport
137
120
    get_workingtree_transport = get_branch_transport
138
121
 
139
 
    def _open_branch(self, name=None, ignore_fallbacks=None, unsupported=False):
 
122
 
 
123
    def open_branch(self, ignore_fallbacks=None, name=None, unsupported=False):
140
124
        """'create' a branch for this dir."""
141
125
        repo = self.open_repository()
142
126
        from bzrlib.plugins.git.branch import LocalGitBranch
149
133
    def list_branches(self):
150
134
        ret = []
151
135
        for name in self._git.get_refs():
152
 
            if name.startswith("refs/heads/"):
153
 
                ret.append(self.open_branch(name=name))
 
136
            ret.append(self.open_branch(name=name))
154
137
        return ret
155
138
 
156
139
    def open_repository(self, shared=False):
160
143
    def open_workingtree(self, recommend_upgrade=True):
161
144
        if not self._git.bare:
162
145
            from dulwich.errors import NoIndexPresent
163
 
            repo = self.open_repository()
164
146
            try:
165
 
                index = repo._git.open_index()
 
147
                from bzrlib.plugins.git.workingtree import GitWorkingTree
 
148
                return GitWorkingTree(self, self.open_repository(),
 
149
                                                      self.open_branch())
166
150
            except NoIndexPresent:
167
151
                pass
168
 
            else:
169
 
                from bzrlib.plugins.git.workingtree import GitWorkingTree
170
 
                return GitWorkingTree(self, repo, self.open_branch(), index)
171
152
        loc = urlutils.unescape_for_display(self.root_transport.base, 'ascii')
172
153
        raise bzr_errors.NoWorkingTree(loc)
173
154