]> dgit.raspbian.org Git - git-annex.git/commitdiff
add key to FileInfo
authorJoey Hess <joeyh@joeyh.name>
Mon, 14 Dec 2020 21:42:02 +0000 (17:42 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 14 Dec 2020 21:42:02 +0000 (17:42 -0400)
MatchingKey is not the thing to use when matching on actual worktreee
files.

Fix reversion in 8.20201116 that made include= and exclude= in
preferred/required content expressions match a path relative to the current
directory, rather than the path from the top of the repository.

13 files changed:
Annex/FileMatcher.hs
Annex/Import.hs
CHANGELOG
CmdLine/Batch.hs
CmdLine/Seek.hs
Command/Add.hs
Command/Import.hs
Command/Info.hs
Command/Multicast.hs
Limit.hs
Types/FileMatcher.hs
doc/bugs/drop_claims_that_content_is_required___40__8.20201127__41__.mdwn
doc/bugs/drop_claims_that_content_is_required___40__8.20201127__41__/comment_1_5d7428158cc90704b96a60eeb55efcd0._comment [new file with mode: 0644]

index a2dcd651c3b69a3b1584df063e3f20c887814438..e2128f2ee1a240658a9e18b6999516dfa7615f04 100644 (file)
@@ -72,7 +72,8 @@ checkMatcher :: FileMatcher Annex -> Maybe Key -> AssociatedFile -> AssumeNotPre
 checkMatcher matcher mkey afile notpresent notconfigured d
        | isEmpty matcher = notconfigured
        | otherwise = case (mkey, afile) of
-               (Nothing, AssociatedFile (Just file)) -> go =<< fileMatchInfo file
+               (mkey, AssociatedFile (Just file)) ->
+                       go =<< fileMatchInfo file mkey
                (Just key, _) -> go (MatchingKey key afile)
                _ -> d
   where
@@ -82,12 +83,13 @@ checkMatcher' :: FileMatcher Annex -> MatchInfo -> AssumeNotPresent -> Annex Boo
 checkMatcher' matcher mi notpresent =
        matchMrun matcher $ \o -> matchAction o notpresent mi
 
-fileMatchInfo :: RawFilePath -> Annex MatchInfo
-fileMatchInfo file = do
+fileMatchInfo :: RawFilePath -> Maybe Key -> Annex MatchInfo
+fileMatchInfo file mkey = do
        matchfile <- getTopFilePath <$> inRepo (toTopFilePath file)
        return $ MatchingFile FileInfo
                { matchFile = matchfile
                , contentFile = Just file
+               , matchKey = mkey
                }
 
 matchAll :: FileMatcher Annex
index 9a5eda2968375c389eae66a668b8d36f27d076be..7c59f9a5ec027bf118ec2c7f4c85a1d88aa57f67 100644 (file)
@@ -531,6 +531,7 @@ importKeys remote importtreeconfig importcontent importablecontents = do
                        let mi = MatchingFile FileInfo
                                { matchFile = f
                                , contentFile = Just tmpfile
+                               , matchKey = Nothing
                                }
                        islargefile <- checkMatcher' matcher mi mempty
                        if islargefile
index af80578008d22bb55089b91a2f333e335f5f9360..adf76257acba3f4254db92edbcca3ac2556c91d5 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -17,6 +17,9 @@ git-annex (8.20201128) UNRELEASED; urgency=medium
   * Avoid autoinit when a repo does not have annex.version or annex.uuid
     set, but has a git-annex objects directory, suggesting it was used
     by git-annex before.
+  * Fix reversion in 8.20201116 that made include= and exclude= in
+    preferred/required content expressions match a path relative to the
+    current directory, rather than the path from the top of the repository.
 
  -- Joey Hess <id@joeyh.name>  Mon, 30 Nov 2020 12:55:49 -0400
 
index a9fc349e531df39ea17ab514631aa253e8f3ecde..d2667a819cc7b9ba48a7953f0e305a749fc94220 100644 (file)
@@ -131,7 +131,7 @@ batchFilesMatching fmt a = do
        matcher <- getMatcher
        go $ \si f ->
                let f' = toRawFilePath f
-               in ifM (matcher $ MatchingFile $ FileInfo (Just f') f')
+               in ifM (matcher $ MatchingFile $ FileInfo (Just f') f' Nothing)
                        ( a (si, f')
                        , return Nothing
                        )
index 4a01e023a36d780fbe574f1de9024c81fea62b61..6faea40119f6849b17bd1986934888e2b97bed34 100644 (file)
@@ -115,6 +115,7 @@ withPathContents a params = do
        checkmatch matcher (f, relf) = matcher $ MatchingFile $ FileInfo
                { contentFile = Just f
                , matchFile = relf
+               , matchKey = Nothing
                }
 
 withWords :: ([String] -> CommandSeek) -> CmdParams -> CommandSeek
@@ -287,7 +288,7 @@ seekFiltered prefilter a listfs = do
   where
        process matcher v@(_si, f) =
                whenM (prefilter v) $
-                       whenM (matcher $ MatchingFile $ FileInfo (Just f) f) $
+                       whenM (matcher $ MatchingFile $ FileInfo (Just f) f Nothing) $
                                a v
 
 data MatcherInfo = MatcherInfo
@@ -365,7 +366,7 @@ seekFilteredKeys seeker listfs = do
                -- checked later, to avoid a slow lookup here.
                (not ((matcherNeedsKey mi || matcherNeedsLocationLog mi) 
                        && not (matcherNeedsFileName mi)))
-               (MatchingFile $ FileInfo (Just f) f)
+               (MatchingFile $ FileInfo (Just f) f Nothing)
                (liftIO $ ofeeder ((si, f), sha))
 
        keyaction f mi content a = 
index 614b406e7370db9e46df1d585fd30c7974d8c873..947b878ba8a36338b0199c2fd0cfc7b432d0d0cd 100644 (file)
@@ -184,7 +184,7 @@ start o si file addunlockedmatcher = do
 perform :: AddOptions -> RawFilePath -> AddUnlockedMatcher -> CommandPerform
 perform o file addunlockedmatcher = withOtherTmp $ \tmpdir -> do
        lockingfile <- not <$> addUnlocked addunlockedmatcher
-               (MatchingFile (FileInfo (Just file) file))
+               (MatchingFile (FileInfo (Just file) file Nothing))
        let cfg = LockDownConfig
                { lockingFile = lockingfile
                , hardlinkFileTmpDir = Just tmpdir
index a9ea16740eff6aecee8fb5c2c68696ca9f3c5265..fd788438f418bab896525846c979758b1a90f2e2 100644 (file)
@@ -241,6 +241,7 @@ startLocal o addunlockedmatcher largematcher mode (srcfile, destfile) =
                let mi = MatchingFile $ FileInfo
                        { contentFile = Just srcfile
                        , matchFile = destfile
+                       , matchKey = Nothing
                        }
                lockingfile <- not <$> addUnlocked addunlockedmatcher mi
                -- Minimal lock down with no hard linking so nothing
index dd96c3a45a6706770f3b7ef20817d4e833720469..34801d19c8523964985ea6bc9d960eb0a4d9b19d 100644 (file)
@@ -569,7 +569,7 @@ getDirStatInfo o dir = do
   where
        initial = (emptyKeyInfo, emptyKeyInfo, emptyNumCopiesStats, M.empty)
        update matcher fast key file vs@(presentdata, referenceddata, numcopiesstats, repodata) =
-               ifM (matcher $ MatchingFile $ FileInfo (Just file) file)
+               ifM (matcher $ MatchingFile $ FileInfo (Just file) file (Just key))
                        ( do
                                !presentdata' <- ifM (inAnnex key)
                                        ( return $ addKey key presentdata
index ffd6c332b5b8fb306071e49a861d7985e2666ac2..b2c6093d4f7010deaf4fb1e1fe12501f92c00454 100644 (file)
@@ -135,7 +135,7 @@ send ups fs = do
                        (fs', cleanup) <- seekHelper id ww LsFiles.inRepo
                                =<< workTreeItems ww fs
                        matcher <- Limit.getMatcher
-                       let addlist f o = whenM (matcher $ MatchingFile $ FileInfo (Just f) f) $
+                       let addlist f o = whenM (matcher $ MatchingFile $ FileInfo (Just f) f Nothing) $
                                liftIO $ hPutStrLn h o
                        forM_ fs' $ \(_, f) -> do
                                mk <- lookupKey f
index 843f097574ced4f178a89a2a2c787d617b58ffd9..2e03e86a990968f4a6ba8a7016daf210d91eede6 100644 (file)
--- a/Limit.hs
+++ b/Limit.hs
@@ -535,9 +535,11 @@ addAccessedWithin duration = do
        secs = fromIntegral (durationSeconds duration)
 
 lookupFileKey :: FileInfo -> Annex (Maybe Key)
-lookupFileKey fi = case contentFile fi of
-       Just f -> lookupKey f
-       Nothing -> return Nothing
+lookupFileKey fi = case matchKey fi of
+       Just k -> return (Just k)
+       Nothing -> case contentFile fi of
+               Just f -> lookupKey f
+               Nothing -> return Nothing
 
 checkKey :: (Key -> Annex Bool) -> MatchInfo -> Annex Bool
 checkKey a (MatchingFile fi) = lookupFileKey fi >>= maybe (return False) a
index 70d9e40d7f23d78e3b260717856b4f5a319b969d..3b5adca1def95a4818d5b725ff10b0abc3f9c6b0 100644 (file)
@@ -18,10 +18,13 @@ import Control.Monad.IO.Class
 import qualified Data.Map as M
 import qualified Data.Set as S
 
--- Information about a file or a key that can be matched on.
+-- Information about a file and/or a key that can be matched on.
 data MatchInfo
        = MatchingFile FileInfo
        | MatchingKey Key AssociatedFile
+       -- ^ This is used when operating on a file that may be in another
+       -- branch. The AssociatedFile is the filename, but it should not be
+       -- accessed from disk when matching.
        | MatchingInfo ProvidedInfo
        | MatchingUserInfo UserProvidedInfo
 
@@ -33,6 +36,8 @@ data FileInfo = FileInfo
        -- ^ filepath to match on; may be relative to top of repo or cwd,
        -- depending on how globs in preferred content expressions
        -- are intended to be matched
+       , matchKey :: Maybe Key
+       -- ^ provided if a key is already known
        }
 
 data ProvidedInfo = ProvidedInfo
index 571fa5cf9141263c3f2929a1f2456c89d4651692..7255a3e2540a485f5170be02ca8a04dc2fac2beb 100644 (file)
@@ -194,3 +194,5 @@ Yes, so far it has worked nicely archiving (and describing via git-annex metadat
 orderly fashion.
 
 [[!meta author=jkniiv]]
+
+> [[fixed|done]] --[[Joey]]
diff --git a/doc/bugs/drop_claims_that_content_is_required___40__8.20201127__41__/comment_1_5d7428158cc90704b96a60eeb55efcd0._comment b/doc/bugs/drop_claims_that_content_is_required___40__8.20201127__41__/comment_1_5d7428158cc90704b96a60eeb55efcd0._comment
new file mode 100644 (file)
index 0000000..6bc441c
--- /dev/null
@@ -0,0 +1,18 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 1"""
+ date="2020-12-14T19:36:20Z"
+ content="""
+Looks like it was caused by [[!commit d032b0885d80d12c00fa8813e88deab1631eef8a]] which made MatchingKey be used
+rather than MatchingFile. Which oops, mean the filename is left relative rather
+than being made into a path from the top of the repo.
+
+Fixed that and your test case works. I do think this would be a better
+expression for you to use though:
+
+       (include=*.mrimg and exclude=*/arkistoidut/* and exclude=arkistoidut/*)
+
+Or maybe just exclude=arkistoidut/* rather than both, depending on if you
+want to support subdirectories of subdirectories with that name, or only
+the single subdirectory in the top of your repo.
+"""]]