From b13a35055611ef2e62324fd202f90f40c8e7a9ac Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 19 Sep 2019 12:20:35 -0400 Subject: [PATCH] added --unlocked and --locked --- CHANGELOG | 1 + CmdLine/GitAnnex/Options.hs | 10 ++++++++++ Limit.hs | 16 ++++++++++++++++ ...t_2_85d90a43142d087e7b6183dd9f8be8cf._comment | 11 +++++++++++ doc/git-annex-matching-options.mdwn | 8 ++++++++ doc/todo/find_unlocked_files.mdwn | 2 ++ 6 files changed, 48 insertions(+) create mode 100644 doc/forum/Find_unlocked__47__locked_files/comment_2_85d90a43142d087e7b6183dd9f8be8cf._comment diff --git a/CHANGELOG b/CHANGELOG index 90210fb23b..f3ff7ebe44 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ git-annex (7.20190913) UNRELEASED; urgency=medium * Added --mimetype and --mimeencoding file matching options. + * Added --unlocked and --locked file matching options. -- Joey Hess Thu, 19 Sep 2019 11:11:19 -0400 diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs index 799c9832ac..a54031c0c8 100644 --- a/CmdLine/GitAnnex/Options.hs +++ b/CmdLine/GitAnnex/Options.hs @@ -292,6 +292,16 @@ keyMatchingOptions' = <> help "match files by mime encoding" <> hidden ) + , globalFlag Limit.addUnlocked + ( long "unlocked" + <> help "match files that are unlocked" + <> hidden + ) + , globalFlag Limit.addLocked + ( long "locked" + <> help "match files that are locked" + <> hidden + ) ] -- Options to match files which may not yet be annexed. diff --git a/Limit.hs b/Limit.hs index f4ae1ea762..cc381a021a 100644 --- a/Limit.hs +++ b/Limit.hs @@ -129,6 +129,22 @@ matchMagic _limitname querymagic selectprovidedinfo (Just magic) glob = Right $ matchMagic limitname _ _ Nothing _ = Left $ "unable to load magic database; \""++limitname++"\" cannot be used" +addUnlocked :: Annex () +addUnlocked = addLimit $ Right $ const $ matchLockStatus False + +addLocked :: Annex () +addLocked = addLimit $ Right $ const $ matchLockStatus True + +matchLockStatus :: Bool -> MatchInfo -> Annex Bool +matchLockStatus _ (MatchingKey _ _) = pure False +matchLockStatus _ (MatchingInfo _) = pure False +matchLockStatus wantlocked (MatchingFile fi) = liftIO $ do + islocked <- isPointerFile (currFile fi) >>= \case + Just _key -> return False + Nothing -> isSymbolicLink + <$> getSymbolicLinkStatus (currFile fi) + return (islocked == wantlocked) + {- Adds a limit to skip files not believed to be present - in a specfied repository. Optionally on a prior date. -} addIn :: String -> Annex () diff --git a/doc/forum/Find_unlocked__47__locked_files/comment_2_85d90a43142d087e7b6183dd9f8be8cf._comment b/doc/forum/Find_unlocked__47__locked_files/comment_2_85d90a43142d087e7b6183dd9f8be8cf._comment new file mode 100644 index 0000000000..da08f40ad8 --- /dev/null +++ b/doc/forum/Find_unlocked__47__locked_files/comment_2_85d90a43142d087e7b6183dd9f8be8cf._comment @@ -0,0 +1,11 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 2""" + date="2019-09-19T16:14:26Z" + content=""" +`git status` only finds unlocked files that have recently been unlocked but +not committed. (In v5 there were no other kind, but it won't find them all +in v7.) + +I've added a --unlocked option to find them. +"""]] diff --git a/doc/git-annex-matching-options.mdwn b/doc/git-annex-matching-options.mdwn index 87f4aeb893..bc8cad5d93 100644 --- a/doc/git-annex-matching-options.mdwn +++ b/doc/git-annex-matching-options.mdwn @@ -159,6 +159,14 @@ in either of two repositories. If the OS or filesystem does not support access times, this will not match any files. +* `--unlocked` + + Matches annexed files that are unlocked. + +* `--locked` + + Matches annexed files that are locked. + * `--mimetype=glob` Looks up the MIME type of a file, and checks if the glob matches it. diff --git a/doc/todo/find_unlocked_files.mdwn b/doc/todo/find_unlocked_files.mdwn index 0f00804b7a..2ed6b157ba 100644 --- a/doc/todo/find_unlocked_files.mdwn +++ b/doc/todo/find_unlocked_files.mdwn @@ -1 +1,3 @@ As suggested at [[forum/Find_unlocked__47__locked_files]], can the file matching conditions be extended to be able to find unlocked files? + +> sure, [[done]] --[[Joey]]