/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

Implement InterTree.iter_changes() as well.

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
    mode_is_executable,
31
32
    mode_kind,
32
33
    )
33
34
 
84
85
    return ret
85
86
 
86
87
 
 
88
def changes_from_git_changes(changes, mapping, specific_file=None, 
 
89
                                require_versioned=False):
 
90
    """Create a iter_changes-like generator from a git stream.
 
91
    
 
92
    source and target are iterators over tuples with: 
 
93
        (filename, sha, mode)
 
94
    """
 
95
    for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in changes:
 
96
        path = (oldpath, newpath)
 
97
        if oldpath is None:
 
98
            fileid = mapping.generate_file_id(newpath)
 
99
            oldexe = None
 
100
            oldkind = None
 
101
            oldname = None
 
102
            oldparent = None
 
103
        else:
 
104
            oldexe = mode_is_executable(oldmode)
 
105
            oldkind = mode_kind(oldmode)
 
106
            try:
 
107
                (oldparentpath, oldname) = oldpath.rsplit("/", 1)
 
108
            except ValueError:
 
109
                oldparent = None
 
110
                oldname = oldpath
 
111
            else:
 
112
                oldparent = mapping.generate_file_id(oldparentpath)
 
113
            fileid = mapping.generate_file_id(oldpath)
 
114
        if newpath is None:
 
115
            newexe = None
 
116
            newkind = None
 
117
            newname = None
 
118
            newparent = None
 
119
        else:
 
120
            newexe = mode_is_executable(newmode)
 
121
            newkind = mode_kind(newmode)
 
122
            try:
 
123
                newparentpath, newname = newpath.rsplit("/", 1)
 
124
            except ValueError:
 
125
                newparent = None
 
126
                newname = newpath
 
127
            else:
 
128
                newparent = mapping.generate_file_id(newparentpath)
 
129
        yield fileid, (oldpath, newpath), (oldsha != newsha), (oldpath is not None, newpath is not None), (oldparent, newparent), (oldname, newname), (oldkind, newkind), (oldexe, newexe)
 
130
 
 
131
 
87
132
class InterGitRevisionTrees(tree.InterTree):
88
133
    """InterTree that works between two git revision trees."""
89
134
 
102
147
        return tree_delta_from_git_changes(changes, self.target.mapping, 
103
148
            specific_file=specific_files)
104
149
 
 
150
    def iter_changes(self, include_unchanged=False, specific_files=None,
 
151
        pb=None, extra_trees=[], require_versioned=True, want_unversioned=False):
 
152
        if self.source._repository._git.object_store != self.target._repository._git.object_store:
 
153
            raise AssertionError
 
154
        changes = self.source._repository._git.object_store.tree_changes(
 
155
            self.source.tree, self.target.tree, 
 
156
            want_unchanged=include_unchanged)
 
157
        return changes_from_git_changes(changes, self.target.mapping, 
 
158
            specific_file=specific_files)
 
159
 
105
160
 
106
161
tree.InterTree.register_optimiser(InterGitRevisionTrees)