/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

Fix RevisionTree.get_file_text().

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    branch,
21
21
    config,
22
22
    revision,
 
23
    tag,
23
24
    )
24
25
from bzrlib.decorators import needs_read_lock
25
26
 
26
27
from bzrlib.plugins.git import ids
27
28
 
 
29
class GitTagDict(tag.BasicTags):
 
30
 
 
31
    def __init__(self, repository):
 
32
        self.repository = repository
 
33
 
 
34
    def get_tag_dict(self):
 
35
        ret = {}
 
36
        for tag in self.repository._git.tags:
 
37
            ret[tag.name] = ids.convert_revision_id_git_to_bzr(tag.commit.id)
 
38
        return ret
 
39
 
 
40
    def set_tag(self, name, revid):
 
41
        raise NotImplementedError(self.set_tag)
 
42
 
28
43
 
29
44
class GitBranchConfig(config.BranchConfig):
30
45
    """BranchConfig that uses locations.conf in place of branch.conf"""
41
56
 
42
57
class GitBranchFormat(branch.BranchFormat):
43
58
 
44
 
    def get_branch_description(self):
 
59
    def get_format_description(self):
45
60
        return 'Git Branch'
46
61
 
 
62
    def supports_tags(self):
 
63
        return True
 
64
 
47
65
 
48
66
class GitBranch(branch.Branch):
49
67
    """An adapter to git repositories for bzr Branch objects."""
50
68
 
51
 
    def __init__(self, gitdir, lockfiles):
 
69
    def __init__(self, bzrdir, repository, head, base, lockfiles):
 
70
        self.repository = repository
52
71
        super(GitBranch, self).__init__()
53
 
        from bzrlib.plugins.git import git_repository
54
 
        self.bzrdir = gitdir
55
72
        self.control_files = lockfiles
56
 
        self.repository = git_repository.GitRepository(gitdir, lockfiles)
57
 
        self.base = gitdir.root_transport.base
58
 
        if '.git' not in gitdir.root_transport.list_dir('.'):
59
 
            raise errors.NotBranchError(self.base)
 
73
        self.bzrdir = bzrdir
 
74
        self.head = head
 
75
        self.base = base
60
76
        self._format = GitBranchFormat()
61
77
 
62
78
    def lock_write(self):
65
81
    @needs_read_lock
66
82
    def last_revision(self):
67
83
        # perhaps should escape this ?
68
 
        head_git_id = self.repository._git.get_head()
69
 
        if head_git_id is None:
 
84
        if self.head is None:
70
85
            return revision.NULL_REVISION
71
 
        return ids.convert_revision_id_git_to_bzr(head_git_id)
72
 
 
73
 
    @needs_read_lock
74
 
    def revision_history(self):
75
 
        node = self.last_revision()
76
 
        if node == revision.NULL_REVISION:
 
86
        return ids.convert_revision_id_git_to_bzr(self.head)
 
87
 
 
88
    def _make_tags(self):
 
89
        return GitTagDict(self.repository)
 
90
 
 
91
    def get_parent(self):
 
92
        """See Branch.get_parent()."""
 
93
        return None
 
94
 
 
95
    def get_stacked_on_url(self):
 
96
        return None
 
97
 
 
98
    def _gen_revision_history(self):
 
99
        if self.head is None:
77
100
            return []
78
 
        ancestors = self.repository.get_revision_graph(node)
79
 
        history = []
80
 
        while node is not None:
81
 
            history.append(node)
82
 
            if len(ancestors[node]) > 0:
83
 
                node = ancestors[node][0]
84
 
            else:
85
 
                node = None
86
 
        return list(reversed(history))
 
101
        skip = 0
 
102
        cms = None
 
103
        ret = []
 
104
        max_count = 1000
 
105
        nextid = self.head
 
106
        while cms != []:
 
107
            cms = self.repository._git.commits(self.head, max_count=max_count, skip=skip)
 
108
            skip += max_count
 
109
            for cm in cms:
 
110
                if cm.id == nextid:
 
111
                    ret.append(ids.convert_revision_id_git_to_bzr(cm.id))
 
112
                    if cm.parents == []:
 
113
                        nextid = None
 
114
                    else:
 
115
                        nextid = cm.parents[0].id
 
116
        ret.reverse()
 
117
        return ret
87
118
 
88
119
    def get_config(self):
89
120
        return GitBranchConfig(self)
94
125
    def unlock(self):
95
126
        self.control_files.unlock()
96
127
 
 
128
    def get_physical_lock_status(self):
 
129
        return False
 
130
 
97
131
    def get_push_location(self):
98
132
        """See Branch.get_push_location."""
99
133
        push_loc = self.get_config().get_user_option('push_location')
105
139
                                          local=True)
106
140
 
107
141
    def supports_tags(self):
108
 
        return False
 
142
        return True