From f8d35d9480e121c929d542c2462fb4886d04cae1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 30 Oct 2023 14:59:09 -0400 Subject: [PATCH] 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 --- CHANGELOG | 1 + Command/LookupKey.hs | 18 ++++++++++-------- ..._96__lookupkey__96___unexpectedly_slow.mdwn | 2 ++ ...1_13003e3b46c5cfab60b6e34fb18731d7._comment | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 doc/bugs/__96__lookupkey__96___unexpectedly_slow/comment_1_13003e3b46c5cfab60b6e34fb18731d7._comment diff --git a/CHANGELOG b/CHANGELOG index 2aaf0c2023..551339a701 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,7 @@ git-annex (10.20230927) UNRELEASED; urgency=medium the behavior of git on Windows, which does not end lines with CR either. * Windows: Fix CRLF handling in some log files. + * lookupkey: Sped up --batch. -- Joey Hess Tue, 10 Oct 2023 13:17:31 -0400 diff --git a/Command/LookupKey.hs b/Command/LookupKey.hs index 8e5d28b4eb..f191aa1e8b 100644 --- a/Command/LookupKey.hs +++ b/Command/LookupKey.hs @@ -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 diff --git a/doc/bugs/__96__lookupkey__96___unexpectedly_slow.mdwn b/doc/bugs/__96__lookupkey__96___unexpectedly_slow.mdwn index 154ca9659f..bac6814d06 100644 --- a/doc/bugs/__96__lookupkey__96___unexpectedly_slow.mdwn +++ b/doc/bugs/__96__lookupkey__96___unexpectedly_slow.mdwn @@ -21,3 +21,5 @@ This surprised me, hence I am reporting it here as a potential bug. ### What version of git-annex are you using? On what operating system? git-annex version: 10.20230126 + +> [[fixed|done]] --[[Joey]] diff --git a/doc/bugs/__96__lookupkey__96___unexpectedly_slow/comment_1_13003e3b46c5cfab60b6e34fb18731d7._comment b/doc/bugs/__96__lookupkey__96___unexpectedly_slow/comment_1_13003e3b46c5cfab60b6e34fb18731d7._comment new file mode 100644 index 0000000000..0fe5dfc5c7 --- /dev/null +++ b/doc/bugs/__96__lookupkey__96___unexpectedly_slow/comment_1_13003e3b46c5cfab60b6e34fb18731d7._comment @@ -0,0 +1,14 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 1""" + date="2023-10-30T18:51:11Z" + content=""" +This is due to lookupkey passing each filename through `git ls-files` +in order to support absolute filepaths input. See +[[!commit cfdfe4df6c8b3fe46bbc7afcc8274237a5b2ce2a]] + +Made it only do that for absolute paths, which should make it at least +marginally faster than git-annex find. I would not expect it to be much +faster though, because git-annex find displaying a little more information +takes negligible CPU time really. +"""]]