summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Command/Whereis.hs18
-rw-r--r--GitAnnex/Options.hs2
-rw-r--r--Seek.hs31
-rw-r--r--debian/changelog3
-rw-r--r--doc/git-annex.mdwn4
-rw-r--r--doc/todo/Enhancement:_git_annex_whereis_KEY.mdwn12
6 files changed, 53 insertions, 17 deletions
diff --git a/Command/Whereis.hs b/Command/Whereis.hs
index 4030cf2f8..0083f8c5c 100644
--- a/Command/Whereis.hs
+++ b/Command/Whereis.hs
@@ -14,20 +14,30 @@ import Command
import Remote
import Logs.Trust
import GitAnnex.Options
+import Types.Key
def :: [Command]
-def = [noCommit $ withOptions [jsonOption] $
+def = [noCommit $ withOptions (jsonOption : keyOptions) $
command "whereis" paramPaths seek SectionQuery
"lists repositories that have file content"]
seek :: CommandSeek
seek ps = do
m <- remoteMap id
- withFilesInGit (whenAnnexed $ start m) ps
+ withKeyOptions
+ (startKeys m)
+ (withFilesInGit $ whenAnnexed $ start m)
+ ps
start :: M.Map UUID Remote -> FilePath -> (Key, Backend) -> CommandStart
-start remotemap file (key, _) = do
- showStart "whereis" file
+start remotemap file (key, _) = start' remotemap key (Just file)
+
+startKeys :: M.Map UUID Remote -> Key -> CommandStart
+startKeys remotemap key = start' remotemap key Nothing
+
+start' :: M.Map UUID Remote -> Key -> AssociatedFile -> CommandStart
+start' remotemap key afile = do
+ showStart "whereis" (fromMaybe (key2file key) afile)
next $ perform remotemap key
perform :: M.Map UUID Remote -> Key -> CommandPerform
diff --git a/GitAnnex/Options.hs b/GitAnnex/Options.hs
index dc9a0be31..235ea00e9 100644
--- a/GitAnnex/Options.hs
+++ b/GitAnnex/Options.hs
@@ -81,6 +81,8 @@ keyOptions =
"operate on all versions of all files"
, Option ['U'] ["unused"] (NoArg (Annex.setFlag "unused"))
"operate on files found by last run of git-annex unused"
+ , Option [] ["key"] (ReqArg (Annex.setField "key") paramKey)
+ "operate on specified key"
]
fromOption :: Option
diff --git a/Seek.hs b/Seek.hs
index 3242dfb33..feb94627b 100644
--- a/Seek.hs
+++ b/Seek.hs
@@ -123,6 +123,8 @@ withNothing _ _ = error "This command takes no parameters."
- If --unused is specified, runs an action on all keys found by
- the last git annex unused scan.
-
+ - If --key is specified, operates only on that key.
+ -
- Otherwise, fall back to a regular CommandSeek action on
- whatever params were passed. -}
withKeyOptions :: (Key -> CommandStart) -> CommandSeek -> CommandSeek
@@ -130,21 +132,24 @@ withKeyOptions keyop fallbackop params = do
bare <- fromRepo Git.repoIsLocalBare
allkeys <- Annex.getFlag "all"
unused <- Annex.getFlag "unused"
+ specifickey <- Annex.getField "key"
auto <- Annex.getState Annex.auto
- case (allkeys || bare , unused, auto ) of
- (True , False , False) -> go loggedKeys
- (False , True , False) -> go unusedKeys'
- (True , True , _ )
- | bare && not allkeys -> go unusedKeys'
- | otherwise -> error "Cannot use --all with --unused."
- (False , False , _ ) -> fallbackop params
- (_ , _ , True )
- | bare -> error "Cannot use --auto in a bare repository."
- | otherwise -> error "Cannot use --auto with --all or --unused."
+ when (auto && bare) $
+ error "Cannot use --auto in a bare repository"
+ case (allkeys, unused, null params, specifickey) of
+ (False , False , True , Nothing)
+ | bare -> go auto loggedKeys
+ | otherwise -> fallbackop params
+ (False , False , _ , Nothing) -> fallbackop params
+ (True , False , True , Nothing) -> go auto loggedKeys
+ (False , True , True , Nothing) -> go auto unusedKeys'
+ (False , False , True , Just ks) -> case file2key ks of
+ Nothing -> error "Invalid key"
+ Just k -> go auto $ return [k]
+ _ -> error "Can only specify one of file names, --all, --unused, or --key"
where
- go a = do
- unless (null params) $
- error "Cannot mix --all or --unused with file names."
+ go True _ = error "Cannot use --auto with --all or --unused or --key"
+ go False a = do
matcher <- Limit.getMatcher
seekActions $ map (process matcher) <$> a
process matcher k = ifM (matcher $ MatchingKey k)
diff --git a/debian/changelog b/debian/changelog
index d3ef17dd1..ca4c7c6dc 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -37,6 +37,9 @@ git-annex (5.20140118) UNRELEASED; urgency=medium
http remote.
* webapp: After upgrading a git repository to git-annex, fix
bug that made it temporarily not be synced with.
+ * whereis: Support --all.
+ * All commands that support --all also support a --key option,
+ which limits them to acting on a single key.
-- Joey Hess <joeyh@debian.org> Sat, 18 Jan 2014 11:54:17 -0400
diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn
index 4deb715d7..fa1175fb6 100644
--- a/doc/git-annex.mdwn
+++ b/doc/git-annex.mdwn
@@ -860,6 +860,10 @@ subdirectories).
Operate on all data that has been determined to be unused by
a previous run of `git-annex unused`.
+* `--key=key`
+
+ Operate on only the specified key.
+
* `--quiet`
Avoid the default verbose display of what is done; only show errors
diff --git a/doc/todo/Enhancement:_git_annex_whereis_KEY.mdwn b/doc/todo/Enhancement:_git_annex_whereis_KEY.mdwn
index 684a1e4fa..604bc5566 100644
--- a/doc/todo/Enhancement:_git_annex_whereis_KEY.mdwn
+++ b/doc/todo/Enhancement:_git_annex_whereis_KEY.mdwn
@@ -5,3 +5,15 @@ Great work on git annex! One possible enhancement occured to me: It would be ver
In a related vein, the "unused" command could report old filenames or describe the associated commits. Tracking old versions is a great feature of your git-based approach, but currently, tasks such as pruning selected content seem unwiedly. Though I might be missing existing solutions. You can easily "cut-off" the history by forcing a drop of all unused content. It would be cool if one could somehow "address" old versions by filename and commit/date and selectively drop just these. The same could go for the "whereis" command, where one could e.g. query which remote holds content which was stored under some filename at some specific date.
Thanks Cheers!
+
+> I agree that it's useful to run whereis on a specific key. This can
+> now be done using `git annex whereis --key KEY`
+> [[done]] --[[Joey]]
+>
+> To report old filenames, unused would have to search back through the
+> contents of symlinks in old versions of the repo, to find symlinks that
+> referred to a key. The best way I know how to do that is `git log -S$KEY`,
+> which is what unused suggests you use. But this is slow --
+> searching for a single key in one of my repos takes 25 seconds.
+> That's why it doesn't do it for you.
+>