2011-12-10 00:27:22 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2011-12-30 20:24:30 +00:00
|
|
|
- Copyright 2011 Joachim Breitner <mail@joachim-breitner.de>
|
2014-01-19 21:35:36 +00:00
|
|
|
- Copyright 2011-2014 Joey Hess <joey@kitenet.net>
|
2011-12-10 00:27:22 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Sync where
|
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import Command
|
2011-12-31 01:17:36 +00:00
|
|
|
import qualified Annex
|
2011-12-10 00:27:22 +00:00
|
|
|
import qualified Annex.Branch
|
2012-06-27 17:08:32 +00:00
|
|
|
import qualified Annex.Queue
|
2014-01-19 21:35:36 +00:00
|
|
|
import qualified Remote
|
|
|
|
import qualified Types.Remote as Remote
|
2012-12-12 23:20:38 +00:00
|
|
|
import Annex.Direct
|
2012-06-27 17:08:32 +00:00
|
|
|
import Annex.CatFile
|
fully support core.symlinks=false in all relevant symlink handling code
Refactored annex link code into nice clean new library.
Audited and dealt with calls to createSymbolicLink.
Remaining calls are all safe, because:
Annex/Link.hs: ( liftIO $ createSymbolicLink linktarget file
only when core.symlinks=true
Assistant/WebApp/Configurators/Local.hs: createSymbolicLink link link
test if symlinks can be made
Command/Fix.hs: liftIO $ createSymbolicLink link file
command only works in indirect mode
Command/FromKey.hs: liftIO $ createSymbolicLink link file
command only works in indirect mode
Command/Indirect.hs: liftIO $ createSymbolicLink l f
refuses to run if core.symlinks=false
Init.hs: createSymbolicLink f f2
test if symlinks can be made
Remote/Directory.hs: go [file] = catchBoolIO $ createSymbolicLink file f >> return True
fast key linking; catches failure to make symlink and falls back to copy
Remote/Git.hs: liftIO $ catchBoolIO $ createSymbolicLink loc file >> return True
ditto
Upgrade/V1.hs: liftIO $ createSymbolicLink link f
v1 repos could not be on a filesystem w/o symlinks
Audited and dealt with calls to readSymbolicLink.
Remaining calls are all safe, because:
Annex/Link.hs: ( liftIO $ catchMaybeIO $ readSymbolicLink file
only when core.symlinks=true
Assistant/Threads/Watcher.hs: ifM ((==) (Just link) <$> liftIO (catchMaybeIO $ readSymbolicLink file))
code that fixes real symlinks when inotify sees them
It's ok to not fix psdueo-symlinks.
Assistant/Threads/Watcher.hs: mlink <- liftIO (catchMaybeIO $ readSymbolicLink file)
ditto
Command/Fix.hs: stopUnless ((/=) (Just link) <$> liftIO (catchMaybeIO $ readSymbolicLink file)) $ do
command only works in indirect mode
Upgrade/V1.hs: getsymlink = takeFileName <$> readSymbolicLink file
v1 repos could not be on a filesystem w/o symlinks
Audited and dealt with calls to isSymbolicLink.
(Typically used with getSymbolicLinkStatus, but that is just used because
getFileStatus is not as robust; it also works on pseudolinks.)
Remaining calls are all safe, because:
Assistant/Threads/SanityChecker.hs: | isSymbolicLink s -> addsymlink file ms
only handles staging of symlinks that were somehow not staged
(might need to be updated to support pseudolinks, but this is
only a belt-and-suspenders check anyway, and I've never seen the code run)
Command/Add.hs: if isSymbolicLink s || not (isRegularFile s)
avoids adding symlinks to the annex, so not relevant
Command/Indirect.hs: | isSymbolicLink s -> void $ flip whenAnnexed f $
only allowed on systems that support symlinks
Command/Indirect.hs: whenM (liftIO $ not . isSymbolicLink <$> getSymbolicLinkStatus f) $ do
ditto
Seek.hs:notSymlink f = liftIO $ not . isSymbolicLink <$> getSymbolicLinkStatus f
used to find unlocked files, only relevant in indirect mode
Utility/FSEvents.hs: | Files.isSymbolicLink s = runhook addSymlinkHook $ Just s
Utility/FSEvents.hs: | Files.isSymbolicLink s ->
Utility/INotify.hs: | Files.isSymbolicLink s ->
Utility/INotify.hs: checkfiletype Files.isSymbolicLink addSymlinkHook f
Utility/Kqueue.hs: | Files.isSymbolicLink s = callhook addSymlinkHook (Just s) change
all above are lower-level, not relevant
Audited and dealt with calls to isSymLink.
Remaining calls are all safe, because:
Annex/Direct.hs: | isSymLink (getmode item) =
This is looking at git diff-tree objects, not files on disk
Command/Unused.hs: | isSymLink (LsTree.mode l) = do
This is looking at git ls-tree, not file on disk
Utility/FileMode.hs:isSymLink :: FileMode -> Bool
Utility/FileMode.hs:isSymLink = checkMode symbolicLinkMode
low-level
Done!!
2013-02-17 19:05:55 +00:00
|
|
|
import Annex.Link
|
2011-12-14 19:56:11 +00:00
|
|
|
import qualified Git.Command
|
2012-06-27 17:08:32 +00:00
|
|
|
import qualified Git.LsFiles as LsFiles
|
2012-06-23 14:22:56 +00:00
|
|
|
import qualified Git.Merge
|
2011-12-30 22:04:01 +00:00
|
|
|
import qualified Git.Branch
|
2011-12-15 22:11:42 +00:00
|
|
|
import qualified Git.Ref
|
|
|
|
import qualified Git
|
2012-06-27 17:08:32 +00:00
|
|
|
import Git.Types (BlobType(..))
|
2011-12-31 01:17:36 +00:00
|
|
|
import qualified Types.Remote
|
2011-12-31 07:27:37 +00:00
|
|
|
import qualified Remote.Git
|
2012-08-08 20:06:01 +00:00
|
|
|
import Types.Key
|
2012-10-11 22:39:21 +00:00
|
|
|
import Config
|
2013-05-25 22:37:56 +00:00
|
|
|
import Annex.ReplaceFile
|
2013-09-19 20:30:37 +00:00
|
|
|
import Git.FileMode
|
2014-01-19 21:35:36 +00:00
|
|
|
import Annex.Wanted
|
|
|
|
import Annex.Content
|
|
|
|
import Command.Get (getKeyFile')
|
2014-02-02 23:57:22 +00:00
|
|
|
import qualified Command.Move
|
2014-01-19 21:35:36 +00:00
|
|
|
import Logs.Location
|
|
|
|
import Annex.Drop
|
2014-02-03 02:46:55 +00:00
|
|
|
import Annex.UUID
|
2011-12-10 00:27:22 +00:00
|
|
|
|
2013-10-16 19:37:06 +00:00
|
|
|
import qualified Data.Set as S
|
2012-06-27 20:03:42 +00:00
|
|
|
import Data.Hash.MD5
|
2013-10-17 17:34:27 +00:00
|
|
|
import Control.Concurrent.MVar
|
2011-12-10 00:27:22 +00:00
|
|
|
|
|
|
|
def :: [Command]
|
2014-01-19 21:35:36 +00:00
|
|
|
def = [withOptions syncOptions $
|
|
|
|
command "sync" (paramOptional (paramRepeating paramRemote))
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
seek SectionCommon "synchronize local repository with remotes"]
|
2011-12-10 00:27:22 +00:00
|
|
|
|
2014-01-19 21:35:36 +00:00
|
|
|
syncOptions :: [Option]
|
|
|
|
syncOptions = [ contentOption ]
|
|
|
|
|
|
|
|
contentOption :: Option
|
2014-01-26 20:25:55 +00:00
|
|
|
contentOption = flagOption [] "content" "also transfer file contents"
|
2014-01-19 21:35:36 +00:00
|
|
|
|
2011-12-29 17:37:30 +00:00
|
|
|
seek :: CommandSeek
|
2011-12-31 01:17:36 +00:00
|
|
|
seek rs = do
|
2013-09-13 18:55:55 +00:00
|
|
|
prepMerge
|
2013-10-17 17:34:27 +00:00
|
|
|
|
|
|
|
-- There may not be a branch checked out until after the commit,
|
2013-11-02 19:29:38 +00:00
|
|
|
-- or perhaps after it gets merged from the remote.
|
|
|
|
-- So only look it up once it's needed, and if once there is a
|
|
|
|
-- branch, cache it.
|
2013-10-17 17:34:27 +00:00
|
|
|
mvar <- liftIO newEmptyMVar
|
|
|
|
let getbranch = ifM (liftIO $ isEmptyMVar mvar)
|
|
|
|
( do
|
2013-11-02 19:29:38 +00:00
|
|
|
branch <- inRepo Git.Branch.current
|
|
|
|
when (isJust branch) $
|
|
|
|
liftIO $ putMVar mvar branch
|
2013-10-17 17:34:27 +00:00
|
|
|
return branch
|
|
|
|
, liftIO $ readMVar mvar
|
|
|
|
)
|
|
|
|
let withbranch a = a =<< getbranch
|
|
|
|
|
2011-12-31 01:17:36 +00:00
|
|
|
remotes <- syncRemotes rs
|
2014-01-19 21:35:36 +00:00
|
|
|
let gitremotes = filter Remote.gitSyncableRemote remotes
|
2014-02-01 14:33:55 +00:00
|
|
|
let dataremotes = filter (not . remoteAnnexIgnore . Remote.gitconfig) remotes
|
2014-01-19 21:35:36 +00:00
|
|
|
|
fix inversion of control in CommandSeek (no behavior changes)
I've been disliking how the command seek actions were written for some
time, with their inversion of control and ugly workarounds.
The last straw to fix it was sync --content, which didn't fit the
Annex [CommandStart] interface well at all. I have not yet made it take
advantage of the changed interface though.
The crucial change, and probably why I didn't do it this way from the
beginning, is to make each CommandStart action be run with exceptions
caught, and if it fails, increment a failure counter in annex state.
So I finally remove the very first code I wrote for git-annex, which
was before I had exception handling in the Annex monad, and so ran outside
that monad, passing state explicitly as it ran each CommandStart action.
This was a real slog from 1 to 5 am.
Test suite passes.
Memory usage is lower than before, sometimes by a couple of megabytes, and
remains constant, even when running in a large repo, and even when
repeatedly failing and incrementing the error counter. So no accidental
laziness space leaks.
Wall clock speed is identical, even in large repos.
This commit was sponsored by an anonymous bitcoiner.
2014-01-20 08:11:42 +00:00
|
|
|
-- Syncing involves many actions, any of which can independently
|
|
|
|
-- fail, without preventing the others from running.
|
2014-01-20 17:31:03 +00:00
|
|
|
seekActions $ return $ concat
|
|
|
|
[ [ commit ]
|
|
|
|
, [ withbranch mergeLocal ]
|
|
|
|
, map (withbranch . pullRemote) gitremotes
|
|
|
|
, [ mergeAnnex ]
|
|
|
|
]
|
2014-01-26 20:25:55 +00:00
|
|
|
whenM (Annex.getFlag $ optionName contentOption) $
|
2014-02-01 14:49:50 +00:00
|
|
|
whenM (seekSyncContent dataremotes) $ do
|
|
|
|
-- Transferring content can take a while,
|
|
|
|
-- and other changes can be pushed to the git-annex
|
|
|
|
-- branch on the remotes in the meantime, so pull
|
|
|
|
-- and merge again to avoid our push overwriting
|
|
|
|
-- those changes.
|
|
|
|
seekActions $ return $ concat
|
|
|
|
[ map (withbranch . pullRemote) gitremotes
|
|
|
|
, [ commitAnnex, mergeAnnex ]
|
|
|
|
]
|
2014-01-20 17:31:03 +00:00
|
|
|
seekActions $ return $ concat
|
|
|
|
[ [ withbranch pushLocal ]
|
|
|
|
, map (withbranch . pushRemote) gitremotes
|
|
|
|
]
|
2011-12-30 20:24:30 +00:00
|
|
|
|
2013-09-13 18:55:55 +00:00
|
|
|
{- Merging may delete the current directory, so go to the top
|
2014-01-19 21:35:36 +00:00
|
|
|
- of the repo. This also means that sync always acts on all files in the
|
|
|
|
- repository, not just on a subdirectory. -}
|
2013-09-13 18:55:55 +00:00
|
|
|
prepMerge :: Annex ()
|
|
|
|
prepMerge = liftIO . setCurrentDirectory =<< fromRepo Git.repoPath
|
|
|
|
|
2011-12-30 23:11:22 +00:00
|
|
|
syncBranch :: Git.Ref -> Git.Ref
|
work around lack of receive.denyCurrentBranch in direct mode
Now that direct mode sets core.bare=true, git's normal prohibition about
pushing into the currently checked out branch doesn't work.
A simple fix for this would be an update hook which blocks the pushes..
but git hooks must be executable, and git-annex needs to be usable on eg,
FAT, which lacks x bits.
Instead, enabling direct mode switches the branch (eg master) to a special
purpose branch (eg annex/direct/master). This branch is not pushed when
syncing; instead any changes that git annex sync commits get written to
master, and it's pushed (along with synced/master) to the remote.
Note that initialization has been changed to always call setDirect,
even if it's just setDirect False for indirect mode. This is needed because
if the user has just cloned a direct mode repo, that nothing has synced
with before, it may have no master branch, and only a annex/direct/master.
Resulting in that branch being checked out locally too. Calling setDirect False
for indirect mode moves back out of this branch, to a new master branch,
and ensures that a manual "git push" doesn't push changes directly to
the annex/direct/master of the remote. (It's possible that the user
makes a commit w/o using git-annex and pushes it, but nothing I can do
about that really.)
This commit was sponsored by Jonathan Harrington.
2013-11-06 01:08:31 +00:00
|
|
|
syncBranch = Git.Ref.under "refs/heads/synced" . fromDirectBranch
|
2011-12-29 17:37:30 +00:00
|
|
|
|
2011-12-31 08:11:39 +00:00
|
|
|
remoteBranch :: Remote -> Git.Ref -> Git.Ref
|
work around lack of receive.denyCurrentBranch in direct mode
Now that direct mode sets core.bare=true, git's normal prohibition about
pushing into the currently checked out branch doesn't work.
A simple fix for this would be an update hook which blocks the pushes..
but git hooks must be executable, and git-annex needs to be usable on eg,
FAT, which lacks x bits.
Instead, enabling direct mode switches the branch (eg master) to a special
purpose branch (eg annex/direct/master). This branch is not pushed when
syncing; instead any changes that git annex sync commits get written to
master, and it's pushed (along with synced/master) to the remote.
Note that initialization has been changed to always call setDirect,
even if it's just setDirect False for indirect mode. This is needed because
if the user has just cloned a direct mode repo, that nothing has synced
with before, it may have no master branch, and only a annex/direct/master.
Resulting in that branch being checked out locally too. Calling setDirect False
for indirect mode moves back out of this branch, to a new master branch,
and ensures that a manual "git push" doesn't push changes directly to
the annex/direct/master of the remote. (It's possible that the user
makes a commit w/o using git-annex and pushes it, but nothing I can do
about that really.)
This commit was sponsored by Jonathan Harrington.
2013-11-06 01:08:31 +00:00
|
|
|
remoteBranch remote = Git.Ref.underBase $ "refs/remotes/" ++ Remote.name remote
|
2011-12-31 07:01:18 +00:00
|
|
|
|
2011-12-31 08:11:39 +00:00
|
|
|
syncRemotes :: [String] -> Annex [Remote]
|
2012-03-14 21:43:34 +00:00
|
|
|
syncRemotes rs = ifM (Annex.getState Annex.fast) ( nub <$> pickfast , wanted )
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2014-01-19 21:35:36 +00:00
|
|
|
pickfast = (++) <$> listed <*> (filterM good =<< fastest <$> available)
|
2012-11-12 05:05:04 +00:00
|
|
|
wanted
|
2014-01-19 21:35:36 +00:00
|
|
|
| null rs = filterM good =<< concat . Remote.byCost <$> available
|
2012-11-12 05:05:04 +00:00
|
|
|
| otherwise = listed
|
2014-01-19 21:35:36 +00:00
|
|
|
listed = catMaybes <$> mapM (Remote.byName . Just) rs
|
|
|
|
available = filter (remoteAnnexSync . Types.Remote.gitconfig)
|
2014-02-01 14:33:55 +00:00
|
|
|
. filter (not . Remote.isXMPPRemote)
|
2013-04-22 18:57:09 +00:00
|
|
|
<$> Remote.remoteList
|
2014-01-19 21:35:36 +00:00
|
|
|
good r
|
|
|
|
| Remote.gitSyncableRemote r = Remote.Git.repoAvail $ Types.Remote.repo r
|
|
|
|
| otherwise = return True
|
2012-11-12 05:05:04 +00:00
|
|
|
fastest = fromMaybe [] . headMaybe . Remote.byCost
|
2011-12-10 00:27:22 +00:00
|
|
|
|
2011-12-10 16:21:22 +00:00
|
|
|
commit :: CommandStart
|
2013-09-25 07:09:06 +00:00
|
|
|
commit = next $ next $ ifM isDirect
|
|
|
|
( do
|
2013-12-01 17:59:39 +00:00
|
|
|
showStart "commit" ""
|
2013-09-25 07:09:06 +00:00
|
|
|
void stageDirect
|
2013-12-01 17:59:39 +00:00
|
|
|
void preCommitDirect
|
|
|
|
commitStaged commitmessage
|
|
|
|
, do
|
2012-12-12 23:20:38 +00:00
|
|
|
showStart "commit" ""
|
2012-12-13 19:58:38 +00:00
|
|
|
Annex.Branch.commit "update"
|
2011-12-10 16:21:22 +00:00
|
|
|
-- Commit will fail when the tree is clean, so ignore failure.
|
2013-12-01 17:59:39 +00:00
|
|
|
_ <- inRepo $ tryIO . Git.Command.runQuiet
|
|
|
|
[ Param "commit"
|
|
|
|
, Param "-a"
|
|
|
|
, Param "-m"
|
|
|
|
, Param commitmessage
|
|
|
|
]
|
|
|
|
return True
|
|
|
|
)
|
|
|
|
where
|
|
|
|
commitmessage = "git-annex automatic sync"
|
|
|
|
|
|
|
|
commitStaged :: String -> Annex Bool
|
|
|
|
commitStaged commitmessage = go =<< inRepo Git.Branch.currentUnsafe
|
|
|
|
where
|
|
|
|
go Nothing = return False
|
|
|
|
go (Just branch) = do
|
|
|
|
parent <- inRepo $ Git.Ref.sha branch
|
|
|
|
void $ inRepo $ Git.Branch.commit False commitmessage branch
|
2014-02-01 21:14:38 +00:00
|
|
|
(maybeToList parent)
|
2011-12-10 16:21:22 +00:00
|
|
|
return True
|
|
|
|
|
2013-11-02 19:29:38 +00:00
|
|
|
mergeLocal :: Maybe Git.Ref -> CommandStart
|
|
|
|
mergeLocal Nothing = stop
|
|
|
|
mergeLocal (Just branch) = go =<< needmerge
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
|
|
|
syncbranch = syncBranch branch
|
2013-08-17 19:29:44 +00:00
|
|
|
needmerge = ifM isBareRepo
|
|
|
|
( return False
|
|
|
|
, do
|
|
|
|
unlessM (inRepo $ Git.Ref.exists syncbranch) $
|
|
|
|
inRepo $ updateBranch syncbranch
|
|
|
|
inRepo $ Git.Branch.changed branch syncbranch
|
|
|
|
)
|
2012-11-12 05:05:04 +00:00
|
|
|
go False = stop
|
|
|
|
go True = do
|
|
|
|
showStart "merge" $ Git.Ref.describe syncbranch
|
|
|
|
next $ next $ mergeFrom syncbranch
|
2011-12-29 17:37:30 +00:00
|
|
|
|
2013-11-02 19:29:38 +00:00
|
|
|
pushLocal :: Maybe Git.Ref -> CommandStart
|
|
|
|
pushLocal Nothing = stop
|
|
|
|
pushLocal (Just branch) = do
|
work around lack of receive.denyCurrentBranch in direct mode
Now that direct mode sets core.bare=true, git's normal prohibition about
pushing into the currently checked out branch doesn't work.
A simple fix for this would be an update hook which blocks the pushes..
but git hooks must be executable, and git-annex needs to be usable on eg,
FAT, which lacks x bits.
Instead, enabling direct mode switches the branch (eg master) to a special
purpose branch (eg annex/direct/master). This branch is not pushed when
syncing; instead any changes that git annex sync commits get written to
master, and it's pushed (along with synced/master) to the remote.
Note that initialization has been changed to always call setDirect,
even if it's just setDirect False for indirect mode. This is needed because
if the user has just cloned a direct mode repo, that nothing has synced
with before, it may have no master branch, and only a annex/direct/master.
Resulting in that branch being checked out locally too. Calling setDirect False
for indirect mode moves back out of this branch, to a new master branch,
and ensures that a manual "git push" doesn't push changes directly to
the annex/direct/master of the remote. (It's possible that the user
makes a commit w/o using git-annex and pushes it, but nothing I can do
about that really.)
This commit was sponsored by Jonathan Harrington.
2013-11-06 01:08:31 +00:00
|
|
|
-- Update the sync branch to match the new state of the branch
|
2012-06-22 19:46:21 +00:00
|
|
|
inRepo $ updateBranch $ syncBranch branch
|
work around lack of receive.denyCurrentBranch in direct mode
Now that direct mode sets core.bare=true, git's normal prohibition about
pushing into the currently checked out branch doesn't work.
A simple fix for this would be an update hook which blocks the pushes..
but git hooks must be executable, and git-annex needs to be usable on eg,
FAT, which lacks x bits.
Instead, enabling direct mode switches the branch (eg master) to a special
purpose branch (eg annex/direct/master). This branch is not pushed when
syncing; instead any changes that git annex sync commits get written to
master, and it's pushed (along with synced/master) to the remote.
Note that initialization has been changed to always call setDirect,
even if it's just setDirect False for indirect mode. This is needed because
if the user has just cloned a direct mode repo, that nothing has synced
with before, it may have no master branch, and only a annex/direct/master.
Resulting in that branch being checked out locally too. Calling setDirect False
for indirect mode moves back out of this branch, to a new master branch,
and ensures that a manual "git push" doesn't push changes directly to
the annex/direct/master of the remote. (It's possible that the user
makes a commit w/o using git-annex and pushes it, but nothing I can do
about that really.)
This commit was sponsored by Jonathan Harrington.
2013-11-06 01:08:31 +00:00
|
|
|
-- In direct mode, we're operating on some special direct mode
|
|
|
|
-- branch, rather than the intended branch, so update the indended
|
|
|
|
-- branch.
|
|
|
|
whenM isDirect $
|
|
|
|
inRepo $ updateBranch $ fromDirectBranch branch
|
2011-12-31 07:08:41 +00:00
|
|
|
stop
|
2011-12-30 22:52:24 +00:00
|
|
|
|
2012-06-22 19:46:21 +00:00
|
|
|
updateBranch :: Git.Ref -> Git.Repo -> IO ()
|
|
|
|
updateBranch syncbranch g =
|
2011-12-30 22:52:24 +00:00
|
|
|
unlessM go $ error $ "failed to update " ++ show syncbranch
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2013-03-03 17:39:07 +00:00
|
|
|
go = Git.Command.runBool
|
|
|
|
[ Param "branch"
|
|
|
|
, Param "-f"
|
2012-11-12 05:05:04 +00:00
|
|
|
, Param $ show $ Git.Ref.base syncbranch
|
|
|
|
] g
|
2011-12-30 21:38:38 +00:00
|
|
|
|
2013-11-02 19:29:38 +00:00
|
|
|
pullRemote :: Remote -> Maybe Git.Ref -> CommandStart
|
2011-12-30 22:04:01 +00:00
|
|
|
pullRemote remote branch = do
|
|
|
|
showStart "pull" (Remote.name remote)
|
2011-12-30 21:38:38 +00:00
|
|
|
next $ do
|
|
|
|
showOutput
|
2012-03-14 21:43:34 +00:00
|
|
|
stopUnless fetch $
|
2013-11-02 19:29:38 +00:00
|
|
|
next $ mergeRemote remote branch
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2013-03-03 17:39:07 +00:00
|
|
|
fetch = inRepo $ Git.Command.runBool
|
|
|
|
[Param "fetch", Param $ Remote.name remote]
|
2011-12-10 00:27:22 +00:00
|
|
|
|
2011-12-30 23:11:22 +00:00
|
|
|
{- The remote probably has both a master and a synced/master branch.
|
|
|
|
- Which to merge from? Well, the master has whatever latest changes
|
2013-06-12 18:54:23 +00:00
|
|
|
- were committed (or pushed changes, if this is a bare remote),
|
|
|
|
- while the synced/master may have changes that some
|
2012-12-12 17:06:03 +00:00
|
|
|
- other remote synced to this remote. So, merge them both. -}
|
2013-09-25 07:09:06 +00:00
|
|
|
mergeRemote :: Remote -> Maybe Git.Ref -> CommandCleanup
|
2012-08-05 20:35:30 +00:00
|
|
|
mergeRemote remote b = case b of
|
|
|
|
Nothing -> do
|
|
|
|
branch <- inRepo Git.Branch.currentUnsafe
|
2013-09-25 07:09:06 +00:00
|
|
|
and <$> mapM merge (branchlist branch)
|
|
|
|
Just _ -> and <$> (mapM merge =<< tomerge (branchlist b))
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
|
|
|
merge = mergeFrom . remoteBranch remote
|
|
|
|
tomerge branches = filterM (changed remote) branches
|
|
|
|
branchlist Nothing = []
|
|
|
|
branchlist (Just branch) = [branch, syncBranch branch]
|
2011-12-30 23:11:22 +00:00
|
|
|
|
2013-11-02 19:29:38 +00:00
|
|
|
pushRemote :: Remote -> Maybe Git.Ref -> CommandStart
|
|
|
|
pushRemote _remote Nothing = stop
|
|
|
|
pushRemote remote (Just branch) = go =<< needpush
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
2014-01-02 17:12:32 +00:00
|
|
|
needpush
|
|
|
|
| remoteAnnexReadOnly (Types.Remote.gitconfig remote) = return False
|
|
|
|
| otherwise = anyM (newer remote) [syncBranch branch, Annex.Branch.name]
|
2012-11-12 05:05:04 +00:00
|
|
|
go False = stop
|
|
|
|
go True = do
|
|
|
|
showStart "push" (Remote.name remote)
|
|
|
|
next $ next $ do
|
|
|
|
showOutput
|
2013-10-26 19:53:05 +00:00
|
|
|
ok <- inRepo $ pushBranch remote branch
|
|
|
|
unless ok $ do
|
|
|
|
warning $ unwords [ "Pushing to " ++ Remote.name remote ++ " failed." ]
|
2013-11-01 15:04:19 +00:00
|
|
|
showLongNote "(non-fast-forward problems can be solved by setting receive.denyNonFastforwards to false in the remote's git config)"
|
2013-10-26 19:53:05 +00:00
|
|
|
return ok
|
2012-06-22 19:46:21 +00:00
|
|
|
|
2013-08-29 18:15:32 +00:00
|
|
|
{- Pushes a regular branch like master to a remote. Also pushes the git-annex
|
|
|
|
- branch.
|
|
|
|
-
|
|
|
|
- If the remote is a bare git repository, it's best to push the regular
|
|
|
|
- branch directly to it, so that cloning/pulling will get it.
|
|
|
|
- On the other hand, if it's not bare, pushing to the checked out branch
|
|
|
|
- will fail, and this is why we push to its syncBranch.
|
2013-06-12 18:54:23 +00:00
|
|
|
-
|
|
|
|
- Git offers no way to tell if a remote is bare or not, so both methods
|
|
|
|
- are tried.
|
|
|
|
-
|
|
|
|
- The direct push is likely to spew an ugly error message, so stderr is
|
2013-08-29 18:15:32 +00:00
|
|
|
- elided. Since git progress display goes to stderr too, the sync push
|
|
|
|
- is done first, and actually sends the data. Then the direct push is
|
|
|
|
- tried, with stderr discarded, to update the branch ref on the remote.
|
|
|
|
-
|
|
|
|
- The sync push forces the update of the remote synced/git-annex branch.
|
|
|
|
- This is necessary if a transition has rewritten the git-annex branch.
|
|
|
|
- Normally any changes to the git-annex branch get pulled and merged before
|
|
|
|
- this push, so this forcing is unlikely to overwrite new data pushed
|
|
|
|
- in from another repository that is also syncing.
|
|
|
|
-
|
|
|
|
- But overwriting of data on synced/git-annex can happen, in a race.
|
|
|
|
- The only difference caused by using a forced push in that case is that
|
|
|
|
- the last repository to push wins the race, rather than the first to push.
|
2013-10-26 19:53:05 +00:00
|
|
|
-
|
|
|
|
- The sync push will fail to overwrite if receive.denyNonFastforwards is
|
|
|
|
- set on the remote.
|
2013-06-12 18:54:23 +00:00
|
|
|
-}
|
2012-06-22 19:46:21 +00:00
|
|
|
pushBranch :: Remote -> Git.Ref -> Git.Repo -> IO Bool
|
2013-08-29 18:15:32 +00:00
|
|
|
pushBranch remote branch g = tryIO (directpush g) `after` syncpush g
|
2013-06-12 18:54:23 +00:00
|
|
|
where
|
2013-08-29 18:15:32 +00:00
|
|
|
syncpush = Git.Command.runBool $ pushparams
|
|
|
|
[ Git.Branch.forcePush $ refspec Annex.Branch.name
|
|
|
|
, refspec branch
|
|
|
|
]
|
|
|
|
directpush = Git.Command.runQuiet $ pushparams
|
work around lack of receive.denyCurrentBranch in direct mode
Now that direct mode sets core.bare=true, git's normal prohibition about
pushing into the currently checked out branch doesn't work.
A simple fix for this would be an update hook which blocks the pushes..
but git hooks must be executable, and git-annex needs to be usable on eg,
FAT, which lacks x bits.
Instead, enabling direct mode switches the branch (eg master) to a special
purpose branch (eg annex/direct/master). This branch is not pushed when
syncing; instead any changes that git annex sync commits get written to
master, and it's pushed (along with synced/master) to the remote.
Note that initialization has been changed to always call setDirect,
even if it's just setDirect False for indirect mode. This is needed because
if the user has just cloned a direct mode repo, that nothing has synced
with before, it may have no master branch, and only a annex/direct/master.
Resulting in that branch being checked out locally too. Calling setDirect False
for indirect mode moves back out of this branch, to a new master branch,
and ensures that a manual "git push" doesn't push changes directly to
the annex/direct/master of the remote. (It's possible that the user
makes a commit w/o using git-annex and pushes it, but nothing I can do
about that really.)
This commit was sponsored by Jonathan Harrington.
2013-11-06 01:08:31 +00:00
|
|
|
[show $ Git.Ref.base $ fromDirectBranch branch]
|
2013-08-29 18:15:32 +00:00
|
|
|
pushparams branches =
|
2013-03-03 17:39:07 +00:00
|
|
|
[ Param "push"
|
|
|
|
, Param $ Remote.name remote
|
2013-08-29 18:15:32 +00:00
|
|
|
] ++ map Param branches
|
2012-11-12 05:05:04 +00:00
|
|
|
refspec b = concat
|
|
|
|
[ show $ Git.Ref.base b
|
|
|
|
, ":"
|
|
|
|
, show $ Git.Ref.base $ syncBranch b
|
|
|
|
]
|
2011-12-29 17:37:30 +00:00
|
|
|
|
2014-02-01 14:49:50 +00:00
|
|
|
commitAnnex :: CommandStart
|
|
|
|
commitAnnex = do
|
|
|
|
Annex.Branch.commit "update"
|
|
|
|
stop
|
|
|
|
|
2011-12-30 20:03:41 +00:00
|
|
|
mergeAnnex :: CommandStart
|
2011-12-30 21:38:38 +00:00
|
|
|
mergeAnnex = do
|
2013-09-25 07:09:06 +00:00
|
|
|
void Annex.Branch.forceUpdate
|
2011-12-30 21:38:38 +00:00
|
|
|
stop
|
2011-12-31 06:18:16 +00:00
|
|
|
|
2012-12-18 19:04:44 +00:00
|
|
|
{- Merges from a branch into the current branch. -}
|
2012-06-27 16:09:01 +00:00
|
|
|
mergeFrom :: Git.Ref -> Annex Bool
|
2012-12-18 19:04:44 +00:00
|
|
|
mergeFrom branch = do
|
|
|
|
showOutput
|
|
|
|
ifM isDirect
|
|
|
|
( maybe go godirect =<< inRepo Git.Branch.current
|
|
|
|
, go
|
|
|
|
)
|
2012-12-12 17:06:03 +00:00
|
|
|
where
|
2012-12-18 19:04:44 +00:00
|
|
|
go = runmerge $ inRepo $ Git.Merge.mergeNonInteractive branch
|
2012-12-12 17:06:03 +00:00
|
|
|
godirect currbranch = do
|
|
|
|
old <- inRepo $ Git.Ref.sha currbranch
|
2012-12-18 19:04:44 +00:00
|
|
|
d <- fromRepo gitAnnexMergeDir
|
|
|
|
r <- runmerge $ inRepo $ mergeDirect d branch
|
2012-12-12 17:06:03 +00:00
|
|
|
new <- inRepo $ Git.Ref.sha currbranch
|
|
|
|
case (old, new) of
|
2012-12-18 19:04:44 +00:00
|
|
|
(Just oldsha, Just newsha) ->
|
|
|
|
mergeDirectCleanup d oldsha newsha
|
2012-12-12 17:06:03 +00:00
|
|
|
_ -> noop
|
|
|
|
return r
|
2013-09-25 07:09:06 +00:00
|
|
|
runmerge a = ifM a
|
2012-12-18 19:04:44 +00:00
|
|
|
( return True
|
2013-11-14 18:36:48 +00:00
|
|
|
, resolveMerge
|
2012-12-18 19:04:44 +00:00
|
|
|
)
|
2012-06-27 16:09:01 +00:00
|
|
|
|
|
|
|
{- Resolves a conflicted merge. It's important that any conflicts be
|
|
|
|
- resolved in a way that itself avoids later merge conflicts, since
|
|
|
|
- multiple repositories may be doing this concurrently.
|
|
|
|
-
|
|
|
|
- Only annexed files are resolved; other files are left for the user to
|
|
|
|
- handle.
|
|
|
|
-
|
|
|
|
- This uses the Keys pointed to by the files to construct new
|
2012-06-27 17:08:32 +00:00
|
|
|
- filenames. So when both sides modified file foo,
|
2013-10-16 18:48:51 +00:00
|
|
|
- it will be deleted, and replaced with files foo.variant-A and
|
|
|
|
- foo.variant-B.
|
2012-06-27 16:09:01 +00:00
|
|
|
-
|
2012-06-27 17:08:32 +00:00
|
|
|
- On the other hand, when one side deleted foo, and the other modified it,
|
|
|
|
- it will be deleted, and the modified version stored as file
|
2013-10-16 18:48:51 +00:00
|
|
|
- foo.variant-A (or B).
|
|
|
|
-
|
|
|
|
- It's also possible that one side has foo as an annexed file, and
|
|
|
|
- the other as a directory or non-annexed file. The annexed file
|
|
|
|
- is renamed to resolve the merge, and the other object is preserved as-is.
|
2012-06-27 16:09:01 +00:00
|
|
|
-}
|
|
|
|
resolveMerge :: Annex Bool
|
|
|
|
resolveMerge = do
|
2012-06-27 17:08:32 +00:00
|
|
|
top <- fromRepo Git.repoPath
|
2012-10-04 23:56:32 +00:00
|
|
|
(fs, cleanup) <- inRepo (LsFiles.unmerged [top])
|
2013-10-16 19:37:06 +00:00
|
|
|
mergedfs <- catMaybes <$> mapM resolveMerge' fs
|
|
|
|
let merged = not (null mergedfs)
|
2013-01-18 01:19:00 +00:00
|
|
|
void $ liftIO cleanup
|
|
|
|
|
|
|
|
(deleted, cleanup2) <- inRepo (LsFiles.deleted [top])
|
2013-02-05 19:11:05 +00:00
|
|
|
unless (null deleted) $
|
|
|
|
Annex.Queue.addCommand "rm" [Params "--quiet -f --"] deleted
|
2013-01-18 01:19:00 +00:00
|
|
|
void $ liftIO cleanup2
|
2013-10-16 19:37:06 +00:00
|
|
|
|
2012-06-27 19:03:13 +00:00
|
|
|
when merged $ do
|
2013-10-16 19:37:06 +00:00
|
|
|
unlessM isDirect $
|
|
|
|
cleanConflictCruft mergedfs top
|
2012-06-27 19:03:13 +00:00
|
|
|
Annex.Queue.flush
|
2013-03-03 17:39:07 +00:00
|
|
|
void $ inRepo $ Git.Command.runBool
|
|
|
|
[ Param "commit"
|
|
|
|
, Param "-m"
|
|
|
|
, Param "git-annex automatic merge conflict fix"
|
|
|
|
]
|
2013-11-14 18:18:15 +00:00
|
|
|
showLongNote "Merge conflict was automatically resolved; you may want to examine the result."
|
2012-06-27 19:03:13 +00:00
|
|
|
return merged
|
2012-06-27 17:08:32 +00:00
|
|
|
|
2013-10-16 19:37:06 +00:00
|
|
|
resolveMerge' :: LsFiles.Unmerged -> Annex (Maybe FilePath)
|
2012-06-27 17:08:32 +00:00
|
|
|
resolveMerge' u
|
2013-10-16 18:48:51 +00:00
|
|
|
| issymlink LsFiles.valUs && issymlink LsFiles.valThem = do
|
|
|
|
kus <- getKey LsFiles.valUs
|
|
|
|
kthem <- getKey LsFiles.valThem
|
|
|
|
case (kus, kthem) of
|
|
|
|
-- Both sides of conflict are annexed files
|
|
|
|
(Just keyUs, Just keyThem) -> do
|
|
|
|
removeoldfile keyUs
|
|
|
|
if keyUs == keyThem
|
|
|
|
then makelink keyUs
|
|
|
|
else do
|
|
|
|
makelink keyUs
|
|
|
|
makelink keyThem
|
2013-10-16 19:37:06 +00:00
|
|
|
return $ Just file
|
2013-10-16 18:48:51 +00:00
|
|
|
-- Our side is annexed, other side is not.
|
|
|
|
(Just keyUs, Nothing) -> do
|
2013-10-16 19:37:06 +00:00
|
|
|
ifM isDirect
|
|
|
|
( do
|
|
|
|
removeoldfile keyUs
|
|
|
|
makelink keyUs
|
2014-02-04 19:31:53 +00:00
|
|
|
movefromdirectmerge file
|
2013-10-16 19:37:06 +00:00
|
|
|
, do
|
|
|
|
unstageoldfile
|
|
|
|
makelink keyUs
|
|
|
|
)
|
|
|
|
return $ Just file
|
2013-10-16 18:48:51 +00:00
|
|
|
-- Our side is not annexed, other side is.
|
|
|
|
(Nothing, Just keyThem) -> do
|
|
|
|
makelink keyThem
|
2013-10-16 19:37:06 +00:00
|
|
|
unstageoldfile
|
|
|
|
return $ Just file
|
2013-10-16 18:48:51 +00:00
|
|
|
-- Neither side is annexed; cannot resolve.
|
2013-10-16 19:37:06 +00:00
|
|
|
(Nothing, Nothing) -> return Nothing
|
|
|
|
| otherwise = return Nothing
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
|
|
|
file = LsFiles.unmergedFile u
|
2013-09-25 07:09:06 +00:00
|
|
|
issymlink select = select (LsFiles.unmergedBlobType u) `elem` [Just SymlinkBlob, Nothing]
|
2013-10-16 18:48:51 +00:00
|
|
|
makelink key = do
|
2012-11-12 05:05:04 +00:00
|
|
|
let dest = mergeFile file key
|
2013-04-04 19:46:33 +00:00
|
|
|
l <- inRepo $ gitAnnexLink dest key
|
2013-05-26 22:10:07 +00:00
|
|
|
replaceFile dest $ makeAnnexLink l
|
|
|
|
stageSymlink dest =<< hashSymlink l
|
2013-09-25 07:09:06 +00:00
|
|
|
whenM isDirect $
|
2012-12-18 21:15:16 +00:00
|
|
|
toDirect key dest
|
2013-10-16 18:48:51 +00:00
|
|
|
removeoldfile keyUs = do
|
|
|
|
ifM isDirect
|
|
|
|
( removeDirect keyUs file
|
|
|
|
, liftIO $ nukeFile file
|
|
|
|
)
|
|
|
|
Annex.Queue.addCommand "rm" [Params "--quiet -f --"] [file]
|
2013-10-16 19:37:06 +00:00
|
|
|
unstageoldfile = Annex.Queue.addCommand "rm" [Params "--quiet -f --cached --"] [file]
|
2013-10-16 18:48:51 +00:00
|
|
|
getKey select = case select (LsFiles.unmergedSha u) of
|
|
|
|
Nothing -> return Nothing
|
|
|
|
Just sha -> catKey sha symLinkMode
|
2014-02-04 19:31:53 +00:00
|
|
|
|
|
|
|
{- Move something out of the direct mode merge directory and into
|
|
|
|
- the git work tree.
|
|
|
|
-
|
|
|
|
- On a filesystem not supporting symlinks, this is complicated
|
|
|
|
- because a directory may contain annex links, but just
|
|
|
|
- moving them into the work tree will not let git know they are
|
|
|
|
- symlinks.
|
|
|
|
-
|
|
|
|
- Also, if the content of the file is available, make it available
|
|
|
|
- in direct mode.
|
|
|
|
-}
|
|
|
|
movefromdirectmerge item = do
|
|
|
|
d <- fromRepo gitAnnexMergeDir
|
|
|
|
liftIO $ rename (d </> item) item
|
|
|
|
mapM_ setuplink =<< liftIO (dirContentsRecursive item)
|
|
|
|
setuplink f = do
|
|
|
|
v <- getAnnexLinkTarget f
|
|
|
|
case v of
|
|
|
|
Nothing -> noop
|
|
|
|
Just target -> do
|
|
|
|
unlessM (coreSymlinks <$> Annex.getGitConfig) $
|
|
|
|
addAnnexLink target f
|
|
|
|
maybe noop (flip toDirect f)
|
|
|
|
(fileKey (takeFileName target))
|
2012-06-27 20:03:42 +00:00
|
|
|
|
2013-10-16 19:37:06 +00:00
|
|
|
{- git-merge moves conflicting files away to files
|
|
|
|
- named something like f~HEAD or f~branch, but the
|
|
|
|
- exact name chosen can vary. Once the conflict is resolved,
|
|
|
|
- this cruft can be deleted. To avoid deleting legitimate
|
|
|
|
- files that look like this, only delete files that are
|
|
|
|
- A) not staged in git and B) look like git-annex symlinks.
|
|
|
|
-}
|
|
|
|
cleanConflictCruft :: [FilePath] -> FilePath -> Annex ()
|
|
|
|
cleanConflictCruft resolvedfs top = do
|
|
|
|
(fs, cleanup) <- inRepo $ LsFiles.notInRepo False [top]
|
|
|
|
mapM_ clean fs
|
|
|
|
void $ liftIO cleanup
|
|
|
|
where
|
|
|
|
clean f
|
|
|
|
| matchesresolved f = whenM (isJust <$> isAnnexLink f) $
|
|
|
|
liftIO $ nukeFile f
|
|
|
|
| otherwise = noop
|
|
|
|
s = S.fromList resolvedfs
|
|
|
|
matchesresolved f = S.member (base f) s
|
|
|
|
base f = reverse $ drop 1 $ dropWhile (/= '~') $ reverse f
|
|
|
|
|
2012-06-27 20:03:42 +00:00
|
|
|
{- The filename to use when resolving a conflicted merge of a file,
|
|
|
|
- that points to a key.
|
|
|
|
-
|
|
|
|
- Something derived from the key needs to be included in the filename,
|
|
|
|
- but rather than exposing the whole key to the user, a very weak hash
|
|
|
|
- is used. There is a very real, although still unlikely, chance of
|
|
|
|
- conflicts using this hash.
|
|
|
|
-
|
|
|
|
- In the event that there is a conflict with the filename generated
|
|
|
|
- for some other key, that conflict will itself be handled by the
|
|
|
|
- conflicted merge resolution code. That case is detected, and the full
|
|
|
|
- key is used in the filename.
|
|
|
|
-}
|
|
|
|
mergeFile :: FilePath -> Key -> FilePath
|
|
|
|
mergeFile file key
|
2012-08-08 20:06:01 +00:00
|
|
|
| doubleconflict = go $ key2file key
|
|
|
|
| otherwise = go $ shortHash $ key2file key
|
2012-11-12 05:05:04 +00:00
|
|
|
where
|
|
|
|
varmarker = ".variant-"
|
2013-05-26 21:42:15 +00:00
|
|
|
doubleconflict = varmarker `isInfixOf` file
|
2012-11-12 05:05:04 +00:00
|
|
|
go v = takeDirectory file
|
|
|
|
</> dropExtension (takeFileName file)
|
|
|
|
++ varmarker ++ v
|
|
|
|
++ takeExtension file
|
2012-06-27 20:03:42 +00:00
|
|
|
|
|
|
|
shortHash :: String -> String
|
2012-09-13 23:14:00 +00:00
|
|
|
shortHash = take 4 . md5s . md5FilePath
|
2011-12-31 07:01:18 +00:00
|
|
|
|
2011-12-31 08:11:39 +00:00
|
|
|
changed :: Remote -> Git.Ref -> Annex Bool
|
2011-12-31 07:01:18 +00:00
|
|
|
changed remote b = do
|
|
|
|
let r = remoteBranch remote b
|
2012-03-14 21:43:34 +00:00
|
|
|
ifM (inRepo $ Git.Ref.exists r)
|
|
|
|
( inRepo $ Git.Branch.changed b r
|
|
|
|
, return False
|
|
|
|
)
|
2011-12-31 07:01:18 +00:00
|
|
|
|
2011-12-31 08:11:39 +00:00
|
|
|
newer :: Remote -> Git.Ref -> Annex Bool
|
2011-12-31 07:01:18 +00:00
|
|
|
newer remote b = do
|
|
|
|
let r = remoteBranch remote b
|
2012-03-14 21:43:34 +00:00
|
|
|
ifM (inRepo $ Git.Ref.exists r)
|
|
|
|
( inRepo $ Git.Branch.changed r b
|
|
|
|
, return True
|
|
|
|
)
|
2014-01-19 21:35:36 +00:00
|
|
|
|
|
|
|
{- If it's preferred content, and we don't have it, get it from one of the
|
|
|
|
- listed remotes (preferring the cheaper earlier ones).
|
|
|
|
-
|
|
|
|
- Send it to each remote that doesn't have it, and for which it's
|
|
|
|
- preferred content.
|
|
|
|
-
|
|
|
|
- Drop it locally if it's not preferred content (honoring numcopies).
|
|
|
|
-
|
|
|
|
- Drop it from each remote that has it, where it's not preferred content
|
|
|
|
- (honoring numcopies).
|
2014-02-01 14:49:50 +00:00
|
|
|
-
|
|
|
|
- If any file movements were generated, returns true.
|
2014-01-19 21:35:36 +00:00
|
|
|
-}
|
2014-02-01 14:49:50 +00:00
|
|
|
seekSyncContent :: [Remote] -> Annex Bool
|
|
|
|
seekSyncContent rs = do
|
|
|
|
mvar <- liftIO $ newEmptyMVar
|
|
|
|
mapM_ (go mvar) =<< seekHelper LsFiles.inRepo []
|
|
|
|
liftIO $ not <$> isEmptyMVar mvar
|
2014-01-20 17:31:03 +00:00
|
|
|
where
|
2014-02-01 14:49:50 +00:00
|
|
|
go mvar f = ifAnnexed f
|
|
|
|
(\v -> void (liftIO (tryPutMVar mvar ())) >> syncFile rs f v)
|
|
|
|
noop
|
2014-01-20 17:31:03 +00:00
|
|
|
|
|
|
|
syncFile :: [Remote] -> FilePath -> (Key, Backend) -> Annex ()
|
|
|
|
syncFile rs f (k, _) = do
|
2014-01-19 21:35:36 +00:00
|
|
|
locs <- loggedLocations k
|
|
|
|
let (have, lack) = partition (\r -> Remote.uuid r `elem` locs) rs
|
|
|
|
|
2014-02-03 02:46:55 +00:00
|
|
|
got <- anyM id =<< handleget have
|
2014-01-20 17:31:03 +00:00
|
|
|
putrs <- catMaybes . snd . unzip <$> (sequence =<< handleput lack)
|
|
|
|
|
2014-02-03 02:46:55 +00:00
|
|
|
u <- getUUID
|
|
|
|
let locs' = concat [if got then [u] else [], putrs, locs]
|
|
|
|
|
2014-02-03 02:37:09 +00:00
|
|
|
-- Using callCommandAction rather than commandAction for drops,
|
2014-01-20 17:31:03 +00:00
|
|
|
-- because a failure to drop does not mean the sync failed.
|
2014-02-03 02:46:55 +00:00
|
|
|
handleDropsFrom locs' rs "unwanted" True k (Just f)
|
2014-01-29 17:44:53 +00:00
|
|
|
Nothing callCommandAction
|
2014-01-20 17:31:03 +00:00
|
|
|
where
|
2014-01-19 21:35:36 +00:00
|
|
|
wantget have = allM id
|
|
|
|
[ pure (not $ null have)
|
|
|
|
, not <$> inAnnex k
|
2014-01-23 20:37:08 +00:00
|
|
|
, wantGet True (Just k) (Just f)
|
2014-01-19 21:35:36 +00:00
|
|
|
]
|
|
|
|
handleget have = ifM (wantget have)
|
|
|
|
( return [ get have ]
|
|
|
|
, return []
|
|
|
|
)
|
2014-01-20 17:31:03 +00:00
|
|
|
get have = commandAction $ do
|
2014-01-19 21:35:36 +00:00
|
|
|
showStart "get" f
|
2014-01-20 17:31:03 +00:00
|
|
|
next $ next $ getViaTmp k $ \dest -> getKeyFile' k (Just f) dest have
|
2014-01-19 21:35:36 +00:00
|
|
|
|
|
|
|
wantput r
|
|
|
|
| Remote.readonly r || remoteAnnexReadOnly (Types.Remote.gitconfig r) = return False
|
2014-01-23 20:37:08 +00:00
|
|
|
| otherwise = wantSend True (Just k) (Just f) (Remote.uuid r)
|
2014-01-19 21:35:36 +00:00
|
|
|
handleput lack = ifM (inAnnex k)
|
|
|
|
( map put <$> (filterM wantput lack)
|
|
|
|
, return []
|
|
|
|
)
|
|
|
|
put dest = do
|
2014-01-20 17:31:03 +00:00
|
|
|
ok <- commandAction $ do
|
|
|
|
showStart "copy" f
|
2014-02-02 23:57:22 +00:00
|
|
|
next $ Command.Move.toPerform dest False k (Just f)
|
2014-01-19 22:11:47 +00:00
|
|
|
return (ok, if ok then Just (Remote.uuid dest) else Nothing)
|