/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

Merge foreign branch utility code.

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