@@ -126,12 +126,9 @@ def read_ls_tree_line(gitTreeLine, files, symlinkFilenames, symlinkObjects):
126126 )
127127
128128
129- def compute_rmet (key , legacy = False ):
129+ def compute_rmet (key ):
130130 if len (key ) == 40 :
131- if legacy :
132- key = f'SHA1--{ key } '
133- else :
134- key = f'GIT--{ key } '
131+ key = f'GIT--{ key } '
135132 keyHash = hashlib .md5 (key .encode ()).hexdigest ()
136133 return f'{ keyHash [0 :3 ]} /{ keyHash [3 :6 ]} /{ key } .log.rmet'
137134
@@ -192,21 +189,30 @@ def encode_remote_url(url):
192189async def get_repo_urls (path , files ):
193190 """For each file provided, obtain the rmet data and append URLs if possible."""
194191 # First obtain the git-annex branch objects
195- gitAnnexBranch = await asyncio .create_subprocess_exec (
192+ rmet_queries = set (['remote.log' , 'trust.log' ])
193+ for f in files :
194+ if 'key' in f :
195+ rmet_queries .add (compute_rmet (f ['key' ]))
196+
197+ query_list = list (rmet_queries )
198+ batch_input = '\n ' .join (f'git-annex:{ p } ' for p in query_list )
199+
200+ process = await asyncio .create_subprocess_exec (
196201 'git' ,
197- 'ls-tree' ,
198- '-l' ,
199- 'git-annex' ,
202+ 'cat-file' ,
203+ '--batch-check' ,
200204 cwd = path ,
205+ stdin = asyncio .subprocess .PIPE ,
201206 stdout = asyncio .subprocess .PIPE ,
202207 )
208+ stdout , _ = await process .communicate (input = batch_input .encode ('utf-8' ))
209+
203210 rmetObjects = {}
204- async for line in gitAnnexBranch .stdout :
205- filename , mode , obj_type , obj_hash , size = parse_ls_tree_line (
206- line .decode ('utf-8' ).rstrip ()
207- )
208- rmetObjects [filename ] = obj_hash
209- await gitAnnexBranch .wait ()
211+ for i , line in enumerate (stdout .decode ('utf-8' ).splitlines ()):
212+ parts = line .split ()
213+ if parts [- 1 ] == 'missing' :
214+ continue
215+ rmetObjects [query_list [i ]] = parts [0 ]
210216
211217 if 'remote.log' not in rmetObjects :
212218 # Skip searching for URLs if no remote.log is present
@@ -218,11 +224,6 @@ async def get_repo_urls(path, files):
218224 if rmetPath in rmetObjects :
219225 # Keep a reference to the files so we can add URLs later
220226 rmetFiles [rmetPath ].append (f )
221- else :
222- # Check for alternate path used by older versions of git-annex
223- rmetPath = compute_rmet (f ['key' ], legacy = True )
224- if rmetPath in rmetObjects :
225- rmetFiles [rmetPath ].append (f )
226227 # Then read those objects with git cat-file --batch
227228 gitObjects = ''
228229 if 'trust.log' in rmetObjects :
0 commit comments