/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

Test that getting an unknown revision fails.

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