Don't deduce type from trailing slash
Instead of using a trailing slash in the path to tell trees from blobs, we actually ask git the type of the object. Also, if the object is a tree but lacks a trailing slash, we redirect to the correct URL. Fixes #6
This commit is contained in:
parent
832f7c8b6d
commit
80e113ab99
3 changed files with 25 additions and 7 deletions
22
http/web.py
22
http/web.py
|
|
@ -137,14 +137,18 @@ if mode == 'source':
|
|||
|
||||
lines = ['null - -']
|
||||
|
||||
if path[-1:] == '/' or path == '':
|
||||
type = 'tree'
|
||||
lines += shell_exec ('cd ..; ./query.py dir '+version+' \''+path+'\'')
|
||||
type = shell_exec ('cd ..; ./query.py type '+version+' \''+path+'\'')
|
||||
if len (type) == 1:
|
||||
type = type[0]
|
||||
if type == 'tree':
|
||||
if path[-1:] == '/' or path == '':
|
||||
lines += shell_exec ('cd ..; ./query.py dir '+version+' \''+path+'\'')
|
||||
else:
|
||||
status = 302
|
||||
location = '/source/'+path+'/?v='+version
|
||||
elif type == 'blob':
|
||||
lines += shell_exec ('cd ..; ./query.py file '+version+' \''+path+'\'')
|
||||
else:
|
||||
type = 'blob'
|
||||
lines += shell_exec ('cd ..; ./query.py file '+version+' \''+path+'\'')
|
||||
|
||||
if len (lines) == 1:
|
||||
print ('<br><b>This file does not exist.</b>')
|
||||
status = 404
|
||||
|
||||
|
|
@ -281,6 +285,10 @@ print (open ('template-tail').read(), end='')
|
|||
|
||||
if status == 404:
|
||||
realprint ('Status: 404 Not Found')
|
||||
elif status == 302:
|
||||
realprint ('Status: 302 Found')
|
||||
realprint ('Location: '+location+'\n')
|
||||
exit()
|
||||
|
||||
realprint ('Content-Type: text/html;charset=utf-8\n')
|
||||
realprint (outputBuffer, end='')
|
||||
|
|
|
|||
6
query.py
6
query.py
|
|
@ -39,6 +39,12 @@ if cmd == 'versions':
|
|||
if db.vers.exists (p):
|
||||
echo (p + b'\n')
|
||||
|
||||
elif cmd == 'type':
|
||||
version = argv[2]
|
||||
path = argv[3]
|
||||
p = script ('get-type', version, path)
|
||||
echo (p)
|
||||
|
||||
elif cmd == 'dir':
|
||||
version = argv[2]
|
||||
path = argv[3]
|
||||
|
|
|
|||
|
|
@ -39,6 +39,10 @@ case $cmd in
|
|||
sed 's/\.0$//'
|
||||
;;
|
||||
|
||||
get-type)
|
||||
git cat-file -t v$1:$2 2>/dev/null
|
||||
;;
|
||||
|
||||
get-blob)
|
||||
git cat-file blob $1
|
||||
;;
|
||||
|
|
|
|||
Loading…
Reference in a new issue