Resolve issue121: add --ask-deps support to amend-record
--------------------------------------------------------
Ganesh Sittampalam <ganesh@earth.li>**20091228223636
Codewise, this patch is good. Is it hot enough to be applied despite
the soft freeze? I'd vote yes, but leave that to the release manager.
>[…]
hunk ./src/Darcs/Commands/AmendRecord.lhs 154
> putStrLn "Finished amending patch:"
> putDocLn $ description newp
>
> -updatePatchHeader :: forall p. (RepoPatch p) => [DarcsFlag] -> PatchInfoAnd p
-> FL Prim
> +updatePatchHeader :: forall p. (RepoPatch p) => [DarcsFlag] -> Repository p
-> PatchInfoAnd p -> FL Prim
> -> IO (Maybe String, PatchInfoAnd p)
updatePatchHeader now needs to know where to offer new dependencies from.
hunk ./src/Darcs/Commands/AmendRecord.lhs 156
> -updatePatchHeader opts oldp chs = do
> +updatePatchHeader opts repository oldp chs = do
> +
> + let newchs = canonizeFL (effect oldp +>+ chs)
> +
> + let old_pdeps = getdeps $ hopefully oldp
> + newdeps <- if AskDeps `elem` opts
> + then askAboutDepends repository newchs opts
old_pdeps
> + else return old_pdeps
> +
Ok, we add the new deps if necessary.
[…]
hunk ./src/Darcs/Commands/Record.lhs 398
> depended-upon patches.
>
> \begin{code}
> -askAboutDepends :: RepoPatch p => Repository p -> FL Prim -> [DarcsFlag] ->
IO [PatchInfo]
> -askAboutDepends repository pa' opts = do
> +askAboutDepends :: RepoPatch p => Repository p -> FL Prim -> [DarcsFlag] ->
[PatchInfo] -> IO [PatchInfo]
> +askAboutDepends repository pa' opts olddeps = do
> + -- ideally we'd just default the olddeps to yes but still ask about them.
> + -- SelectChanges doesn't currently (17/12/09) offer a way to do this so would
> + -- have to have this support added first.
> pps <- read_repo repository
> pa <- n2pia `fmap` anonymous (fromPrims pa')
> let ps = (reverseRL $ headRL pps)+>+(pa:>:NilFL)
hunk ./src/Darcs/Commands/Record.lhs 407
> (pc, tps) = patchChoicesTps ps
> - ta = case filter ((pa `unsafeCompare`) . tpPatch) $ unsafeUnFL tps of
> - [tp] -> tag tp
> + tas = case filter (\tp -> pa `unsafeCompare` tpPatch tp || info
(tpPatch tp) `elem` olddeps) $ unsafeUnFL tps of
> [] -> error "askAboutDepends: []"
This gets the tags of the old dependencies. I think that in a followup
patch, this should be abstracted into a function for retrieving a list
of tags corresponding to patches matching some function in a
PatchChoices, which would go in Darcs.Patch.Choices.
hunk ./tests/issue121.sh 1
> +#!/usr/bin/env bash
> +## Test for issue121 - amend-record --ask-deps
> +##
> +## Copyright (C) 2009 Ganesh Sittampalam
> +##
> +## 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
> +darcs init --repo R # Create our test repos.
> +
> +cd R
> +touch a
> +darcs add a
> +darcs rec --ignore-times -am 'add a'
> +(echo '1' ; echo '1' ; echo '1') > a
> +darcs rec --ignore-times -am 'patch X'
> +(echo '2' ; echo '1' ; echo '1') > a
> +darcs rec --ignore-times -am 'patch Y'
> +(echo '2' ; echo '1' ; echo '2') > a
> +darcs rec --ignore-times -am 'patch Z'
> +
> +darcs obliterate --dry-run --patch 'patch Y' | not grep 'patch Z'
> +
> +echo 'yy' | darcs amend-rec --ask-deps
> +
> +darcs obliterate --dry-run --patch 'patch Y' | grep 'patch Z'
Test for this functionality. Y and Z depend on X. Then Z is made to
depend on Y. First, unpulling Y leaves Z alone, then it unpulls it too.
|