darcs

Issue 2416 ounparse is not always a proper inverse for oparse

Title ounparse is not always a proper inverse for oparse
Priority Status needs-diagnosis/design
Milestone Resolved in
Superseder Nosy List bfrk, ganesh
Assigned To
Topics

Created on 2014-11-12.21:42:58 by ganesh, last changed 2014-11-13.22:05:53 by bfrk.

Messages
msg17774 (view) Author: ganesh Date: 2014-11-12.21:42:56
For example:

Prelude Darcs.UI.Options.Core Darcs.UI.Options.Flags Darcs.UI.Options.All> oparse patchname id [(PatchName "\381")]
Just "\381"

Prelude Darcs.UI.Options.Core Darcs.UI.Options.Flags Darcs.UI.Options.All> ounparse patchname id (Just "\381")
[PatchName "}"]

We should either try to fix this and add unit tests to check that they are inverses for each other, or document that they aren't inverses.
msg17775 (view) Author: bfrk Date: 2014-11-13.00:42:05
The intention is that they are inverse. The reason this fails for
patchname is the use of D.Util.BytesString.decodeString. It is defined
there as

-- | Take a @String@ that represents byte values and re-decode it
acording to
-- the current locale.
decodeString :: String -> String
decodeString = decodeLocale . encodeLatin1

This function is also used by the options 'author' and 'from' (but not
by e.g. 'to' or 'cc'), and in D.UI.Flags.getEasyAuthor.
D.Util.BytesString does not define an inverse function.

My problem is: I do not understand why the decodeString function is
needed at all.
msg17776 (view) Author: bfrk Date: 2014-11-13.01:12:23
I have just verified that base-4.4.0.0 first introduces a locale-aware
System.Environment.getArgs. Unfortunately I could not find out which ghc
version that corresponds to. If the ghc version is older or equally old
as the oldest supported in Darcs, then I guess we can simply remove the
decodeString function and all its uses.
msg17777 (view) Author: ganesh Date: 2014-11-13.06:11:51
Darcs supports back to GHC 7.4, which uses base 4.5.

Using a standard function is attractive if it works. Otherwise, could we use decodeString 
on the whole command-line at the point we get the arguments?

I'm not sure what is supposed to happen to defaults read from files rather than the 
command-line.
msg17782 (view) Author: bfrk Date: 2014-11-13.18:26:19
Ok. (I see now that the cabal file, too, lists 4.5 as lower bound.) That
means we *can* assume that the String we get from getArgs uses the
user's current locale when it converts the command line args to a
String. *If* later stages correctly encode the String to utf-8 when
storing it in the patch file, then there is nothing else to do and
decodeString can *and should* be replaced with 'id'.
msg17783 (view) Author: bfrk Date: 2014-11-13.22:05:52
I like the idea of adding unit tests. I think QC would be well suited.
Now I need to find out how to add QC tests to the test suite...
History
Date User Action Args
2014-11-12 21:42:58ganeshcreate
2014-11-13 00:42:07bfrksetmessages: + msg17775
2014-11-13 01:12:24bfrksetmessages: + msg17776
2014-11-13 06:11:53ganeshsetmessages: + msg17777
2014-11-13 18:26:21bfrksetmessages: + msg17782
2014-11-13 22:05:53bfrksetmessages: + msg17783