better layout

And a theoretical fix to branchstate cache invalidation, but not a bug
that could actually happen.
This commit is contained in:
Joey Hess 2011-10-07 13:59:34 -04:00
parent 82e655efd0
commit dfee6e1ed6

View file

@ -121,40 +121,37 @@ commit message = do
{- Ensures that the branch is up-to-date; should be called before {- Ensures that the branch is up-to-date; should be called before
- data is read from it. Runs only once per git-annex run. -} - data is read from it. Runs only once per git-annex run. -}
update :: Annex () update :: Annex ()
update = do update = onceonly $ do
state <- getState -- check what needs updating before taking the lock
unless (branchUpdated state) $ do fs <- getJournalFiles
-- check what needs updating before taking the lock c <- filterM changedbranch =<< siblingBranches
fs <- getJournalFiles let (refs, branches) = unzip c
c <- filterM changedbranch =<< siblingBranches unless (null fs && null refs) $ withIndex $ lockJournal $ do
let (refs, branches) = unzip c {- Before refs are merged into the index, it's
unless (null fs && null refs) $ withIndex $ lockJournal $ do - important to first stage the journal into the
{- Before refs are merged into the index, it's - index. Otherwise, any changes in the journal
- important to first stage the journal into the - would later get staged, and might overwrite
- index. Otherwise, any changes in the journal - changes made during the merge.
- would later get staged, and might overwrite -
- changes made during the merge. - It would be cleaner to handle the merge by
- - updating the journal, not the index, with changes
- It would be cleaner to handle the merge by - from the branches.
- updating the journal, not the index, with changes -}
- from the branches. unless (null fs) $ stageJournalFiles fs
g <- gitRepo
unless (null branches) $ do
showSideAction $ "merging " ++
(unwords $ map Git.refDescribe branches) ++
" into " ++ name
{- Note: This merges the branches into the index.
- Any unstaged changes in the git-annex branch
- (if it's checked out) will be removed. So,
- documentation advises users not to directly
- modify the branch.
-} -}
unless (null fs) $ stageJournalFiles fs liftIO $ Git.UnionMerge.merge_index g branches
g <- gitRepo liftIO $ Git.commit g "update" fullname (nub $ fullname:refs)
unless (null branches) $ do invalidateCache
showSideAction $ "merging " ++
(unwords $ map Git.refDescribe branches) ++
" into " ++ name
{- Note: This merges the branches into the index.
- Any unstaged changes in the git-annex branch
- (if it's checked out) will be removed. So,
- documentation advises users not to directly
- modify the branch.
-}
liftIO $ Git.UnionMerge.merge_index g branches
liftIO $ Git.commit g "update" fullname (nub $ fullname:refs)
invalidateCache
Annex.changeState $ \s -> s { Annex.branchstate = state { branchUpdated = True } }
where where
changedbranch (_, branch) = do changedbranch (_, branch) = do
g <- gitRepo g <- gitRepo
@ -166,6 +163,14 @@ update = do
Params "--oneline -n1" Params "--oneline -n1"
] ]
return $ not $ L.null diffs return $ not $ L.null diffs
onceonly a = unlessM (branchUpdated <$> getState) $ do
r <- a
Annex.changeState setupdated
return r
setupdated s = s { Annex.branchstate = new }
where
new = old { branchUpdated = True }
old = Annex.branchstate s
{- Checks if a git ref exists. -} {- Checks if a git ref exists. -}
refExists :: GitRef -> Annex Bool refExists :: GitRef -> Annex Bool