darcs

Patch 736 Style Darcs.SelectChanges (and 2 more)

Title Style Darcs.SelectChanges (and 2 more)
Superseder Nosy List stulli
Related Issues
Status accepted Assigned To stulli
Milestone

Created on 2012-03-06.22:14:17 by stulli, last changed 2012-04-22.19:30:13 by gh.

Files
File name Status Uploaded Type Edit Remove
compiler-errors.txt mndrix, 2012-03-15.19:38:57 text/plain
dirty-fix-for-compile-error-in-selectchanges.dpatch gh, 2012-03-16.18:29:06 application/x-darcs-patch
patch-preview.txt stulli, 2012-03-06.22:14:16 text/x-darcs-patch
patch-preview.txt stulli, 2012-03-10.17:24:39 text/x-darcs-patch
patch-preview.txt gh, 2012-03-16.18:29:06 text/x-darcs-patch
style-darcs_selectchanges.dpatch stulli, 2012-03-06.22:14:16 application/x-darcs-patch
style-darcs_selectchanges.dpatch stulli, 2012-03-10.17:24:39 application/x-darcs-patch
unnamed stulli, 2012-03-06.22:14:16
unnamed owst, 2012-03-06.23:05:22 text/html
unnamed stulli, 2012-03-10.17:24:39
unnamed gh, 2012-03-16.18:29:06
See mailing list archives for discussion on individual patches.
Messages
msg15213 (view) Author: stulli Date: 2012-03-06.22:14:16
3 patches for repository http://darcs.net/screened:

Tue Mar  6 19:42:42 CET 2012  Andreas Brandt <andreas.brandt.de@googlemail.com>
  * Style Darcs.SelectChanges

Tue Mar  6 20:58:25 CET 2012  Andreas Brandt <andreas.brandt.de@googlemail.com>
  * Resolve issue2145: darcs amend-record now can be navigated with 'j'

Tue Mar  6 21:37:17 CET 2012  Andreas Brandt <andreas.brandt.de@googlemail.com>
  * Tidy up wspfr
  Some style improvements and renaming variables to CamelCase
Attachments
msg15215 (view) Author: owst Date: 2012-03-06.23:05:22
Hi Andreas,

Thanks for the patches. I've made a few comments inline.

> [Style Darcs.SelectChanges
> Andreas Brandt <andreas.brandt.de@googlemail.com>**20120306184242
>  Ignore-this: 40305ee44a317015df8e7869c916c83f
> ] hunk ./src/Darcs/SelectChanges.hs 245
>  keysFor = concatMap (map kp)
>
>  -- | The function for selecting a patch to amend record. Read at your
own risks.
> -withSelectedPatchFromRepo :: forall p C(r u t). (RepoPatch p, ApplyState
p ~ Tree)
> -                          => String -> Repository p C(r u t) ->
[DarcsFlag]
> -                          -> (FORALL(a) (FL (PatchInfoAnd p) :>
PatchInfoAnd p) C(a r) -> IO ()) -> IO ()
> +withSelectedPatchFromRepo ::
> +       forall p C(r u t). (RepoPatch p, ApplyState p ~ Tree)
> +    => String   -- name of calling command (always "amend" as of now)
> +    -> Repository p C(r u t)
> +    -> [DarcsFlag]
> +    -> (FORALL(a) (FL (PatchInfoAnd p) :> PatchInfoAnd p) C(a r) -> IO
())
> +    -> IO ()
>  withSelectedPatchFromRepo jn repository o job = do
>      p_s <- readRepo repository
> hunk ./src/Darcs/SelectChanges.hs 254
> -    sp <- wspfr jn (matchAPatchread o)
> -                              (newset2RL p_s) NilFL
> +    sp <- wspfr jn (matchAPatchread o) (newset2RL p_s) NilFL

All looks good up to here.

