Silence Git and treat empty responses as errors
This commit is contained in:
parent
bab7dce487
commit
6cae0dd8c3
2 changed files with 22 additions and 6 deletions
22
http/web.py
22
http/web.py
|
|
@ -18,6 +18,13 @@ def shell_exec (cmd):
|
|||
del a[-1]
|
||||
return a
|
||||
|
||||
realprint = print
|
||||
outputBuffer = ''
|
||||
|
||||
def print (arg, end='\n'):
|
||||
global outputBuffer
|
||||
outputBuffer += arg + end;
|
||||
|
||||
# enable debugging
|
||||
import cgitb
|
||||
cgitb.enable()
|
||||
|
|
@ -27,7 +34,7 @@ import os
|
|||
from re import search, sub
|
||||
from collections import OrderedDict
|
||||
|
||||
print ('Content-Type: text/html;charset=utf-8\n')
|
||||
status = 200
|
||||
|
||||
form = cgi.FieldStorage()
|
||||
version = form.getvalue ('v')
|
||||
|
|
@ -119,6 +126,9 @@ if mode == 'source':
|
|||
type = 'blob'
|
||||
lines += shell_exec ('cd ..; ./query.py file '+version+' \''+path+'\'')
|
||||
|
||||
if len (lines) == 1:
|
||||
status = 404
|
||||
|
||||
if type == 'tree':
|
||||
if path != '':
|
||||
lines[0] = 'back - -'
|
||||
|
|
@ -189,7 +199,7 @@ elif mode == 'ident':
|
|||
if m:
|
||||
num = int (m.group(1))
|
||||
|
||||
print ('Defined in', num, 'files:')
|
||||
print ('Defined in'+str(num)+'files:')
|
||||
print ('<ul>')
|
||||
for i in range (0, num):
|
||||
l = next (lines)
|
||||
|
|
@ -203,7 +213,7 @@ elif mode == 'ident':
|
|||
m = search ('Referenced in (\d*) file', next (lines))
|
||||
num = int (m.group(1))
|
||||
|
||||
print ('Referenced in', num, 'files:')
|
||||
print ('Referenced in'+str(num)+'files:')
|
||||
print ('<ul>')
|
||||
for i in range (0, num):
|
||||
l = next (lines)
|
||||
|
|
@ -227,6 +237,7 @@ elif mode == 'ident':
|
|||
else:
|
||||
if ident != '':
|
||||
print ('Not used')
|
||||
status = 404
|
||||
|
||||
elif mode == 'search':
|
||||
head = sub ('\$banner', '', head)
|
||||
|
|
@ -241,3 +252,8 @@ else:
|
|||
|
||||
print (open ('template-tail').read(), end='')
|
||||
|
||||
if status == 404:
|
||||
realprint ('Status: 404 Not Found')
|
||||
|
||||
realprint ('Content-Type: text/html;charset=utf-8\n')
|
||||
realprint (outputBuffer, end='')
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@ case $cmd in
|
|||
;;
|
||||
|
||||
get-file)
|
||||
git cat-file blob v$1:$2
|
||||
git cat-file blob v$1:$2 2>/dev/null
|
||||
;;
|
||||
|
||||
get-dir)
|
||||
git ls-tree -l "v$1:$2" |
|
||||
git ls-tree -l "v$1:$2" 2>/dev/null |
|
||||
awk '{print $2" "$5" "$4}' |
|
||||
grep -v ' \.' |
|
||||
sort -t ' ' -k 1,1r -k 2,2
|
||||
|
|
@ -58,7 +58,7 @@ case $cmd in
|
|||
ref=v$1:$2
|
||||
fi
|
||||
|
||||
git cat-file blob $ref |
|
||||
git cat-file blob $ref 2>/dev/null |
|
||||
tr '\n<>' '\1\2\3' |
|
||||
sed 's/\/\*/</g' |
|
||||
sed 's/\*\//>/g' |
|
||||
|
|
|
|||
Loading…
Reference in a new issue