/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:
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
 
from bzrlib.plugins.git import ids
 
27
from bzrlib.plugins.git.mapping import default_mapping
 
28
 
 
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] = default_mapping.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)
27
43
 
28
44
 
29
45
class GitBranchConfig(config.BranchConfig):
41
57
 
42
58
class GitBranchFormat(branch.BranchFormat):
43
59
 
44
 
    def get_branch_description(self):
 
60
    def get_format_description(self):
45
61
        return 'Git Branch'
46
62
 
 
63
    def supports_tags(self):
 
64
        return True
 
65
 
47
66
 
48
67
class GitBranch(branch.Branch):
49
68
    """An adapter to git repositories for bzr Branch objects."""
50
69
 
51
 
    def __init__(self, gitdir, lockfiles):
 
70
    def __init__(self, bzrdir, repository, head, base, lockfiles):
 
71
        self.repository = repository
52
72
        super(GitBranch, self).__init__()
53
 
        from bzrlib.plugins.git import git_repository
54
 
        self.bzrdir = gitdir
55
73
        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)
 
74
        self.bzrdir = bzrdir
 
75
        self.head = head
 
76
        self.base = base
60
77
        self._format = GitBranchFormat()
61
78
 
62
79
    def lock_write(self):
65
82
    @needs_read_lock
66
83
    def last_revision(self):
67
84
        # perhaps should escape this ?
68
 
        head_git_id = self.repository._git.get_head()
69
 
        if head_git_id is None:
 
85
        if self.head is None:
70
86
            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:
 
87
        return default_mapping.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:
77
101
            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))
 
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.reverse()
 
118
        return ret
87
119
 
88
120
    def get_config(self):
89
121
        return GitBranchConfig(self)
94
126
    def unlock(self):
95
127
        self.control_files.unlock()
96
128
 
 
129
    def get_physical_lock_status(self):
 
130
        return False
 
131
 
97
132
    def get_push_location(self):
98
133
        """See Branch.get_push_location."""
99
134
        push_loc = self.get_config().get_user_option('push_location')
105
140
                                          local=True)
106
141
 
107
142
    def supports_tags(self):
108
 
        return False
 
143
        return True
 
144
 
 
145
    def sprout(self, to_bzrdir, revision_id=None):
 
146
        """See Branch.sprout()."""
 
147
        result = to_bzrdir.create_branch()
 
148
        self.copy_content_into(result, revision_id=revision_id)
 
149
        result.set_parent(self.bzrdir.root_transport.base)
 
150
        return result
 
151