Merge lp:~mwhudson/loggerhead/sorry-rob into lp:~mwhudson/loggerhead/iter_changes-forevar

Proposed by Michael Hudson-Doyle
Status: Merged
Merge reported by: Michael Hudson-Doyle
Merged at revision: not available
Proposed branch: lp:~mwhudson/loggerhead/sorry-rob
Merge into: lp:~mwhudson/loggerhead/iter_changes-forevar
Diff against target: None lines
To merge this branch: bzr merge lp:~mwhudson/loggerhead/sorry-rob
Reviewer Review Type Date Requested Status
Martin Albisetti (community) Approve
Michael Hudson-Doyle Pending
Review via email: mp+4648@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Hi gentle reviewer,

This branch, which depends on the iter_changes-forevar branch, contorts
slightly to avoid loading inventories on the +filediff page fragments,
which and then contorts some more so that all the inventory information
needed to render a revision page comparing against its parent is stored
in the filechange cache. On a wide tree like launchpad this means
revision and +filediff pages load about 10x faster once the cache is
populated.

Cheers,
mwh

lp:~mwhudson/loggerhead/sorry-rob updated
314. By Michael Hudson-Doyle

remove debugging print

315. By Michael Hudson-Doyle

work for the initial revision

316. By Michael Hudson-Doyle

merge trunk

Revision history for this message
Martin Albisetti (beuno) wrote :

