Merge lp:~jelmer/loggerhead/no-such-file into lp:loggerhead

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 499
Proposed branch: lp:~jelmer/loggerhead/no-such-file
Merge into: lp:loggerhead
Diff against target: 161 lines (+21/-24)
6 files modified
loggerhead/controllers/annotate_ui.py (+1/-1)
loggerhead/controllers/download_ui.py (+4/-5)
loggerhead/controllers/view_ui.py (+9/-10)
loggerhead/history.py (+3/-4)
loggerhead/templates/view.pt (+1/-1)
loggerhead/tests/test_controllers.py (+3/-3)
To merge this branch: bzr merge lp:~jelmer/loggerhead/no-such-file
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+385139@code.launchpad.net

Description of the change

Hide file ids in loggerhead URLs.

This has the added benefit of fixing a bug in the download URL generation,
which didn't properly decode file id bytestrings on Python 3.

To post a comment you must log in.
lp:~jelmer/loggerhead/no-such-file updated
501. By Jelmer Vernooij

Fix tests.

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'loggerhead/controllers/annotate_ui.py'
2--- loggerhead/controllers/annotate_ui.py 2018-10-20 16:16:22 +0000
3+++ loggerhead/controllers/annotate_ui.py 2020-06-04 20:32:36 +0000
4@@ -32,7 +32,7 @@
5 raise TypeError(revid)
6 path = self._history.get_path(revid, file_id)
7
8- tree = self.tree_for(file_id, revid)
9+ tree = self.tree_for(path, revid)
10
11 change_cache = {}
12 last_line_revid = None
13
14=== modified file 'loggerhead/controllers/download_ui.py'
15--- loggerhead/controllers/download_ui.py 2018-10-20 15:28:43 +0000
16+++ loggerhead/controllers/download_ui.py 2020-06-04 20:32:36 +0000
17@@ -22,7 +22,7 @@
18 import urllib
19
20 from breezy.errors import (
21- NoSuchId,
22+ NoSuchFile,
23 NoSuchRevision,
24 )
25 from breezy import osutils, urlutils
26@@ -50,17 +50,16 @@
27 return args
28
29 def __call__(self, environ, start_response):
30- # /download/<rev_id>/<file_id>/[filename]
31+ # /download/<rev_id>/<filename>
32 h = self._history
33 args = self.get_args(environ)
34 if len(args) < 2:
35 raise httpexceptions.HTTPMovedPermanently(
36 self._branch.absolute_url('/changes'))
37 revid = h.fix_revid(args[0])
38- file_id = urlutils.unquote_to_bytes(osutils.safe_utf8(args[1]))
39 try:
40- path, filename, content = h.get_file(file_id, revid)
41- except (NoSuchId, NoSuchRevision):
42+ path, filename, content = h.get_file(args[1], revid)
43+ except (NoSuchFile, NoSuchRevision):
44 raise httpexceptions.HTTPNotFound()
45 mime_type, encoding = mimetypes.guess_type(filename)
46 if mime_type is None:
47
48=== modified file 'loggerhead/controllers/view_ui.py'
49--- loggerhead/controllers/view_ui.py 2020-01-19 20:09:08 +0000
50+++ loggerhead/controllers/view_ui.py 2020-06-04 20:32:36 +0000
51@@ -49,20 +49,19 @@
52
53 template_name = 'view'
54
55- def tree_for(self, file_id, revid):
56- if not isinstance(file_id, bytes):
57- raise TypeError(file_id)
58+ def tree_for(self, path, revid):
59+ if not isinstance(path, str):
60+ raise TypeError(path)
61 if not isinstance(revid, bytes):
62 raise TypeError(revid)
63 rev_tree = self._history.revision_tree(revid)
64- file_revid = rev_tree.get_file_revision(rev_tree.id2path(file_id))
65+ file_revid = rev_tree.get_file_revision(path)
66 return self._history._branch.repository.revision_tree(file_revid)
67
68- def text_lines(self, file_id, revid):
69- path = self._history.get_path(revid, file_id)
70+ def text_lines(self, path, revid):
71 file_name = os.path.basename(path)
72
73- tree = self.tree_for(file_id, revid)
74+ tree = self.tree_for(path, revid)
75 file_text = tree.get_file_text(path)
76
77 encoding = 'utf-8'
78@@ -88,9 +87,9 @@
79
80 return hl_lines
81
82- def file_contents(self, file_id, revid):
83+ def file_contents(self, path, revid):
84 try:
85- file_lines = self.text_lines(file_id, revid)
86+ file_lines = self.text_lines(path, revid)
87 except BinaryFile:
88 # bail out; this isn't displayable text
89 return ['(This is a binary file.)']
90@@ -158,7 +157,7 @@
91 'filename': filename,
92 'navigation': navigation,
93 'change': change,
94- 'contents': self.file_contents(file_id, revid),
95+ 'contents': self.file_contents(path, revid),
96 'fileview_active': True,
97 'directory_breadcrumbs': directory_breadcrumbs,
98 'branch_breadcrumbs': branch_breadcrumbs,
99
100=== modified file 'loggerhead/history.py'
101--- loggerhead/history.py 2020-05-06 19:18:04 +0000
102+++ loggerhead/history.py 2020-06-04 20:32:36 +0000
103@@ -773,14 +773,13 @@
104 changes = self.get_file_changes(entry)
105 entry.changes = changes
106
107- def get_file(self, file_id, revid):
108+ def get_file(self, path, revid):
109 """Returns (path, filename, file contents)"""
110- if not isinstance(file_id, bytes):
111- raise TypeError(file_id)
112+ if not isinstance(path, str):
113+ raise TypeError(path)
114 if not isinstance(revid, bytes):
115 raise TypeError(revid)
116 rev_tree = self._branch.repository.revision_tree(revid)
117- path = rev_tree.id2path(file_id)
118 display_path = path
119 if not display_path.startswith('/'):
120 path = '/' + path
121
122=== modified file 'loggerhead/templates/view.pt'
123--- loggerhead/templates/view.pt 2012-02-22 08:28:09 +0000
124+++ loggerhead/templates/view.pt 2020-06-04 20:32:36 +0000
125@@ -64,7 +64,7 @@
126 </li>
127 <li id="last">
128 <a tal:attributes="href python:url(['/download',
129- revno_url, file_id, filename])"
130+ revno_url, file_path])"
131 >download file</a>
132 </li>
133 </ul>
134
135=== modified file 'loggerhead/tests/test_controllers.py'
136--- loggerhead/tests/test_controllers.py 2020-01-19 20:09:08 +0000
137+++ loggerhead/tests/test_controllers.py 2020-06-04 20:32:36 +0000
138@@ -387,7 +387,7 @@
139
140 def test_download(self):
141 app = self.setUpLoggerhead()
142- response = app.get('/download/1/myfilename-id/myfilename')
143+ response = app.get('/download/1/myfilename')
144 self.assertEqual(
145 b'some\nmultiline\ndata\nwith<htmlspecialchars\n', response.body)
146 self.assertThat(
147@@ -398,14 +398,14 @@
148 app = self.setUpLoggerhead()
149 e = self.assertRaises(
150 AppError,
151- app.get, '/download/norev/myfilename-id/myfilename')
152+ app.get, '/download/norev/myfilename')
153 self.assertContainsRe(str(e), '404 Not Found')
154
155 def test_download_bad_fileid(self):
156 app = self.setUpLoggerhead()
157 e = self.assertRaises(
158 AppError,
159- app.get, '/download/1/myfilename-notid/myfilename')
160+ app.get, '/download/1/notmyfilename')
161 self.assertContainsRe(str(e), '404 Not Found')
162
163

Subscribers

People subscribed via source and target branches