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.
|
|
|
|
-
|
2018-09-12 17:53:03 +00:00
|
|
|
- Copyright 2010-2018 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
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2011-10-30 03:48:46 +00:00
|
|
|
import Types.Command
|
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
|
2015-07-08 21:59:06 +00:00
|
|
|
import CmdLine.GitAnnex.Options
|
2013-07-03 17:02:42 +00:00
|
|
|
import Logs.Location
|
2013-07-03 19:26:59 +00:00
|
|
|
import Logs.Unused
|
support findred and --branch with file matching options
* findref: Support file matching options: --include, --exclude,
--want-get, --want-drop, --largerthan, --smallerthan, --accessedwithin
* Commands supporting --branch now apply file matching options --include,
--exclude, --want-get, --want-drop to filenames from the branch.
Previously, combining --branch with those would fail to match anything.
* add, import, findref: Support --time-limit.
This commit was sponsored by Jake Vosloo on Patreon.
2018-12-09 17:38:35 +00:00
|
|
|
import Types.ActionItem
|
2016-08-03 16:37:12 +00:00
|
|
|
import Types.Transfer
|
|
|
|
import Logs.Transfer
|
|
|
|
import Remote.List
|
|
|
|
import qualified Remote
|
2013-08-22 17:57:07 +00:00
|
|
|
import Annex.CatFile
|
2018-10-19 21:51:25 +00:00
|
|
|
import Annex.CurrentBranch
|
2015-06-02 18:20:38 +00:00
|
|
|
import Annex.Content
|
2018-09-12 19:20:34 +00:00
|
|
|
import Annex.InodeSentinal
|
|
|
|
import qualified Database.Keys
|
2011-11-08 19:34:10 +00:00
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withFilesInGit :: (FilePath -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
2017-10-16 18:10:03 +00:00
|
|
|
withFilesInGit a l = seekActions $ prepFiltered a $
|
|
|
|
seekHelper LsFiles.inRepo l
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withFilesInGitNonRecursive :: String -> (FilePath -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
2017-10-16 18:10:03 +00:00
|
|
|
withFilesInGitNonRecursive needforce a l = ifM (Annex.getState Annex.force)
|
|
|
|
( withFilesInGit a l
|
|
|
|
, if null l
|
2016-11-16 01:29:54 +00:00
|
|
|
then giveup needforce
|
2017-10-16 18:10:03 +00:00
|
|
|
else seekActions $ prepFiltered a (getfiles [] l)
|
2015-02-10 20:06:53 +00:00
|
|
|
)
|
|
|
|
where
|
|
|
|
getfiles c [] = return (reverse c)
|
2017-10-16 18:10:03 +00:00
|
|
|
getfiles c ((WorkTreeItem p):ps) = do
|
2015-02-10 20:06:53 +00:00
|
|
|
(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
|
2016-11-16 01:29:54 +00:00
|
|
|
_ -> giveup needforce
|
2015-02-10 20:06:53 +00:00
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withFilesNotInGit :: Bool -> (FilePath -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
2017-10-16 18:10:03 +00:00
|
|
|
withFilesNotInGit skipdotfiles a l
|
2014-03-26 18:52:07 +00:00
|
|
|
| skipdotfiles = do
|
|
|
|
{- dotfiles are not acted on unless explicitly listed -}
|
|
|
|
files <- filter (not . dotfile) <$>
|
2017-10-16 18:10:03 +00:00
|
|
|
seekunless (null ps && not (null l)) ps
|
2014-03-26 18:52:07 +00:00
|
|
|
dotfiles <- seekunless (null dotps) dotps
|
|
|
|
go (files++dotfiles)
|
2017-10-16 18:10:03 +00:00
|
|
|
| otherwise = go =<< seekunless False l
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2017-10-16 18:10:03 +00:00
|
|
|
(dotps, ps) = partition (\(WorkTreeItem f) -> dotfile f) l
|
2012-11-11 04:51:07 +00:00
|
|
|
seekunless True _ = return []
|
2017-10-16 18:10:03 +00:00
|
|
|
seekunless _ l' = do
|
2012-11-11 04:51:07 +00:00
|
|
|
force <- Annex.getState Annex.force
|
|
|
|
g <- gitRepo
|
2017-10-16 18:10:03 +00:00
|
|
|
liftIO $ Git.Command.leaveZombie
|
|
|
|
<$> LsFiles.notInRepo force (map (\(WorkTreeItem f) -> f) l') g
|
|
|
|
go fs = seekActions $ prepFiltered a $
|
|
|
|
return $ concat $ segmentPaths (map (\(WorkTreeItem f) -> f) l) fs
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withPathContents :: ((FilePath, FilePath) -> CommandSeek) -> CmdParams -> CommandSeek
|
2015-02-06 19:58:06 +00:00
|
|
|
withPathContents a params = do
|
|
|
|
matcher <- Limit.getMatcher
|
2018-04-26 16:06:12 +00:00
|
|
|
forM_ params $ \p -> do
|
|
|
|
fs <- liftIO $ get p
|
2018-10-01 18:12:06 +00:00
|
|
|
forM fs $ \f ->
|
|
|
|
whenM (checkmatch matcher f) $
|
|
|
|
a f
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
|
|
|
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
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withWords :: ([String] -> CommandSeek) -> CmdParams -> 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
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withStrings :: (String -> CommandSeek) -> CmdParams -> 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
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withPairs :: ((String, String) -> CommandSeek) -> CmdParams -> 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
|
2016-11-16 01:29:54 +00:00
|
|
|
pairs _ _ = giveup "expected pairs"
|
2012-02-16 20:36:35 +00:00
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withFilesToBeCommitted :: (FilePath -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
2017-10-16 18:10:03 +00:00
|
|
|
withFilesToBeCommitted a l = seekActions $ prepFiltered a $
|
|
|
|
seekHelper LsFiles.stagedNotDeleted l
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withFilesOldUnlocked :: (FilePath -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
2015-12-15 18:08:07 +00:00
|
|
|
withFilesOldUnlocked = withFilesOldUnlocked' LsFiles.typeChanged
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2015-12-11 20:05:56 +00:00
|
|
|
{- Unlocked files before v6 have changed type from a symlink to a regular file.
|
2013-08-22 17:57:07 +00:00
|
|
|
-
|
|
|
|
- Furthermore, unlocked files used to be a git-annex symlink,
|
|
|
|
- not some other sort of symlink.
|
|
|
|
-}
|
2018-10-01 18:12:06 +00:00
|
|
|
withFilesOldUnlocked' :: ([FilePath] -> Git.Repo -> IO ([FilePath], IO Bool)) -> (FilePath -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
2017-10-16 18:10:03 +00:00
|
|
|
withFilesOldUnlocked' typechanged a l = seekActions $
|
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
|
|
|
prepFiltered a unlockedfiles
|
2013-08-22 17:57:07 +00:00
|
|
|
where
|
2017-10-16 18:10:03 +00:00
|
|
|
unlockedfiles = filterM isOldUnlocked =<< seekHelper typechanged l
|
2014-11-10 19:36:24 +00:00
|
|
|
|
2015-12-15 18:08:07 +00:00
|
|
|
isOldUnlocked :: FilePath -> Annex Bool
|
|
|
|
isOldUnlocked f = liftIO (notSymlink f) <&&>
|
2014-11-10 19:36:24 +00:00
|
|
|
(isJust <$> catKeyFile f <||> isJust <$> catKeyFileHEAD f)
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withFilesOldUnlockedToBeCommitted :: (FilePath -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
2018-09-12 17:53:03 +00:00
|
|
|
withFilesOldUnlockedToBeCommitted = withFilesOldUnlocked' LsFiles.typeChangedStaged
|
|
|
|
|
2018-09-12 19:20:34 +00:00
|
|
|
{- v6 unlocked pointer files that are staged, and whose content has not been
|
|
|
|
- modified-}
|
2018-10-01 18:12:06 +00:00
|
|
|
withUnmodifiedUnlockedPointers :: (FilePath -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
2018-09-12 19:20:34 +00:00
|
|
|
withUnmodifiedUnlockedPointers a l = seekActions $
|
2018-09-12 17:53:03 +00:00
|
|
|
prepFiltered a unlockedfiles
|
|
|
|
where
|
2018-09-12 19:20:34 +00:00
|
|
|
unlockedfiles = filterM isV6UnmodifiedUnlocked
|
|
|
|
=<< seekHelper LsFiles.typeChangedStaged l
|
2018-09-12 17:53:03 +00:00
|
|
|
|
2018-09-12 19:20:34 +00:00
|
|
|
isV6UnmodifiedUnlocked :: FilePath -> Annex Bool
|
|
|
|
isV6UnmodifiedUnlocked f = catKeyFile f >>= \case
|
|
|
|
Nothing -> return False
|
|
|
|
Just k -> sameInodeCache f =<< Database.Keys.getInodeCaches k
|
2018-09-12 17:53:03 +00:00
|
|
|
|
2013-02-20 18:12:55 +00:00
|
|
|
{- Finds files that may be modified. -}
|
2018-10-01 18:12:06 +00:00
|
|
|
withFilesMaybeModified :: (FilePath -> CommandSeek) -> [WorkTreeItem] -> 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
|
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withKeys :: (Key -> CommandSeek) -> CmdParams -> CommandSeek
|
2017-10-16 18:10:03 +00:00
|
|
|
withKeys a l = seekActions $ return $ map (a . parse) l
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2016-11-16 01:29:54 +00:00
|
|
|
parse p = fromMaybe (giveup "bad key") $ file2key p
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withNothing :: CommandSeek -> CmdParams -> CommandSeek
|
|
|
|
withNothing a [] = a
|
2016-11-16 01:29:54 +00:00
|
|
|
withNothing _ _ = giveup "This command takes no parameters."
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2016-08-03 16:37:12 +00:00
|
|
|
{- Handles the --all, --branch, --unused, --failed, --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
|
2018-10-01 18:12:06 +00:00
|
|
|
- whatever params were passed.
|
|
|
|
-}
|
2016-07-20 19:22:55 +00:00
|
|
|
withKeyOptions
|
|
|
|
:: Maybe KeyOptions
|
|
|
|
-> Bool
|
2018-10-01 18:12:06 +00:00
|
|
|
-> ((Key, ActionItem) -> CommandSeek)
|
2017-10-16 18:10:03 +00:00
|
|
|
-> ([WorkTreeItem] -> CommandSeek)
|
|
|
|
-> [WorkTreeItem]
|
2016-07-20 19:22:55 +00:00
|
|
|
-> CommandSeek
|
--branch, stage 1
Added --branch option to copy, drop, fsck, get, metadata, mirror, move, and
whereis commands. This option makes git-annex operate on files that are
included in a specified branch (or other treeish).
The names of the files from the branch that are being operated on are not
displayed yet; only the keys. Displaying the filenames will need changes
to every affected command.
Also, note that --branch can be specified repeatedly. This is not really
documented, but seemed worth supporting, especially since we may later want
the ability to operate on all branches matching a refspec. However, when
operating on two branches that contain the same key, that key will be
operated on twice.
2016-07-20 16:05:22 +00:00
|
|
|
withKeyOptions ko auto keyaction = withKeyOptions' ko auto mkkeyaction
|
2015-06-16 20:50:03 +00:00
|
|
|
where
|
--branch, stage 1
Added --branch option to copy, drop, fsck, get, metadata, mirror, move, and
whereis commands. This option makes git-annex operate on files that are
included in a specified branch (or other treeish).
The names of the files from the branch that are being operated on are not
displayed yet; only the keys. Displaying the filenames will need changes
to every affected command.
Also, note that --branch can be specified repeatedly. This is not really
documented, but seemed worth supporting, especially since we may later want
the ability to operate on all branches matching a refspec. However, when
operating on two branches that contain the same key, that key will be
operated on twice.
2016-07-20 16:05:22 +00:00
|
|
|
mkkeyaction = do
|
|
|
|
matcher <- Limit.getMatcher
|
support findred and --branch with file matching options
* findref: Support file matching options: --include, --exclude,
--want-get, --want-drop, --largerthan, --smallerthan, --accessedwithin
* Commands supporting --branch now apply file matching options --include,
--exclude, --want-get, --want-drop to filenames from the branch.
Previously, combining --branch with those would fail to match anything.
* add, import, findref: Support --time-limit.
This commit was sponsored by Jake Vosloo on Patreon.
2018-12-09 17:38:35 +00:00
|
|
|
return $ \v@(k, ai) ->
|
|
|
|
let i = case ai of
|
|
|
|
ActionItemBranchFilePath (BranchFilePath _ topf) ->
|
|
|
|
MatchingKey k (AssociatedFile $ Just $ getTopFilePath topf)
|
|
|
|
_ -> MatchingKey k (AssociatedFile Nothing)
|
|
|
|
in whenM (matcher i) $
|
2018-10-01 18:12:06 +00:00
|
|
|
keyaction v
|
2016-07-20 19:22:55 +00:00
|
|
|
|
|
|
|
withKeyOptions'
|
|
|
|
:: Maybe KeyOptions
|
|
|
|
-> Bool
|
2018-10-01 18:12:06 +00:00
|
|
|
-> Annex ((Key, ActionItem) -> Annex ())
|
2017-10-16 18:10:03 +00:00
|
|
|
-> ([WorkTreeItem] -> CommandSeek)
|
|
|
|
-> [WorkTreeItem]
|
2016-07-20 19:22:55 +00:00
|
|
|
-> CommandSeek
|
--branch, stage 1
Added --branch option to copy, drop, fsck, get, metadata, mirror, move, and
whereis commands. This option makes git-annex operate on files that are
included in a specified branch (or other treeish).
The names of the files from the branch that are being operated on are not
displayed yet; only the keys. Displaying the filenames will need changes
to every affected command.
Also, note that --branch can be specified repeatedly. This is not really
documented, but seemed worth supporting, especially since we may later want
the ability to operate on all branches matching a refspec. However, when
operating on two branches that contain the same key, that key will be
operated on twice.
2016-07-20 16:05:22 +00:00
|
|
|
withKeyOptions' ko auto mkkeyaction fallbackaction params = do
|
2013-07-03 19:26:59 +00:00
|
|
|
bare <- fromRepo Git.repoIsLocalBare
|
2014-01-26 18:59:47 +00:00
|
|
|
when (auto && bare) $
|
2016-11-16 01:29:54 +00:00
|
|
|
giveup "Cannot use --auto in a bare repository"
|
2015-07-09 16:44:03 +00:00
|
|
|
case (null params, ko) of
|
|
|
|
(True, Nothing)
|
2018-04-26 18:21:27 +00:00
|
|
|
| bare -> noauto $ runkeyaction finishCheck loggedKeys
|
2015-07-08 21:59:06 +00:00
|
|
|
| otherwise -> fallbackaction params
|
2015-07-09 16:44:03 +00:00
|
|
|
(False, Nothing) -> fallbackaction params
|
2018-04-26 18:21:27 +00:00
|
|
|
(True, Just WantAllKeys) -> noauto $ runkeyaction finishCheck loggedKeys
|
|
|
|
(True, Just WantUnusedKeys) -> noauto $ runkeyaction (pure . Just) unusedKeys'
|
2016-08-03 16:37:12 +00:00
|
|
|
(True, Just WantFailedTransfers) -> noauto runfailedtransfers
|
2018-04-26 18:21:27 +00:00
|
|
|
(True, Just (WantSpecificKey k)) -> noauto $ runkeyaction (pure . Just) (return [k])
|
|
|
|
(True, Just WantIncompleteKeys) -> noauto $ runkeyaction (pure . Just) incompletekeys
|
--branch, stage 1
Added --branch option to copy, drop, fsck, get, metadata, mirror, move, and
whereis commands. This option makes git-annex operate on files that are
included in a specified branch (or other treeish).
The names of the files from the branch that are being operated on are not
displayed yet; only the keys. Displaying the filenames will need changes
to every affected command.
Also, note that --branch can be specified repeatedly. This is not really
documented, but seemed worth supporting, especially since we may later want
the ability to operate on all branches matching a refspec. However, when
operating on two branches that contain the same key, that key will be
operated on twice.
2016-07-20 16:05:22 +00:00
|
|
|
(True, Just (WantBranchKeys bs)) -> noauto $ runbranchkeys bs
|
2016-11-16 01:29:54 +00:00
|
|
|
(False, Just _) -> giveup "Can only specify one of file names, --all, --branch, --unused, --failed, --key, or --incomplete"
|
2013-07-03 17:02:42 +00:00
|
|
|
where
|
--branch, stage 1
Added --branch option to copy, drop, fsck, get, metadata, mirror, move, and
whereis commands. This option makes git-annex operate on files that are
included in a specified branch (or other treeish).
The names of the files from the branch that are being operated on are not
displayed yet; only the keys. Displaying the filenames will need changes
to every affected command.
Also, note that --branch can be specified repeatedly. This is not really
documented, but seemed worth supporting, especially since we may later want
the ability to operate on all branches matching a refspec. However, when
operating on two branches that contain the same key, that key will be
operated on twice.
2016-07-20 16:05:22 +00:00
|
|
|
noauto a
|
2016-11-16 01:29:54 +00:00
|
|
|
| auto = giveup "Cannot use --auto with --all or --branch or --unused or --key or --incomplete"
|
--branch, stage 1
Added --branch option to copy, drop, fsck, get, metadata, mirror, move, and
whereis commands. This option makes git-annex operate on files that are
included in a specified branch (or other treeish).
The names of the files from the branch that are being operated on are not
displayed yet; only the keys. Displaying the filenames will need changes
to every affected command.
Also, note that --branch can be specified repeatedly. This is not really
documented, but seemed worth supporting, especially since we may later want
the ability to operate on all branches matching a refspec. However, when
operating on two branches that contain the same key, that key will be
operated on twice.
2016-07-20 16:05:22 +00:00
|
|
|
| otherwise = a
|
2015-06-02 18:20:38 +00:00
|
|
|
incompletekeys = staleKeysPrune gitAnnexTmpObjectDir True
|
2018-04-26 18:21:27 +00:00
|
|
|
runkeyaction checker getks = do
|
--branch, stage 1
Added --branch option to copy, drop, fsck, get, metadata, mirror, move, and
whereis commands. This option makes git-annex operate on files that are
included in a specified branch (or other treeish).
The names of the files from the branch that are being operated on are not
displayed yet; only the keys. Displaying the filenames will need changes
to every affected command.
Also, note that --branch can be specified repeatedly. This is not really
documented, but seemed worth supporting, especially since we may later want
the ability to operate on all branches matching a refspec. However, when
operating on two branches that contain the same key, that key will be
operated on twice.
2016-07-20 16:05:22 +00:00
|
|
|
keyaction <- mkkeyaction
|
2016-07-20 19:22:55 +00:00
|
|
|
ks <- getks
|
2018-04-26 18:21:27 +00:00
|
|
|
forM_ ks $ checker >=> maybe noop
|
2018-10-01 18:12:06 +00:00
|
|
|
(\k -> keyaction (k, mkActionItem k))
|
--branch, stage 1
Added --branch option to copy, drop, fsck, get, metadata, mirror, move, and
whereis commands. This option makes git-annex operate on files that are
included in a specified branch (or other treeish).
The names of the files from the branch that are being operated on are not
displayed yet; only the keys. Displaying the filenames will need changes
to every affected command.
Also, note that --branch can be specified repeatedly. This is not really
documented, but seemed worth supporting, especially since we may later want
the ability to operate on all branches matching a refspec. However, when
operating on two branches that contain the same key, that key will be
operated on twice.
2016-07-20 16:05:22 +00:00
|
|
|
runbranchkeys bs = do
|
|
|
|
keyaction <- mkkeyaction
|
|
|
|
forM_ bs $ \b -> do
|
|
|
|
(l, cleanup) <- inRepo $ LsTree.lsTree b
|
2016-07-20 19:22:55 +00:00
|
|
|
forM_ l $ \i -> do
|
|
|
|
let bfp = mkActionItem $ BranchFilePath b (LsTree.file i)
|
2018-10-01 18:12:06 +00:00
|
|
|
maybe noop (\k -> keyaction (k, bfp))
|
--branch, stage 1
Added --branch option to copy, drop, fsck, get, metadata, mirror, move, and
whereis commands. This option makes git-annex operate on files that are
included in a specified branch (or other treeish).
The names of the files from the branch that are being operated on are not
displayed yet; only the keys. Displaying the filenames will need changes
to every affected command.
Also, note that --branch can be specified repeatedly. This is not really
documented, but seemed worth supporting, especially since we may later want
the ability to operate on all branches matching a refspec. However, when
operating on two branches that contain the same key, that key will be
operated on twice.
2016-07-20 16:05:22 +00:00
|
|
|
=<< catKey (LsTree.sha i)
|
2016-07-20 17:44:33 +00:00
|
|
|
unlessM (liftIO cleanup) $
|
|
|
|
error ("git ls-tree " ++ Git.fromRef b ++ " failed")
|
2016-08-03 16:37:12 +00:00
|
|
|
runfailedtransfers = do
|
|
|
|
keyaction <- mkkeyaction
|
|
|
|
rs <- remoteList
|
|
|
|
ts <- concat <$> mapM (getFailedTransfers . Remote.uuid) rs
|
|
|
|
forM_ ts $ \(t, i) ->
|
2018-10-01 18:12:06 +00:00
|
|
|
keyaction (transferKey t, mkActionItem (t, i))
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
prepFiltered :: (FilePath -> CommandSeek) -> Annex [FilePath] -> Annex [CommandSeek]
|
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
|
2018-10-01 18:12:06 +00:00
|
|
|
process matcher f = whenM (matcher $ MatchingFile $ FileInfo f f) $ a f
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
seekActions :: Annex [CommandSeek] -> Annex ()
|
|
|
|
seekActions gen = sequence_ =<< gen
|
2013-01-06 20:56:55 +00:00
|
|
|
|
2017-10-16 18:10:03 +00:00
|
|
|
seekHelper :: ([FilePath] -> Git.Repo -> IO ([FilePath], IO Bool)) -> [WorkTreeItem] -> Annex [FilePath]
|
|
|
|
seekHelper a l = inRepo $ \g ->
|
|
|
|
concat . concat <$> forM (segmentXargsOrdered l')
|
Bugfix: Passing a command a filename that does not exist sometimes did not display an error, when a path to a directory was also passed.
It was relying on segmentPaths to work correctly, so when it didn't,
sometimes the file that did not exist got matched up with a non-null
list of results. Fixed by always checking if each parameter exists.
There are two reason segmentPaths might not work correctly.
For one, it assumes that when the original list of paths
has more than 100 paths, it's not worth paying the CPU cost to
preserve input orders.
And then, it fails when a directory such as "." or ".." or
/path/to/repo is in the input list, and the list of found paths
does not start with that same thing. It should probably not be using
dirContains, but something else.
But, it's not clear how to handle this fully. Consider
when [".", "subdir"] has been expanded by git ls-files to
["subdir/1", "subdir/2"]
-- Both of the inputs contained those results, so there's
no one right answer for segmentPaths. All these would be equally valid:
[["subdir/1", "subdir/2"], []]
[[], ["subdir/1", "subdir/2"]]
[["subdir/1"], [""subdir/2"]]
So I've not tried to improve segmentPaths.
2017-03-02 17:06:20 +00:00
|
|
|
(runSegmentPaths (\fs -> Git.Command.leaveZombie <$> a fs g))
|
2017-10-16 18:10:03 +00:00
|
|
|
where
|
|
|
|
l' = map (\(WorkTreeItem f) -> f) l
|
|
|
|
|
|
|
|
-- An item in the work tree, which may be a file or a directory.
|
|
|
|
newtype WorkTreeItem = WorkTreeItem FilePath
|
2013-02-06 16:40:59 +00:00
|
|
|
|
2018-10-19 21:51:25 +00:00
|
|
|
-- When in an adjusted branch that hides some files, it may not exist
|
|
|
|
-- in the current work tree, but in the original branch. This allows
|
|
|
|
-- seeking for such files.
|
|
|
|
newtype AllowHidden = AllowHidden Bool
|
|
|
|
|
2017-10-16 18:10:03 +00:00
|
|
|
-- Many git commands seek work tree items matching some criteria,
|
|
|
|
-- and silently skip over anything that does not exist. But users expect
|
|
|
|
-- an error message when one of the files they provided as a command-line
|
|
|
|
-- parameter doesn't exist, so this checks that each exists.
|
|
|
|
workTreeItems :: CmdParams -> Annex [WorkTreeItem]
|
2018-10-19 21:51:25 +00:00
|
|
|
workTreeItems = workTreeItems' (AllowHidden False)
|
|
|
|
|
|
|
|
workTreeItems' :: AllowHidden -> CmdParams -> Annex [WorkTreeItem]
|
|
|
|
workTreeItems' (AllowHidden allowhidden) ps = do
|
|
|
|
currbranch <- getCurrentBranch
|
2017-10-16 18:10:03 +00:00
|
|
|
forM_ ps $ \p ->
|
2018-10-19 21:51:25 +00:00
|
|
|
unlessM (exists p <||> hidden currbranch p) $ do
|
2017-10-16 18:10:03 +00:00
|
|
|
toplevelWarning False (p ++ " not found")
|
|
|
|
Annex.incError
|
|
|
|
return (map WorkTreeItem ps)
|
2018-10-19 21:51:25 +00:00
|
|
|
where
|
|
|
|
exists p = isJust <$> liftIO (catchMaybeIO $ getSymbolicLinkStatus p)
|
|
|
|
hidden currbranch p
|
|
|
|
| allowhidden = do
|
|
|
|
f <- liftIO $ relPathCwdToFile p
|
|
|
|
isJust <$> catObjectMetaDataHidden f currbranch
|
|
|
|
| otherwise = return False
|
2017-06-01 15:40:47 +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
|