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

SupportĀ listingĀ tags.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    )
25
25
from bzrlib.decorators import needs_read_lock
26
26
 
27
 
from bzrlib.plugins.git.foreign import ForeignBranch
28
 
from bzrlib.plugins.git.mapping import default_mapping
 
27
from bzrlib.plugins.git import ids
29
28
 
30
29
class GitTagDict(tag.BasicTags):
31
30
 
32
 
    def __init__(self, branch):
33
 
        self.branch = branch
34
 
        self.repository = branch.repository
 
31
    def __init__(self, repository):
 
32
        self.repository = repository
35
33
 
36
34
    def get_tag_dict(self):
37
35
        ret = {}
38
36
        for tag in self.repository._git.tags:
39
 
            ret[tag.name] = self.branch.mapping.revision_id_foreign_to_bzr(tag.ref)
 
37
            ret[tag.name] = ids.convert_revision_id_git_to_bzr(tag.commit.id)
40
38
        return ret
41
39
 
42
 
    def set_tag(self, name, revid):
43
 
        raise NotImplementedError(self.set_tag)
44
 
 
45
40
 
46
41
class GitBranchConfig(config.BranchConfig):
47
42
    """BranchConfig that uses locations.conf in place of branch.conf"""
65
60
        return True
66
61
 
67
62
 
68
 
class GitBranch(ForeignBranch):
 
63
class GitBranch(branch.Branch):
69
64
    """An adapter to git repositories for bzr Branch objects."""
70
65
 
71
 
    def __init__(self, bzrdir, repository, name, head, lockfiles):
 
66
    def __init__(self, bzrdir, repository, head, base, lockfiles):
72
67
        self.repository = repository
73
 
        super(GitBranch, self).__init__(default_mapping)
 
68
        super(GitBranch, self).__init__()
74
69
        self.control_files = lockfiles
75
70
        self.bzrdir = bzrdir
76
 
        self.name = name
77
71
        self.head = head
78
 
        self.base = bzrdir.transport.base
 
72
        self.base = base
79
73
        self._format = GitBranchFormat()
80
74
 
81
75
    def lock_write(self):
82
76
        self.control_files.lock_write()
83
77
 
84
 
    def get_stacked_on_url(self):
85
 
        # Git doesn't do stacking (yet...)
86
 
        return None
87
 
 
88
 
    def get_parent(self):
89
 
        """See Branch.get_parent()."""
90
 
        return None
91
 
 
92
 
    def lock_read(self):
93
 
        self.control_files.lock_read()
94
 
 
95
 
    def unlock(self):
96
 
        self.control_files.unlock()
97
 
 
98
 
    def get_physical_lock_status(self):
99
 
        return False
100
 
 
101
 
 
102
 
class LocalGitBranch(GitBranch):
103
 
 
104
78
    @needs_read_lock
105
79
    def last_revision(self):
106
80
        # perhaps should escape this ?
107
81
        if self.head is None:
108
82
            return revision.NULL_REVISION
109
 
        return self.mapping.revision_id_foreign_to_bzr(self.head)
 
83
        return ids.convert_revision_id_git_to_bzr(self.head)
110
84
 
111
85
    def _make_tags(self):
112
 
        return GitTagDict(self)
 
86
        return GitTagDict(self.repository)
 
87
 
 
88
    def get_parent(self):
 
89
        """See Branch.get_parent()."""
 
90
        return None
 
91
 
 
92
    def get_stacked_on_url(self):
 
93
        return None
113
94
 
114
95
    def _gen_revision_history(self):
115
96
        if self.head is None:
116
97
            return []
117
 
        ret = list(self.repository.iter_reverse_revision_history(self.last_revision()))
 
98
        skip = 0
 
99
        cms = None
 
100
        ret = []
 
101
        max_count = 1000
 
102
        nextid = self.head
 
103
        while cms != []:
 
104
            cms = self.repository._git.commits(self.head, max_count=max_count, skip=skip)
 
105
            skip += max_count
 
106
            for cm in cms:
 
107
                if cm.id == nextid:
 
108
                    ret.append(ids.convert_revision_id_git_to_bzr(cm.id))
 
109
                    if cm.parents == []:
 
110
                        nextid = None
 
111
                    else:
 
112
                        nextid = cm.parents[0].id
118
113
        ret.reverse()
119
114
        return ret
120
115
 
121
116
    def get_config(self):
122
117
        return GitBranchConfig(self)
123
118
 
 
119
    def lock_read(self):
 
120
        self.control_files.lock_read()
 
121
 
 
122
    def unlock(self):
 
123
        self.control_files.unlock()
 
124
 
 
125
    def get_physical_lock_status(self):
 
126
        return False
 
127
 
124
128
    def get_push_location(self):
125
129
        """See Branch.get_push_location."""
126
130
        push_loc = self.get_config().get_user_option('push_location')
133
137
 
134
138
    def supports_tags(self):
135
139
        return True
136
 
 
137
 
    def sprout(self, to_bzrdir, revision_id=None):
138
 
        """See Branch.sprout()."""
139
 
        result = to_bzrdir.create_branch()
140
 
        self.copy_content_into(result, revision_id=revision_id)
141
 
        result.set_parent(self.bzrdir.root_transport.base)
142
 
        return result
143