/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

Fix branch cloning.

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
27
28
from bzrlib.plugins.git.mapping import default_mapping
28
29
 
29
30
class GitTagDict(tag.BasicTags):
35
36
    def get_tag_dict(self):
36
37
        ret = {}
37
38
        for tag in self.repository._git.tags:
38
 
            ret[tag.name] = default_mapping.convert_revision_id_git_to_bzr(tag.commit.id)
 
39
            ret[tag.name] = self.branch.mapping.revision_id_foreign_to_bzr(tag.ref)
39
40
        return ret
40
41
 
41
42
    def set_tag(self, name, revid):
64
65
        return True
65
66
 
66
67
 
67
 
class GitBranch(branch.Branch):
 
68
class GitBranch(ForeignBranch):
68
69
    """An adapter to git repositories for bzr Branch objects."""
69
70
 
70
 
    def __init__(self, bzrdir, repository, head, base, lockfiles):
 
71
    def __init__(self, bzrdir, repository, name, head, lockfiles):
71
72
        self.repository = repository
72
 
        super(GitBranch, self).__init__()
 
73
        super(GitBranch, self).__init__(default_mapping)
73
74
        self.control_files = lockfiles
74
75
        self.bzrdir = bzrdir
 
76
        self.name = name
75
77
        self.head = head
76
 
        self.base = base
 
78
        self.base = bzrdir.transport.base
77
79
        self._format = GitBranchFormat()
78
80
 
79
81
    def lock_write(self):
80
82
        self.control_files.lock_write()
81
83
 
 
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
 
82
104
    @needs_read_lock
83
105
    def last_revision(self):
84
106
        # perhaps should escape this ?
85
107
        if self.head is None:
86
108
            return revision.NULL_REVISION
87
 
        return default_mapping.convert_revision_id_git_to_bzr(self.head)
 
109
        return self.mapping.revision_id_foreign_to_bzr(self.head)
88
110
 
89
111
    def _make_tags(self):
90
112
        return GitTagDict(self)
91
113
 
92
 
    def get_parent(self):
93
 
        """See Branch.get_parent()."""
94
 
        return None
95
 
 
96
 
    def get_stacked_on_url(self):
97
 
        return None
98
 
 
99
114
    def _gen_revision_history(self):
100
115
        if self.head is None:
101
116
            return []
102
 
        skip = 0
103
 
        cms = None
104
 
        ret = []
105
 
        max_count = 1000
106
 
        nextid = self.head
107
 
        while cms != []:
108
 
            cms = self.repository._git.commits(self.head, max_count=max_count, skip=skip)
109
 
            skip += max_count
110
 
            for cm in cms:
111
 
                if cm.id == nextid:
112
 
                    ret.append(default_mapping.convert_revision_id_git_to_bzr(cm.id))
113
 
                    if cm.parents == []:
114
 
                        nextid = None
115
 
                    else:
116
 
                        nextid = cm.parents[0].id
 
117
        ret = list(self.repository.iter_reverse_revision_history(self.last_revision()))
117
118
        ret.reverse()
118
119
        return ret
119
120
 
120
121
    def get_config(self):
121
122
        return GitBranchConfig(self)
122
123
 
123
 
    def lock_read(self):
124
 
        self.control_files.lock_read()
125
 
 
126
 
    def unlock(self):
127
 
        self.control_files.unlock()
128
 
 
129
 
    def get_physical_lock_status(self):
130
 
        return False
131
 
 
132
124
    def get_push_location(self):
133
125
        """See Branch.get_push_location."""
134
126
        push_loc = self.get_config().get_user_option('push_location')