/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 breezy/git/filegraph.py

  • Committer: Jelmer Vernooij
  • Date: 2018-06-14 17:59:16 UTC
  • mto: This revision was merged to the branch mainline in revision 7065.
  • Revision ID: jelmer@jelmer.uk-20180614175916-a2e2xh5k533guq1x
Move breezy.plugins.git to breezy.git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""File graph access."""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
20
22
import stat
21
23
 
22
24
from dulwich.errors import (
30
32
    NULL_REVISION,
31
33
    )
32
34
 
33
 
from .mapping import (
34
 
    encode_git_path,
35
 
    )
36
 
 
37
35
 
38
36
class GitFileLastChangeScanner(object):
39
37
 
42
40
        self.store = self.repository._git.object_store
43
41
 
44
42
    def find_last_change_revision(self, path, commit_id):
45
 
        if not isinstance(path, bytes):
46
 
            raise TypeError(path)
47
43
        commit = self.store[commit_id]
48
44
        target_mode, target_sha = tree_lookup_path(self.store.__getitem__,
49
 
                                                   commit.tree, path)
50
 
        if path == b'':
 
45
            commit.tree, path)
 
46
        if path == '':
51
47
            target_mode = stat.S_IFDIR
52
48
        if target_mode is None:
53
 
            raise AssertionError("sha %r for %r in %r" %
54
 
                                 (target_sha, path, commit_id))
 
49
            raise AssertionError("sha %r for %r in %r" % (target_sha, path, commit_id))
55
50
        while True:
56
51
            parent_commits = []
57
52
            for parent_commit in [self.store[c] for c in commit.parents]:
58
53
                try:
59
54
                    mode, sha = tree_lookup_path(self.store.__getitem__,
60
 
                                                 parent_commit.tree, path)
 
55
                        parent_commit.tree, path)
61
56
                except (NotTreeError, KeyError):
62
57
                    continue
63
58
                else:
64
59
                    parent_commits.append(parent_commit)
65
 
                if path == b'':
 
60
                if path == '':
66
61
                    mode = stat.S_IFDIR
67
62
                # Candidate found iff, mode or text changed,
68
63
                # or is a directory that didn't previously exist.
69
64
                if mode != target_mode or (
70
 
                        not stat.S_ISDIR(target_mode) and sha != target_sha):
71
 
                    return (path, commit.id)
 
65
                    not stat.S_ISDIR(target_mode) and sha != target_sha):
 
66
                        return (path, commit.id)
72
67
            if parent_commits == []:
73
68
                break
74
69
            commit = parent_commits[0]
82
77
        self.store = self.change_scanner.repository._git.object_store
83
78
 
84
79
    def _get_parents(self, file_id, text_revision):
85
 
        commit_id, mapping = (
86
 
            self.change_scanner.repository.lookup_bzr_revision_id(
87
 
                text_revision))
 
80
        commit_id, mapping = self.change_scanner.repository.lookup_bzr_revision_id(
 
81
            text_revision)
88
82
        try:
89
 
            path = encode_git_path(mapping.parse_file_id(file_id))
 
83
            path = mapping.parse_file_id(file_id)
90
84
        except ValueError:
91
85
            raise KeyError(file_id)
92
86
        text_parents = []
93
87
        for commit_parent in self.store[commit_id].parents:
94
88
            try:
95
 
                (path, text_parent) = (
96
 
                    self.change_scanner.find_last_change_revision(
97
 
                        path, commit_parent))
 
89
                (path, text_parent) = self.change_scanner.find_last_change_revision(path, commit_parent)
98
90
            except KeyError:
99
91
                continue
100
92
            if text_parent not in text_parents:
101
93
                text_parents.append(text_parent)
102
 
        return tuple([
103
 
            (file_id,
104
 
                self.change_scanner.repository.lookup_foreign_revision_id(p))
105
 
            for p in text_parents])
 
94
        return tuple([(file_id,
 
95
            self.change_scanner.repository.lookup_foreign_revision_id(p)) for p
 
96
            in text_parents])
106
97
 
107
98
    def get_parent_map(self, keys):
108
99
        ret = {}
111
102
            if text_revision == NULL_REVISION:
112
103
                ret[key] = ()
113
104
                continue
114
 
            if not isinstance(file_id, bytes):
115
 
                raise TypeError(file_id)
116
 
            if not isinstance(text_revision, bytes):
117
 
                raise TypeError(text_revision)
118
105
            try:
119
106
                ret[key] = self._get_parents(file_id, text_revision)
120
107
            except KeyError: