summaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-12-15 15:34:28 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-12-15 15:34:28 -0400
commit59654d08a2335bf716f38b76095121c6e4c62535 (patch)
treef4d450caa09cfc4e373ee946b2cef956f9429757 /Annex
parent271fe1ce457447b0aee8d825b9186a0b579b56d0 (diff)
reorg
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Direct.hs2
-rw-r--r--Annex/View.hs4
-rw-r--r--Annex/WorkTree.hs35
3 files changed, 38 insertions, 3 deletions
diff --git a/Annex/Direct.hs b/Annex/Direct.hs
index 8fced2d44..8c3d5bb56 100644
--- a/Annex/Direct.hs
+++ b/Annex/Direct.hs
@@ -399,7 +399,7 @@ changedDirect oldk f = do
whenM (pure (null locs) <&&> not <$> inAnnex oldk) $
logStatus oldk InfoMissing
-{- Enable/disable direct mode. -}
+{- Git config settings to enable/disable direct mode. -}
setDirect :: Bool -> Annex ()
setDirect wantdirect = do
if wantdirect
diff --git a/Annex/View.hs b/Annex/View.hs
index 567522a54..8ddbb9c63 100644
--- a/Annex/View.hs
+++ b/Annex/View.hs
@@ -22,7 +22,7 @@ import Git.Sha
import Git.HashObject
import Git.Types
import Git.FilePath
-import qualified Backend
+import Annex.WorkTree
import Annex.Index
import Annex.Link
import Annex.CatFile
@@ -342,7 +342,7 @@ applyView' mkviewedfile getfilemetadata view = do
hasher <- inRepo hashObjectStart
forM_ l $ \f -> do
relf <- getTopFilePath <$> inRepo (toTopFilePath f)
- go uh hasher relf =<< Backend.lookupFile f
+ go uh hasher relf =<< lookupFile f
liftIO $ do
hashObjectStop hasher
void $ stopUpdateIndex uh
diff --git a/Annex/WorkTree.hs b/Annex/WorkTree.hs
new file mode 100644
index 000000000..26144e7f9
--- /dev/null
+++ b/Annex/WorkTree.hs
@@ -0,0 +1,35 @@
+{- git-annex worktree files
+ -
+ - Copyright 2013-2015 Joey Hess <id@joeyh.name>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Annex.WorkTree where
+
+import Common.Annex
+import Annex.Link
+import Annex.CatFile
+
+{- Looks up the key corresponding to an annexed file,
+ - by examining what the file links to.
+ -
+ - An unlocked file will not have a link on disk, so fall back to
+ - looking for a pointer to a key in git.
+ -}
+lookupFile :: FilePath -> Annex (Maybe Key)
+lookupFile file = do
+ mkey <- isAnnexLink file
+ case mkey of
+ Just key -> makeret key
+ Nothing -> maybe (return Nothing) makeret =<< catKeyFile file
+ where
+ makeret = return . Just
+
+{- Modifies an action to only act on files that are already annexed,
+ - and passes the key on to it. -}
+whenAnnexed :: (FilePath -> Key -> Annex (Maybe a)) -> FilePath -> Annex (Maybe a)
+whenAnnexed a file = ifAnnexed file (a file) (return Nothing)
+
+ifAnnexed :: FilePath -> (Key -> Annex a) -> Annex a -> Annex a
+ifAnnexed file yes no = maybe no yes =<< lookupFile file