2014-02-18 21:38:23 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
|
|
|
- Copyright 2014 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.View where
|
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import Command
|
|
|
|
import qualified Git
|
|
|
|
import qualified Git.Command
|
|
|
|
import qualified Git.Ref
|
|
|
|
import qualified Git.Branch
|
|
|
|
import Types.MetaData
|
|
|
|
import Types.View
|
|
|
|
import Annex.View
|
|
|
|
import Logs.View
|
|
|
|
|
|
|
|
def :: [Command]
|
|
|
|
def = [notBareRepo $ notDirect $
|
2014-02-19 18:55:34 +00:00
|
|
|
command "view" paramView seek SectionMetaData "enter a view branch"]
|
2014-02-18 21:38:23 +00:00
|
|
|
|
|
|
|
seek :: CommandSeek
|
|
|
|
seek = withWords start
|
|
|
|
|
|
|
|
start :: [String] -> CommandStart
|
|
|
|
start [] = error "Specify metadata to include in view"
|
|
|
|
start params = do
|
|
|
|
showStart "view" ""
|
|
|
|
view <- mkView params
|
|
|
|
go view =<< currentView
|
|
|
|
where
|
|
|
|
go view Nothing = next $ perform view
|
|
|
|
go view (Just v)
|
|
|
|
| v == view = stop
|
|
|
|
| otherwise = error "Already in a view. Use 'git annex vadd' to further refine this view."
|
|
|
|
|
|
|
|
perform :: View -> CommandPerform
|
|
|
|
perform view = do
|
2014-02-19 00:01:56 +00:00
|
|
|
showSideAction "searching"
|
2014-02-19 00:57:14 +00:00
|
|
|
next $ checkoutViewBranch view applyView
|
2014-02-18 21:38:23 +00:00
|
|
|
|
|
|
|
paramView :: String
|
|
|
|
paramView = paramPair (paramRepeating "FIELD=VALUE") (paramRepeating "TAG")
|
|
|
|
|
|
|
|
parseViewParam :: String -> (MetaField, String)
|
|
|
|
parseViewParam s = case separate (== '=') s of
|
|
|
|
(tag, []) -> (tagMetaField, tag)
|
|
|
|
(field, wanted) -> either error (\f -> (f, wanted)) (mkMetaField field)
|
|
|
|
|
|
|
|
mkView :: [String] -> Annex View
|
|
|
|
mkView params = do
|
|
|
|
v <- View <$> viewbranch <*> pure []
|
add tip about metadata driven views (and more flexible view filtering)
While writing this documentation, I realized that there needed to be a way
to stay in a view like tag=* while adding a filter like tag=work that
applies to the same field.
So, there are really two ways a view can be refined. It can have a new
"field=explicitvalue" filter added to it, which does not change the
"shape" of the view, but narrows the files it shows.
Or, it can have a new view added, which adds another level of
subdirectories.
So, added a vfilter command, which takes explicit values to add to the
filter, and rejects changes that would change the shape of the view.
And, made vadd only accept changes that change the shape of the view.
And, changed the View data type slightly; now components that can match
multiple metadata values can be visible, or not visible.
This commit was sponsored by Stelian Iancu.
2014-02-19 19:10:18 +00:00
|
|
|
return $ fst $ refineView v $
|
|
|
|
map parseViewParam $ reverse params
|
2014-02-18 21:38:23 +00:00
|
|
|
where
|
|
|
|
viewbranch = fromMaybe (error "not on any branch!")
|
|
|
|
<$> inRepo Git.Branch.current
|
|
|
|
|
2014-02-19 00:57:14 +00:00
|
|
|
checkoutViewBranch :: View -> (View -> Annex Git.Branch) -> CommandCleanup
|
|
|
|
checkoutViewBranch view mkbranch = do
|
|
|
|
oldcwd <- liftIO getCurrentDirectory
|
|
|
|
|
|
|
|
{- Change to top of repository before creating view branch. -}
|
|
|
|
liftIO . setCurrentDirectory =<< fromRepo Git.repoPath
|
|
|
|
branch <- mkbranch view
|
|
|
|
|
2014-02-19 01:57:21 +00:00
|
|
|
showOutput
|
2014-02-18 21:38:23 +00:00
|
|
|
ok <- inRepo $ Git.Command.runBool
|
|
|
|
[ Param "checkout"
|
2014-02-19 05:09:17 +00:00
|
|
|
, Param (Git.fromRef $ Git.Ref.base branch)
|
2014-02-18 21:38:23 +00:00
|
|
|
]
|
|
|
|
when ok $ do
|
|
|
|
setView view
|
|
|
|
{- A git repo can easily have empty directories in it,
|
|
|
|
- and this pollutes the view, so remove them. -}
|
2014-02-19 00:57:14 +00:00
|
|
|
liftIO $ removeemptydirs "."
|
|
|
|
unlessM (liftIO $ doesDirectoryExist oldcwd) $ do
|
|
|
|
top <- fromRepo Git.repoPath
|
2014-02-18 21:38:23 +00:00
|
|
|
showLongNote (cwdmissing top)
|
|
|
|
return ok
|
|
|
|
where
|
|
|
|
removeemptydirs top = mapM_ (tryIO . removeDirectory)
|
|
|
|
=<< dirTreeRecursiveSkipping (".git" `isSuffixOf`) top
|
|
|
|
cwdmissing top = unlines
|
|
|
|
[ "This view does not include the subdirectory you are currently in."
|
|
|
|
, "Perhaps you should: cd " ++ top
|
|
|
|
]
|