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.
|
|
|
|
-
|
2020-05-28 19:55:17 +00:00
|
|
|
- Copyright 2010-2020 Joey Hess <id@joeyh.name>
|
2011-10-30 03:48:46 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2011-10-30 03:48:46 +00:00
|
|
|
-}
|
|
|
|
|
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
|
2020-07-10 19:11:14 +00:00
|
|
|
import qualified Git.Types as Git
|
2014-04-17 22:41:24 +00:00
|
|
|
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
|
sped up the --all option by 2x to 16x by using git cat-file --buffer
This assumes that no location log files will have a newline or carriage
return in their name. catObjectStream skips any such files due to
cat-file not supporting them.
Keys have been prevented from containing newlines since 2011,
commit 480495beb4a3422f006ee529df807a20cc944727. If some old repo
had a key with a newline in it, --all will just skip processing that key.
Other things, like .git/annex/unused files certianly assume no newlines in
keys too, and AFAICR, such keys never actually worked.
Carriage return is escaped by preSanitizeKeyName since 2013. WORM keys
generated before that point could perhaps contain a CR. (URL probably not,
http probably doesn't support an URL with a raw CR in it.) So, added
a warning in fsck about such keys. Although, fsck --all will naturally
skip them, so won't be able to warn about them. Not entirely
satisfactory, but I'll bet there are not really any such keys in
existence.
Thanks to Lukey for finding this optimisation.
2020-07-07 17:46:45 +00:00
|
|
|
import Logs
|
2013-07-03 19:26:59 +00:00
|
|
|
import Logs.Unused
|
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
|
2020-07-13 18:09:08 +00:00
|
|
|
import Git.CatFile
|
2018-10-19 21:51:25 +00:00
|
|
|
import Annex.CurrentBranch
|
2015-06-02 18:20:38 +00:00
|
|
|
import Annex.Content
|
2020-07-10 17:54:52 +00:00
|
|
|
import Annex.Link
|
2018-09-12 19:20:34 +00:00
|
|
|
import Annex.InodeSentinal
|
2020-07-10 17:54:52 +00:00
|
|
|
import Annex.Concurrent
|
sped up the --all option by 2x to 16x by using git cat-file --buffer
This assumes that no location log files will have a newline or carriage
return in their name. catObjectStream skips any such files due to
cat-file not supporting them.
Keys have been prevented from containing newlines since 2011,
commit 480495beb4a3422f006ee529df807a20cc944727. If some old repo
had a key with a newline in it, --all will just skip processing that key.
Other things, like .git/annex/unused files certianly assume no newlines in
keys too, and AFAICR, such keys never actually worked.
Carriage return is escaped by preSanitizeKeyName since 2013. WORM keys
generated before that point could perhaps contain a CR. (URL probably not,
http probably doesn't support an URL with a raw CR in it.) So, added
a warning in fsck about such keys. Although, fsck --all will naturally
skip them, so won't be able to warn about them. Not entirely
satisfactory, but I'll bet there are not really any such keys in
existence.
Thanks to Lukey for finding this optimisation.
2020-07-07 17:46:45 +00:00
|
|
|
import qualified Annex.Branch
|
|
|
|
import qualified Annex.BranchState
|
2018-09-12 19:20:34 +00:00
|
|
|
import qualified Database.Keys
|
2019-12-06 19:37:12 +00:00
|
|
|
import qualified Utility.RawFilePath as R
|
2020-07-10 17:54:52 +00:00
|
|
|
import Utility.Tuple
|
|
|
|
|
|
|
|
import Control.Concurrent.Async
|
|
|
|
import System.Posix.Types
|
2011-11-08 19:34:10 +00:00
|
|
|
|
2020-05-28 19:55:17 +00:00
|
|
|
withFilesInGit :: WarnUnmatchWhen -> (RawFilePath -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
2020-07-10 17:54:52 +00:00
|
|
|
withFilesInGit ww a l = seekFiltered a $
|
|
|
|
seekHelper id ww LsFiles.inRepo l
|
|
|
|
|
|
|
|
withFilesInGitAnnex :: WarnUnmatchWhen -> (RawFilePath -> Key -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
2020-07-10 18:17:35 +00:00
|
|
|
withFilesInGitAnnex ww a l = seekFilteredKeys a $
|
2020-07-10 17:54:52 +00:00
|
|
|
seekHelper fst3 ww LsFiles.inRepoDetails l
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2020-07-10 19:40:06 +00:00
|
|
|
withFilesInGitAnnexNonRecursive :: WarnUnmatchWhen -> String -> (RawFilePath -> Key -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
|
|
|
withFilesInGitAnnexNonRecursive ww needforce a l = ifM (Annex.getState Annex.force)
|
|
|
|
( withFilesInGitAnnex ww a l
|
2017-10-16 18:10:03 +00:00
|
|
|
, if null l
|
2016-11-16 01:29:54 +00:00
|
|
|
then giveup needforce
|
2020-07-10 19:40:06 +00:00
|
|
|
else seekFilteredKeys 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
|
2020-05-28 19:55:17 +00:00
|
|
|
os <- seekOptions ww
|
2020-07-10 19:40:06 +00:00
|
|
|
(fs, cleanup) <- inRepo $ LsFiles.inRepoDetails os [toRawFilePath p]
|
2015-02-10 20:06:53 +00:00
|
|
|
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
|
|
|
|
2019-12-26 20:24:40 +00:00
|
|
|
withFilesNotInGit :: (RawFilePath -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
|
|
|
withFilesNotInGit a l = go =<< seek
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2019-12-26 20:24:40 +00:00
|
|
|
seek = 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
|
2020-05-28 19:55:17 +00:00
|
|
|
<$> LsFiles.notInRepo [] force (map (\(WorkTreeItem f) -> toRawFilePath f) l) g
|
2020-07-10 17:54:52 +00:00
|
|
|
go fs = seekFiltered a $
|
|
|
|
return $ concat $ segmentPaths id (map (\(WorkTreeItem f) -> toRawFilePath f) l) fs
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2019-11-26 19:27:22 +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
|
2019-12-09 17:49:05 +00:00
|
|
|
{ currFile = toRawFilePath f
|
|
|
|
, matchFile = toRawFilePath relf
|
2015-02-06 19:58:06 +00:00
|
|
|
}
|
2012-05-31 23:47:18 +00:00
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withWords :: ([String] -> CommandSeek) -> CmdParams -> CommandSeek
|
2020-07-10 17:54:52 +00:00
|
|
|
withWords a params = a params
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withStrings :: (String -> CommandSeek) -> CmdParams -> CommandSeek
|
2020-07-10 17:54:52 +00:00
|
|
|
withStrings a params = sequence_ $ 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
|
2020-07-10 17:54:52 +00:00
|
|
|
withPairs a params = sequence_ $ 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
|
|
|
|
2019-11-25 20:18:19 +00:00
|
|
|
withFilesToBeCommitted :: (RawFilePath -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
2020-07-10 17:54:52 +00:00
|
|
|
withFilesToBeCommitted a l = seekFiltered a $
|
|
|
|
seekHelper id WarnUnmatchWorkTreeItems (const LsFiles.stagedNotDeleted) l
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2019-08-30 17:54:57 +00:00
|
|
|
{- unlocked pointer files that are staged, and whose content has not been
|
2018-09-12 19:20:34 +00:00
|
|
|
- modified-}
|
2020-05-28 19:55:17 +00:00
|
|
|
withUnmodifiedUnlockedPointers :: WarnUnmatchWhen -> (RawFilePath -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
2020-07-10 17:54:52 +00:00
|
|
|
withUnmodifiedUnlockedPointers ww a l = seekFiltered a unlockedfiles
|
2018-09-12 17:53:03 +00:00
|
|
|
where
|
2019-08-30 17:54:57 +00:00
|
|
|
unlockedfiles = filterM isUnmodifiedUnlocked
|
2020-07-10 17:54:52 +00:00
|
|
|
=<< seekHelper id ww (const LsFiles.typeChangedStaged) l
|
2018-09-12 17:53:03 +00:00
|
|
|
|
2019-11-25 20:18:19 +00:00
|
|
|
isUnmodifiedUnlocked :: RawFilePath -> Annex Bool
|
2019-08-30 17:54:57 +00:00
|
|
|
isUnmodifiedUnlocked f = catKeyFile f >>= \case
|
2018-09-12 19:20:34 +00:00
|
|
|
Nothing -> return False
|
2019-12-11 18:12:22 +00:00
|
|
|
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. -}
|
2020-05-28 19:55:17 +00:00
|
|
|
withFilesMaybeModified :: WarnUnmatchWhen -> (RawFilePath -> CommandSeek) -> [WorkTreeItem] -> CommandSeek
|
2020-07-10 17:54:52 +00:00
|
|
|
withFilesMaybeModified ww a params = seekFiltered a $
|
|
|
|
seekHelper id ww LsFiles.modified params
|
2013-02-20 18:12:55 +00:00
|
|
|
|
2018-10-01 18:12:06 +00:00
|
|
|
withKeys :: (Key -> CommandSeek) -> CmdParams -> CommandSeek
|
2020-07-10 17:54:52 +00:00
|
|
|
withKeys a l = sequence_ $ map (a . parse) l
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2019-01-14 17:17:47 +00:00
|
|
|
parse p = fromMaybe (giveup "bad key") $ deserializeKey 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
|
2019-06-06 16:53:24 +00:00
|
|
|
ActionItemBranchFilePath (BranchFilePath _ topf) _ ->
|
2019-12-09 17:49:05 +00:00
|
|
|
MatchingKey k (AssociatedFile $ Just $ getTopFilePath topf)
|
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
|
|
|
_ -> 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)
|
sped up the --all option by 2x to 16x by using git cat-file --buffer
This assumes that no location log files will have a newline or carriage
return in their name. catObjectStream skips any such files due to
cat-file not supporting them.
Keys have been prevented from containing newlines since 2011,
commit 480495beb4a3422f006ee529df807a20cc944727. If some old repo
had a key with a newline in it, --all will just skip processing that key.
Other things, like .git/annex/unused files certianly assume no newlines in
keys too, and AFAICR, such keys never actually worked.
Carriage return is escaped by preSanitizeKeyName since 2013. WORM keys
generated before that point could perhaps contain a CR. (URL probably not,
http probably doesn't support an URL with a raw CR in it.) So, added
a warning in fsck about such keys. Although, fsck --all will naturally
skip them, so won't be able to warn about them. Not entirely
satisfactory, but I'll bet there are not really any such keys in
existence.
Thanks to Lukey for finding this optimisation.
2020-07-07 17:46:45 +00:00
|
|
|
| bare -> noauto runallkeys
|
2015-07-08 21:59:06 +00:00
|
|
|
| otherwise -> fallbackaction params
|
2015-07-09 16:44:03 +00:00
|
|
|
(False, Nothing) -> fallbackaction params
|
sped up the --all option by 2x to 16x by using git cat-file --buffer
This assumes that no location log files will have a newline or carriage
return in their name. catObjectStream skips any such files due to
cat-file not supporting them.
Keys have been prevented from containing newlines since 2011,
commit 480495beb4a3422f006ee529df807a20cc944727. If some old repo
had a key with a newline in it, --all will just skip processing that key.
Other things, like .git/annex/unused files certianly assume no newlines in
keys too, and AFAICR, such keys never actually worked.
Carriage return is escaped by preSanitizeKeyName since 2013. WORM keys
generated before that point could perhaps contain a CR. (URL probably not,
http probably doesn't support an URL with a raw CR in it.) So, added
a warning in fsck about such keys. Although, fsck --all will naturally
skip them, so won't be able to warn about them. Not entirely
satisfactory, but I'll bet there are not really any such keys in
existence.
Thanks to Lukey for finding this optimisation.
2020-07-07 17:46:45 +00:00
|
|
|
(True, Just WantAllKeys) -> noauto runallkeys
|
|
|
|
(True, Just WantUnusedKeys) -> noauto $ runkeyaction unusedKeys'
|
2016-08-03 16:37:12 +00:00
|
|
|
(True, Just WantFailedTransfers) -> noauto runfailedtransfers
|
sped up the --all option by 2x to 16x by using git cat-file --buffer
This assumes that no location log files will have a newline or carriage
return in their name. catObjectStream skips any such files due to
cat-file not supporting them.
Keys have been prevented from containing newlines since 2011,
commit 480495beb4a3422f006ee529df807a20cc944727. If some old repo
had a key with a newline in it, --all will just skip processing that key.
Other things, like .git/annex/unused files certianly assume no newlines in
keys too, and AFAICR, such keys never actually worked.
Carriage return is escaped by preSanitizeKeyName since 2013. WORM keys
generated before that point could perhaps contain a CR. (URL probably not,
http probably doesn't support an URL with a raw CR in it.) So, added
a warning in fsck about such keys. Although, fsck --all will naturally
skip them, so won't be able to warn about them. Not entirely
satisfactory, but I'll bet there are not really any such keys in
existence.
Thanks to Lukey for finding this optimisation.
2020-07-07 17:46:45 +00:00
|
|
|
(True, Just (WantSpecificKey k)) -> noauto $ runkeyaction (return [k])
|
|
|
|
(True, Just WantIncompleteKeys) -> noauto $ runkeyaction 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
|
sped up the --all option by 2x to 16x by using git cat-file --buffer
This assumes that no location log files will have a newline or carriage
return in their name. catObjectStream skips any such files due to
cat-file not supporting them.
Keys have been prevented from containing newlines since 2011,
commit 480495beb4a3422f006ee529df807a20cc944727. If some old repo
had a key with a newline in it, --all will just skip processing that key.
Other things, like .git/annex/unused files certianly assume no newlines in
keys too, and AFAICR, such keys never actually worked.
Carriage return is escaped by preSanitizeKeyName since 2013. WORM keys
generated before that point could perhaps contain a CR. (URL probably not,
http probably doesn't support an URL with a raw CR in it.) So, added
a warning in fsck about such keys. Although, fsck --all will naturally
skip them, so won't be able to warn about them. Not entirely
satisfactory, but I'll bet there are not really any such keys in
existence.
Thanks to Lukey for finding this optimisation.
2020-07-07 17:46:45 +00:00
|
|
|
|
2015-06-02 18:20:38 +00:00
|
|
|
incompletekeys = staleKeysPrune gitAnnexTmpObjectDir True
|
sped up the --all option by 2x to 16x by using git cat-file --buffer
This assumes that no location log files will have a newline or carriage
return in their name. catObjectStream skips any such files due to
cat-file not supporting them.
Keys have been prevented from containing newlines since 2011,
commit 480495beb4a3422f006ee529df807a20cc944727. If some old repo
had a key with a newline in it, --all will just skip processing that key.
Other things, like .git/annex/unused files certianly assume no newlines in
keys too, and AFAICR, such keys never actually worked.
Carriage return is escaped by preSanitizeKeyName since 2013. WORM keys
generated before that point could perhaps contain a CR. (URL probably not,
http probably doesn't support an URL with a raw CR in it.) So, added
a warning in fsck about such keys. Although, fsck --all will naturally
skip them, so won't be able to warn about them. Not entirely
satisfactory, but I'll bet there are not really any such keys in
existence.
Thanks to Lukey for finding this optimisation.
2020-07-07 17:46:45 +00:00
|
|
|
|
|
|
|
-- List all location log files on the git-annex branch,
|
|
|
|
-- and use those to get keys. Pass through cat-file
|
|
|
|
-- to get the contents of the location logs, and pre-cache
|
|
|
|
-- those. This significantly speeds up typical operations
|
|
|
|
-- that need to look at the location log for each key.
|
|
|
|
runallkeys = do
|
|
|
|
keyaction <- mkkeyaction
|
|
|
|
config <- Annex.getGitConfig
|
|
|
|
g <- Annex.gitRepo
|
|
|
|
|
|
|
|
void Annex.Branch.update
|
|
|
|
(l, cleanup) <- inRepo $ LsTree.lsTree
|
|
|
|
LsTree.LsTreeRecursive
|
|
|
|
Annex.Branch.fullname
|
|
|
|
let getk = locationLogFileKey config . getTopFilePath
|
|
|
|
let go reader = liftIO reader >>= \case
|
|
|
|
Nothing -> return ()
|
|
|
|
Just (f, content) -> do
|
|
|
|
case getk f of
|
|
|
|
Just k -> do
|
2020-07-08 17:56:14 +00:00
|
|
|
maybe noop (Annex.BranchState.setCache (getTopFilePath f)) content
|
sped up the --all option by 2x to 16x by using git cat-file --buffer
This assumes that no location log files will have a newline or carriage
return in their name. catObjectStream skips any such files due to
cat-file not supporting them.
Keys have been prevented from containing newlines since 2011,
commit 480495beb4a3422f006ee529df807a20cc944727. If some old repo
had a key with a newline in it, --all will just skip processing that key.
Other things, like .git/annex/unused files certianly assume no newlines in
keys too, and AFAICR, such keys never actually worked.
Carriage return is escaped by preSanitizeKeyName since 2013. WORM keys
generated before that point could perhaps contain a CR. (URL probably not,
http probably doesn't support an URL with a raw CR in it.) So, added
a warning in fsck about such keys. Although, fsck --all will naturally
skip them, so won't be able to warn about them. Not entirely
satisfactory, but I'll bet there are not really any such keys in
existence.
Thanks to Lukey for finding this optimisation.
2020-07-07 17:46:45 +00:00
|
|
|
keyaction (k, mkActionItem k)
|
|
|
|
Nothing -> return ()
|
|
|
|
go reader
|
2020-07-10 19:11:14 +00:00
|
|
|
catObjectStreamLsTree l (isJust . getk . LsTree.file) g go
|
sped up the --all option by 2x to 16x by using git cat-file --buffer
This assumes that no location log files will have a newline or carriage
return in their name. catObjectStream skips any such files due to
cat-file not supporting them.
Keys have been prevented from containing newlines since 2011,
commit 480495beb4a3422f006ee529df807a20cc944727. If some old repo
had a key with a newline in it, --all will just skip processing that key.
Other things, like .git/annex/unused files certianly assume no newlines in
keys too, and AFAICR, such keys never actually worked.
Carriage return is escaped by preSanitizeKeyName since 2013. WORM keys
generated before that point could perhaps contain a CR. (URL probably not,
http probably doesn't support an URL with a raw CR in it.) So, added
a warning in fsck about such keys. Although, fsck --all will naturally
skip them, so won't be able to warn about them. Not entirely
satisfactory, but I'll bet there are not really any such keys in
existence.
Thanks to Lukey for finding this optimisation.
2020-07-07 17:46:45 +00:00
|
|
|
liftIO $ void cleanup
|
|
|
|
|
|
|
|
runkeyaction 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
|
sped up the --all option by 2x to 16x by using git cat-file --buffer
This assumes that no location log files will have a newline or carriage
return in their name. catObjectStream skips any such files due to
cat-file not supporting them.
Keys have been prevented from containing newlines since 2011,
commit 480495beb4a3422f006ee529df807a20cc944727. If some old repo
had a key with a newline in it, --all will just skip processing that key.
Other things, like .git/annex/unused files certianly assume no newlines in
keys too, and AFAICR, such keys never actually worked.
Carriage return is escaped by preSanitizeKeyName since 2013. WORM keys
generated before that point could perhaps contain a CR. (URL probably not,
http probably doesn't support an URL with a raw CR in it.) So, added
a warning in fsck about such keys. Although, fsck --all will naturally
skip them, so won't be able to warn about them. Not entirely
satisfactory, but I'll bet there are not really any such keys in
existence.
Thanks to Lukey for finding this optimisation.
2020-07-07 17:46:45 +00:00
|
|
|
forM_ ks $ \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
|
2019-02-21 21:32:59 +00:00
|
|
|
(l, cleanup) <- inRepo $ LsTree.lsTree LsTree.LsTreeRecursive b
|
2019-06-06 16:53:24 +00:00
|
|
|
forM_ l $ \i -> catKey (LsTree.sha i) >>= \case
|
|
|
|
Nothing -> noop
|
|
|
|
Just k ->
|
|
|
|
let bfp = mkActionItem (BranchFilePath b (LsTree.file i), k)
|
|
|
|
in keyaction (k, bfp)
|
2016-07-20 17:44:33 +00:00
|
|
|
unlessM (liftIO cleanup) $
|
|
|
|
error ("git ls-tree " ++ Git.fromRef b ++ " failed")
|
sped up the --all option by 2x to 16x by using git cat-file --buffer
This assumes that no location log files will have a newline or carriage
return in their name. catObjectStream skips any such files due to
cat-file not supporting them.
Keys have been prevented from containing newlines since 2011,
commit 480495beb4a3422f006ee529df807a20cc944727. If some old repo
had a key with a newline in it, --all will just skip processing that key.
Other things, like .git/annex/unused files certianly assume no newlines in
keys too, and AFAICR, such keys never actually worked.
Carriage return is escaped by preSanitizeKeyName since 2013. WORM keys
generated before that point could perhaps contain a CR. (URL probably not,
http probably doesn't support an URL with a raw CR in it.) So, added
a warning in fsck about such keys. Although, fsck --all will naturally
skip them, so won't be able to warn about them. Not entirely
satisfactory, but I'll bet there are not really any such keys in
existence.
Thanks to Lukey for finding this optimisation.
2020-07-07 17:46:45 +00:00
|
|
|
|
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
|
|
|
|
2020-07-10 17:54:52 +00:00
|
|
|
seekFiltered :: (RawFilePath -> CommandSeek) -> Annex [RawFilePath] -> Annex ()
|
|
|
|
seekFiltered a fs = do
|
2011-10-30 03:48:46 +00:00
|
|
|
matcher <- Limit.getMatcher
|
2020-07-10 17:54:52 +00:00
|
|
|
sequence_ =<< (map (process matcher) <$> fs)
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2019-11-26 19:27:22 +00:00
|
|
|
process matcher f =
|
2019-12-09 17:49:05 +00:00
|
|
|
whenM (matcher $ MatchingFile $ FileInfo f f) $ a f
|
2011-10-30 03:48:46 +00:00
|
|
|
|
2020-07-10 19:11:14 +00:00
|
|
|
-- This is significantly faster than using lookupKey after seekFiltered.
|
2020-07-10 18:17:35 +00:00
|
|
|
seekFilteredKeys :: (RawFilePath -> Key -> CommandSeek) -> Annex [(RawFilePath, Git.Sha, FileMode)] -> Annex ()
|
2020-07-13 16:36:15 +00:00
|
|
|
seekFilteredKeys a listfs = do
|
2020-07-10 17:54:52 +00:00
|
|
|
g <- Annex.gitRepo
|
2020-07-10 19:11:14 +00:00
|
|
|
matcher <- Limit.getMatcher
|
2020-07-13 16:36:15 +00:00
|
|
|
-- Run here, not in the async, because it could throw an exception
|
|
|
|
-- The list should be built lazily.
|
|
|
|
l <- listfs
|
2020-07-13 18:09:08 +00:00
|
|
|
catObjectMetaDataStream g $ \mdfeeder mdcloser mdreader ->
|
|
|
|
catObjectStream g $ \feeder closer reader -> do
|
|
|
|
processertid <- liftIO . async =<< forkState
|
|
|
|
(process matcher feeder mdfeeder mdcloser False l)
|
|
|
|
mdprocessertid <- liftIO . async =<< forkState
|
|
|
|
(mdprocess matcher mdreader feeder closer)
|
|
|
|
goread reader
|
|
|
|
join (liftIO (wait mdprocessertid))
|
|
|
|
join (liftIO (wait processertid))
|
2020-07-10 17:54:52 +00:00
|
|
|
where
|
|
|
|
goread reader = liftIO reader >>= \case
|
|
|
|
Just (f, content) -> do
|
|
|
|
maybe noop (a f) (parseLinkTargetOrPointerLazy =<< content)
|
|
|
|
goread reader
|
2020-07-10 19:11:14 +00:00
|
|
|
Nothing -> return ()
|
|
|
|
|
|
|
|
feedmatches matcher feeder f sha =
|
|
|
|
whenM (matcher $ MatchingFile $ FileInfo f f) $
|
|
|
|
liftIO $ feeder (f, sha)
|
|
|
|
|
2020-07-13 18:09:08 +00:00
|
|
|
process matcher feeder mdfeeder mdcloser seenpointer ((f, sha, mode):rest) =
|
|
|
|
case Git.toTreeItemType mode of
|
|
|
|
Just Git.TreeSymlink -> do
|
|
|
|
-- Once a pointer file has been seen,
|
|
|
|
-- symlinks have to be sent via the
|
|
|
|
-- metadata processor too. That is slightly
|
|
|
|
-- slower, but preserves the requested
|
|
|
|
-- file order.
|
|
|
|
if seenpointer
|
|
|
|
then liftIO $ mdfeeder (f, sha)
|
|
|
|
else feedmatches matcher feeder f sha
|
|
|
|
process matcher feeder mdfeeder mdcloser seenpointer rest
|
|
|
|
Just Git.TreeSubmodule ->
|
|
|
|
process matcher feeder mdfeeder mdcloser seenpointer rest
|
2020-07-10 19:11:14 +00:00
|
|
|
-- Might be a pointer file, might be other
|
|
|
|
-- file in git, possibly large. Avoid catting
|
|
|
|
-- large files by first looking up the size.
|
2020-07-13 18:09:08 +00:00
|
|
|
Just _ -> do
|
|
|
|
liftIO $ mdfeeder (f, sha)
|
|
|
|
process matcher feeder mdfeeder mdcloser True rest
|
|
|
|
Nothing ->
|
|
|
|
process matcher feeder mdfeeder mdcloser seenpointer rest
|
|
|
|
process _ _ _ mdcloser _ [] = liftIO $ void mdcloser
|
|
|
|
|
|
|
|
mdprocess matcher mdreader feeder closer = liftIO mdreader >>= \case
|
|
|
|
Just (f, Just (sha, size, _type))
|
|
|
|
| size < maxPointerSz -> do
|
|
|
|
feedmatches matcher feeder f sha
|
|
|
|
mdprocess matcher mdreader feeder closer
|
|
|
|
Just _ -> mdprocess matcher mdreader feeder closer
|
|
|
|
Nothing -> liftIO $ void closer
|
2020-07-10 19:11:14 +00:00
|
|
|
|
2020-07-10 17:54:52 +00:00
|
|
|
seekHelper :: (a -> RawFilePath) -> WarnUnmatchWhen -> ([LsFiles.Options] -> [RawFilePath] -> Git.Repo -> IO ([a], IO Bool)) -> [WorkTreeItem] -> Annex [a]
|
|
|
|
seekHelper c ww a l = do
|
2020-05-28 19:55:17 +00:00
|
|
|
os <- seekOptions ww
|
|
|
|
inRepo $ \g ->
|
|
|
|
concat . concat <$> forM (segmentXargsOrdered l')
|
2020-07-10 17:54:52 +00:00
|
|
|
(runSegmentPaths c (\fs -> Git.Command.leaveZombie <$> a os fs g) . map toRawFilePath)
|
2017-10-16 18:10:03 +00:00
|
|
|
where
|
|
|
|
l' = map (\(WorkTreeItem f) -> f) l
|
|
|
|
|
2020-05-28 19:55:17 +00:00
|
|
|
data WarnUnmatchWhen = WarnUnmatchLsFiles | WarnUnmatchWorkTreeItems
|
|
|
|
|
|
|
|
seekOptions :: WarnUnmatchWhen -> Annex [LsFiles.Options]
|
|
|
|
seekOptions WarnUnmatchLsFiles =
|
|
|
|
ifM (annexSkipUnknown <$> Annex.getGitConfig)
|
|
|
|
( return []
|
|
|
|
, return [LsFiles.ErrorUnmatch]
|
|
|
|
)
|
|
|
|
seekOptions WarnUnmatchWorkTreeItems = return []
|
|
|
|
|
2017-10-16 18:10:03 +00:00
|
|
|
-- An item in the work tree, which may be a file or a directory.
|
2019-11-26 19:27:22 +00:00
|
|
|
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
|
|
|
|
|
2020-05-28 19:55:17 +00:00
|
|
|
-- git ls-files without --error-unmatch seeks work tree items matching
|
|
|
|
-- some criteria, and silently skips over anything that does not exist.
|
|
|
|
|
2020-05-11 19:03:35 +00:00
|
|
|
-- Also, when two directories are symlinked, referring to a file
|
2020-05-28 19:55:17 +00:00
|
|
|
-- inside the symlinked directory will be silently skipped by
|
|
|
|
-- git ls-files without --error-unmatch.
|
|
|
|
--
|
|
|
|
-- Sometimes a command needs to use git-lsfiles that way, perhaps repeatedly.
|
|
|
|
-- 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 when run with WarnUnmatchWorkTreeItems.
|
|
|
|
--
|
|
|
|
-- Note that, unlike --error-unmatch, using this does not warn
|
|
|
|
-- about command-line parameters that exist, but are not checked into git.
|
|
|
|
workTreeItems :: WarnUnmatchWhen -> CmdParams -> Annex [WorkTreeItem]
|
2018-10-19 21:51:25 +00:00
|
|
|
workTreeItems = workTreeItems' (AllowHidden False)
|
|
|
|
|
2020-05-28 19:55:17 +00:00
|
|
|
workTreeItems' :: AllowHidden -> WarnUnmatchWhen -> CmdParams -> Annex [WorkTreeItem]
|
|
|
|
workTreeItems' (AllowHidden allowhidden) ww ps = do
|
|
|
|
case ww of
|
|
|
|
WarnUnmatchWorkTreeItems -> runcheck
|
|
|
|
WarnUnmatchLsFiles ->
|
|
|
|
whenM (annexSkipUnknown <$> Annex.getGitConfig)
|
|
|
|
runcheck
|
|
|
|
return (map WorkTreeItem ps)
|
2018-10-19 21:51:25 +00:00
|
|
|
where
|
2020-05-28 19:55:17 +00:00
|
|
|
runcheck = do
|
|
|
|
currbranch <- getCurrentBranch
|
|
|
|
forM_ ps $ \p -> do
|
|
|
|
relf <- liftIO $ relPathCwdToFile p
|
|
|
|
ifM (not <$> (exists p <||> hidden currbranch relf))
|
|
|
|
( prob (p ++ " not found")
|
|
|
|
, whenM (viasymlink (upFrom relf)) $
|
|
|
|
prob (p ++ " is beyond a symbolic link")
|
|
|
|
)
|
|
|
|
|
2018-10-19 21:51:25 +00:00
|
|
|
exists p = isJust <$> liftIO (catchMaybeIO $ getSymbolicLinkStatus p)
|
2020-05-11 19:03:35 +00:00
|
|
|
|
|
|
|
viasymlink Nothing = return False
|
|
|
|
viasymlink (Just p) =
|
|
|
|
ifM (liftIO $ isSymbolicLink <$> getSymbolicLinkStatus p)
|
|
|
|
( return True
|
|
|
|
, viasymlink (upFrom p)
|
|
|
|
)
|
|
|
|
|
|
|
|
hidden currbranch f
|
|
|
|
| allowhidden = isJust
|
|
|
|
<$> catObjectMetaDataHidden (toRawFilePath f) currbranch
|
2018-10-19 21:51:25 +00:00
|
|
|
| otherwise = return False
|
2017-06-01 15:40:47 +00:00
|
|
|
|
2020-05-11 19:03:35 +00:00
|
|
|
prob msg = do
|
|
|
|
toplevelWarning False msg
|
|
|
|
Annex.incError
|
|
|
|
|
2019-11-25 20:18:19 +00:00
|
|
|
notSymlink :: RawFilePath -> IO Bool
|
2019-12-06 19:37:12 +00:00
|
|
|
notSymlink f = liftIO $ not . isSymbolicLink <$> R.getSymbolicLinkStatus f
|