Looks good, just kill the extra import for bzrlib.errors, and you're set to merge!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'loggerhead/controllers/filediff_ui.py'
--- loggerhead/controllers/filediff_ui.py 2009-03-17 06:43:34 +0000
+++ loggerhead/controllers/filediff_ui.py 2009-03-19 02:39:59 +0000
@@ -3,6 +3,7 @@
33
4from bzrlib import diff4from bzrlib import diff
5from bzrlib import errors5from bzrlib import errors
6from bzrlib import osutils
67
7from loggerhead import util8from loggerhead import util
8from loggerhead.controllers import TemplatedBranchView9from loggerhead.controllers import TemplatedBranchView
@@ -52,25 +53,24 @@
52 return chunks53 return chunks
5354
5455
55def diff_chunks_for_file(file_id, old_tree, new_tree):56def diff_chunks_for_file(repository, file_id, compare_revid, revid):
56 try:57 lines = {}
57 old_lines = old_tree.get_file_lines(file_id)58 args = []
58 except errors.NoSuchId:59 for r in (compare_revid, revid):
59 old_lines = []60 if r == 'null:':
60 try:61 lines[r] = []
61 new_lines = new_tree.get_file_lines(file_id)62 else:
62 except errors.NoSuchId:63 args.append((file_id, r, r))
63 new_lines = []64 for r, bytes_iter in repository.iter_files_bytes(args):
65 lines[r] = osutils.split_lines(bytes_iter)
66 print lines.keys()
64 buffer = StringIO()67 buffer = StringIO()
65 if old_lines != new_lines:68 try:
66 try:69 diff.internal_diff('', lines[compare_revid], '', lines[revid], buffer)
67 diff.internal_diff('', old_lines, '', new_lines, buffer)70 except errors.BinaryFile:
68 except errors.BinaryFile:71 difftext = ''
69 difftext = ''
70 else:
71 difftext = buffer.getvalue()
72 else:72 else:
73 difftext = ''73 difftext = buffer.getvalue()
7474
75 return _process_diff(difftext)75 return _process_diff(difftext)
7676
@@ -87,9 +87,8 @@
87 file_id = urllib.unquote(self.args[2])87 file_id = urllib.unquote(self.args[2])
8888
89 repository = self._history._branch.repository89 repository = self._history._branch.repository
90 old_tree, new_tree = repository.revision_trees([compare_revid, revid])90 chunks = diff_chunks_for_file(
9191 self._history._branch.repository, file_id, compare_revid, revid)
92 chunks = diff_chunks_for_file(file_id, old_tree, new_tree)
9392
94 return {93 return {
95 'util': util,94 'util': util,
9695
=== modified file 'loggerhead/controllers/revision_ui.py'
--- loggerhead/controllers/revision_ui.py 2009-03-19 00:44:05 +0000
+++ loggerhead/controllers/revision_ui.py 2009-03-19 03:06:42 +0000
@@ -23,6 +23,8 @@
23 import json as simplejson23 import json as simplejson
24import urllib24import urllib
2525
26from bzrlib import errors
27
26from paste.httpexceptions import HTTPServerError28from paste.httpexceptions import HTTPServerError
2729
28from loggerhead import util30from loggerhead import util
@@ -70,32 +72,27 @@
70 change = h.get_changes([revid])[0]72 change = h.get_changes([revid])[0]
7173
72 if compare_revid is None:74 if compare_revid is None:
73 if change.parents:75 file_changes = h.get_file_changes(change)
74 cr = change.parents[0].revid
75 else:
76 cr = 'null:'
77 else:76 else:
78 cr = compare_revid77 file_changes = h.file_changes_for_revision_ids(
78 compare_revid, change.revid)
7979
80 if path in ('', '/'):80 if path in ('', '/'):
81 path = None81 path = None
8282
83 old_tree = h._branch.repository.revision_tree(cr)
84 new_tree = h._branch.repository.revision_tree(change.revid)
85 file_changes = h.file_changes_from_revision_trees(
86 old_tree, new_tree)
87
88 link_data = {}83 link_data = {}
89 path_to_id = {}84 path_to_id = {}
90 if path:85 if path:
86 item = [x for x in file_changes.text_changes if x.filename == path][0]
91 diff_chunks = diff_chunks_for_file(87 diff_chunks = diff_chunks_for_file(
92 new_tree.path2id(path), old_tree, new_tree)88 self._history._branch.repository, item.file_id,
89 item.old_revision, item.new_revision)
93 else:90 else:
94 diff_chunks = None91 diff_chunks = None
95 for i, item in enumerate(file_changes.text_changes):92 for i, item in enumerate(file_changes.text_changes):
96 item.index = i93 item.index = i
97 link_data['diff-' + str(i)] = '%s/%s/%s' % (94 link_data['diff-' + str(i)] = '%s/%s/%s' % (
98 dq(revid), dq(cr), dq(item.file_id))95 dq(item.new_revision), dq(item.old_revision), dq(item.file_id))
99 path_to_id[item.filename] = 'diff-' + str(i)96 path_to_id[item.filename] = 'diff-' + str(i)
10097
101 h.add_branch_nicks(change)98 h.add_branch_nicks(change)
10299
=== modified file 'loggerhead/history.py'
--- loggerhead/history.py 2009-03-19 03:12:58 +0000
+++ loggerhead/history.py 2009-03-19 03:13:32 +0000
@@ -131,18 +131,29 @@
131 return len(self.revid_list)131 return len(self.revid_list)
132132
133class FileChangeReporter(object):133class FileChangeReporter(object):
134 def __init__(self):134 def __init__(self, old_inv, new_inv):
135 self.added = []135 self.added = []
136 self.modified = []136 self.modified = []
137 self.renamed = []137 self.renamed = []
138 self.removed = []138 self.removed = []
139 self.text_changes = []139 self.text_changes = []
140 self.old_inv = old_inv
141 self.new_inv = new_inv
142
143 def revid(self, inv, file_id):
144 try:
145 return inv[file_id].revision
146 except bzrlib.errors.NoSuchId:
147 return 'null:'
148
140 def report(self, file_id, paths, versioned, renamed, modified,149 def report(self, file_id, paths, versioned, renamed, modified,
141 exe_change, kind):150 exe_change, kind):
142 if modified not in ('unchanged', 'kind changed'):151 if modified not in ('unchanged', 'kind changed'):
143 self.text_changes.append(util.Container(152 self.text_changes.append(util.Container(
144 filename=rich_filename(paths[1], kind[0]),153 filename=rich_filename(paths[1], kind[0]),
145 file_id=file_id))154 file_id=file_id,
155 old_revision=self.revid(self.old_inv, file_id),
156 new_revision=self.revid(self.new_inv, file_id)))
146 if versioned == 'added':157 if versioned == 'added':
147 self.added.append(util.Container(158 self.added.append(util.Container(
148 filename=rich_filename(paths[1], kind),159 filename=rich_filename(paths[1], kind),
@@ -588,11 +599,10 @@
588 def get_file_changes_uncached(self, entry):599 def get_file_changes_uncached(self, entry):
589 repo = self._branch.repository600 repo = self._branch.repository
590 if entry.parents:601 if entry.parents:
591 old_tree = repo.revision_tree(entry.parents[0].revid)602 old_revid = entry.parents[0].revid
592 else:603 else:
593 old_tree = repo.revision_tree(bzrlib.revision.NULL_REVISION)604 old_revid = bzrlib.revision.NULL_REVISION
594 new_tree = repo.revision_tree(entry.revid)605 return self.file_changes_for_revision_ids(old_revid, entry.revid)
595 return self.file_changes_from_revision_trees(old_tree, new_tree)
596606
597 def get_file_changes(self, entry):607 def get_file_changes(self, entry):
598 if self._file_change_cache is None:608 if self._file_change_cache is None:
@@ -614,7 +624,7 @@
614 path = '/' + path624 path = '/' + path
615 return path, inv_entry.name, rev_tree.get_file_text(file_id)625 return path, inv_entry.name, rev_tree.get_file_text(file_id)
616626
617 def file_changes_from_revision_trees(self, old_tree, new_tree):627 def file_changes_for_revision_ids(self, old_revid, new_revid):
618 """628 """
619 Return a nested data structure containing the changes in a delta::629 Return a nested data structure containing the changes in a delta::
620630
@@ -627,7 +637,10 @@
627 ),637 ),
628 text_changes: list((filename, file_id)),638 text_changes: list((filename, file_id)),
629 """639 """
630 reporter = FileChangeReporter()640 old_tree, new_tree = self._branch.repository.revision_trees(
641 [old_revid, new_revid])
642
643 reporter = FileChangeReporter(old_tree.inventory, new_tree.inventory)
631644
632 bzrlib.delta.report_changes(new_tree.iter_changes(old_tree), reporter)645 bzrlib.delta.report_changes(new_tree.iter_changes(old_tree), reporter)
633646

Subscribers

People subscribed via source and target branches

to all changes: