Merge lp:~twom/loggerhead/add-download-compatibility-api into lp:loggerhead

Proposed by Tom Wardill
Status: Merged
Merged at revision: 504
Proposed branch: lp:~twom/loggerhead/add-download-compatibility-api
Merge into: lp:loggerhead
Diff against target: 79 lines (+31/-2)
3 files modified
loggerhead/controllers/download_ui.py (+7/-1)
loggerhead/history.py (+15/-1)
loggerhead/tests/test_controllers.py (+9/-0)
To merge this branch: bzr merge lp:~twom/loggerhead/add-download-compatibility-api
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+387058@code.launchpad.net

Commit message

Add compatibility download API

Description of the change

There is a breaking change in the download URL structure to use /download/revid/filename. This restores the ability to use /download/revid/fileid/filename, but checks the newer structure first.

To post a comment you must log in.
505. By Tom Wardill

Remove old code

506. By Tom Wardill

No need to check contents here

Revision history for this message
Colin Watson (cjwatson) wrote :

We may not be able to support this indefinitely, since I don't know how long the file ID APIs will continue to exist in Breezy, but we can cross that bridge when we come to it.

review: Approve
507. By Tom Wardill

Add encode for py3 compat

508. By Tom Wardill

Encode the correct argument

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/download_ui.py'
2--- loggerhead/controllers/download_ui.py 2020-06-04 19:21:17 +0000
3+++ loggerhead/controllers/download_ui.py 2020-07-08 17:12:29 +0000
4@@ -23,6 +23,7 @@
5
6 from breezy.errors import (
7 NoSuchFile,
8+ NoSuchId,
9 NoSuchRevision,
10 )
11 from breezy import osutils, urlutils
12@@ -60,7 +61,12 @@
13 try:
14 path, filename, content = h.get_file(args[1], revid)
15 except (NoSuchFile, NoSuchRevision):
16- raise httpexceptions.HTTPNotFound()
17+ # Compatibility API for /download/rev_id/file_id/<filename>
18+ try:
19+ path, filename, content = h.get_file_by_fileid(
20+ args[1].encode('UTF-8'), revid)
21+ except (NoSuchId, NoSuchRevision):
22+ raise httpexceptions.HTTPNotFound()
23 mime_type, encoding = mimetypes.guess_type(filename)
24 if mime_type is None:
25 mime_type = 'application/octet-stream'
26
27=== modified file 'loggerhead/history.py'
28--- loggerhead/history.py 2020-06-04 19:21:17 +0000
29+++ loggerhead/history.py 2020-07-08 17:12:29 +0000
30@@ -217,7 +217,7 @@
31 finally:
32 rev_info_memory_cache_lock.release()
33
34-# Used to store locks that prevent multiple threads from building a
35+# Used to store locks that prevent multiple threads from building a
36 # revision graph for the same branch at the same time, because that can
37 # cause severe performance issues that are so bad that the system seems
38 # to hang.
39@@ -786,6 +786,20 @@
40 return (display_path, breezy.osutils.basename(path),
41 rev_tree.get_file_text(path))
42
43+ def get_file_by_fileid(self, fileid, revid):
44+ """Returns (path, filename, file contents)"""
45+ if not isinstance(fileid, bytes):
46+ raise TypeError(fileid)
47+ if not isinstance(revid, bytes):
48+ raise TypeError(revid)
49+ rev_tree = self._branch.repository.revision_tree(revid)
50+ path = rev_tree.id2path(fileid)
51+ display_path = path
52+ if not display_path.startswith('/'):
53+ path = '/' + path
54+ return (display_path, breezy.osutils.basename(path),
55+ rev_tree.get_file_text(path))
56+
57 def file_changes_for_revision_ids(self, old_revid, new_revid):
58 """
59 Return a nested data structure containing the changes in a delta::
60
61=== modified file 'loggerhead/tests/test_controllers.py'
62--- loggerhead/tests/test_controllers.py 2020-07-07 10:35:12 +0000
63+++ loggerhead/tests/test_controllers.py 2020-07-08 17:12:29 +0000
64@@ -394,6 +394,15 @@
65 response,
66 MatchesDownloadHeaders('myfilename', 'application/octet-stream'))
67
68+ def test_download_with_revid(self):
69+ app = self.setUpLoggerhead()
70+ response = app.get('/download/1/myfilename-id/myfilename')
71+ self.assertEqual(
72+ b'some\nmultiline\ndata\nwith<htmlspecialchars\n', response.body)
73+ self.assertThat(
74+ response,
75+ MatchesDownloadHeaders('myfilename', 'application/octet-stream'))
76+
77 def test_download_bad_revision(self):
78 app = self.setUpLoggerhead()
79 e = self.assertRaises(

Subscribers

People subscribed via source and target branches