This version passes my test. Initially the tests were failing because I had not created a hash for the empty pristine (yay tests!) and also because my (somewhat random) use of the NoUpdateWorking flag was causing darcs to delete the tentative pending patch.
Fri Sep 4 08:15:00 CEST 2009 Eric Kow <[email protected]> * Resolve issue1584: Provide optimize --upgrade command. This can be used for an inplace upgrade to the latest hashed format. Right now it only handles old-fashioned => hashed, but there may be future format changes for which this can be reused. Wed Sep 2 08:00:31 CEST 2009 Eric Kow <[email protected]> * Test for issue1584, the optimize --upgrade feature.
New patches: [Resolve issue1584: Provide optimize --upgrade command. Eric Kow <[email protected]>**20090904061500 Ignore-this: 70db8c49379c0be0b9779176518a880d This can be used for an inplace upgrade to the latest hashed format. Right now it only handles old-fashioned => hashed, but there may be future format changes for which this can be reused. ] hunk ./src/Darcs/Arguments.lhs 45 in_reply_to, get_in_reply_to, target, cc, get_cc, output, output_auto_name, recursive, inventory_choices, get_inventory_choices, + upgradeFormat, askdeps, ignoretimes, lookforadds, ask_long_comment, sendmail_cmd, environmentHelpSendmail, hunk ./src/Darcs/Arguments.lhs 269 getContent PristinePlain = NoContent getContent PristineNone = NoContent getContent NoUpdateWorking = NoContent +getContent UpgradeFormat = NoContent getContent Relink = NoContent getContent RelinkPristine = NoContent getContent NoLinks = NoContent hunk ./src/Darcs/Arguments.lhs 945 DarcsNoArgOption [] ["old-fashioned-inventory"] UseOldFashionedInventory "Convert from hashed to darcs-1 format"] +upgradeFormat :: DarcsOption +upgradeFormat = + DarcsNoArgOption [] ["upgrade"] UpgradeFormat + "upgrade repository to latest compatible format" + xmloutput = DarcsNoArgOption [] ["xml-output"] XMLOutput "generate XML formatted output" hunk ./src/Darcs/Commands/Optimize.lhs 31 import Darcs.Hopefully ( hopefully, info ) import Darcs.Commands ( DarcsCommand(..), nodefaults ) -import Darcs.Arguments ( DarcsFlag( Compress, UnCompress, +import Darcs.Arguments ( DarcsFlag( UpgradeFormat, UseHashedInventory, + Compress, UnCompress, NoCompress, Reorder, TagName, CheckPoint, Relink, RelinkPristine ), hunk ./src/Darcs/Commands/Optimize.lhs 41 relink, relink_pristine, sibling, flagsToSiblings, working_repo_dir, umask_option, + upgradeFormat, ) import Darcs.Repository.Prefs ( get_preflist ) import Darcs.Repository ( Repository, PatchSet, withRepoLock, ($-), withGutsOf, hunk ./src/Darcs/Commands/Optimize.lhs 66 import Darcs.Sealed ( FlippedSeal(..), unsafeUnseal ) import Darcs.Global ( darcsdir ) #include "impossible.h" +-- imports for optimize --upgrade; to be tidied +import qualified Data.ByteString as B (empty) +import System.Directory ( createDirectoryIfMissing, removeFile ) +import System.FilePath.Posix ( takeExtension, (</>) ) + +import Progress ( beginTedious, endTedious, tediousSize, progress ) +import SHA1 ( sha1PS ) +import Darcs.Flags ( compression ) +import Darcs.Lock ( rm_recursive ) +import Darcs.Ordered ( mapFL, mapRL_RL, bunchFL, lengthRL ) +import Darcs.ProgressPatches ( progressFL ) +import Darcs.Repository.Cache ( hashedDir, HashedDir(HashedPristineDir) ) +import Darcs.Repository.Format ( identifyRepoFormat, + create_repo_format, writeRepoFormat, format_has, + RepoProperty ( HashedInventory ) ) +import qualified Darcs.Repository.HashedRepo as HashedRepo +import Darcs.Repository.Prefs ( getCaches ) +import Darcs.Repository.Repair ( replayRepository, RepositoryConsistency(..) ) +import Darcs.Utils ( catchall ) +#include "gadts.h" optimize_description :: String optimize_description = "Optimize the repository." hunk ./src/Darcs/Commands/Optimize.lhs 129 working_repo_dir, reorder_patches, sibling, relink, - relink_pristine]} + relink_pristine, + upgradeFormat + ]} optimize_cmd :: [DarcsFlag] -> [String] -> IO () hunk ./src/Darcs/Commands/Optimize.lhs 134 +optimize_cmd opts _ | UpgradeFormat `elem` opts = optimizeUpgradeFormat optimize_cmd origopts _ = withRepoLock opts $- \repository -> do cleanRepository repository do_reorder opts repository hunk ./src/Darcs/Commands/Optimize.lhs 339 _ -> Nothing lt = fromJust last_tag choose_order ps = ps +\end{code} + +The \verb|--upgrade| option for \verb!darcs optimize' performs an inplace +upgrade of your repository to the lastest \emph{compatible} format. Right this +means that darcs 1 old-fashioned repositories will be upgraded to darcs-1 +hashed repositories (and notably, not to darcs 2 repositories as that would not +be compatible; see \verb!darcs convert!). + +\begin{code} +optimizeUpgradeFormat :: IO () +optimizeUpgradeFormat = do + debugMessage $ "Upgrading to hashed..." + rf <- either fail return =<< identifyRepoFormat "." + debugMessage $ "Found our format" + if format_has HashedInventory rf + then putStrLn "No action taken because this repository already is hashed." + else do putStrLn "Checking repository in case of corruption" + withRepoLock [] $- \repository -> do + state <- replayRepository repository [] return + case state of + RepositoryConsistent -> do + putStrLn "The repository is consistent." + actuallyUpgradeFormat repository + _repoIsBroken -> + putStrLn "Corruption detected! Please run darcs repair first" + +actuallyUpgradeFormat :: RepoPatch p => Repository p C(r u t) -> IO () +actuallyUpgradeFormat repository = do + -- convert patches/inventory + patches <- read_repo repository + let k = "Hashing patch" + beginTedious k + tediousSize k (lengthRL $ concatRL patches) + let patches' = mapRL_RL (mapRL_RL (progress k)) patches + cache <- getCaches [] "." + let compr = compression [] -- default compression? + HashedRepo.write_tentative_inventory cache compr patches' + endTedious k + -- convert pristine by applying patches + -- I'm not sure if the best way to convert pristine is to copy it or + -- to apply the patches. I believe the apply method is more reliable + let patchesToApply = progressFL "Applying patch" $ reverseRL $ concatRL $ patches' + createDirectoryIfMissing False $ darcsdir </> hashedDir HashedPristineDir + writeFile (darcsdir </> hashedDir HashedPristineDir </> sha1PS B.empty) "" + sequence_ $ mapFL (HashedRepo.apply_to_tentative_pristine cache []) $ bunchFL 100 patchesToApply + -- now make it official + HashedRepo.finalize_tentative_changes repository compr + writeRepoFormat (create_repo_format [UseHashedInventory]) (darcsdir </> "format") + -- clean out old-fashioned junk + removeFile $ darcsdir </> "inventory" + removeFile $ darcsdir </> "tentative_inventory" + rm_recursive (darcsdir </> "pristine") `catchall` rm_recursive (darcsdir </> "current") + withCurrentDirectory (darcsdir </> "patches") $ do + gzs <- filter ((== ".gz") . takeExtension) `fmap` getDirectoryContents "." + mapM_ removeFile gzs \end{code} hunk ./src/Darcs/Commands/Repair.lhs 20 \darcsCommand{repair} \begin{code} -module Darcs.Commands.Repair ( repair ) where +module Darcs.Commands.Repair ( repair, repair_cmd ) where import System.IO import Darcs.Commands hunk ./src/Darcs/Flags.hs 81 | UseFormat2 | PristinePlain | PristineNone | NoUpdateWorking | Sibling AbsolutePath | Relink | RelinkPristine | NoLinks + | UpgradeFormat | Files | NoFiles | Directories | NoDirectories | Pending | NoPending | PosthookCmd String | NoPosthook | AskPosthook | RunPosthook [Test for issue1584, the optimize --upgrade feature. Eric Kow <[email protected]>**20090902060031 Ignore-this: 5c3032156f75f224f08fa19e5311a0d3 ] addfile ./tests/issue1584_optimize_upgrade.sh hunk ./tests/issue1584_optimize_upgrade.sh 1 +#!/usr/bin/env bash +## Test for issue1584 - darcs optimize --upgrade +## +## Copyright (C) 2009 Eric Kow <[email protected]> +## +## Permission is hereby granted, free of charge, to any person +## obtaining a copy of this software and associated documentation +## files (the "Software"), to deal in the Software without +## restriction, including without limitation the rights to use, copy, +## modify, merge, publish, distribute, sublicense, and/or sell copies +## of the Software, and to permit persons to whom the Software is +## furnished to do so, subject to the following conditions: +## +## The above copyright notice and this permission notice shall be +## included in all copies or substantial portions of the Software. +## +## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +## MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +## NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +## BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +## ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +## CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +## SOFTWARE. + +. ../tests/lib # Load some portability helpers. +rm -rf R # Another script may have left a mess. +darcs init --repo R --old-fashioned # Create our test repos. +mkdir R/d/ R/e/ # Change the working tree. +echo 'Example content.' >R/d/f +darcs record --repo R -lam 'Add d/f and e.' +darcs mv --repo R d/f e/ # Unrecorded change +darcs whatsnew --repo R | grep 'move ./d/f' +darcs optimize --repo R --upgrade +darcs check --repo R +grep hashed R/_darcs/format +not grep darcs-2 R/_darcs/format +darcs whatsnew --repo R | grep 'move ./d/f' Context: [TAG 2.3.0 Petr Rockai <[email protected]>**20090723115125 Ignore-this: e326d4ddff92c578e8fe8a3c23d00193 ] Patch bundle hash: 813101eb9e50979fe45d0f7c267b74757069df2d
_______________________________________________ darcs-users mailing list [email protected] http://lists.osuosl.org/mailman/listinfo/darcs-users