>      case sp of
>       Just (FlippedSeal (skipped :> selected')) -> job (skipped :>
selected')
>       Nothing -> do putStrLn $ "Cancelling "++jn++" since no patch was
selected."
> hunk ./src/Darcs/SelectChanges.hs 259
>
> --- | This ensures that the selected patch commutes freely with the
skipped patches, including pending
> --- and also that the skipped sequences has an ending context that
matches the recorded state, z,
> --- of the repository.
> +-- | This ensures that the selected patch commutes freely with the
skipped
> +-- patches, including pending and also that the skipped sequences has an
> +-- ending context that matches the recorded state, z, of the repository.

Maybe this could take this opertunity to name this function something
better. I
just sat for a while wondering what on earth wspfr could stand for :-) I
know
it's part of the development tips wiki page, but I'm not a fan of this
naming
convention...

>  wspfr :: (RepoPatch p, ApplyState p ~ Tree)
> hunk ./src/Darcs/SelectChanges.hs 263
> -      => String -> (FORALL(a b) (PatchInfoAnd p) C(a b) -> Bool)
> -      -> RL (PatchInfoAnd p) C(x y) -> FL (PatchInfoAnd p) C(y u)
> +      => String
> +      -> (FORALL(a b) (PatchInfoAnd p) C(a b) -> Bool)
> +      -> RL (PatchInfoAnd p) C(x y)
> +      -> FL (PatchInfoAnd p) C(y u)
>        -> IO (Maybe (FlippedSeal (FL (PatchInfoAnd p) :> (PatchInfoAnd
p)) C(u)))
>  wspfr _ _ NilRL _ = return Nothing
>  wspfr jn matches (p:<:pps) skipped
> [Resolve issue2145: darcs amend-record now can be navigated with 'j'
> Andreas Brandt <andreas.brandt.de@googlemail.com>**20120306195825
>  Ignore-this: d906e2588f8e7e18e391c2336d61340c
> ] hunk ./src/Darcs/SelectChanges.hs 269
>        -> FL (PatchInfoAnd p) C(y u)
>        -> IO (Maybe (FlippedSeal (FL (PatchInfoAnd p) :> (PatchInfoAnd
p)) C(u)))
>  wspfr _ _ NilRL _ = return Nothing
> -wspfr jn matches (p:<:pps) skipped
> +wspfr jn matches remaining@(p:<:pps) skipped
>      | not $ matches p = wspfr jn matches pps (p:>:skipped)
>      | otherwise =
>      case commuteFLorComplain (p :> skipped) of
> hunk ./src/Darcs/SelectChanges.hs 283
>                      [[ KeyPress 'y' (jn++" this patch")
>                       , KeyPress 'n' ("don't "++jn++" it")
>                       , KeyPress 'k' "back up to previous patch"
> +                     , KeyPress 'j' "skip to next patch"
>                      ]]
>            advanced_options =
>                      [[ KeyPress 'v' "view this patch in full"
> hunk ./src/Darcs/SelectChanges.hs 303
>          'k' -> case skipped of
>                    NilFL -> repeat_this
>                    (prev :>: skipped') -> wspfr jn matches (prev :<: p
:<: pps) skipped'
> +        'j' -> case remaining of
> +                  NilRL -> repeat_this
> +                  (prev :<: remaining') -> wspfr jn matches remaining'
(prev :>: skipped)

You've already matched against a non-NilRL value, so you don't need to
match it
again (the first wspfr case catches the NilRL case).

>          'v' -> printPatch p >> repeat_this
>          'p' -> printPatchPager p >> repeat_this
>          'x' -> do putDocLn $ prefix "    " $ summary p
> [Tidy up wspfr
> Andreas Brandt <andreas.brandt.de@googlemail.com>**20120306203717
>  Ignore-this: 36ef9444431a9c0850526c4256f1561f
>  Some style improvements and renaming variables to CamelCase
> ] hunk ./src/Darcs/SelectChanges.hs 256
>      p_s <- readRepo repository
>      sp <- wspfr jn (matchAPatchread o) (newset2RL p_s) NilFL
>      case sp of
> -     Just (FlippedSeal (skipped :> selected')) -> job (skipped :>
selected')
> -     Nothing -> do putStrLn $ "Cancelling "++jn++" since no patch was
selected."
> +        Just (FlippedSeal (skipped :> selected')) -> job (skipped :>
selected')

Why not use an @-pattern here, too?

> +        Nothing ->
> +            putStrLn $ "Cancelling " ++ jn ++ " since no patch was
selected."
>
>  -- | This ensures that the selected patch commutes freely with the
skipped
>  -- patches, including pending and also that the skipped sequences has an
> hunk ./src/Darcs/SelectChanges.hs 279
>                    wspfr jn matches pps (p:>:skipped)
>      Right (skipped' :> p') -> do
>        printFriendly [] p
> -      let repeat_this  = wspfr jn matches (p:<:pps) skipped
> -          basic_options =
> -                    [[ KeyPress 'y' (jn++" this patch")
> -                     , KeyPress 'n' ("don't "++jn++" it")
> -                     , KeyPress 'k' "back up to previous patch"
> -                     , KeyPress 'j' "skip to next patch"
> -                    ]]
> -          advanced_options =
> -                    [[ KeyPress 'v' "view this patch in full"
> -                     , KeyPress 'p' "view this patch in full with pager"
> -                     , KeyPress 'x' "view a summary of this patch"
> -                     , KeyPress 'q' ("cancel "++jn)
> -                    ]]
> -      let prompt'  = "Shall I "++jn++" this patch?"
> -      yorn <- promptChar $ PromptConfig { pPrompt = prompt'
> -                                        , pBasicCharacters = keysFor
basic_options
> -                                        , pAdvancedCharacters = keysFor
advanced_options
> -                                        , pDefault = Just 'n'
> -                                        , pHelp = "?h" }
> +      yorn <- promptChar $
> +                  PromptConfig { pPrompt = prompt'
> +                               , pBasicCharacters = keysFor basicOptions
> +                               , pAdvancedCharacters = keysFor
advancedOptions
> +                               , pDefault = Just 'n'
> +                               , pHelp = "?h" }
>        case yorn of
>          'y' -> return $ Just $ flipSeal $ skipped' :> p'
>          'n' -> wspfr jn matches pps (p:>:skipped)
> hunk ./src/Darcs/SelectChanges.hs 289
>          'k' -> case skipped of
> -                  NilFL -> repeat_this
> -                  (prev :>: skipped') -> wspfr jn matches (prev :<: p
:<: pps) skipped'
> +                   NilFL -> repeat_this
> +                   (prev :>: skipped') ->
> +                       wspfr jn matches (prev :<: remaining) skipped'
>          'j' -> case remaining of
> hunk ./src/Darcs/SelectChanges.hs 293
> -                  NilRL -> repeat_this
> -                  (prev :<: remaining') -> wspfr jn matches remaining'
(prev :>: skipped)
> +                   NilRL -> repeat_this
> +                   (prev :<: remaining') ->
> +                       wspfr jn matches remaining' (prev :>: skipped)
>          'v' -> printPatch p >> repeat_this
>          'p' -> printPatchPager p >> repeat_this
>          'x' -> do putDocLn $ prefix "    " $ summary p
> hunk ./src/Darcs/SelectChanges.hs 300
>                    repeat_this
> -        'q' -> do putStrLn $ jn_cap++" cancelled."
> +        'q' -> do putStrLn $ jn_cap ++ " cancelled."
>                    exitWith $ ExitSuccess
> hunk ./src/Darcs/SelectChanges.hs 302
> -        _   -> do putStrLn $ helpFor jn basic_options advanced_options
> +        _   -> do putStrLn $ helpFor jn basicOptions advancedOptions
>                    repeat_this
> hunk ./src/Darcs/SelectChanges.hs 304
> -  where jn_cap = (toUpper $ head jn) : tail jn
> +  where repeat_this = wspfr jn matches (p:<:pps) skipped
> +        prompt' = "Shall I " ++ jn ++ " this patch?"
> +        jn_cap = (toUpper $ head jn) : tail jn
> +        basicOptions =
> +                    [[ KeyPress 'y' (jn ++ " this patch")
> +                     , KeyPress 'n' ("don't " ++ jn ++ " it")
> +                     , KeyPress 'k' "back up to previous patch"
> +                     , KeyPress 'j' "skip to next patch"
> +                    ]]
> +        advancedOptions =
> +                    [[ KeyPress 'v' "view this patch in full"
> +                     , KeyPress 'p' "view this patch in full with pager"
> +                     , KeyPress 'x' "view a summary of this patch"
> +                     , KeyPress 'q' ("cancel " ++ jn)
> +                    ]]
>
>  -- After selecting with a splitter, the results may not be canonical
>  canonizeAfterSplitter :: (FL p :> FL p) C(x y) -> Reader
(PatchSelectionContext p) ((FL p :> FL p) C(x y))
> replace ./src/Darcs/SelectChanges.hs [A-Za-z_0-9] jn_cap jnCapital
> replace ./src/Darcs/SelectChanges.hs [A-Za-z_0-9] p_s patchSet
> replace ./src/Darcs/SelectChanges.hs [A-Za-z_0-9] repeat_this repeatThis

You could also replace basic_options since it's used as an identifier in
lastQuestion, too.

Otherwise, great - thanks!

--
Owen.
Attachments
msg15224 (view) Author: stulli Date: 2012-03-07.21:00:32
> name change wspfr
Actually i kind of dislike 'withSelectedPatchFromRepo' too.
There is no patch we give as an argument like, for example, in
withCurrentDirectory.
'selectPatchFromRepo' would make more sense IMO.

For wspfr it could be something like
'selectPatchFromPatchSet/PatchList'

> NilRL matching
Yes, that's why NilRL is being ignored in the 'n'-case aswell.
Will amend accordingly.

> Why not use an @-pattern here, too?
I don't know what the return type of wspfr means so i'd struggle
to give the @-pattern a name. A further understanding of 
'commuteFLorComplain' might help aswell.
Generally i try not to modify code i don't understand at all..

> replace basic_options
I saw that basicOptions was already used. From the message i got
from earlier replaces i concluded that all occurrences of
basicOptions would first be replaced by basic_options before
changing to basicOptions again and thus marking the places
where basicOptions already has been before as modified by me.
No big deal so i'll amend with a replace.
msg15247 (view) Author: ganesh Date: 2012-03-09.21:50:51
Dropping these for now because of a conflict with patch744 after 
discussing with stulli on IRC.
msg15258 (view) Author: stulli Date: 2012-03-10.17:24:39
I adapted the two style patches so they don't conflict with
patch744.
Since i realized i was wrong about the naming issues in my last comment
i won't change any function names for now.

The Resolve patch is obsolete because of patch744.

2 patches for repository http://darcs.net/screened:

Wed Mar  7 23:32:29 CET 2012  Andreas Brandt <andreas.brandt.de@googlemail.com>
  * Style Darcs.SelectChanges

Sat Mar 10 00:53:02 CET 2012  Andreas Brandt <andreas.brandt.de@googlemail.com>
  * Tidy up wspfr
  Some style improvements and renaming variables to CamelCase
Attachments
msg15332 (view) Author: gh Date: 2012-03-15.15:52:28
These new patches apply cleanly and look good.
msg15333 (view) Author: gh Date: 2012-03-15.15:55:42
Needs patch744 to be pushed to reviewed first.
msg15339 (view) Author: mndrix Date: 2012-03-15.19:38:57
Patch "Tidy up wspfr" causes the attached compiler errors in screened.
Attachments
msg15348 (view) Author: gh Date: 2012-03-16.18:29:06
Fixing the compilation error by going against the spirit of Andreas' patch.

I believe that in order to reintroduce the local function "previousPatch",
one needs to add a type signature for it with the correct type witnesses.

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

Fri Mar 16 14:55:02 ART 2012  Guillaume Hoffmann <guillaumh@gmail.com>
  * dirty fix for compile error in SelectChanges
Attachments
msg15405 (view) Author: mndrix Date: 2012-03-28.02:03:44
Dependency patch744 is in reviewed, but now it's waiting on the dependency 
"resolve issue1166 --unified flag for record, amend-record, revert and 
unrevert" (part of patch738).

Since this patch has already been reviewed by owst, ganesh and gh, I'm 
marking it as accepted-pending-tests
msg15604 (view) Author: gh Date: 2012-04-22.19:30:13
Pushing remaing patches now that patch738 is in.
History
Date User Action Args
2012-03-06 22:14:17stullicreate
2012-03-06 23:05:23owstsetfiles: + unnamed
messages: + msg15215
2012-03-07 21:00:32stullisetmessages: + msg15224
2012-03-09 21:50:51ganeshsetstatus: needs-screening -> followup-in-progress
messages: + msg15247
2012-03-10 17:24:40stullisetfiles: + patch-preview.txt, style-darcs_selectchanges.dpatch, unnamed
messages: + msg15258
2012-03-10 19:33:58stullisetstatus: followup-in-progress -> needs-screening
2012-03-15 15:52:28ghsetstatus: needs-screening -> accepted
messages: + msg15332
2012-03-15 15:55:42ghsetstatus: accepted -> accepted-pending-tests
messages: + msg15333
2012-03-15 19:38:57mndrixsetstatus: accepted-pending-tests -> followup-requested
files: + compiler-errors.txt
messages: + msg15339
assignedto: stulli
2012-03-16 18:29:06ghsetfiles: + patch-preview.txt, dirty-fix-for-compile-error-in-selectchanges.dpatch, unnamed
messages: + msg15348
2012-03-16 18:48:00ghsetstatus: followup-requested -> needs-review
2012-03-28 02:03:45mndrixsetstatus: needs-review -> accepted-pending-tests
messages: + msg15405
2012-04-22 19:30:13ghsetstatus: accepted-pending-tests -> accepted
messages: + msg15604