summaryrefslogtreecommitdiff
path: root/Command/VAdd.hs
blob: e766f3939370b372a7828b391ca62557a46ba77d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{- git-annex command
 -
 - Copyright 2014 Joey Hess <joey@kitenet.net>
 -
 - Licensed under the GNU GPL version 3 or higher.
 -}

module Command.VAdd where

import Common.Annex
import Command
import Annex.View
import Logs.View
import Command.View (paramView, parseViewParam, checkoutViewBranch)

def :: [Command]
def = [notBareRepo $ notDirect $
	command "vadd" paramView seek SectionUtility "refine current view"]

seek :: CommandSeek
seek = withWords start

start :: [String] -> CommandStart
start params = do
	showStart "vadd" ""
	go =<< currentView
  where
	go Nothing = error "Not in a view."
	go (Just view) = do
		let (view', change) = calc view Unchanged (reverse params)
		case change of
			Unchanged -> do
				showNote "unchanged"
				next $ next $ return True
			Narrowing -> next $ next $
				checkoutViewBranch view' narrowView
			Widening -> error "Widening view to match more files is not currently supported."

	calc v c [] = (v, c)
	calc v c (p:ps) =
		let (v', c') = uncurry (refineView v) (parseViewParam p)
		in calc v' (max c c') ps