Directory and file queries
This commit is contained in:
parent
10b9e273e7
commit
cf0e1bd666
3 changed files with 46 additions and 9 deletions
18
lib.py
18
lib.py
|
|
@ -10,7 +10,21 @@ def script (*args):
|
|||
p = p.stdout
|
||||
return p
|
||||
|
||||
def script_lines (*args):
|
||||
p = script (args)
|
||||
def scriptLines (*args):
|
||||
p = script (*args)
|
||||
p = p.split (b'\n')
|
||||
del p[-1]
|
||||
return p
|
||||
|
||||
def unescape (bstr):
|
||||
subs = (
|
||||
('<','/*'),
|
||||
('>','*/'),
|
||||
('\1','\n'),
|
||||
('\2','<'),
|
||||
('\3','>'))
|
||||
for a,b in subs:
|
||||
a = a.encode()
|
||||
b = b.encode()
|
||||
bstr = bstr.replace (a, b)
|
||||
return bstr
|
||||
|
|
|
|||
20
query.py
20
query.py
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from sys import argv
|
||||
from lib import echo, script
|
||||
from lib import echo, script, scriptLines, unescape
|
||||
|
||||
cmd = argv[1]
|
||||
|
||||
|
|
@ -15,11 +15,25 @@ elif cmd == 'dir':
|
|||
p = script ('get-dir', version, path)
|
||||
echo (p)
|
||||
|
||||
elif cmd == 'source':
|
||||
elif cmd == 'file':
|
||||
version = argv[2]
|
||||
path = argv[3]
|
||||
ext = path[-2:]
|
||||
|
||||
pass
|
||||
if ext == '.c' or ext == '.h':
|
||||
tokens = scriptLines ('tokenize-file', version, path)
|
||||
del tokens[-1]
|
||||
toBe = True
|
||||
for tok in tokens:
|
||||
toBe = not toBe
|
||||
if toBe:
|
||||
tok = b'\033[31m' + tok + b'\033[0m'
|
||||
else:
|
||||
tok = unescape (tok)
|
||||
echo (tok)
|
||||
else:
|
||||
p = script ('get-file', version, path)
|
||||
echo (p)
|
||||
|
||||
elif cmd == 'ident':
|
||||
version = argv[2]
|
||||
|
|
|
|||
17
script.sh
17
script.sh
|
|
@ -3,7 +3,7 @@
|
|||
# FIXME: hardcoded path
|
||||
cd /srv/git/linux
|
||||
|
||||
test $# -gt 0 || set invalid
|
||||
test $# -gt 0 || set help
|
||||
|
||||
cmd=$1
|
||||
shift
|
||||
|
|
@ -20,6 +20,10 @@ case $cmd in
|
|||
git cat-file blob $1
|
||||
;;
|
||||
|
||||
get-file)
|
||||
git cat-file blob v$1:$2
|
||||
;;
|
||||
|
||||
get-dir)
|
||||
git ls-tree -l "v$1:$2" |
|
||||
awk '{print $2" "$5" "$4}' |
|
||||
|
|
@ -42,8 +46,8 @@ case $cmd in
|
|||
sed -r "s/^\S* blob (\S*)\t(([^/]*\/)*(.*))$/$format/"
|
||||
;;
|
||||
|
||||
tokenize-blob)
|
||||
git cat-file blob $1 |
|
||||
tokenize-file)
|
||||
git cat-file blob v$1:$2 |
|
||||
tr '\n<>' '\1\2\3' |
|
||||
sed 's/\/\*/</g' |
|
||||
sed 's/\*\//>/g' |
|
||||
|
|
@ -65,7 +69,12 @@ case $cmd in
|
|||
rmdir $tmp
|
||||
;;
|
||||
|
||||
help)
|
||||
echo "Usage: $0 subcommand [args]..."
|
||||
exit 1
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Usage: $0 [list-tags | get-blob | get-dir | list-blobs | tokenize-blob | parse-defs]"
|
||||
echo "$0: Unknown subcommand: $cmd"
|
||||
exit 1
|
||||
esac
|
||||
|
|
|
|||
Loading…
Reference in a new issue