The fromkey command now takes the key as its first parameter. The --key option is no longer used.

This commit is contained in:
Joey Hess 2011-10-31 12:47:13 -04:00
parent cc1ea8f844
commit 380839299e
8 changed files with 27 additions and 43 deletions

View file

@ -60,7 +60,6 @@ data AnnexState = AnnexState
, catfilehandle :: Maybe CatFileHandle
, forcebackend :: Maybe String
, forcenumcopies :: Maybe Int
, defaultkey :: Maybe String
, toremote :: Maybe String
, fromremote :: Maybe String
, limit :: Either [Utility.Matcher.Token (FilePath -> Annex Bool)] (Utility.Matcher.Matcher (FilePath -> Annex Bool))
@ -85,7 +84,6 @@ newState gitrepo = AnnexState
, catfilehandle = Nothing
, forcebackend = Nothing
, forcenumcopies = Nothing
, defaultkey = Nothing
, toremote = Nothing
, fromremote = Nothing
, limit = Left []

View file

@ -12,26 +12,26 @@ import Command
import qualified Annex.Queue
import Annex.Content
import Types.Key
import Config
def :: [Command]
def = [command "fromkey" paramPath seek "adds a file using a specific key"]
def = [command "fromkey" (paramPair paramKey paramPath) seek
"adds a file using a specific key"]
seek :: [CommandSeek]
seek = [withFilesMissing start]
seek = [withWords start]
start :: FilePath -> CommandStart
start file = notBareRepo $ do
key <- cmdlineKey
start :: [String] -> CommandStart
start (keyname:file:[]) = notBareRepo $ do
let key = maybe (error "bad key") id $ readKey keyname
inbackend <- inAnnex key
unless inbackend $ error $
"key ("++keyName key++") is not present in backend"
"key ("++ keyname ++") is not present in backend"
showStart "fromkey" file
next $ perform file
next $ perform key file
start _ = error "specify a key and a dest file"
perform :: FilePath -> CommandPerform
perform file = do
key <- cmdlineKey
perform :: Key -> FilePath -> CommandPerform
perform key file = do
link <- calcGitLink file key
liftIO $ createDirectoryIfMissing True (parentDir file)
liftIO $ createSymbolicLink link file

View file

@ -23,7 +23,7 @@ seek = [withWords start]
start :: [FilePath] -> CommandStart
start (src:dest:[]) = do
showStart "setkey" dest
showStart "setcontent" dest
next $ perform src dest
start _ = error "specify a src file and a dest file"

View file

@ -10,7 +10,6 @@ module Config where
import Common.Annex
import qualified Git
import qualified Annex
import Types.Key (readKey)
type ConfigKey = String
@ -92,15 +91,3 @@ getNumCopies v =
g <- gitRepo
return $ read $ Git.configGet g config "1"
config = "annex.numcopies"
{- The Key specified by the --key parameter. -}
cmdlineKey :: Annex Key
cmdlineKey = do
k <- Annex.getState Annex.defaultkey
case k of
Nothing -> nokey
Just "" -> nokey
Just kstring -> maybe badkey return $ readKey kstring
where
nokey = error "please specify the key with --key"
badkey = error "bad key"

2
debian/changelog vendored
View file

@ -15,6 +15,8 @@ git-annex (3.20111026) UNRELEASED; urgency=low
* unused, dropunused: Now work in bare repositories.
* Removed the setkey command, and added a setcontent command with a more
useful interface.
* The fromkey command now takes the key as its first parameter. The --key
option is no longer used.
-- Joey Hess <joeyh@debian.org> Thu, 27 Oct 2011 13:58:53 -0400

View file

@ -4,5 +4,6 @@
subject="comment 4"
date="2011-05-14T16:29:35Z"
content="""
Although, if you really do want to shoot yourself in the foot, or know you have the old content, you can use `git-annex setkey`.
Although, if you really do want to shoot yourself in the foot, or know you
have the old content, you can use `git-annex setcontent`.
"""]]

View file

@ -318,7 +318,7 @@ subdirectories).
This is meant to be called from git's pre-commit hook. `git annex init`
automatically creates a pre-commit hook using this.
* fromkey file
* fromkey key file
This plumbing-level command can be used to manually set up a file
in the git repository to link to a specified key.
@ -406,10 +406,6 @@ subdirectories).
are in the annex, their backend is known and this option is not
necessary.
* --key=name
Specifies a key to operate on.
* -c name=value
Used to override git configuration settings. May be specified multiple times.

20
test.hs
View file

@ -88,7 +88,7 @@ blackbox = TestLabel "blackbox" $ TestList
-- test order matters, later tests may rely on state from earlier
[ test_init
, test_add
, test_setkey
, test_setcontent
, test_unannex
, test_drop
, test_get
@ -118,15 +118,15 @@ test_add = "git-annex add" ~: TestList [basic, sha1dup, subdirs]
writeFile annexedfile $ content annexedfile
git_annex "add" ["-q", annexedfile] @? "add failed"
annexed_present annexedfile
writeFile sha1annexedfile $ content sha1annexedfile
git_annex "add" ["-q", sha1annexedfile, "--backend=SHA1"] @? "add with SHA1 failed"
annexed_present sha1annexedfile
writeFile ingitfile $ content ingitfile
boolSystem "git" [Param "add", File ingitfile] @? "git add failed"
boolSystem "git" [Params "commit -q -a -m commit"] @? "git commit failed"
git_annex "add" ["-q", ingitfile] @? "add ingitfile should be no-op"
unannexed ingitfile
sha1dup = TestCase $ intmpclonerepo $ do
writeFile sha1annexedfile $ content sha1annexedfile
git_annex "add" ["-q", sha1annexedfile, "--backend=SHA1"] @? "add with SHA1 failed"
annexed_present sha1annexedfile
writeFile sha1annexedfiledup $ content sha1annexedfiledup
git_annex "add" ["-q", sha1annexedfiledup, "--backend=SHA1"] @? "add of second file with same SHA1 failed"
annexed_present sha1annexedfiledup
@ -140,15 +140,15 @@ test_add = "git-annex add" ~: TestList [basic, sha1dup, subdirs]
changeWorkingDirectory "dir"
git_annex "add" ["-q", "../dir2"] @? "add of ../subdir failed"
test_setkey :: Test
test_setkey = "git-annex setkey/fromkey" ~: TestCase $ inmainrepo $ do
test_setcontent :: Test
test_setcontent = "git-annex setcontent/fromkey" ~: TestCase $ intmpclonerepo $ do
git_annex "drop" ["-q", "--force", sha1annexedfile] @? "drop failed"
writeFile tmp $ content sha1annexedfile
r <- annexeval $ Types.Backend.getKey backendSHA1 tmp
let key = show $ fromJust r
git_annex "setkey" ["-q", "--key", key, tmp] @? "setkey failed"
git_annex "fromkey" ["-q", "--key", key, sha1annexedfile] @? "fromkey failed"
boolSystem "git" [Params "commit -q -a -m commit"] @? "git commit failed"
annexed_present sha1annexedfile
git_annex "setcontent" ["-q", tmp, sha1annexedfile] @? "setcontent failed"
git_annex "fromkey" ["-q", key, sha1annexedfiledup] @? "fromkey failed"
annexed_present sha1annexedfiledup
where
tmp = "tmpfile"