git-annex/Types/View.hs
Joey Hess aa0350ff49
add directory to views for files that lack specified metadata
* view: New field?=glob and ?tag syntax that includes a directory "_"
  in the view for files that do not have the specified metadata set.
* Added annex.viewunsetdirectory git config to change the name of the
  "_" directory in a view.

When in a view using the new syntax, old git-annex will fail to parse the
view log. It errors with "Not in a view.", which is not ideal. But that
only affects view commands.

annex.viewunsetdirectory is included in the View for a couple of reasons.
One is to avoid needing to warn the user that it should not be changed when
in a view, since that would confuse git-annex. Another reason is that it
helped with plumbing the value through to some pure functions.

annex.viewunsetdirectory is actually mangled the same as any other view
directory. So if it's configured to something like "N/A", there won't be
multiple levels of directories, which would also confuse git-annex.

Sponsored-By: Jack Hill on Patreon
2023-02-07 16:28:46 -04:00

69 lines
1.8 KiB
Haskell

{- types for metadata based branch views
-
- Copyright 2014-2023 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
{-# LANGUAGE OverloadedStrings #-}
module Types.View where
import Types.MetaData
import Utility.QuickCheck
import Utility.Monad
import qualified Git
import qualified Data.Set as S
{- A view is a list of fields with filters on their allowed values,
- which are applied to files in a parent git branch. -}
data View = View
{ viewParentBranch :: Git.Branch
, viewComponents :: [ViewComponent]
}
deriving (Eq, Read, Show)
instance Arbitrary View where
arbitrary = View (Git.Ref "foo")
<$> resize 10 (listOf arbitrary)
data ViewComponent = ViewComponent
{ viewField :: MetaField
, viewFilter :: ViewFilter
, viewVisible :: Bool
}
deriving (Eq, Read, Show)
instance Arbitrary ViewComponent where
arbitrary = ViewComponent <$> arbitrary <*> arbitrary <*> arbitrary
data ViewFilter
= FilterValues (S.Set MetaValue)
| FilterGlob String
| ExcludeValues (S.Set MetaValue)
| FilterValuesOrUnset (S.Set MetaValue) ViewUnset
| FilterGlobOrUnset String ViewUnset
deriving (Eq, Read, Show)
newtype ViewUnset = ViewUnset String
deriving (Eq, Read, Show)
instance Arbitrary ViewFilter where
arbitrary = do
s <- S.fromList <$> resize 10 (listOf arbitrary)
ifM arbitrary
( return (FilterValues s)
, return (ExcludeValues s)
)
mkViewComponent :: MetaField -> ViewFilter -> ViewComponent
mkViewComponent f vf = ViewComponent f vf (multiValue vf)
{- Can a ViewFilter match multiple different MetaValues? -}
multiValue :: ViewFilter -> Bool
multiValue (FilterValues s) = S.size s > 1
multiValue (FilterGlob _) = True
multiValue (ExcludeValues _) = False
multiValue (FilterValuesOrUnset _ _) = True
multiValue (FilterGlobOrUnset _ _) = True