lookupkey: Sped up --batch

When the file is relative, it does not need to be passed
through git lsfiles to normalize it.

Sponsored-by: Kevin Mueller on Patreon
This commit is contained in:
Joey Hess 2023-10-30 14:59:09 -04:00
parent 8a540138b6
commit f8d35d9480
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 27 additions and 8 deletions

View file

@ -50,11 +50,13 @@ display Nothing = return False
-- To support absolute filenames, pass through git ls-files.
-- But, this plumbing command does not recurse through directories.
seekSingleGitFile :: FilePath -> Annex (Maybe RawFilePath)
seekSingleGitFile file = do
(l, cleanup) <- inRepo (Git.LsFiles.inRepo [] [toRawFilePath file])
r <- case l of
(f:[]) | takeFileName (fromRawFilePath f) == takeFileName file ->
return (Just f)
_ -> return Nothing
void $ liftIO cleanup
return r
seekSingleGitFile file
| isRelative file = return (Just (toRawFilePath file))
| otherwise = do
(l, cleanup) <- inRepo (Git.LsFiles.inRepo [] [toRawFilePath file])
r <- case l of
(f:[]) | takeFileName (fromRawFilePath f) == takeFileName file ->
return (Just f)
_ -> return Nothing
void $ liftIO cleanup
return r