[darcs-users] index format (Was: Re: hashed-storage index)

Jason Dagit dagit at codersbase.com
Mon Jun 8 06:52:24 UTC 2009


Hi Petr,

On Sun, Jun 7, 2009 at 11:01 PM, Petr Rockai <me at mornfall.net> wrote:

> Hi,
>
> before the questions about index behaviour get completely out of hand, here
> comes the layout and usage documentation...
>
> The _darcs/index is a binary file, that overlays a hashed tree over the
> working
> copy. This means that every working file and directory has an entry in the
> index, that contains its path and hash and validity data. The validity data
> is
> a "last seen" timestamp plus the file size.
>
> There are two entry types, a file entry and a directory entry. Both have a
> common binary format (from Index.hs):
>
>    data Item = Item { iPath :: BS.ByteString
>                     , iName :: BS.ByteString
>                     , iHash :: BS.ByteString
>                     , iSize :: Ptr Int64
>                     , iAux :: Ptr Int64 -- end-offset for dirs, mtime for
> files
>                     } deriving Show
>
> the actual on-disk layout can be seen from the peekItem implementation:
>
>    peekItem :: ForeignPtr () -> Int -> Maybe Int -> IO Item
>    peekItem fp off dirlen =
>        withForeignPtr fp $ \p -> do
>          nl' :: Int32 <- peekByteOff p off
>          let nl = fromIntegral nl'
>              path = fromForeignPtr (castForeignPtr fp) (off + 4) (nl - 1)
>              hash = fromForeignPtr (castForeignPtr fp) (off + 4 + nl) 64
>              name' = snd $ BS.splitAt (fromJust dirlen) path
>              name = (BS.last name' == '/') ? (BS.init name', name')
>          return $! Item { iName = isJust dirlen ? (name, undefined)
>                         , iPath = path
>                         , iHash = hash
>                         , iSize = plusPtr p (off + 4 + nl + 64)
>                         , iAux = plusPtr p (off + 4 + nl + 64 + 8)
>                         }


I take it that you've defined (?) with the type:
(?) :: Bool -> (a, a) -> a

Is the above real code or pseudo code?  The use of 'undefined' and
explicitly checking for '/' seem like potential bugs waiting to happen.
Using fromJust seems equally risky, and I see that you guard it and then use
undefined.  Why do you prefer undefined over a fromJust failure?  In
particular, the fromJust that darcs provides gives you line number
information becase it is implemented as a CPP macro.  Also, do you provide
justification for your constants?  eg., 4, 8, 64.  Would those constants
change on other platforms?

Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osuosl.org/pipermail/darcs-users/attachments/20090607/299eb635/attachment-0001.htm>


More information about the darcs-users mailing list