/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

Add Makefile.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    branch,
21
21
    config,
22
22
    revision,
23
 
    tag,
24
23
    )
25
24
from bzrlib.decorators import needs_read_lock
26
25
 
27
26
from bzrlib.plugins.git import ids
28
27
 
29
 
class GitTagDict(tag.BasicTags):
30
 
 
31
 
    def __init__(self, branch):
32
 
        self.branch = branch
33
 
        self.repository = branch.repository
34
 
 
35
 
    def get_tag_dict(self):
36
 
        ret = {}
37
 
        for tag in self.repository._git.tags:
38
 
            ret[tag.name] = ids.convert_revision_id_git_to_bzr(tag.commit.id)
39
 
        return ret
40
 
 
41
 
    def set_tag(self, name, revid):
42
 
        raise NotImplementedError(self.set_tag)
43
 
 
44
28
 
45
29
class GitBranchConfig(config.BranchConfig):
46
30
    """BranchConfig that uses locations.conf in place of branch.conf"""
57
41
 
58
42
class GitBranchFormat(branch.BranchFormat):
59
43
 
60
 
    def get_format_description(self):
 
44
    def get_branch_description(self):
61
45
        return 'Git Branch'
62
46
 
63
 
    def supports_tags(self):
64
 
        return True
65
 
 
66
47
 
67
48
class GitBranch(branch.Branch):
68
49
    """An adapter to git repositories for bzr Branch objects."""
69
50
 
70
 
    def __init__(self, bzrdir, repository, head, base, lockfiles):
71
 
        self.repository = repository
 
51
    def __init__(self, gitdir, lockfiles):
72
52
        super(GitBranch, self).__init__()
 
53
        from bzrlib.plugins.git import git_repository
 
54
        self.bzrdir = gitdir
73
55
        self.control_files = lockfiles
74
 
        self.bzrdir = bzrdir
75
 
        self.head = head
76
 
        self.base = base
 
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)
77
60
        self._format = GitBranchFormat()
78
61
 
79
62
    def lock_write(self):
82
65
    @needs_read_lock
83
66
    def last_revision(self):
84
67
        # perhaps should escape this ?
85
 
        if self.head is None:
 
68
        head_git_id = self.repository._git.get_head()
 
69
        if head_git_id is None:
86
70
            return revision.NULL_REVISION
87
 
        return ids.convert_revision_id_git_to_bzr(self.head)
88
 
 
89
 
    def _make_tags(self):
90
 
        return GitTagDict(self)
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
 
 
99
 
    def _gen_revision_history(self):
100
 
        if self.head is None:
 
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:
101
77
            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(ids.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.reverse()
118
 
        return ret
 
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))
119
87
 
120
88
    def get_config(self):
121
89
        return GitBranchConfig(self)
126
94
    def unlock(self):
127
95
        self.control_files.unlock()
128
96
 
129
 
    def get_physical_lock_status(self):
130
 
        return False
131
 
 
132
97
    def get_push_location(self):
133
98
        """See Branch.get_push_location."""
134
99
        push_loc = self.get_config().get_user_option('push_location')
140
105
                                          local=True)
141
106
 
142
107
    def supports_tags(self):
143
 
        return True
 
108
        return False