darcs

Patch 264 Resolve issue1817: --external-merge broken, by bumping

Title Resolve issue1817: --external-merge broken, by bumping
Superseder Nosy List kowey, mornfall
Related Issues
Status accepted Assigned To
Milestone

Created on 2010-06-03.20:59:05 by mornfall, last changed 2011-05-10.19:06:12 by darcswatch. Tracked on DarcsWatch.

Files
File name Status Uploaded Type Edit Remove
make-the-external_resolution_sh-test-a-bit-more-thorough_.dpatch mornfall, 2010-06-03.20:59:05 text/x-darcs-patch
unnamed mornfall, 2010-06-03.20:59:05
See mailing list archives for discussion on individual patches.
Messages
msg11224 (view) Author: mornfall Date: 2010-06-03.20:59:05
Hi,

this should fix Dan's trouble. It's on HEAD, since the fix is only on h-s
branch 0.5, but it could be trivially backported to h-s 0.4 (and therefore
darcs 2.4.x) as well, with enough persuasion.

Yours,
   Petr.

2 patches for repository darcs-unstable@darcs.net:darcs:

Thu Jun  3 22:52:51 CEST 2010  Petr Rockai <me@mornfall.net>
  * Make the external-resolution.sh test a bit more thorough.

Thu Jun  3 22:53:30 CEST 2010  Petr Rockai <me@mornfall.net>
  * Resolve issue1817: --external-merge broken, by bumping h-s dependency to 0.5.1.
  
  This h-s releases fixes a problem in index handling code where reading files
  from a Tree that was created from an index only worked in the same working
  directory in which the index had been opened. This was breaking
  externalResolution which called readBlob on index'd files (working) from a
  temporary directory.
Attachments
msg11260 (view) Author: kowey Date: 2010-06-06.12:55:17
Hey Petr,

On Thu, Jun 03, 2010 at 20:59:05 +0000, Petr Ročkai wrote:
> this should fix Dan's trouble. It's on HEAD, since the fix is only on h-s
> branch 0.5, but it could be trivially backported to h-s 0.4 (and therefore
> darcs 2.4.x) as well, with enough persuasion.

Unless I'm mistaken, you've forgotten to push some patches to
hashed-storage.

http://repos.mornfall.net/hashed-storage

Thanks,

-- 
Eric Kow <http://www.nltg.brighton.ac.uk/home/Eric.Kow>
PGP Key ID: 08AC04F9
msg11263 (view) Author: mornfall Date: 2010-06-06.14:39:29
I have pushed the missing patches now, sorry for the inconvenience. This is the 
relevant diff:

Thu Jun  3 22:41:50 CEST 2010  Petr Rockai <me@mornfall.net>
  * Make readBlob work out of the original working directory for Index Trees.
diff -rN -u -p old-hashed-storage/Storage/Hashed/Index.hs new-hashed-
storage/Storage/Hashed/Index.hs
--- old-hashed-storage/Storage/Hashed/Index.hs  2010-06-06 16:40:45.000000000 
+0200
+++ new-hashed-storage/Storage/Hashed/Index.hs  2010-06-06 16:40:45.000000000 
+0200
@@ -50,13 +50,14 @@ import Bundled.Posix( getFileStatusBS, m
                       getFileStatus, fileSize, fileExists )
 import System.IO.MMap( mmapFileForeignPtr, mmapFileByteString, Mode(..) )
 import System.IO( )
-import System.Directory( doesFileExist )
+import System.Directory( doesFileExist, getCurrentDirectory )
 #if mingw32_HOST_OS
 import System.Directory( renameFile )
 import System.FilePath( (<.>) )
 #else
 import System.Directory( removeFile )
 #endif
+import System.FilePath( (</>) )
 
 import Control.Monad( when )
 import Control.Exception.Extensible
@@ -220,6 +221,7 @@ mmapIndex indexpath req_size = do
             return (x, size)
 
 data IndexM m = Index { mmap :: (ForeignPtr ())
+                      , basedir :: FilePath
                       , hashtree :: Tree m -> Hash
                       , predicate :: AnchoredPath -> TreeItem m -> Bool }
               | EmptyIndex
