40
46
template_path = 'loggerhead.templates.inventory'
42
def get_values(self, h, args, kw, headers):
44
revid = h.fix_revid(args[0])
48
def get_filelist(self, inv, path, sort_type, revno_url):
50
return the list of all files (and their attributes) within a given
53
@param inv: The inventory.
54
@param path: The path of a directory within the inventory.
55
@param sort_type: How to sort the results... XXX.
57
file_id = inv.path2id(path)
61
if dir_ie.kind != 'directory':
62
raise HTTPMovedPermanently(self._branch.context_url(['/view', revno_url, path]))
66
for filename, entry in dir_ie.children.iteritems():
67
revid_set.add(entry.revision)
70
for change in self._history.get_changes(list(revid_set)):
71
change_dict[change.revid] = change
73
for filename, entry in dir_ie.children.iteritems():
75
if entry.kind == 'directory':
78
absolutepath = pathname
80
absolutepath = path + '/' + pathname
81
revid = entry.revision
83
file = util.Container(
84
filename=filename, executable=entry.executable,
85
kind=entry.kind, absolutepath=absolutepath,
86
file_id=entry.file_id, size=entry.text_size, revid=revid,
87
change=change_dict[revid])
88
file_list.append(file)
90
if sort_type == 'filename':
91
file_list.sort(key=lambda x: x.filename.lower()) # case-insensitive
92
elif sort_type == 'size':
93
file_list.sort(key=lambda x: x.size)
94
elif sort_type == 'date':
95
file_list.sort(key=lambda x: x.change.date)
97
# Always sort directories first.
98
file_list.sort(key=lambda x: x.kind != 'directory')
102
def get_values(self, path, kwargs, headers):
103
history = self._history
104
branch = history._branch
49
inv = h.get_inventory(revid)
51
self.log.exception('Exception fetching changes')
52
raise HTTPServerError('Could not fetch changes')
106
revid = self.get_revid()
107
rev_tree = branch.repository.revision_tree(revid)
108
except errors.NoSuchRevision:
54
file_id = kw.get('file_id', inv.root.file_id)
55
start_revid = kw.get('start_revid', None)
56
sort_type = kw.get('sort', None)
111
file_id = kwargs.get('file_id', None)
112
start_revid = kwargs.get('start_revid', None)
113
sort_type = kwargs.get('sort', 'filename')
58
115
# no navbar for revisions
59
116
navigation = util.Container()
61
change = h.get_changes([ revid ])[0]
62
# add parent & merge-point branch-nick info, in case it's useful
63
h.get_branch_nicks([ change ])
119
path = path.rstrip('/')
120
file_id = rev_tree.path2id(path)
128
path = rev_tree.id2path(file_id)
129
except errors.NoSuchId:
65
path = inv.id2path(file_id)
66
if not path.startswith('/'):
68
idpath = inv.get_idpath(file_id)
132
# Are we at the top of the tree
133
if path in ['/', '']:
70
136
updir = dirname(path)
71
updir_file_id = idpath[-2]
138
# Directory Breadcrumbs
139
directory_breadcrumbs = util.directory_breadcrumbs(
140
self._branch.friendly_name,
141
self._branch.is_root,
144
if not is_null_rev(revid):
146
change = history.get_changes([ revid ])[0]
147
# If we're looking at the tip, use head: in the URL instead
148
if revid == branch.last_revision():
151
revno_url = history.get_revno(revid)
152
history.add_branch_nicks(change)
154
# Create breadcrumb trail for the path within the branch
155
branch_breadcrumbs = util.branch_breadcrumbs(path, rev_tree, 'files')
156
filelist = self.get_filelist(rev_tree.inventory, path, sort_type, revno_url)
163
branch_breadcrumbs = []
79
167
'branch': self._branch,
170
'revno_url': revno_url,
86
'updir_file_id': updir_file_id,
87
'filelist': h.get_filelist(inv, file_id, sort_type),
89
'posixpath': posixpath,
174
'filelist': filelist,
90
175
'navigation': navigation,
91
176
'url': self._branch.context_url,
92
177
'start_revid': start_revid,
93
178
'fileview_active': True,
179
'directory_breadcrumbs': directory_breadcrumbs,
180
'branch_breadcrumbs': branch_breadcrumbs,