Merge lp:~a1s/loggerhead/non-branch-directories into lp:loggerhead

Proposed by Aleksandr Smyshliaev
Status: Merged
Approved by: Colin Watson
Approved revision: 543
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: lp:~a1s/loggerhead/non-branch-directories
Merge into: lp:loggerhead
Diff against target: 46 lines (+11/-4)
2 files modified
loggerhead/controllers/directory_ui.py (+10/-3)
loggerhead/templates/directory.pt (+1/-1)
To merge this branch: bzr merge lp:~a1s/loggerhead/non-branch-directories
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+432550@code.launchpad.net

Commit message

Fix displaying non-branch directories

Description of the change

I've changed the directory template to handle the timestamp for non-branch directories in the same way as it is done for the branch directories, and initialized all DirEntry attributes for non-branches. The last change time is taken from the DirectoryUI transport.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

Thanks for this!

I confess I didn't completely follow the bug report, though I think I see what you mean by looking at the template. Do you have an example of a page that crashes at the moment, or some other way to reproduce the crash? (This would be helpful because we could use it to QA your fix.)

This needs a small fix, but otherwise looks good to me.

review: Needs Fixing
Revision history for this message
Aleksandr Smyshliaev (a1s) wrote :

I get this error by accessing the loggerhead index page because my root directory contains some shared repositories as well as simple branches. But any directory with non-branch sub-directories also triggers this error. For example, home directory or /usr.

Revision history for this message
Colin Watson (cjwatson) :
543. By Aleksandr Smyshliaev

Avoid bare `except:`

Revision history for this message
Aleksandr Smyshliaev (a1s) :
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/directory_ui.py'
2--- loggerhead/controllers/directory_ui.py 2022-08-29 16:33:16 +0000
3+++ loggerhead/controllers/directory_ui.py 2022-11-22 05:45:16 +0000
4@@ -33,11 +33,18 @@
5
6 class DirEntry(object):
7
8- def __init__(self, dirname, parity, branch):
9+ def __init__(self, dirname, parity, branch, transport):
10 self.dirname = urlutils.unquote(dirname)
11 self.parity = parity
12 self.branch = branch
13- if branch is not None:
14+ if branch is None:
15+ self.last_revision = None
16+ try:
17+ self.last_change_time = datetime.datetime.utcfromtimestamp(
18+ transport.stat(self.dirname).st_mtime)
19+ except Exception:
20+ self.last_change_time = None
21+ else:
22 # If a branch is empty, bzr raises an exception when trying this
23 try:
24 self.last_revision = branch.repository.get_revision(branch.last_revision())
25@@ -88,7 +95,7 @@
26 else:
27 if not b.get_config().get_user_option_as_bool('http_serve', default=True):
28 continue
29- dirs.append(DirEntry(d, parity, b))
30+ dirs.append(DirEntry(d, parity, b, self.transport))
31 parity = 1 - parity
32 # Create breadcrumb trail
33 directory_breadcrumbs = util.directory_breadcrumbs(
34
35=== modified file 'loggerhead/templates/directory.pt'
36--- loggerhead/templates/directory.pt 2022-08-23 13:55:18 +0000
37+++ loggerhead/templates/directory.pt 2022-11-22 05:45:16 +0000
38@@ -63,7 +63,7 @@
39 </a>
40 <a tal:attributes="href string:${dir.dirname}/" tal:content="dir.dirname" /></td>
41 <td class="date"></td>
42- <td class="date" colspan="4" tal:content="dir.last_change"></td>
43+ <td class="date" colspan="4" tal:content="python:util._approximatedate(dir.last_change_time)"></td>
44 </tr>
45 </tal:non-branch-row>
46 </tal:block>

Subscribers

People subscribed via source and target branches