On Mon, Jun 11, 2007 at 10:28:49AM -0700, Dustin Sallings <[EMAIL PROTECTED]> 
was heard to say:
> 
> On Jun 11, 2007, at 2:07 , Lele Gaifax wrote:
> 
> >Uhm, sorry, but after re-reading your previous email, where you added
> >this little test recipe::
> >
> >    cd /tmp
> >    mkdir tailor-test
> >    cd tailor-test
> >    mkdir foo
> >
> >    cd foo
> >    darcs init
> >    echo "This is some data" > A
> >    darcs add A && darcs record -a -m "Adding A"
> >    darcs mv A B && darcs record -a -m "Renaming A"
> >
> >my comment above does not have any sense: there were *two* distinct
> >changesets!
> 
>       I've run into some similar problems, and I believe I've sent in one  
> changeset that solved half of them.  However, I'd since run into a  
> different variation and came up with a better fix but have not  
> submitted it.
> 
>       How do you actually run these tests?  If I can run them, I can test  
> my newer changes and make sure it's working for all the scenarios  
> I've encountered.

  Just pasting those lines into a shell should demonstrate the bug I
was talking about.

  I've gotten a comment on my blog post on this topic that explains
what's happening: the "copy" command on a mercurial repository expects
you to perform the copy in the filesystem first.  If not, it fails
silently (well, it prints the error message, but it doesn't throw an
exception or anything).  So I patched tailor to do the copy first, and
it seems to work OK.  (see the attached patch)

  I don't know if there's a better solution (e.g., something as simple
as using shellutils).  Another reply on this bug suggested that tailor
should be rewritten to use a different API.  That may be, but OTOH this
would be a reasonable temporary fix if it doesn't break anything else.

  Daniel
Mon Jun 11 07:44:54 PDT 2007  Daniel Burrows <[EMAIL PROTECTED]>
  * Fix renaming files in Mercurial.
  mercurial's copy command on repositories requires the caller to copy the
  file by hand first.  This change invokes mercurial.util.copyfile prior to
  calling copy(); without, it tailor deletes files instead of renaming them!
diff -rN -u old-tailor/vcpx/repository/hg.py new-tailor/vcpx/repository/hg.py
--- old-tailor/vcpx/repository/hg.py	2007-06-11 20:50:03.000000000 -0700
+++ new-tailor/vcpx/repository/hg.py	2007-06-11 20:50:03.000000000 -0700
@@ -13,7 +13,7 @@
 
 __docformat__ = 'reStructuredText'
 
-from mercurial import ui, hg, commands
+from mercurial import ui, hg, commands, util
 
 from vcpx.repository import Repository
 from vcpx.source import UpdatableSourceWorkingDir
@@ -377,10 +377,15 @@
             # loop over all files under the old directory and
             # do a copy on them.
             for f in self._walk(oldname):
-                oldpath = join(oldname, f)
-                repo.copy(oldpath, join(newname, f))
+                oldpath = join(self.repository.basedir, oldname, f)
+                newpath = join(self.repository.basedir, newname, f)
+                util.copyfile(oldpath, newpath)
+                repo.copy(oldpath, newpath)
                 repo.remove([oldpath], unlink=True)
         else:
+            oldpath = join(self.repository.basedir, normpath(oldname))
+            newpath = join(self.repository.basedir, normpath(newname))
+            util.copyfile(oldpath, newpath)
             repo.copy(oldname, newname)
             repo.remove([oldname], unlink=True)
 

Reply via email to