Hi all,
This patch essentially delegates generating the set of context patches to
another function in another module. The patch is accepted for the HEAD and 2.5
branches if the tests go alright.
> hunk ./src/Darcs/Commands/Changes.lhs 297
>
> changesContext :: RepoPatch p => Repository p C(r u t) -> [DarcsFlag] -> IO
()
> changesContext repository opts = do
> - r <- readRepo repository
> - putStrLn "\nContext:\n"
> - case r of
> - PatchSet (_:<:_) _ ->
> - case slightlyOptimizePatchset r of
> - PatchSet ps (Tagged t _ _ :<: _) ->
> - putDocLnWith simplePrinters $ changelog opts' (PatchSet NilRL
NilRL) $
> - getChangesInfo opts' []
> - (PatchSet (ps +<+ t :<: NilRL) -- FIXME ugly!!!
> - NilRL)
> - PatchSet ps NilRL ->
> - putDocLnWith simplePrinters $ changelog opts' (PatchSet NilRL
NilRL) $
> - getChangesInfo opts' [] (PatchSet ps NilRL)
> - _ -> return ()
> - where opts' = if HumanReadable `elem` opts || XMLOutput `elem` opts
> - then opts
> - else MachineReadable : opts
> + FlippedSeal ps' <- contextPatches `fmap` readRepo repository
> + let ps = mapRL (\p -> (seal2 p, [])) ps'
> + unless fancy $ putStrLn "\nContext:\n"
> + putDocLnWith simplePrinters $ changelog opts' emptyset (ps, [], empty)
> + where opts' = if fancy then opts else MachineReadable : opts
> + fancy = HumanReadable `elem` opts || XMLOutput `elem` opts
> + emptyset = PatchSet NilRL NilRL
>
> log :: DarcsCommand
> log = commandAlias "log" Nothing changes
So instead of reading the patch set and optimizing it ourselves, we delegate
selecting the patches to 'contextPatches'. Formatting it is done by
'changelog' as it always was.
> hunk ./src/Darcs/Patch/Bundle.hs 24
> #include "gadts.h"
>
> module Darcs.Patch.Bundle ( hashBundle, makeBundle, makeBundle2,
makeBundleN, scanBundle,
> - makeContext, scanContext, patchFilename
> + contextPatches, scanContext, patchFilename
> ) where
>
> import Data.Char ( isAlpha, toLower, isDigit, isSpace )
So makeContext is gone and replaced by contextPatches.
> hunk ./src/Darcs/Patch/Bundle.hs 205
> ps' = dropSpace ps
> -}
>
> -makeContext :: [PatchInfo] -> Doc
> -makeContext common =
> - text ""
> - $$ text "Context:"
> - $$ text ""
> - $$ (vcat $ map showPatchInfo $ common)
> - $$ text ""
> +
> +contextPatches :: RepoPatch p => PatchSet p C(Origin x) -> FlippedSeal (RL
(PatchInfoAnd p)) C(x)
> +contextPatches set = case slightlyOptimizePatchset set of
> + PatchSet ps (Tagged t _ _ :<: _) -> flipSeal (ps +<+ (t :<: NilRL))
> + PatchSet ps NilRL -> flipSeal ps
Here the old function makeContext goes away, apparently it wasn't used
anymore. Its place is taken by contextPatches, which does not ouput a Doc but
just a set of patches.
This new function has only a 2-way case statement. In the old code in
Darcs.Commands.Changes it was three-way and it printed nothing in the case of
a clean tag. Here clean tags fall under the case of "a tag followed by zero or
more patches" as far as I can see.
Apparently, contextPatches is not used by the code that makes the context for
patch bundles. Why is that?
> addfile ./tests/issue1888-changes-context.sh
> hunk ./tests/issue1888-changes-context.sh 1
> +#!/usr/bin/env bash
> +## Test for issue1888 - changes --context is broken when topmost patch is a
> +## clean tag.
> +
> +## Copyright (C) 2010 Petr Rockai
> +##
> +## 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.
> +
> +. lib # Load some portability helpers.
> +rm -rf R # Another script may have left a mess.
> +darcs init --repo R # Create our test repos.
> +
> +cd R
> +
> +echo a > a ; darcs rec -lam "patch_a"
> +darcs changes --context | grep patch_a
> +
> +darcs tag -m "tag_a"
> +darcs changes --context | not grep patch_a
> +darcs changes --context | grep tag_a
> +
> +echo b > a; darcs rec -lam "patch_b"
> +darcs changes --context | not grep patch_a
> +darcs changes --context | grep tag_a
> +darcs changes --context | grep patch_b
A test that tests if a clean tag is included in the context.
Reinier
|