[darcs-users] A comment about possible code duplication

Iago Abal iago.abal at gmail.com
Sun Nov 14 01:35:40 UTC 2010


Ok sorry, I mean "old" `isSuperdir` "name"

On Sun, Nov 14, 2010 at 1:26 AM, Iago Abal <iago.abal at gmail.com> wrote:

> Hi all, I prefer to ask instead of submit a patch because maybe there is a
> good reason for the following:
>
> In Darcs.Patch.Prim
>
>> isSuperdir :: FileName -> FileName -> Bool
>
> isSuperdir d1 d2 = isd (fn2fp d1) (fn2fp d2)
>
>     where isd s1 s2 =
>
>               length s2 >= length s1 + 1 && take (length s1 + 1) s2 == s1
>> ++ "/"
>
>
> In Darcs.Patch.FileName
>
>> movedirfilename :: FileName -> FileName -> FileName -> FileName
>
> movedirfilename old new name =
>
>     if name' == old' then new
>
>                      else if *length name' > length old' &&*
>
> *                             take (length old'+1) name' == old'++"/"*
>
>                           then fp2fn ("./"++new'++drop (length old') name')
>
>                           else name
>
>     where old' = fn2fp $ normPath old
>
>           new' = fn2fp $ normPath new
>
>           name' = fn2fp $ normPath name
>
>
> I think movedirfilename will be more readable if the bold code is replaced
> by "name" `isSuperdir` "old". Since some normalization is performed I don't
> know if the use of isSuperdir :: FileName -> FileName -> Bool is the best
> choice, but anyway, I think a where clause "where isSuperdir = ..." will be
> very appreciated when reading movedirfilename.
>
> --
> Iago Abal Rivas
>



-- 
Iago Abal Rivas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osuosl.org/pipermail/darcs-users/attachments/20101114/365c181f/attachment.html>


More information about the darcs-users mailing list