@@ -291,7 +293,7 @@ readFile index state item =
        size <- xlatePeek64 $ iSize item
        let mtime' = modificationTime st
            size' = fromIntegral $ fileSize st
-           readblob = readSegment (BSC.unpack $ iPath item, Nothing)
+           readblob = readSegment (basedir index </> BSC.unpack (iPath item), 
Nothing)
            exists = fileExists st
            we_changed = mtime /= mtime' || size /= size'
            hash = iHash' item
@@ -329,8 +331,10 @@ updateIndex index =
 readIndex :: FilePath -> (Tree IO -> Hash) -> IO Index
 readIndex indexpath ht = do
   (mmap_ptr, mmap_size) <- mmapIndex indexpath 0
+  base <- getCurrentDirectory
   return $ if mmap_size == 0 then EmptyIndex
                              else Index { mmap = mmap_ptr
+                                        , basedir = base
                                         , hashtree = ht
                                         , predicate = \_ _ -> True }
msg11278 (view) Author: kowey Date: 2010-06-06.17:46:07
Seems to make sense.  Applied (the version bump), thanks!

On Sun, Jun 06, 2010 at 14:39:29 +0000, Petr Ročkai wrote:
>  data IndexM m = Index { mmap :: (ForeignPtr ())
> +                      , basedir :: FilePath
>                        , hashtree :: Tree m -> Hash
>                        , predicate :: AnchoredPath -> TreeItem m -> Bool }

> @@ -291,7 +293,7 @@ readFile index state item =
>         size <- xlatePeek64 $ iSize item
>         let mtime' = modificationTime st
>             size' = fromIntegral $ fileSize st
> -           readblob = readSegment (BSC.unpack $ iPath item, Nothing)
> +           readblob = readSegment (basedir index </> BSC.unpack (iPath item), 

I'm assuming here that absolute path </> BSC.unpack (iPath item) always
does the right thing (and if I understand correctly, you would never
ever have anything like "..").

>  readIndex :: FilePath -> (Tree IO -> Hash) -> IO Index
>  readIndex indexpath ht = do
>    (mmap_ptr, mmap_size) <- mmapIndex indexpath 0
> +  base <- getCurrentDirectory
>    return $ if mmap_size == 0 then EmptyIndex
>                               else Index { mmap = mmap_ptr
> +                                        , basedir = base
>                                          , hashtree = ht
>                                          , predicate = \_ _ -> True }
> 

Basically, hold on the current working directory in case we cd somewhere
else in the meantime.

By the way, you may want to tweak the comment for readIndex to add an
example index path.

For the interested, darcs uses it like this:

I.readIndex "_darcs/index" darcsTreeHash

-- 
Eric Kow <http://www.nltg.brighton.ac.uk/home/Eric.Kow>
PGP Key ID: 08AC04F9
msg11291 (view) Author: darcswatch Date: 2010-06-06.19:49:17
This patch bundle (with 2 patches) was just applied to the repository http://darcs.net/.
This message was brought to you by DarcsWatch
http://darcswatch.nomeata.de/repo_http:__darcs.net_.html#bundle-bc4aa47dffb77fc09d135667e8709419078ad4e5
msg14150 (view) Author: darcswatch Date: 2011-05-10.19:06:12
This patch bundle (with 2 patches) was just applied to the repository http://darcs.net/reviewed.
This message was brought to you by DarcsWatch
http://darcswatch.nomeata.de/repo_http:__darcs.net_reviewed.html#bundle-bc4aa47dffb77fc09d135667e8709419078ad4e5
History
Date User Action Args
2010-06-03 20:59:05mornfallcreate
2010-06-03 21:00:37darcswatchsetdarcswatchurl: http://darcswatch.nomeata.de/repo_http:__darcs.net_.html#bundle-bc4aa47dffb77fc09d135667e8709419078ad4e5
2010-06-06 12:55:17koweysetnosy: + kowey
messages: + msg11260
2010-06-06 14:39:29mornfallsetmessages: + msg11263
2010-06-06 17:46:07koweysetmessages: + msg11278
2010-06-06 19:49:17darcswatchsetstatus: needs-review -> accepted
messages: + msg11291
2011-05-10 19:06:12darcswatchsetmessages: + msg14150