DRAFT: don't apply this yet. I'm sending this now because I'm not sure when I'll get another chance to work on it. This doesn't quite work. It seems to be fine if I run it by hand -- perhaps converting the GHC repo would be a good test -- but for some reason if I run the test through cabal test tests/issue1584_etc I get some complaint about not being able to fetch something from the caches.
Interestingly the tests appear to pass if I just run 'cabal test' [perhaps this is due to the stylised nature of the test suites making it such that different repos are populating the cache with coincidentally the right content?] Bleah... Tue Sep 1 00:18:36 CEST 2009 Eric Kow <ko...@darcs.net> * 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 <ko...@darcs.net> * Test for issue1584, the optimize --upgrade feature.
New patches: [Resolve issue1584: Provide optimize --upgrade command. Eric Kow <ko...@darcs.net>**20090831221836 Ignore-this: 6e745b9705cc2504fbada2c0bd5c49d9 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, NoUpdateWorking, + 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 System.Directory ( createDirectoryIfMissing, removeFile ) +import System.FilePath.Posix ( takeExtension, (</>) ) + +import Progress ( beginTedious, endTedious, tediousSize, progress ) +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 127 working_repo_dir, reorder_patches, sibling, relink, - relink_pristine]} + relink_pristine, + upgradeFormat + ]} optimize_cmd :: [DarcsFlag] -> [String] -> IO () hunk ./src/Darcs/Commands/Optimize.lhs 132 +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 337 _ -> 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" + let opts = [ NoUpdateWorking ] + withRepoLock opts $- \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 + sequence_ $ mapFL (HashedRepo.apply_to_tentative_pristine cache []) $ bunchFL 100 patchesToApply + HashedRepo.finalize_tentative_changes repository compr + -- 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 + -- note new format + writeRepoFormat (create_repo_format [UseHashedInventory]) (darcsdir </> "format") \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 <ko...@darcs.net>**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 <ko...@darcs.net> +## +## 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 <m...@mornfall.net>**20090723115125 Ignore-this: e326d4ddff92c578e8fe8a3c23d00193 ] Patch bundle hash: f87daa29619128358c3a5f20180399676eb9542c
_______________________________________________ darcs-users mailing list darcs-users@darcs.net http://lists.osuosl.org/mailman/listinfo/darcs-users