/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 branch.py

properly error out about not support lightweight checkouts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    tag,
24
24
    )
25
25
from bzrlib.decorators import needs_read_lock
 
26
from bzrlib.trace import mutter
26
27
 
27
28
from bzrlib.plugins.git.foreign import ForeignBranch
28
 
from bzrlib.plugins.git.mapping import default_mapping
 
29
from bzrlib.plugins.git.errors import LightWeightCheckoutsNotSupported
 
30
 
 
31
from dulwich.objects import (
 
32
        Commit,
 
33
        Tag,
 
34
        )
29
35
 
30
36
class GitTagDict(tag.BasicTags):
31
37
 
35
41
 
36
42
    def get_tag_dict(self):
37
43
        ret = {}
38
 
        for tag in self.repository._git.tags:
39
 
            ret[tag.name] = self.branch.mapping.revision_id_foreign_to_bzr(tag.ref)
 
44
        for k,v in self.repository._git.tags.iteritems():
 
45
            obj = self.repository._git.get_object(v)
 
46
            while isinstance(obj, Tag):
 
47
                v = obj.object[1]
 
48
                obj = self.repository._git.get_object(v)
 
49
            if not isinstance(obj, Commit):
 
50
                mutter("Tag %s points at object %r that is not a commit, ignoring", k, obj)
 
51
                continue
 
52
            ret[k] = self.branch.mapping.revision_id_foreign_to_bzr(v)
40
53
        return ret
41
54
 
42
55
    def set_tag(self, name, revid):
43
 
        raise NotImplementedError(self.set_tag)
 
56
        self.repository._git.tags[name] = revid
44
57
 
45
58
 
46
59
class GitBranchConfig(config.BranchConfig):
51
64
        # do not provide a BranchDataConfig
52
65
        self.option_sources = self.option_sources[0], self.option_sources[2]
53
66
 
54
 
    def set_user_option(self, name, value, local=False):
 
67
    def set_user_option(self, name, value, store=config.STORE_BRANCH, warn_masked=False):
55
68
        """Force local to True"""
56
 
        config.BranchConfig.set_user_option(self, name, value, local=True)
 
69
        config.BranchConfig.set_user_option(self, name, value, store=config.STORE_LOCATION, warn_masked=warn_masked)
57
70
 
58
71
 
59
72
class GitBranchFormat(branch.BranchFormat):
68
81
class GitBranch(ForeignBranch):
69
82
    """An adapter to git repositories for bzr Branch objects."""
70
83
 
71
 
    def __init__(self, bzrdir, repository, head, base, lockfiles):
 
84
    def __init__(self, bzrdir, repository, name, head, lockfiles):
72
85
        self.repository = repository
73
 
        super(GitBranch, self).__init__(default_mapping)
 
86
        super(GitBranch, self).__init__(repository.get_mapping())
74
87
        self.control_files = lockfiles
75
88
        self.bzrdir = bzrdir
 
89
        self.name = name
76
90
        self.head = head
77
 
        self.base = base
 
91
        self.base = bzrdir.transport.base
78
92
        self._format = GitBranchFormat()
79
93
 
80
94
    def lock_write(self):
81
95
        self.control_files.lock_write()
82
96
 
 
97
    def get_stacked_on_url(self):
 
98
        # Git doesn't do stacking (yet...)
 
99
        return None
 
100
 
 
101
    def get_parent(self):
 
102
        """See Branch.get_parent()."""
 
103
        return None
 
104
 
 
105
    def set_parent(self, url):
 
106
        pass
 
107
 
 
108
    def lock_read(self):
 
109
        self.control_files.lock_read()
 
110
 
 
111
    def unlock(self):
 
112
        self.control_files.unlock()
 
113
 
 
114
    def get_physical_lock_status(self):
 
115
        return False
 
116
 
 
117
 
 
118
class LocalGitBranch(GitBranch):
 
119
 
83
120
    @needs_read_lock
84
121
    def last_revision(self):
85
122
        # perhaps should escape this ?
87
124
            return revision.NULL_REVISION
88
125
        return self.mapping.revision_id_foreign_to_bzr(self.head)
89
126
 
 
127
    def create_checkout(self, to_location, revision_id=None, 
 
128
                        lightweight=False, accelerator_tree=None, hardlink=False):
 
129
        if lightweight:
 
130
            raise LightWeightCheckoutsNotSupported()
 
131
        return self._create_heavyweight_checkout(to_location, revision_id, hardlink)
 
132
 
 
133
    def _create_heavyweight_checkout(self, to_location, revision_id=None, 
 
134
                                     hardlink=False):
 
135
        """Create a new heavyweight checkout of this branch.
 
136
 
 
137
        :param to_location: URL of location to create the new checkout in.
 
138
        :param revision_id: Revision that should be the tip of the checkout.
 
139
        :param hardlink: Whether to hardlink
 
140
        :return: WorkingTree object of checkout.
 
141
        """
 
142
        checkout_branch = BzrDir.create_branch_convenience(
 
143
            to_location, force_new_tree=False, format=get_rich_root_format())
 
144
        checkout = checkout_branch.bzrdir
 
145
        checkout_branch.bind(self)
 
146
        # pull up to the specified revision_id to set the initial 
 
147
        # branch tip correctly, and seed it with history.
 
148
        checkout_branch.pull(self, stop_revision=revision_id)
 
149
        return checkout.create_workingtree(revision_id, hardlink=hardlink)
 
150
 
90
151
    def _make_tags(self):
91
152
        return GitTagDict(self)
92
153
 
93
 
    def get_parent(self):
94
 
        """See Branch.get_parent()."""
95
 
        return None
96
 
 
97
 
    def get_stacked_on_url(self):
98
 
        return None
99
 
 
100
154
    def _gen_revision_history(self):
101
155
        if self.head is None:
102
156
            return []
103
 
        skip = 0
104
 
        cms = None
105
 
        ret = []
106
 
        max_count = 1000
107
 
        nextid = self.head
108
 
        while cms != []:
109
 
            cms = self.repository._git.commits(self.head, max_count=max_count, skip=skip)
110
 
            skip += max_count
111
 
            for cm in cms:
112
 
                if cm.id == nextid:
113
 
                    ret.append(self.mapping.revision_id_foreign_to_bzr(cm.id))
114
 
                    if cm.parents == []:
115
 
                        nextid = None
116
 
                    else:
117
 
                        nextid = cm.parents[0].id
 
157
        ret = list(self.repository.iter_reverse_revision_history(self.last_revision()))
118
158
        ret.reverse()
119
159
        return ret
120
160
 
121
161
    def get_config(self):
122
162
        return GitBranchConfig(self)
123
163
 
124
 
    def lock_read(self):
125
 
        self.control_files.lock_read()
126
 
 
127
 
    def unlock(self):
128
 
        self.control_files.unlock()
129
 
 
130
 
    def get_physical_lock_status(self):
131
 
        return False
132
 
 
133
164
    def get_push_location(self):
134
165
        """See Branch.get_push_location."""
135
166
        push_loc = self.get_config().get_user_option('push_location')
138
169
    def set_push_location(self, location):
139
170
        """See Branch.set_push_location."""
140
171
        self.get_config().set_user_option('push_location', location,
141
 
                                          local=True)
 
172
                                          store=config.STORE_LOCATION)
142
173
 
143
174
    def supports_tags(self):
144
175
        return True