[darcs-devel] darcs patch: Only copy files needed in external resolution

Edwin Thomson edwin.thomson at businesswebsoftware.com
Mon Nov 6 04:04:55 PST 2006


Eric Y. Kow wrote:
> Do we really want error here, and not fail?  Is it darcs going wrong or
> just something unexpected happening?
> 
> If it's fail that we want, perhaps we should just generalise it
> apply_to_slurpy :: (Monad m) => Patch -> Slurpy -> m Slurpy
You're right, we want fail.  I've gone for using your generalisation 
(making a new function for it felt wrong, anyway).

> Eric makes sure he understands
Eric understands.

> Edwin: can you explain to me what happens when files get added or
> removed?  I assume that the filenames part is ok, because it hasn't
> changed from the original code, but does the right thing happen
> wrt to write_files?

Yes, those cause problems, as do conflicts involving directories.  I've 
modified write_files to fix this.

The new version of "Only copy files needed in external_resolution" is to 
fix these.  Also attached is "External resolution can resolve 
conflicting adds", which fixes a behaviour which is also present in the 
old external_merge code - when conflicting adds are resolved, darcs 
doesn't notice the resulting file, because it's not in cleanmerged and 
smart_diff doesn't look for adds by default.  I've submitted this as a 
separate patch because it changes the behaviour and might mess up in the 
presence of merging tools that create temporary files.

Edwin
-------------- next part --------------

New patches:

[Only copy files needed in external_resolution
edwin.thomson at businesswebsoftware.com**20061106114719] {
hunk ./PatchApply.lhs 97
-apply_to_slurpy :: Patch -> Slurpy -> Maybe Slurpy
+apply_to_slurpy :: (Monad m) => Patch -> Slurpy -> m Slurpy
hunk ./PatchApply.lhs 99
-                          Left _ -> Nothing
-                          Right (s', ()) -> Just s'
-
+                          Left err -> fail err
+                          Right (s', ()) -> return s'
+                                    
hunk ./Resolution.lhs 31
-import SlurpDirectory ( Slurpy, slurp, list_slurpy )
+import SlurpDirectory ( Slurpy, slurp, write_files )
hunk ./Resolution.lhs 38
-import External ( cloneTree, clonePaths )
+import External ( cloneTree )
+import PatchApply ( apply_to_slurpy )
hunk ./Resolution.lhs 153
- (_, s) <- slurp_recorded_and_unrecorded "."
- former_dir <- getCurrentDirectory
- withTempDir "version1" $ \d1 -> do
-   clonePaths former_dir d1 (list_slurpy s)
-   setCurrentDirectory former_dir
-   withTempDir "ancestor" $ \da -> do
-     cloneTree d1 "."
-     apply [] False (invert p1)
+ (_, s1) <- slurp_recorded_and_unrecorded "."
+ sa <- apply_to_slurpy (invert p1) s1
+ sm <- apply_to_slurpy pmerged s1
+ s2 <- apply_to_slurpy p2 sa
+ let nms = list_conflicted_files pmerged
+     nas = apply_to_filepaths False (invert pmerged) nms
+     n1s = apply_to_filepaths False p1 nas
+     n2s = apply_to_filepaths False p2 nas
+     ns = zip4 nas n1s n2s nms
+  in do
+   former_dir <- getCurrentDirectory
+   withTempDir "version1" $ \d1 -> do
+     write_files s1 n1s
hunk ./Resolution.lhs 167
-     withTempDir "cleanmerged" $ \dc -> do
-       cloneTree d1 "."
-       apply [] False pmerged
+     withTempDir "ancestor" $ \da -> do
+       write_files sa nas
hunk ./Resolution.lhs 171
-         cloneTree dc "."
+         write_files sm nms
hunk ./Resolution.lhs 173
-         withTempDir "version2" $ \d2 -> do
-           cloneTree da "."
-           apply [] False p2
-           let nms = list_conflicted_files pmerged
-               nas = apply_to_filepaths False (invert pmerged) nms
-               n1s = apply_to_filepaths False p1 nas
-               n2s = apply_to_filepaths False p2 nas
-               ns = zip4 nas n1s n2s nms
-             in do
+         withTempDir "cleanmerged" $ \dc -> do
+           cloneTree dm "."
+           setCurrentDirectory former_dir
+           withTempDir "version2" $ \d2 -> do
+             write_files s2 n2s
hunk ./Resolution.lhs 179
-             sm <- slurp dc
+             sc <- slurp dc
hunk ./Resolution.lhs 182
-             case smart_diff [] ftf sm sfixed of
+             case smart_diff [] ftf sc sfixed of
hunk ./SlurpDirectory.lhs 43
-                        SlurpMonad(..), withSlurpy
+                        SlurpMonad(..), withSlurpy, write_files
hunk ./SlurpDirectory.lhs 152
+
+
+write_file :: Slurpy -> FileName -> IO ()
+write_file s fn = case withSlurpy s $ smReadFilePS fn of
+                     Left err -> fail err
+                     Right (_, c) -> do
+                       ensureDirectories (super_name fn)
+                       mWriteFilePS fn c
+                       
+try_write_file :: Slurpy -> FilePath -> IO ()
+try_write_file s fp = let fn = fp2fn fp in
+  if slurp_hasfile fn s
+      then write_file s fn
+      else if slurp_hasdir fn s
+               then ensureDirectories fn
+               else return ()
+
+ensureDirectories :: WriteableDirectory m => FileName -> m ()
+ensureDirectories d = do
+          isPar <- mDoesDirectoryExist d
+          if isPar 
+            then return ()
+            else ensureDirectories (super_name d) >> (mCreateDirectory d)
+
+write_files ::  Slurpy -> [FilePath] -> IO ()
+write_files s fps = mapM_ (try_write_file s) fps
+
+
}

[External resolution can resolve conflicting adds
edwin.thomson at businesswebsoftware.com**20061106114755] {
hunk ./Resolution.lhs 36
+import DarcsFlags ( DarcsFlag(LookForAdds) )
hunk ./Resolution.lhs 183
-             case smart_diff [] ftf sc sfixed of
+             case smart_diff [LookForAdds] ftf sc sfixed of
}

Context:

[Added --store-in-memory option for diff
edwin.thomson at businesswebsoftware.com**20061006122802
 
] 
[Test pull.pl, CREATE_DIR_ERROR: removed TODO now that directory name is printed in error message
Marnix Klooster <marnix.klooster at gmail.com>**20060304164033
 Also removes a superfluous (and erroneous) chdir statement, which tried to
 change to non-existing directory templ (last character was ell instead of one).
 
 Also improves the description of this test.
] 
[remove TODO from pull.pl.
David Roundy <droundy at darcs.net>**20060805192700] 
[fixes in pull.pl.
David Roundy <droundy at darcs.net>**20060805221055
 The first fix avoids a false error that shows up because of identical
 timestamps.  The second verifies that revert -a doesn't prompt user.
] 
[add new obliterate test.
David Roundy <droundy at darcs.net>**20060806122536] 
[clean up docs on DarcsRepo format.
David Roundy <droundy at darcs.net>**20060808104321] 
[Read sftp batch file in from stdin (part of issue237).
Eric Kow <eric.kow at gmail.com>**20060812143113
 
 Passing the batch file in from stdin allows for sftp to be used with
 password-based authentication.  According to the sftp user manual regarding
 the -b switch:
   Since it lacks user interaction it should be
   used in conjunction with non-interactive authentication
 
 Credit for this idea goes to Ori Avtalion.
 
] 
[Extend runSSH function to accept argument for stdin.
Eric Kow <eric.kow at gmail.com>**20060812142932] 
[fail if replace token pattern contains spaces (issue231)
Tommy Pettersson <ptp at lysator.liu.se>**20060806110807
 It would otherwise create a badly formated patch in pending with unexpected
 results for subsequent commands.
] 
[fix negation of result in test
Tommy Pettersson <ptp at lysator.liu.se>**20060806104215
 Negation with ! "uses" the result and thus there is no "failure", so the
 script wouldn't have exit with failure.
] 
[add test that replace with spaces fail
Tommy Pettersson <ptp at lysator.liu.se>**20060806103033] 
[unset default author environment variables in test suite harness
Tommy Pettersson <ptp at lysator.liu.se>**20060805151210
 This makes it harder to accidently write tests that fail because no author
 is set.
] 
[set author in pull_two test so it doesn't hang
Tommy Pettersson <ptp at lysator.liu.se>**20060804181518] 
[add new test that triggers bug in refactoring.
David Roundy <droundy at darcs.net>**20060804103830] 
[make test external stay in its temp1 dir
Tommy Pettersson <ptp at lysator.liu.se>**20060804134139] 
[Do not run sftp with the -q flag (issue240).
Eric Kow <eric.kow at gmail.com>**20060811212030
 
 sftp does not recognise it, and so any command which uses it fails.
 
] 
[Refactor calls to ssh/scp/sftp.
Eric Kow <eric.kow at gmail.com>**20060706202509
 
] 
[Extend test suite for patch matching.
Eric Kow <eric.kow at gmail.com>**20060513192501
 
] 
[Implement help --match (issue91).
Eric Kow <eric.kow at gmail.com>**20060513185610
 
 Also, refactor matching code in a way that encourages developers
 to document for help --match any new matchers they create.
 
] 
[Replace dateparser.sh with more general match.pl for testing --match.
Eric Kow <eric.kow at gmail.com>**20060513104942
 
] 
[Add tests for pristine error and quiet mode when removing a directory.
Eric Kow <eric.kow at gmail.com>**20060513100021] 
[Replace test rmdir.sh with rmdir.pl.
Eric Kow <eric.kow at gmail.com>**20060513043823] 
[remove some tabs from haskell source
Tommy Pettersson <ptp at lysator.liu.se>**20060730122505] 
[use FastPackeString when examining executable scripts in Get
Tommy Pettersson <ptp at lysator.liu.se>**20060729130645] 
[add some changelog entries
Tommy Pettersson <ptp at lysator.liu.se>**20060718152611] 
[Minor tweaks to list_authors.
Juliusz Chroboczek <jch at pps.jussieu.fr>**20060720180602] 
[Fixed typo in documentation.
Michal Sojka <sojkam1 at fel.cvut.cz>**20060514095212] 
[Added elc and pyc to binaries.
Juliusz Chroboczek <jch at pps.jussieu.fr>**20060713184214] 
[Run ssh/scp/sftp quietly.
Eric Kow <eric.kow at gmail.com>**20060707025245
 
 This is useful for silencing Putty, and could also be for OpenSSH should
 we decide to stop redirecting to /dev/null.
 
] 
[Added up links in web interface.
Peter Stuifzand <peter at stuifzand.com>**20060610082238
 Added a link to the 'projects' part of the cgi repository interface, so that
 you go back to the project list.
] 
[Add a test suite for calling external programs.
Eric Kow <eric.kow at gmail.com>**20060521045407
 
 For now this only includes a test for ssh (issue171).
 
] 
[Suppress non-empty dir warning if Quiet.
Eric Kow <eric.kow at gmail.com>**20060513053456] 
[Add forgotten file umask.h.
Juliusz Chroboczek <jch at pps.jussieu.fr>**20060423174844] 
[Add --umask to all commands that write to the current repository.
Juliusz Chroboczek <jch at pps.jussieu.fr>**20060407195655] 
[Add option --umask.
Juliusz Chroboczek <jch at pps.jussieu.fr>**20060407194552] 
[Actually switch umasks in withRepoLock.
Juliusz Chroboczek <jch at pps.jussieu.fr>**20060407194202] 
[Implement withUMask.
Juliusz Chroboczek <jch at pps.jussieu.fr>**20060407193312] 
[Add umask.c.
Juliusz Chroboczek <jch at pps.jussieu.fr>**20060407193255] 
[Propagate opts to withRepoLock.
Juliusz Chroboczek <jch at pps.jussieu.fr>**20060325190622] 
[TAG 1.0.8
Tommy Pettersson <ptp at lysator.liu.se>**20060616160213] 
Patch bundle hash:
f11698993016bd0c44bb3042cf6d347ad035492c


More information about the darcs-devel mailing list