flush the git queue when a new type of action is being added to it
This allows the queue to be used in a single process for multiple possibly conflicting commands, like add and rm, without running them out of order. This assumes that running the same git subcommand with different parameters cannot itself conflict.
This commit is contained in:
parent
bd7857d903
commit
7a6fb8ae4e
2 changed files with 20 additions and 10 deletions
|
@ -20,7 +20,7 @@ import Config
|
||||||
add :: String -> [CommandParam] -> [FilePath] -> Annex ()
|
add :: String -> [CommandParam] -> [FilePath] -> Annex ()
|
||||||
add command params files = do
|
add command params files = do
|
||||||
q <- get
|
q <- get
|
||||||
store $ Git.Queue.add q command params files
|
store =<< inRepo (Git.Queue.add q command params files)
|
||||||
|
|
||||||
{- Runs the queue if it is full. Should be called periodically. -}
|
{- Runs the queue if it is full. Should be called periodically. -}
|
||||||
flushWhenFull :: Annex ()
|
flushWhenFull :: Annex ()
|
||||||
|
|
28
Git/Queue.hs
28
Git/Queue.hs
|
@ -1,6 +1,6 @@
|
||||||
{- git repository command queue
|
{- git repository command queue
|
||||||
-
|
-
|
||||||
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
- Copyright 2010,2012 Joey Hess <joey@kitenet.net>
|
||||||
-
|
-
|
||||||
- Licensed under the GNU GPL version 3 or higher.
|
- Licensed under the GNU GPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
@ -33,6 +33,12 @@ data Action = Action
|
||||||
, getParams :: [CommandParam]
|
, getParams :: [CommandParam]
|
||||||
} deriving (Show, Eq, Ord)
|
} deriving (Show, Eq, Ord)
|
||||||
|
|
||||||
|
{- Compares two actions by subcommand. -}
|
||||||
|
(===) :: Action -> Action -> Bool
|
||||||
|
a === b = getSubcommand a == getSubcommand b
|
||||||
|
(/==) :: Action -> Action -> Bool
|
||||||
|
a /== b = not $ a === b
|
||||||
|
|
||||||
{- A queue of actions to perform (in any order) on a git repository,
|
{- A queue of actions to perform (in any order) on a git repository,
|
||||||
- with lists of files to perform them on. This allows coalescing
|
- with lists of files to perform them on. This allows coalescing
|
||||||
- similar git commands. -}
|
- similar git commands. -}
|
||||||
|
@ -59,16 +65,20 @@ defaultLimit = 10240
|
||||||
new :: Maybe Int -> Queue
|
new :: Maybe Int -> Queue
|
||||||
new lim = Queue 0 (fromMaybe defaultLimit lim) M.empty
|
new lim = Queue 0 (fromMaybe defaultLimit lim) M.empty
|
||||||
|
|
||||||
{- Adds an action to a queue. -}
|
{- Adds an action to a queue. If the queue already contains a different
|
||||||
add :: Queue -> String -> [CommandParam] -> [FilePath] -> Queue
|
- action, it will be flushed; this is to ensure that conflicting actions,
|
||||||
add (Queue cur lim m) subcommand params files = Queue (cur + 1) lim m'
|
- like add and rm, are run in the right order. -}
|
||||||
|
add :: Queue -> String -> [CommandParam] -> [FilePath] -> Repo -> IO Queue
|
||||||
|
add q@(Queue _ _ m) subcommand params files repo
|
||||||
|
| null (filter (/== action) (M.keys m)) = go q
|
||||||
|
| otherwise = go =<< flush q repo
|
||||||
where
|
where
|
||||||
action = Action subcommand params
|
action = Action subcommand params
|
||||||
-- There are probably few items in the map, but there
|
go (Queue cur lim m') =
|
||||||
-- can be a lot of files per item. So, optimise adding
|
return $ Queue (cur + 1) lim $
|
||||||
-- files.
|
M.insertWith' const action fs m'
|
||||||
m' = M.insertWith' const action fs m
|
where
|
||||||
!fs = files ++ M.findWithDefault [] action m
|
!fs = files ++ M.findWithDefault [] action m'
|
||||||
|
|
||||||
{- Is a queue large enough that it should be flushed? -}
|
{- Is a queue large enough that it should be flushed? -}
|
||||||
full :: Queue -> Bool
|
full :: Queue -> Bool
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue