16
16
# You should have received a copy of the GNU General Public License
17
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
# Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
25
from paste.httpexceptions import HTTPNotFound
25
from paste.httpexceptions import HTTPNotFound, HTTPMovedPermanently
27
from bzrlib import errors
28
from bzrlib.revision import is_null as is_null_rev
27
from breezy import errors
28
from breezy.revision import is_null as is_null_rev
30
30
from loggerhead import util
31
31
from loggerhead.controllers import TemplatedBranchView
34
log = logging.getLogger("loggerhead.controllers")
38
36
if path is not None:
39
37
path = path.rstrip('/')
40
path = urllib.quote(posixpath.dirname(path))
38
path = urllib.quote(posixpath.dirname(path).encode('utf-8'))
44
42
class InventoryUI(TemplatedBranchView):
46
44
template_path = 'loggerhead.templates.inventory'
48
def get_filelist(self, inv, path, sort_type):
47
def get_filelist(self, tree, path, sort_type, revno_url):
50
49
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.
53
@param path: The path of a directory within the tree.
55
54
@param sort_type: How to sort the results... XXX.
57
file_id = inv.path2id(path)
58
if tree.kind(path) != 'directory':
59
raise HTTPMovedPermanently(self._branch.context_url(['/view', revno_url, path]))
63
for filename, entry in dir_ie.children.iteritems():
63
child_entries = list(tree.iter_child_entries(path))
65
for entry in child_entries:
64
66
revid_set.add(entry.revision)
67
69
for change in self._history.get_changes(list(revid_set)):
68
70
change_dict[change.revid] = change
70
for filename, entry in dir_ie.children.iteritems():
72
for entry in child_entries:
72
74
if entry.kind == 'directory':
77
79
absolutepath = path + '/' + pathname
78
80
revid = entry.revision
82
# TODO: For the JSON rendering, this inlines the "change" aka
83
# revision information attached to each file. Consider either
84
# pulling this out as a separate changes dict, or possibly just
85
# including the revision id and having a separate request to get
86
# back the revision info.
80
87
file = util.Container(
81
filename=filename, executable=entry.executable,
88
filename=entry.name, executable=entry.executable,
82
89
kind=entry.kind, absolutepath=absolutepath,
83
90
file_id=entry.file_id, size=entry.text_size, revid=revid,
84
91
change=change_dict[revid])
133
137
updir = dirname(path)
135
# Directory Breadcrumbs
136
directory_breadcrumbs = util.directory_breadcrumbs(
137
self._branch.friendly_name,
138
self._branch.is_root,
141
139
if not is_null_rev(revid):
143
140
change = history.get_changes([ revid ])[0]
144
141
# If we're looking at the tip, use head: in the URL instead
145
142
if revid == branch.last_revision():
148
145
revno_url = history.get_revno(revid)
149
146
history.add_branch_nicks(change)
147
filelist = self.get_filelist(rev_tree, path, sort_type, revno_url)
151
# Create breadcrumb trail for the path within the branch
152
branch_breadcrumbs = util.branch_breadcrumbs(path, rev_tree, 'files')
153
filelist = self.get_filelist(rev_tree.inventory, path, sort_type)
155
150
start_revid = None
159
154
revno_url = 'head:'
160
branch_breadcrumbs = []
164
'branch': self._branch,
167
159
'revno_url': revno_url,
168
160
'change': change,
171
163
'filelist': filelist,
172
'navigation': navigation,
173
'url': self._branch.context_url,
174
164
'start_revid': start_revid,
167
def add_template_values(self, values):
168
super(InventoryUI, self).add_template_values(values)
169
# Directory Breadcrumbs
170
directory_breadcrumbs = util.directory_breadcrumbs(
171
self._branch.friendly_name,
172
self._branch.is_root,
175
path = values['path']
176
revid = values['revid']
177
# no navbar for revisions
178
navigation = util.Container()
180
if is_null_rev(revid):
181
branch_breadcrumbs = []
183
# Create breadcrumb trail for the path within the branch
184
branch = self._history._branch
185
rev_tree = branch.repository.revision_tree(revid)
186
branch_breadcrumbs = util.branch_breadcrumbs(path, rev_tree, 'files')
175
188
'fileview_active': True,
176
189
'directory_breadcrumbs': directory_breadcrumbs,
177
190
'branch_breadcrumbs': branch_breadcrumbs,
191
'navigation': navigation,