darcs

Patch 321 Resolve issue1888: fix changes --context.

Title Resolve issue1888: fix changes --context.
Superseder Nosy List kowey, mornfall, tux_rocker
Related Issues
Status accepted Assigned To tux_rocker
Milestone

Created on 2010-07-29.19:02:30 by mornfall, last changed 2011-05-10.18:06:29 by darcswatch. Tracked on DarcsWatch.

Files
File name Status Uploaded Type Edit Remove
resolve-issue1888_-fix-changes-__context_.dpatch mornfall, 2010-07-29.19:02:30 text/x-darcs-patch
unnamed mornfall, 2010-07-29.19:02:30
See mailing list archives for discussion on individual patches.
Messages
msg11900 (view) Author: mornfall Date: 2010-07-29.19:02:30
Fixes changes --context, at a cost of slight refactor. Comes with a test (which
fails with current HEAD). I have also fixed an unrelated bug, where output of
changes --context --xml is not actually xml. Although if apps rely on that bug,
we may want to restore it (just remove the unless fancy bit in changesContext).

Yours,
   Petr.

1 patch for repository http://darcs.net/:

Thu Jul 29 20:51:43 CEST 2010  Petr Rockai <me@mornfall.net>
  * Resolve issue1888: fix changes --context.
Attachments
msg11911 (view) Author: tux_rocker Date: 2010-08-02.16:53:58
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
msg11914 (view) Author: darcswatch Date: 2010-08-02.18:22:11
This patch bundle (with 1 patches) was just applied to the repository http://darcs.net/.
This message was brought to you by DarcsWatch
http://darcswatch.nomeata.de/repo_http:__darcs.net_.html#bundle-c91c03451f721b1e8af1e4ca36e5988763f475b6
msg14101 (view) Author: darcswatch Date: 2011-05-10.18:06:29
This patch bundle (with 1 patches) was just applied to the repository http://darcs.net/reviewed.
This message was brought to you by DarcsWatch
http://darcswatch.nomeata.de/repo_http:__darcs.net_reviewed.html#bundle-c91c03451f721b1e8af1e4ca36e5988763f475b6
History
Date User Action Args
2010-07-29 19:02:30mornfallcreate
2010-07-29 19:09:47darcswatchsetdarcswatchurl: http://darcswatch.nomeata.de/repo_http:__darcs.net_.html#bundle-c91c03451f721b1e8af1e4ca36e5988763f475b6
2010-08-02 15:47:04koweysetassignedto: kowey
nosy: + kowey
2010-08-02 16:53:59tux_rockersetnosy: + tux_rocker
messages: + msg11911
2010-08-02 17:09:11koweysetstatus: needs-review -> accepted-pending-tests
assignedto: kowey -> tux_rocker
2010-08-02 18:22:11darcswatchsetstatus: accepted-pending-tests -> accepted
messages: + msg11914
2010-08-04 18:24:50mornfalllinkpatch322 superseder
2011-05-10 18:06:29darcswatchsetmessages: + msg14101