~jelmer/loggerhead/breezy-compat

« back to all changes in this revision

Viewing changes to loggerhead/controllers/filediff_ui.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:
58
58
    return chunks
59
59
 
60
60
 
61
 
def diff_chunks_for_file(repository, file_id, compare_revid, revid,
 
61
def diff_chunks_for_file(repository, path, compare_revid, revid,
62
62
                         context_lines=None):
63
63
    if context_lines is None:
64
64
        context_lines = 3
65
65
    lines = {}
66
 
    args = []
67
66
    for r in (compare_revid, revid):
68
67
        if r == b'null:':
69
68
            lines[r] = []
70
69
        else:
71
 
            args.append((file_id, r, r))
72
 
    for r, bytes_iter in repository.iter_files_bytes(args):
73
 
        lines[r] = osutils.split_lines(b''.join(bytes_iter))
 
70
            tree = repository.revision_tree(r)
 
71
            lines[r] = tree.get_file_lines(path)
74
72
    buffer = BytesIO()
75
73
    try:
76
74
        diff.internal_diff('', lines[compare_revid], '', lines[revid], buffer, context_lines=context_lines)
90
88
    def get_values(self, path, kwargs, headers):
91
89
        revid = urlutils.unquote_to_bytes(self.args[0])
92
90
        compare_revid = urlutils.unquote_to_bytes(self.args[1])
93
 
        file_id = urlutils.unquote_to_bytes(self.args[2])
 
91
        path = urlutils.unquote(self.args[2])
94
92
 
95
93
        try:
96
94
            context_lines = int(kwargs['context'])
98
96
            context_lines = None
99
97
 
100
98
        chunks = diff_chunks_for_file(
101
 
            self._history._branch.repository, file_id, compare_revid, revid,
 
99
            self._history._branch.repository, path, compare_revid, revid,
102
100
            context_lines=context_lines)
103
101
 
104
102
        return {