summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Annex/Init.hs18
-rw-r--r--Annex/UUID.hs12
-rw-r--r--Assistant/XMPP/Git.hs2
-rw-r--r--CmdLine/GitAnnex.hs2
-rw-r--r--Command/Reinit.hs38
-rw-r--r--Types/UUID.hs5
-rw-r--r--debian/changelog4
-rw-r--r--doc/git-annex.mdwn11
8 files changed, 81 insertions, 11 deletions
diff --git a/Annex/Init.hs b/Annex/Init.hs
index 0cb41872c..637b130ee 100644
--- a/Annex/Init.hs
+++ b/Annex/Init.hs
@@ -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
diff --git a/Annex/UUID.hs b/Annex/UUID.hs
index 4e274503b..5ed887689 100644
--- a/Annex/UUID.hs
+++ b/Annex/UUID.hs
@@ -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
diff --git a/Assistant/XMPP/Git.hs b/Assistant/XMPP/Git.hs
index ab34dce1e..36ada5c08 100644
--- a/Assistant/XMPP/Git.hs
+++ b/Assistant/XMPP/Git.hs
@@ -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)
diff --git a/CmdLine/GitAnnex.hs b/CmdLine/GitAnnex.hs
index 7fdad4dae..523c3f055 100644
--- a/CmdLine/GitAnnex.hs
+++ b/CmdLine/GitAnnex.hs
@@ -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
diff --git a/Command/Reinit.hs b/Command/Reinit.hs
new file mode 100644
index 000000000..0fc1e8314
--- /dev/null
+++ b/Command/Reinit.hs
@@ -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
diff --git a/Types/UUID.hs b/Types/UUID.hs
index 8a304dffa..df3884059 100644
--- a/Types/UUID.hs
+++ b/Types/UUID.hs
@@ -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
diff --git a/debian/changelog b/debian/changelog
index 08703d9c5..5fcec002a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -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
diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn
index d6f3d21b2..32680b32c 100644
--- a/doc/git-annex.mdwn
+++ b/doc/git-annex.mdwn
@@ -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 ...]`