sync, assistant: Include repository name in head branch commit message.

Note that while the assistant detects changes made to remote names, I left
the commit message fixed rather than calculating it after every commit. It
doesn't seem worth the CPU to do the latter.
This commit is contained in:
Joey Hess 2015-02-11 13:33:55 -04:00
parent 07eec0b396
commit f5b830e07c
5 changed files with 33 additions and 6 deletions

View file

@ -50,6 +50,7 @@ commitThread = namedThread "Committer" $ do
delayadd <- liftAnnex $ delayadd <- liftAnnex $
maybe delayaddDefault (return . Just . Seconds) maybe delayaddDefault (return . Just . Seconds)
=<< annexDelayAdd <$> Annex.getGitConfig =<< annexDelayAdd <$> Annex.getGitConfig
msg <- liftAnnex Command.Sync.commitMsg
waitChangeTime $ \(changes, time) -> do waitChangeTime $ \(changes, time) -> do
readychanges <- handleAdds havelsof delayadd changes readychanges <- handleAdds havelsof delayadd changes
if shouldCommit False time (length readychanges) readychanges if shouldCommit False time (length readychanges) readychanges
@ -60,7 +61,7 @@ commitThread = namedThread "Committer" $ do
, "changes" , "changes"
] ]
void $ alertWhile commitAlert $ void $ alertWhile commitAlert $
liftAnnex commitStaged liftAnnex $ commitStaged msg
recordCommit recordCommit
let numchanges = length readychanges let numchanges = length readychanges
mapM_ checkChangeContent readychanges mapM_ checkChangeContent readychanges
@ -212,15 +213,15 @@ shouldCommit scanning now len changes
recentchanges = filter thissecond changes recentchanges = filter thissecond changes
timeDelta c = now `diffUTCTime` changeTime c timeDelta c = now `diffUTCTime` changeTime c
commitStaged :: Annex Bool commitStaged :: String -> Annex Bool
commitStaged = do commitStaged msg = do
{- This could fail if there's another commit being made by {- This could fail if there's another commit being made by
- something else. -} - something else. -}
v <- tryNonAsync Annex.Queue.flush v <- tryNonAsync Annex.Queue.flush
case v of case v of
Left _ -> return False Left _ -> return False
Right _ -> do Right _ -> do
ok <- Command.Sync.commitStaged Git.Branch.AutomaticCommit "" ok <- Command.Sync.commitStaged Git.Branch.AutomaticCommit msg
when ok $ when ok $
Command.Sync.updateSyncBranch =<< inRepo Git.Branch.current Command.Sync.updateSyncBranch =<< inRepo Git.Branch.current
return ok return ok

View file

@ -12,6 +12,7 @@ module Command.Sync (
mergeLocal, mergeLocal,
mergeRemote, mergeRemote,
commitStaged, commitStaged,
commitMsg,
pushBranch, pushBranch,
updateBranch, updateBranch,
syncBranch, syncBranch,
@ -41,10 +42,12 @@ import qualified Command.Move
import Logs.Location import Logs.Location
import Annex.Drop import Annex.Drop
import Annex.UUID import Annex.UUID
import Logs.UUID
import Annex.AutoMerge import Annex.AutoMerge
import Annex.Ssh import Annex.Ssh
import Control.Concurrent.MVar import Control.Concurrent.MVar
import qualified Data.Map as M
cmd :: [Command] cmd :: [Command]
cmd = [withOptions syncOptions $ cmd = [withOptions syncOptions $
@ -145,8 +148,8 @@ syncRemotes rs = ifM (Annex.getState Annex.fast) ( nub <$> pickfast , wanted )
commit :: CommandStart commit :: CommandStart
commit = next $ next $ do commit = next $ next $ do
commitmessage <- fromMaybe "git-annex automatic sync" commitmessage <- maybe commitMsg return
<$> Annex.getField (optionName messageOption) =<< Annex.getField (optionName messageOption)
showStart "commit" "" showStart "commit" ""
Annex.Branch.commit "update" Annex.Branch.commit "update"
ifM isDirect ifM isDirect
@ -163,6 +166,12 @@ commit = next $ next $ do
return True return True
) )
commitMsg :: Annex String
commitMsg = do
u <- getUUID
m <- uuidMap
return $ "git-annex in " ++ fromMaybe "unknown" (M.lookup u m)
commitStaged :: Git.Branch.CommitMode -> String -> Annex Bool commitStaged :: Git.Branch.CommitMode -> String -> Annex Bool
commitStaged commitmode commitmessage = go =<< inRepo Git.Branch.currentUnsafe commitStaged commitmode commitmessage = go =<< inRepo Git.Branch.currentUnsafe
where where

1
debian/changelog vendored
View file

@ -25,6 +25,7 @@ git-annex (5.20150206) UNRELEASED; urgency=medium
* metadata: When setting metadata, do not recurse into directories by * metadata: When setting metadata, do not recurse into directories by
default, since that can be surprising behavior and difficult to recover default, since that can be surprising behavior and difficult to recover
from. The old behavior is available by using --force. from. The old behavior is available by using --force.
* sync, assistant: Include repository name in head branch commit message.
-- Joey Hess <id@joeyh.name> Fri, 06 Feb 2015 13:57:08 -0400 -- Joey Hess <id@joeyh.name> Fri, 06 Feb 2015 13:57:08 -0400

View file

@ -8,3 +8,8 @@ Could not commit staged changes.
</pre> </pre>
This was trying to fix [[a broken merge|forum/canceling_wrong_repository_merge/]]... --[[anarcat]] This was trying to fix [[a broken merge|forum/canceling_wrong_repository_merge/]]... --[[anarcat]]
> While I think it's silly to use empty dummy commit messages when there
> is nothing of value to say about the commit, I guess I can add value
> by putting in the name of the repository where the commit was made. So,
> [[done]] --[[Joey]]

View file

@ -0,0 +1,11 @@
[[!comment format=mdwn
username="joey"
subject="""comment 1"""
date="2015-02-11T17:15:04Z"
content="""
It's completely legal for git commits to have empty commit messages. Why
would rebase care? Seems like a bug in rebase.
Note that only the git-annex assistant currently uses empty commit
messages.
"""]]