unused --from: Allow specifiying a repository by uuid or description.

This commit was sponsored by Jake Vosloo on Patreon.
This commit is contained in:
Joey Hess 2018-07-11 16:01:35 -04:00
parent 7f2e76c462
commit cc2cb46857
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 23 additions and 16 deletions

View file

@ -16,6 +16,7 @@ git-annex (6.20180627) UNRELEASED; urgency=medium
so they're available even when the standalone tarball is installed
in a directory owned by root. Note that this prevents using the
standalone bundle in environments where HOME is not writable.
* unused --from: Allow specifiying a repository by uuid or description.
-- Joey Hess <id@joeyh.name> Fri, 22 Jun 2018 10:36:22 -0400

View file

@ -93,15 +93,15 @@ checkUnused refspec = chain 0
v' <- a v
chain v' as
checkRemoteUnused :: String -> RefSpec -> CommandPerform
checkRemoteUnused name refspec = go =<< fromJust <$> Remote.byNameWithUUID (Just name)
checkRemoteUnused :: RemoteName -> RefSpec -> CommandPerform
checkRemoteUnused remotename refspec = go =<< Remote.nameToUUID remotename
where
go r = do
go u = do
showAction "checking for unused data"
_ <- check "" (remoteUnusedMsg r) (remoteunused r) 0
r <- Remote.byUUID u
_ <- check "" (remoteUnusedMsg r remotename) (remoteunused u) 0
next $ return True
remoteunused r = excludeReferenced refspec
<=< loggedKeysFor $ Remote.uuid r
remoteunused u = excludeReferenced refspec =<< loggedKeysFor u
check :: FilePath -> ([(Int, Key)] -> String) -> Annex [Key] -> Int -> Annex Int
check file msg a c = do
@ -142,16 +142,14 @@ unusedMsg' u mheader mtrailer = unlines $
["(To see where data was previously used, try: git log --stat -S'KEY')"] ++
mtrailer
remoteUnusedMsg :: Remote -> [(Int, Key)] -> String
remoteUnusedMsg r u = unusedMsg' u
["Some annexed data on " ++ name ++ " is not used by any files:"]
[dropMsg $ Just r]
where
name = Remote.name r
remoteUnusedMsg :: Maybe Remote -> RemoteName -> [(Int, Key)] -> String
remoteUnusedMsg mr remotename u = unusedMsg' u
["Some annexed data on " ++ remotename ++ " is not used by any files:"]
(if isJust mr then [dropMsg (Just remotename)] else [])
dropMsg :: Maybe Remote -> String
dropMsg :: Maybe RemoteName -> String
dropMsg Nothing = dropMsg' ""
dropMsg (Just r) = dropMsg' $ " --from " ++ Remote.name r
dropMsg (Just remotename) = dropMsg' $ " --from " ++ remotename
dropMsg' :: String -> String
dropMsg' s = "\nTo remove unwanted data: git-annex dropunused" ++ s ++ " NUMBER\n"

View file

@ -24,9 +24,12 @@ For example, to move all unused data to origin:
Only show unused temp and bad files.
* `--from=remote`
* `--from=repository`
Check for unused data that is located on a remote.
Check for unused data that is located in a repository.
The repository should be specified using the name of a configured remote,
or the UUID or description of a repository.
* `--used-refspec=+ref:-ref`

View file

@ -7,3 +7,8 @@ git annex unused supports an --from option to select a specific remote to find u
[...]
As git annex at least for newly-deleted files knows when those are stored in the given repository, git annex should at least find those.
> [[done]], made it suppose the uuid or description.
>
> Of course, `dropunused --from` still needs the name of a remote, so this
> is only useful for querying.. --[[Joey]]