2011-10-30 03:48:46 +00:00
|
|
|
{- git-annex command seeking
|
|
|
|
-
|
|
|
|
- These functions find appropriate files or other things based on
|
|
|
|
- the values a user passes to a command, and prepare actions operating
|
|
|
|
- on them.
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2010-2014 Joey Hess <id@joeyh.name>
|
2011-10-30 03:48:46 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
2014-01-26 20:25:55 +00:00
|
|
|
module CmdLine.Seek where
|
2011-10-30 03:48:46 +00:00
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import Types.Command
|
|
|
|
import Types.Key
|
2013-05-25 03:07:26 +00:00
|
|
|
import Types.FileMatcher
|
2011-10-30 03:48:46 +00:00
|
|
|
import qualified Annex
|
|
|
|
import qualified Git
|
2012-10-04 23:56:32 +00:00
|
|
|
import qualified Git.Command
|
2011-10-30 03:48:46 +00:00
|
|
|
import qualified Git.LsFiles as LsFiles
|
2014-04-17 22:41:24 +00:00
|
|
|
import qualified Git.LsTree as LsTree
|
|
|
|
import Git.FilePath
|
2011-10-30 03:48:46 +00:00
|
|
|
import qualified Limit
|
2014-01-26 20:25:55 +00:00
|
|
|
import CmdLine.Option
|
2014-01-29 17:44:53 +00:00
|
|
|
import CmdLine.Action
|
2013-07-03 17:02:42 +00:00
|
|
|
import Logs.Location
|
2013-07-03 19:26:59 +00:00
|
|
|
import Logs.Unused
|
2013-08-22 17:57:07 +00:00
|
|
|
import Annex.CatFile
|
2015-06-02 18:20:38 +00:00
|
|
|
import Annex.Content
|
2011-11-08 19:34:10 +00:00
|
|
|
|
2011-10-30 03:48:46 +00:00
|
|
|
withFilesInGit :: (FilePath -> CommandStart) -> CommandSeek
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
withFilesInGit a params = seekActions $ prepFiltered a $
|
|
|
|
seekHelper LsFiles.inRepo params
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2015-02-10 20:06:53 +00:00
|
|
|
withFilesInGitNonRecursive :: (FilePath -> CommandStart) -> CommandSeek
|
|
|
|
withFilesInGitNonRecursive a params = ifM (Annex.getState Annex.force)
|
|
|
|
( withFilesInGit a params
|
|
|
|
, if null params
|
|
|
|
then needforce
|
|
|
|
else seekActions $ prepFiltered a (getfiles [] params)
|
|
|
|
)
|
|
|
|
where
|
|
|
|
getfiles c [] = return (reverse c)
|
|
|
|
getfiles c (p:ps) = do
|
|
|
|
(fs, cleanup) <- inRepo $ LsFiles.inRepo [p]
|
|
|
|
case fs of
|
|
|
|
[f] -> do
|
|
|
|
void $ liftIO $ cleanup
|
|
|
|
getfiles (f:c) ps
|
|
|
|
[] -> do
|
|
|
|
void $ liftIO $ cleanup
|
|
|
|
getfiles c ps
|
|
|
|
_ -> needforce
|
|
|
|
needforce = error "Not recursively setting metadata. Use --force to do that."
|
|
|
|
|
2014-03-26 18:52:07 +00:00
|
|
|
withFilesNotInGit :: Bool -> (FilePath -> CommandStart) -> CommandSeek
|
|
|
|
withFilesNotInGit skipdotfiles a params
|
|
|
|
| skipdotfiles = do
|
|
|
|
{- dotfiles are not acted on unless explicitly listed -}
|
|
|
|
files <- filter (not . dotfile) <$>
|
|
|
|
seekunless (null ps && not (null params)) ps
|
|
|
|
dotfiles <- seekunless (null dotps) dotps
|
|
|
|
go (files++dotfiles)
|
|
|
|
| otherwise = go =<< seekunless False params
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
|
|
|
(dotps, ps) = partition dotfile params
|
|
|
|
seekunless True _ = return []
|
|
|
|
seekunless _ l = do
|
|
|
|
force <- Annex.getState Annex.force
|
|
|
|
g <- gitRepo
|
|
|
|
liftIO $ Git.Command.leaveZombie <$> LsFiles.notInRepo force l g
|
2014-03-26 18:52:07 +00:00
|
|
|
go l = seekActions $ prepFiltered a $
|
|
|
|
return $ concat $ segmentPaths params l
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2014-04-17 22:41:24 +00:00
|
|
|
withFilesInRefs :: (FilePath -> Key -> CommandStart) -> CommandSeek
|
|
|
|
withFilesInRefs a = mapM_ go
|
|
|
|
where
|
|
|
|
go r = do
|
|
|
|
matcher <- Limit.getMatcher
|
|
|
|
l <- inRepo $ LsTree.lsTree (Git.Ref r)
|
|
|
|
forM_ l $ \i -> do
|
|
|
|
let f = getTopFilePath $ LsTree.file i
|
|
|
|
v <- catKey (Git.Ref $ LsTree.sha i) (LsTree.mode i)
|
|
|
|
case v of
|
|
|
|
Nothing -> noop
|
|
|
|
Just k -> whenM (matcher $ MatchingKey k) $
|
2015-04-10 21:08:07 +00:00
|
|
|
commandAction $ a f k
|
2014-04-17 22:41:24 +00:00
|
|
|
|
2012-05-31 23:47:18 +00:00
|
|
|
withPathContents :: ((FilePath, FilePath) -> CommandStart) -> CommandSeek
|
2015-02-06 19:58:06 +00:00
|
|
|
withPathContents a params = do
|
|
|
|
matcher <- Limit.getMatcher
|
|
|
|
seekActions $ map a <$> (filterM (checkmatch matcher) =<< ps)
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2015-02-06 19:58:06 +00:00
|
|
|
ps = concat <$> liftIO (mapM get params)
|
2012-11-11 04:51:07 +00:00
|
|
|
get p = ifM (isDirectory <$> getFileStatus p)
|
2015-01-09 17:11:56 +00:00
|
|
|
( map (\f -> (f, makeRelative (parentDir p) f))
|
2013-12-18 19:05:29 +00:00
|
|
|
<$> dirContentsRecursiveSkipping (".git" `isSuffixOf`) True p
|
2012-11-11 04:51:07 +00:00
|
|
|
, return [(p, takeFileName p)]
|
|
|
|
)
|
2015-02-06 19:58:06 +00:00
|
|
|
checkmatch matcher (f, relf) = matcher $ MatchingFile $ FileInfo
|
2015-02-06 20:03:02 +00:00
|
|
|
{ currFile = f
|
2015-02-06 19:58:06 +00:00
|
|
|
, matchFile = relf
|
|
|
|
}
|
2012-05-31 23:47:18 +00:00
|
|
|
|
2011-10-30 03:48:46 +00:00
|
|
|
withWords :: ([String] -> CommandStart) -> CommandSeek
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
withWords a params = seekActions $ return [a params]
|
2011-10-30 03:48:46 +00:00
|
|
|
|
|
|
|
withStrings :: (String -> CommandStart) -> CommandSeek
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
withStrings a params = seekActions $ return $ map a params
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2012-02-16 20:36:35 +00:00
|
|
|
withPairs :: ((String, String) -> CommandStart) -> CommandSeek
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
withPairs a params = seekActions $ return $ map a $ pairs [] params
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
|
|
|
pairs c [] = reverse c
|
|
|
|
pairs c (x:y:xs) = pairs ((x,y):c) xs
|
|
|
|
pairs _ _ = error "expected pairs"
|
2012-02-16 20:36:35 +00:00
|
|
|
|
2011-10-30 03:48:46 +00:00
|
|
|
withFilesToBeCommitted :: (String -> CommandStart) -> CommandSeek
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
withFilesToBeCommitted a params = seekActions $ prepFiltered a $
|
2011-11-08 19:34:10 +00:00
|
|
|
seekHelper LsFiles.stagedNotDeleted params
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2012-02-14 03:42:44 +00:00
|
|
|
withFilesUnlocked :: (FilePath -> CommandStart) -> CommandSeek
|
2011-10-30 03:48:46 +00:00
|
|
|
withFilesUnlocked = withFilesUnlocked' LsFiles.typeChanged
|
|
|
|
|
2012-02-14 03:42:44 +00:00
|
|
|
withFilesUnlockedToBeCommitted :: (FilePath -> CommandStart) -> CommandSeek
|
2011-10-30 03:48:46 +00:00
|
|
|
withFilesUnlockedToBeCommitted = withFilesUnlocked' LsFiles.typeChangedStaged
|
|
|
|
|
2013-08-22 17:57:07 +00:00
|
|
|
{- Unlocked files have changed type from a symlink to a regular file.
|
|
|
|
-
|
|
|
|
- Furthermore, unlocked files used to be a git-annex symlink,
|
|
|
|
- not some other sort of symlink.
|
|
|
|
-}
|
2012-10-04 23:56:32 +00:00
|
|
|
withFilesUnlocked' :: ([FilePath] -> Git.Repo -> IO ([FilePath], IO Bool)) -> (FilePath -> CommandStart) -> CommandSeek
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
withFilesUnlocked' typechanged a params = seekActions $
|
|
|
|
prepFiltered a unlockedfiles
|
2013-08-22 17:57:07 +00:00
|
|
|
where
|
2014-11-10 19:36:24 +00:00
|
|
|
unlockedfiles = filterM isUnlocked =<< seekHelper typechanged params
|
|
|
|
|
|
|
|
isUnlocked :: FilePath -> Annex Bool
|
|
|
|
isUnlocked f = liftIO (notSymlink f) <&&>
|
|
|
|
(isJust <$> catKeyFile f <||> isJust <$> catKeyFileHEAD f)
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2013-02-20 18:12:55 +00:00
|
|
|
{- Finds files that may be modified. -}
|
|
|
|
withFilesMaybeModified :: (FilePath -> CommandStart) -> CommandSeek
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
withFilesMaybeModified a params = seekActions $
|
2013-02-20 18:12:55 +00:00
|
|
|
prepFiltered a $ seekHelper LsFiles.modified params
|
|
|
|
|
2011-10-30 03:48:46 +00:00
|
|
|
withKeys :: (Key -> CommandStart) -> CommandSeek
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
withKeys a params = seekActions $ return $ map (a . parse) params
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
|
|
|
parse p = fromMaybe (error "bad key") $ file2key p
|
2011-10-30 03:48:46 +00:00
|
|
|
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
{- Gets the value of a field options, which is fed into
|
|
|
|
- a conversion function.
|
more command-specific options
Made --from and --to command-specific options.
Added generic storage for values of command-specific options,
which allows removing some of the special case fields in AnnexState.
(Also added generic storage for command-specific flags, although there are
not yet any.)
Note that this storage uses a Map, so repeatedly looking up the same value
is slightly more expensive than looking up an AnnexState field. But, the
value can be looked up once in the seek stage, transformed as necessary,
and passed in a closure to the start stage, and this avoids that overhead.
Still, I'm hesitant to use this for things like force or fast flags.
It's probably best to reserve it for flags that are only used by a few
commands, or options like --from and --to that it's important only be
allowed to be used with commands that implement them, to avoid user
confusion.
2012-01-06 07:06:25 +00:00
|
|
|
-}
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
getOptionField :: Option -> (Maybe String -> Annex a) -> Annex a
|
2014-01-26 20:25:55 +00:00
|
|
|
getOptionField option converter = converter <=< Annex.getField $ optionName option
|
more command-specific options
Made --from and --to command-specific options.
Added generic storage for values of command-specific options,
which allows removing some of the special case fields in AnnexState.
(Also added generic storage for command-specific flags, although there are
not yet any.)
Note that this storage uses a Map, so repeatedly looking up the same value
is slightly more expensive than looking up an AnnexState field. But, the
value can be looked up once in the seek stage, transformed as necessary,
and passed in a closure to the start stage, and this avoids that overhead.
Still, I'm hesitant to use this for things like force or fast flags.
It's probably best to reserve it for flags that are only used by a few
commands, or options like --from and --to that it's important only be
allowed to be used with commands that implement them, to avoid user
confusion.
2012-01-06 07:06:25 +00:00
|
|
|
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
getOptionFlag :: Option -> Annex Bool
|
2014-01-26 20:25:55 +00:00
|
|
|
getOptionFlag option = Annex.getFlag (optionName option)
|
2012-01-07 22:13:12 +00:00
|
|
|
|
2011-10-30 03:48:46 +00:00
|
|
|
withNothing :: CommandStart -> CommandSeek
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
withNothing a [] = seekActions $ return [a]
|
2011-10-30 03:48:46 +00:00
|
|
|
withNothing _ _ = error "This command takes no parameters."
|
|
|
|
|
2015-06-02 18:20:38 +00:00
|
|
|
{- Handles the --all, --unused, --key, and --incomplete options,
|
|
|
|
- which specify particular keys to run an action on.
|
2013-07-03 19:26:59 +00:00
|
|
|
-
|
2015-06-02 18:20:38 +00:00
|
|
|
- In a bare repo, --all is the default.
|
2013-07-03 19:26:59 +00:00
|
|
|
-
|
2015-06-02 18:20:38 +00:00
|
|
|
- Otherwise falls back to a regular CommandSeek action on
|
2013-07-03 17:02:42 +00:00
|
|
|
- whatever params were passed. -}
|
2015-03-25 21:06:14 +00:00
|
|
|
withKeyOptions :: Bool -> (Key -> CommandStart) -> CommandSeek -> CommandSeek
|
|
|
|
withKeyOptions auto keyop fallbackop params = do
|
2013-07-03 19:26:59 +00:00
|
|
|
bare <- fromRepo Git.repoIsLocalBare
|
2013-11-27 10:50:20 +00:00
|
|
|
allkeys <- Annex.getFlag "all"
|
2013-07-03 19:26:59 +00:00
|
|
|
unused <- Annex.getFlag "unused"
|
2015-06-02 18:20:38 +00:00
|
|
|
incomplete <- Annex.getFlag "incomplete"
|
2014-01-26 18:59:47 +00:00
|
|
|
specifickey <- Annex.getField "key"
|
|
|
|
when (auto && bare) $
|
|
|
|
error "Cannot use --auto in a bare repository"
|
2015-06-02 18:20:38 +00:00
|
|
|
case (allkeys, unused, incomplete, null params, specifickey) of
|
|
|
|
(False , False , False , True , Nothing)
|
2014-01-26 18:59:47 +00:00
|
|
|
| bare -> go auto loggedKeys
|
|
|
|
| otherwise -> fallbackop params
|
2015-06-02 18:20:38 +00:00
|
|
|
(False , False , False , _ , Nothing) -> fallbackop params
|
|
|
|
(True , False , False , True , Nothing) -> go auto loggedKeys
|
|
|
|
(False , True , False , True , Nothing) -> go auto unusedKeys'
|
|
|
|
(False , False , True , True , Nothing) -> go auto incompletekeys
|
|
|
|
(False , False , False , True , Just ks) -> case file2key ks of
|
2014-01-26 18:59:47 +00:00
|
|
|
Nothing -> error "Invalid key"
|
|
|
|
Just k -> go auto $ return [k]
|
2015-06-02 18:20:38 +00:00
|
|
|
_ -> error "Can only specify one of file names, --all, --unused, --key, or --incomplete"
|
2013-07-03 17:02:42 +00:00
|
|
|
where
|
2015-06-02 18:20:38 +00:00
|
|
|
go True _ = error "Cannot use --auto with --all or --unused or --key or --incomplete"
|
2014-01-26 18:59:47 +00:00
|
|
|
go False a = do
|
2014-01-18 18:58:56 +00:00
|
|
|
matcher <- Limit.getMatcher
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
seekActions $ map (process matcher) <$> a
|
2014-01-18 18:58:56 +00:00
|
|
|
process matcher k = ifM (matcher $ MatchingKey k)
|
|
|
|
( keyop k , return Nothing)
|
2015-06-02 18:20:38 +00:00
|
|
|
incompletekeys = staleKeysPrune gitAnnexTmpObjectDir True
|
2011-10-30 03:48:46 +00:00
|
|
|
|
|
|
|
prepFiltered :: (FilePath -> CommandStart) -> Annex [FilePath] -> Annex [CommandStart]
|
2012-02-14 05:11:02 +00:00
|
|
|
prepFiltered a fs = do
|
2011-10-30 03:48:46 +00:00
|
|
|
matcher <- Limit.getMatcher
|
2012-07-19 04:43:36 +00:00
|
|
|
map (process matcher) <$> fs
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2014-01-18 18:51:55 +00:00
|
|
|
process matcher f = ifM (matcher $ MatchingFile $ FileInfo f f)
|
2012-11-11 04:51:07 +00:00
|
|
|
( a f , return Nothing )
|
2011-10-30 03:48:46 +00:00
|
|
|
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
seekActions :: Annex [CommandStart] -> Annex ()
|
|
|
|
seekActions gen = do
|
|
|
|
as <- gen
|
|
|
|
mapM_ commandAction as
|
2013-01-06 20:56:55 +00:00
|
|
|
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
seekHelper :: ([FilePath] -> Git.Repo -> IO ([FilePath], IO Bool)) -> [FilePath] -> Annex [FilePath]
|
|
|
|
seekHelper a params = do
|
2015-04-02 05:18:00 +00:00
|
|
|
ll <- inRepo $ \g -> concat <$> forM (segmentXargsOrdered params)
|
|
|
|
(runSegmentPaths (\fs -> Git.Command.leaveZombie <$> a fs g))
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
forM_ (map fst $ filter (null . snd) $ zip params ll) $ \p ->
|
2015-04-30 19:28:17 +00:00
|
|
|
unlessM (isJust <$> liftIO (catchMaybeIO $ getSymbolicLinkStatus p)) $ do
|
|
|
|
toplevelWarning False (p ++ " not found")
|
|
|
|
Annex.incError
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
return $ concat ll
|
2013-02-06 16:40:59 +00:00
|
|
|
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
notSymlink :: FilePath -> IO Bool
|
|
|
|
notSymlink f = liftIO $ not . isSymbolicLink <$> getSymbolicLinkStatus f
|