lookupkey: Sped up --batch
authorJoey Hess <joeyh@joeyh.name>
Mon, 30 Oct 2023 18:59:09 +0000 (14:59 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 30 Oct 2023 18:59:09 +0000 (14:59 -0400)
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
Command/LookupKey.hs
doc/bugs/__96__lookupkey__96___unexpectedly_slow.mdwn
doc/bugs/__96__lookupkey__96___unexpectedly_slow/comment_1_13003e3b46c5cfab60b6e34fb18731d7._comment [new file with mode: 0644]

index 2aaf0c2023ee83c111d215dedaa50a7a470c1beb..551339a701db5e8cf44239fe22df265cec98dd23 100644 (file)
--- 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 <id@joeyh.name>  Tue, 10 Oct 2023 13:17:31 -0400
 
index 8e5d28b4eb92de172820b809a7f4498e91ab35df..f191aa1e8b1c6193b7c6a4af5111d8c2df60354a 100644 (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
index 154ca9659fde41beb7abc1d6c20e10f56293c754..bac6814d0615e64e6780c55b7be495a04585fed0 100644 (file)
@@ -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 (file)
index 0000000..0fe5dfc
--- /dev/null
@@ -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.
+"""]]