reinit: New command that can initialize a new reposotory using the configuration of a previously known repository. Useful if a repository got deleted and you want to clone it back the way it was.

This commit is contained in:
Joey Hess 2014-04-15 20:13:35 -04:00
parent 162565d928
commit 915d038bec
8 changed files with 81 additions and 11 deletions

View file

@ -11,6 +11,7 @@ module Annex.Init (
ensureInitialized,
isInitialized,
initialize,
initialize',
uninitialize,
probeCrippledFileSystem,
) where
@ -60,6 +61,17 @@ genDescription Nothing = do
initialize :: Maybe String -> Annex ()
initialize mdescription = do
prepUUID
initialize'
u <- getUUID
{- This will make the first commit to git, so ensure git is set up
- properly to allow commits when running it. -}
ensureCommit $ do
Annex.Branch.create
describeUUID u =<< genDescription mdescription
initialize' :: Annex ()
initialize' = do
checkFifoSupport
checkCrippledFileSystem
unlessM isBare $
@ -75,12 +87,6 @@ initialize mdescription = do
switchHEADBack
)
createInodeSentinalFile
u <- getUUID
{- This will make the first commit to git, so ensure git is set up
- properly to allow commits when running it. -}
ensureCommit $ do
Annex.Branch.create
describeUUID u =<< genDescription mdescription
uninitialize :: Annex ()
uninitialize = do

View file

@ -21,6 +21,7 @@ module Annex.UUID (
gCryptNameSpace,
removeRepoUUID,
storeUUID,
storeUUIDIn,
setUUID,
) where
@ -70,7 +71,7 @@ getRepoUUID r = do
where
updatecache u = do
g <- gitRepo
when (g /= r) $ storeUUID cachekey u
when (g /= r) $ storeUUIDIn cachekey u
cachekey = remoteConfig r "uuid"
removeRepoUUID :: Annex ()
@ -84,10 +85,13 @@ getUncachedUUID = toUUID . Git.Config.get key ""
{- Make sure that the repo has an annex.uuid setting. -}
prepUUID :: Annex ()
prepUUID = whenM ((==) NoUUID <$> getUUID) $
storeUUID configkey =<< liftIO genUUID
storeUUID =<< liftIO genUUID
storeUUID :: ConfigKey -> UUID -> Annex ()
storeUUID configfield = setConfig configfield . fromUUID
storeUUID :: UUID -> Annex ()
storeUUID = storeUUIDIn configkey
storeUUIDIn :: ConfigKey -> UUID -> Annex ()
storeUUIDIn configfield = setConfig configfield . fromUUID
{- Only sets the configkey in the Repo; does not change .git/config -}
setUUID :: Git.Repo -> UUID -> IO Git.Repo

View file

@ -74,7 +74,7 @@ makeXMPPGitRemote :: String -> JID -> UUID -> Assistant Bool
makeXMPPGitRemote buddyname jid u = do
remote <- liftAnnex $ addRemote $
makeGitRemote buddyname $ gitXMPPLocation jid
liftAnnex $ storeUUID (remoteConfig (Remote.repo remote) "uuid") u
liftAnnex $ storeUUIDIn (remoteConfig (Remote.repo remote) "uuid") u
liftAnnex $ void remoteListRefresh
remote' <- liftAnnex $ fromMaybe (error "failed to add remote")
<$> Remote.byName (Just buddyname)

View file

@ -57,6 +57,7 @@ import qualified Command.Info
import qualified Command.Status
import qualified Command.Migrate
import qualified Command.Uninit
import qualified Command.Reinit
import qualified Command.NumCopies
import qualified Command.Trust
import qualified Command.Untrust
@ -125,6 +126,7 @@ cmds = concat
, Command.Reinject.def
, Command.Unannex.def
, Command.Uninit.def
, Command.Reinit.def
, Command.PreCommit.def
, Command.NumCopies.def
, Command.Trust.def

38
Command/Reinit.hs Normal file
View file

@ -0,0 +1,38 @@
{- git-annex command
-
- Copyright 2014 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Command.Reinit where
import Common.Annex
import Command
import Annex.Init
import Annex.UUID
import Types.UUID
import qualified Remote
def :: [Command]
def = [dontCheck repoExists $
command "reinit" (paramUUID ++ " or " ++ paramDesc) seek SectionUtility ""]
seek :: CommandSeek
seek = withWords start
start :: [String] -> CommandStart
start ws = do
showStart "reinit" s
next $ perform s
where
s = unwords ws
perform :: String -> CommandPerform
perform s = do
u <- if isUUID s
then return $ toUUID s
else Remote.nameToUUID s
storeUUID u
initialize'
next $ return True

View file

@ -8,6 +8,8 @@
module Types.UUID where
import qualified Data.Map as M
import qualified Data.UUID as U
import Data.Maybe
-- A UUID is either an arbitrary opaque string, or UUID info may be missing.
data UUID = NoUUID | UUID String
@ -21,4 +23,7 @@ toUUID :: String -> UUID
toUUID [] = NoUUID
toUUID s = UUID s
isUUID :: String -> Bool
isUUID = isJust . U.fromString
type UUIDMap = M.Map UUID String

4
debian/changelog vendored
View file

@ -17,6 +17,10 @@ git-annex (5.20140413) UNRELEASED; urgency=medium
* Avoid depending on shakespeare except for when building the webapp.
* uninit: Avoid making unncessary copies of files.
* info: Allow use in a repository where annex.uuid is not set.
* reinit: New command that can initialize a new reposotory using
the configuration of a previously known repository.
Useful if a repository got deleted and you want
to clone it back the way it was.
-- Joey Hess <joeyh@debian.org> Fri, 11 Apr 2014 21:33:35 -0400

View file

@ -845,6 +845,17 @@ subdirectories).
repository, and remove all of git-annex's other data, leaving you with a
git repository plus the previously annexed files.
* `reinit uuid|description`
Normally, initializing a repository generates a new, unique identifier
(UUID) for that repository. Occasionally it may be useful to reuse a
UUID -- for example, if a repository got deleted, and you're
setting it back up.
Use this with caution; it can be confusing to have two existing
repositories with the same UUID. Also, you will probably want to run
a fsck.
# PLUMBING COMMANDS
* `pre-commit [path ...]`