/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

Switch to using GitPython rather than our own in-house stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
class GitBranchFormat(branch.BranchFormat):
43
43
 
44
 
    def get_format_description(self):
 
44
    def get_branch_description(self):
45
45
        return 'Git Branch'
46
46
 
47
47
 
48
48
class GitBranch(branch.Branch):
49
49
    """An adapter to git repositories for bzr Branch objects."""
50
50
 
51
 
    def __init__(self, bzrdir, repository, head, base, lockfiles):
 
51
    def __init__(self, gitdir, lockfiles):
52
52
        super(GitBranch, self).__init__()
 
53
        from bzrlib.plugins.git import git_repository
 
54
        self.bzrdir = gitdir
53
55
        self.control_files = lockfiles
54
 
        self.bzrdir = bzrdir
55
 
        self.repository = repository
56
 
        self.head = head
57
 
        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)
58
60
        self._format = GitBranchFormat()
59
61
 
60
62
    def lock_write(self):
63
65
    @needs_read_lock
64
66
    def last_revision(self):
65
67
        # perhaps should escape this ?
66
 
        if self.head is None:
 
68
        head_git_id = self.repository._git.get_head()
 
69
        if head_git_id is None:
67
70
            return revision.NULL_REVISION
68
 
        return ids.convert_revision_id_git_to_bzr(self.head)
69
 
 
70
 
    def get_parent(self):
71
 
        """See Branch.get_parent()."""
72
 
        return None
73
 
 
74
 
    def get_stacked_on_url(self):
75
 
        return None
76
 
 
77
 
    def _gen_revision_history(self):
78
 
        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:
79
77
            return []
80
 
        skip = 0
81
 
        cms = None
82
 
        ret = []
83
 
        max_count = 1000
84
 
        nextid = self.head
85
 
        while cms != []:
86
 
            cms = self.repository._git.commits(self.head, max_count=max_count, skip=skip)
87
 
            skip += max_count
88
 
            for cm in cms:
89
 
                if cm.id == nextid:
90
 
                    ret.append(ids.convert_revision_id_git_to_bzr(cm.id))
91
 
                    if cm.parents == []:
92
 
                        nextid = None
93
 
                    else:
94
 
                        nextid = cm.parents[0].id
95
 
        ret.reverse()
96
 
        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))
97
87
 
98
88
    def get_config(self):
99
89
        return GitBranchConfig(self)
104
94
    def unlock(self):
105
95
        self.control_files.unlock()
106
96
 
107
 
    def get_physical_lock_status(self):
108
 
        return False
109
 
 
110
97
    def get_push_location(self):
111
98
        """See Branch.get_push_location."""
112
99
        push_loc = self.get_config().get_user_option('push_location')