16 lines
2.0 KiB
Plaintext
16 lines
2.0 KiB
Plaintext
def fetch(spec):
|
|
key,repo,rev,files=spec;cache=R/('.local-evidence/anima-'+key+'-git');subprocess.run(['git','init','--bare',str(cache)],check=True,capture_output=True)
|
|
def git(*args):return subprocess.check_output(['git','-C',str(cache),*args],timeout=80)
|
|
p=subprocess.run(['git','-C',str(cache),'fetch','--filter=blob:none','--depth=1','https://github.com/'+repo+'.git',rev],capture_output=True,timeout=100);(REF/(key+'-fetch.txt')).write_bytes(p.stdout+p.stderr);assert p.returncode==0,p.stderr
|
|
commit=git('rev-parse','FETCH_HEAD^{commit}').decode().strip();obj=git('rev-parse','FETCH_HEAD').decode().strip();tree=git('rev-parse',commit+'^{tree}').decode().strip();cb=git('cat-file','commit',commit);tb=git('cat-file','tag' if obj!=commit else 'commit',obj);(REF/(key+'-commit.txt')).write_bytes(cb);(REF/(key+'-tag.txt')).write_bytes(tb);(REF/(key+'-tag.json')).write_text(json.dumps(dict(object=obj,commit=commit,tag=rev),indent=2)+'\n')
|
|
entries=[]
|
|
for line in git('ls-tree','-r',commit).decode().splitlines():
|
|
meta,path=line.split('\t');mode,typ,sha=meta.split();entries.append(dict(path=path,mode=mode,type=typ,sha=sha))
|
|
(REF/(key+'-tree.json')).write_text(json.dumps(dict(sha=tree,truncated=False,tree=entries),indent=2)+'\n');result=[]
|
|
for f in files:
|
|
ent=next((x for x in entries if x['path']==f),None)
|
|
if not ent:print('MISSING',key,f,flush=True);continue
|
|
raw=git('show',commit+':'+f);assert len(raw)<3000000;name=key+'__'+f.replace('/','__');(REF/name).write_bytes(raw)
|
|
result.append(dict(id=key,repo=repo,file=f,local_file=name,commit=commit,tree=tree,tag=rev,url=f'https://raw.githubusercontent.com/{repo}/{commit}/{f}',sha256=hashlib.sha256(raw).hexdigest(),git_blob_sha1=ent['sha'],acquisition_time=now,reverified_at=now,license_file=key+'__LICENSE',identity_root='.',identity_key=key,transport='filtered Git necessary text only',applicability='本图独立准确版本静态核准,不执行或认证安装/恢复'))
|
|
print('FETCH',key,commit,len(result),flush=True);return result
|