I believe this version addresses the easy issues. Wed Sep 2 08:00:31 CEST 2009 Eric Kow <[email protected]> * Test for issue1584, the optimize --upgrade feature.
Tue Sep 22 22:11:49 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. Tue Sep 22 22:12:31 CEST 2009 Eric Kow <[email protected]> * Resolve issue1583: on darcs get, suggest upgrading source repo to hashed.
New patches: [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' [Resolve issue1584: Provide optimize --upgrade command. Eric Kow <[email protected]>**20090922201149 Ignore-this: e72ddff8c879de637e6a7dcb824624d6 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 now +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 + -- the faster alternative would be to copy pristine, but 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 + debugMessage "Cleaning out old-fashioned repository files..." + removeFile $ darcsdir </> "inventory" + removeFile $ darcsdir </> "tentative_inventory" + rm_recursive (darcsdir </> "pristine") `catchall` rm_recursive (darcsdir </> "current") + rmGzsIn (darcsdir </> "patches") + rmGzsIn (darcsdir </> "inventories") + let checkpointDir = darcsdir </> "checkpoints" + hasCheckPoints <- doesDirectoryExist checkpointDir + when hasCheckPoints $ rm_recursive checkpointDir + putStrLn "Done upgrading!" + where + rmGzsIn dir = + withCurrentDirectory dir $ 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 [Resolve issue1583: on darcs get, suggest upgrading source repo to hashed. Eric Kow <[email protected]>**20090922201231 Ignore-this: 629571ddac3c867dce4cbb60eee80522 ] hunk ./src/Darcs/Commands/Get.lhs 194 putInfo $ text "Finished getting." where copy_repo = withRepository opts $- \repository -> do - if format_has HashedInventory rf || format_has HashedInventory rfsource - then do debugMessage "Identifying and copying repository..." - identifyRepositoryFor repository repodir >>= copyRepository - when (SetScriptsExecutable `elem` opts) setScriptsExecutable - else copy_repo_old_fashioned repository opts repodir + let hashUs = format_has HashedInventory rf + hashThem = format_has HashedInventory rfsource + case () of _ | hashUs && hashThem -> do + debugMessage "Identifying and copying repository..." + copyRepoHashed repository + | hashUs -> do + putInfo $ text "Converting old-fashioned repository to hashed format..." + $$ text "*******************************************************************************" + $$ text "Fetching a hashed repository would be faster. Perhaps you could persuade" + $$ text "the maintainer to run darcs optimize --upgrade with darcs 2.3.1 or higher?" + $$ text "*******************************************************************************" + copyRepoHashed repository + | hashThem -> do + putInfo $ text "Fetching a hashed repository as an old-fashioned one..." + copyRepoHashed repository + | otherwise -> copy_repo_old_fashioned repository opts repodir + copyRepoHashed repository = + do identifyRepositoryFor repository repodir >>= copyRepository + when (SetScriptsExecutable `elem` opts) setScriptsExecutable make_repo_name :: [DarcsFlag] -> FilePath -> IO String make_repo_name (NewRepo n:_) _ = Context: [TAG 2.3.0 Petr Rockai <[email protected]>**20090723115125 Ignore-this: e326d4ddff92c578e8fe8a3c23d00193 ] Patch bundle hash: 105129ce748072b79701be483a3b90daa0b16f93
_______________________________________________ darcs-users mailing list [email protected] http://lists.osuosl.org/mailman/listinfo/darcs-users
