~jelmer/loggerhead/breezy-compat

« back to all changes in this revision

Viewing changes to loggerhead/history.py

  • Committer: Jelmer Vernooij
  • Date: 2019-09-21 22:50:23 UTC
  • Revision ID: jelmer@jelmer.uk-20190921225023-esteo4f1jxtbp1fy
Avoid relying on file ids.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
import re
34
34
import textwrap
35
35
import threading
36
 
import tarfile
37
36
 
38
37
from breezy import tag
 
38
from breezy import version_info as breezy_version
39
39
import breezy.branch
40
40
import breezy.delta
41
41
import breezy.errors
122
122
        self.old_tree = old_tree
123
123
        self.new_tree = new_tree
124
124
 
125
 
    def revid(self, tree, file_id):
 
125
    def revid(self, tree, path):
126
126
        try:
127
 
            path = tree.id2path(file_id)
128
 
        except breezy.errors.NoSuchId:
 
127
            return tree.get_file_revision(path)
 
128
        except breezy.errors.NoSuchFile:
129
129
            return b'null:'
130
 
        else:
131
 
            return tree.get_file_revision(path)
132
 
 
133
 
    def report(self, file_id, paths, versioned, renamed, modified,
134
 
               exe_change, kind):
 
130
 
 
131
    if breezy_version >= (3, 1):
 
132
        def report(self, paths, versioned, renamed, modified,
 
133
                   exe_change, kind):
 
134
            return self._report(
 
135
                paths, versioned, renamed, modified,
 
136
                exe_change, kind)
 
137
    else:
 
138
        def report(self, file_id, paths, versioned, renamed, modified,
 
139
                   exe_change, kind):
 
140
            return self._report(
 
141
                paths, versioned, renamed, modified,
 
142
                exe_change, kind)
 
143
 
 
144
    def _report(self, paths, versioned, renamed, modified, exe_change, kind):
135
145
        if modified not in ('unchanged', 'kind changed'):
136
146
            if versioned == 'removed':
137
147
                filename = rich_filename(paths[0], kind[0])
138
148
            else:
139
149
                filename = rich_filename(paths[1], kind[1])
140
150
            self.text_changes.append(util.Container(
141
 
                filename=filename, file_id=file_id,
142
 
                old_revision=self.revid(self.old_tree, file_id),
143
 
                new_revision=self.revid(self.new_tree, file_id)))
 
151
                filename=filename,
 
152
                old_revision=self.revid(self.old_tree, paths[0]),
 
153
                new_revision=self.revid(self.new_tree, paths[1]),
 
154
                old_path=paths[0],
 
155
                new_path=paths[1]))
144
156
        if versioned == 'added':
145
157
            self.added.append(util.Container(
146
158
                filename=rich_filename(paths[1], kind), kind=kind[1]))