/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 tree.py

  • Committer: Jelmer Vernooij
  • Date: 2010-05-13 12:34:24 UTC
  • mto: (0.200.912 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20100513123424-c1sk9vcg2ekrcsol
Some refactoring, support proper file ids in revision deltas.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    GitInventory,
29
29
    )
30
30
from bzrlib.plugins.git.mapping import (
31
 
    GitFileIdMap,
32
31
    mode_is_executable,
33
32
    mode_kind,
34
33
    )
47
46
        except KeyError, r:
48
47
            raise errors.NoSuchRevision(repository, revision_id)
49
48
        self.tree = commit.tree
50
 
        try:
51
 
            file_id_map_sha = store[self.tree][self.mapping.BZR_FILE_IDS_FILE][1]
52
 
        except KeyError:
53
 
            file_ids = {}
54
 
        else:
55
 
            file_ids = self.mapping.import_fileid_map(store[file_id_map_sha])
56
 
        fileid_map = GitFileIdMap(file_ids, self.mapping)
57
 
        self._inventory = GitInventory(self.tree, self.mapping, fileid_map, store, 
58
 
                                       revision_id)
 
49
        fileid_map = self.mapping.get_fileid_map(store.__getitem__, self.tree)
 
50
        self._inventory = GitInventory(self.tree, self.mapping, fileid_map,
 
51
            store, revision_id)
59
52
 
60
53
    def get_revision_id(self):
61
54
        return self._revision_id
70
63
        return entry.object.data
71
64
 
72
65
 
73
 
def tree_delta_from_git_changes(changes, mapping, specific_file=None, 
74
 
                                require_versioned=False):
 
66
def tree_delta_from_git_changes(changes, mapping,
 
67
        (old_fileid_map, new_fileid_map), specific_file=None,
 
68
        require_versioned=False):
75
69
    """Create a TreeDelta from two git trees.
76
70
    
77
71
    source and target are iterators over tuples with: 
79
73
    """
80
74
    ret = delta.TreeDelta()
81
75
    for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes:
 
76
        if mapping.is_control_file(oldpath):
 
77
            oldpath = None
 
78
        if mapping.is_control_file(newpath):
 
79
            newpath = None
 
80
        if oldpath is None and newpath is None:
 
81
            continue
82
82
        if oldpath is None:
83
 
            ret.added.append((newpath, mapping.generate_file_id(newpath), mode_kind(newmode)))
 
83
            ret.added.append((newpath, new_fileid_map.lookup_file_id(newpath.encode("utf-8")), mode_kind(newmode)))
84
84
        elif newpath is None:
85
 
            ret.removed.append((oldpath, mapping.generate_file_id(oldpath), mode_kind(oldmode)))
 
85
            ret.removed.append((oldpath, old_fileid_map.lookup_file_id(oldpath.encode("utf-8")), mode_kind(oldmode)))
86
86
        elif oldpath != newpath:
87
 
            ret.renamed.append((oldpath, newpath, mapping.generate_file_id(oldpath), mode_kind(newmode), (oldsha != newsha), (oldmode != newmode)))
 
87
            ret.renamed.append((oldpath, newpath, old_fileid_map.lookup_file_id(oldpath.encode("utf-8")), mode_kind(newmode), (oldsha != newsha), (oldmode != newmode)))
88
88
        elif mode_kind(oldmode) != mode_kind(newmode):
89
 
            ret.kind_changed.append((newpath, mapping.generate_file_id(newpath), mode_kind(oldmode), mode_kind(newmode)))
 
89
            ret.kind_changed.append((newpath, new_fileid_map.lookup_file_id(newpath.encode("utf-8")), mode_kind(oldmode), mode_kind(newmode)))
90
90
        elif oldsha != newsha or oldmode != newmode:
91
 
            ret.modified.append((newpath, mapping.generate_file_id(newpath), mode_kind(newmode), (oldsha != newsha), (oldmode != newmode)))
 
91
            ret.modified.append((newpath, new_fileid_map.lookup_file_id(newpath.encode("utf-8")), mode_kind(newmode), (oldsha != newsha), (oldmode != newmode)))
92
92
        else:
93
 
            ret.unchanged.append((newpath, mapping.generate_file_id(newpath), mode_kind(newmode)))
 
93
            ret.unchanged.append((newpath, new_fileid_map.lookup_file_id(newpath.encode("utf-8")), mode_kind(newmode)))
94
94
    return ret
95
95
 
96
96
 
157
157
            raise AssertionError
158
158
        changes = self.source._repository._git.object_store.tree_changes(
159
159
            self.source.tree, self.target.tree, want_unchanged=want_unchanged)
 
160
        source_fileid_map = self.source.mapping.get_fileid_map(
 
161
            self.source._repository._git.object_store.__getitem__,
 
162
            self.source.tree)
 
163
        target_fileid_map = self.target.mapping.get_fileid_map(
 
164
            self.target._repository._git.object_store.__getitem__,
 
165
            self.target.tree)
160
166
        return tree_delta_from_git_changes(changes, self.target.mapping, 
 
167
            (source_fileid_map, target_fileid_map),
161
168
            specific_file=specific_files)
162
169
 
163
170
    def iter_changes(self, include_unchanged=False, specific_files=None,