changeset 9530:ba8a86d86fd6

Merge with -crew-stable
author Matt Mackall <mpm@selenic.com>
date Wed, 07 Oct 2009 23:25:41 -0500
parents effa05849027 (current diff) e61e7b3e46d0 (diff)
children e151b66bcf38
files mercurial/util.py
diffstat 8 files changed, 95 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/common.py	Sat Oct 03 15:57:48 2009 -0500
+++ b/hgext/convert/common.py	Wed Oct 07 23:25:41 2009 -0500
@@ -365,7 +365,7 @@
             return
         for i, line in enumerate(fp):
             try:
-                key, value = line[:-1].rsplit(' ', 1)
+                key, value = line.splitlines()[0].rsplit(' ', 1)
             except ValueError:
                 raise util.Abort(_('syntax error in %s(%d): key/value pair expected')
                                  % (self.path, i+1))
--- a/hgext/convert/darcs.py	Sat Oct 03 15:57:48 2009 -0500
+++ b/hgext/convert/darcs.py	Wed Oct 07 23:25:41 2009 -0500
@@ -85,6 +85,17 @@
         self.checkexit(fp.close())
         return etree.getroot()
 
+    def manifest(self):
+        man = []
+        output, status = self.run('show', 'files', no_directories=True,
+                                  repodir=self.tmppath)
+        self.checkexit(status)
+        for line in output.split('\n'):
+            path = line[2:]
+            if path:
+                man.append(path)
+        return man
+
     def getheads(self):
         return self.parents[None]
 
@@ -107,18 +118,35 @@
             output, status = self.run('revert', all=True, repodir=self.tmppath)
             self.checkexit(status, output)
 
-    def getchanges(self, rev):
-        self.pull(rev)
+    def getchanges(self, rev):        
         copies = {}
         changes = []
+        man = None
         for elt in self.changes[rev].find('summary').getchildren():
             if elt.tag in ('add_directory', 'remove_directory'):
                 continue
             if elt.tag == 'move':
-                changes.append((elt.get('from'), rev))
-                copies[elt.get('from')] = elt.get('to')
+                if man is None:
+                    man = self.manifest()
+                source, dest = elt.get('from'), elt.get('to')
+                if source in man:
+                    # File move
+                    changes.append((source, rev))
+                    changes.append((dest, rev))
+                    copies[dest] = source
+                else:
+                    # Directory move, deduce file moves from manifest
+                    source = source + '/'
+                    for f in man:
+                        if not f.startswith(source):
+                            continue
+                        fdest = dest + '/' + f[len(source):]
+                        changes.append((f, rev))
+                        changes.append((fdest, rev))
+                        copies[fdest] = f
             else:
                 changes.append((elt.text.strip(), rev))
+        self.pull(rev)
         self.lastrev = rev
         return sorted(changes), copies
 
--- a/mercurial/util.py	Sat Oct 03 15:57:48 2009 -0500
+++ b/mercurial/util.py	Wed Oct 07 23:25:41 2009 -0500
@@ -444,7 +444,14 @@
 
         temp = tempname(dst)
         os.rename(dst, temp)
-        os.unlink(temp)
+        try:
+            os.unlink(temp)
+        except:
+            # Some rude AV-scanners on Windows may cause the unlink to
+            # fail. Not aborting here just leaks the temp file, whereas
+            # aborting at this point may leave serious inconsistencies.
+            # Ideally, we would notify the user here.
+            pass
         os.rename(src, dst)
 
 def unlink(f):
--- a/tests/hghave	Sat Oct 03 15:57:48 2009 -0500
+++ b/tests/hghave	Wed Oct 07 23:25:41 2009 -0500
@@ -51,7 +51,7 @@
     return matchoutput('cvsps -h -q 2>&1', r'cvsps version', True)
 
 def has_darcs():
-    return matchoutput('darcs', r'darcs version', True)
+    return matchoutput('darcs --version', r'2\.[2-9]', True)
 
 def has_mtn():
     return matchoutput('mtn --version', r'monotone', True) and not matchoutput(
--- a/tests/test-convert-darcs	Sat Oct 03 15:57:48 2009 -0500
+++ b/tests/test-convert-darcs	Wed Oct 07 23:25:41 2009 -0500
@@ -1,19 +1,13 @@
 #!/bin/sh
 
 "$TESTDIR/hghave" darcs || exit 80
-if darcs --version 2>&1 | grep '^2\.' > /dev/null; then
-    # FIXME: darcs 2 will fail with
-    ### Abort: timeout after 180 seconds.
-    echo 'skipped: test currently disabled for darcs 2'
-    exit 80
-fi
 
 echo "[extensions]" >> $HGRCPATH
 echo "convert=" >> $HGRCPATH
 echo 'hgext.graphlog =' >> $HGRCPATH
 
 DARCS_EMAIL='test@example.org'; export DARCS_EMAIL
-HOME=do_not_use_HOME_darcs; export HOME
+HOME=`pwd`/do_not_use_HOME_darcs; export HOME
 
 # skip if we can't import elementtree
 mkdir dummy
@@ -47,8 +41,21 @@
 
 echo % merge branch
 darcs pull -a ../darcs-clone
+sleep 1
 echo e > a
+echo f > f
+mkdir dir
+echo d > dir/d
+echo d > dir/d2
 darcs record -a -l -m p2
+
+echo % test file and directory move
+darcs mv f ff
+# Test remove + move
+darcs remove dir/d2
+rm dir/d2
+darcs mv dir dir2
+darcs record -a -l -m p3
 cd ..
 
 glog()
@@ -56,7 +63,7 @@
     hg glog --template '{rev} "{desc|firstline}" files: {files}\n' "$@"
 }
 
-hg convert darcs-repo darcs-repo-hg 2>&1 | grep -v hGetLine | grep -v '^$'
+hg convert darcs-repo darcs-repo-hg
 # The converter does not currently handle patch conflicts very well.
 # When they occur, it reverts *all* changes and moves forward,
 # letting the conflict resolving patch fix collisions.
--- a/tests/test-convert-darcs.out	Sat Oct 03 15:57:48 2009 -0500
+++ b/tests/test-convert-darcs.out	Wed Oct 07 23:25:41 2009 -0500
@@ -5,19 +5,25 @@
 % update source
 Finished recording patch 'p1.2'
 % merge branch
+Backing up ./a(-darcs-backup0)
 We have conflicts in the following files:
 ./a
 Finished pulling and applying.
 Finished recording patch 'p2'
+% test file and directory move
+Finished recording patch 'p3'
 initializing destination darcs-repo-hg repository
 scanning source...
 sorting...
 converting...
-3 p0
-2 p1.2
-1 p1.1
-0 p2
-o  3 "p2" files: a
+4 p0
+3 p1.2
+2 p1.1
+1 p2
+0 p3
+o  4 "p3" files: dir/d dir/d2 dir2/d f ff
+|
+o  3 "p2" files: a dir/d dir/d2 f
 |
 o  2 "p1.1" files:
 |
@@ -27,3 +33,5 @@
 
 7225b30cdf38257d5cc7780772c051b6f33e6d6b 644   a
 1e88685f5ddec574a34c70af492f95b6debc8741 644   b
+d278f41640da5fc303a4cf9894af31c2983fc11d 644   dir2/d
+ef5c76581d78340f568d5f48d679bf307452cbc9 644   ff
--- a/tests/test-convert-hg-source	Sat Oct 03 15:57:48 2009 -0500
+++ b/tests/test-convert-hg-source	Wed Oct 07 23:25:41 2009 -0500
@@ -38,6 +38,25 @@
 hg out ../orig
 cd ..
 
+echo '% check shamap LF and CRLF handling'
+cat > rewrite.py <<EOF
+import sys
+# Interlace LF and CRLF
+lines = [(l.rstrip() + ((i % 2) and '\n' or '\r\n'))
+         for i, l in enumerate(file(sys.argv[1]))]
+file(sys.argv[1], 'wb').write(''.join(lines))
+EOF
+python rewrite.py new/.hg/shamap
+cd orig
+hg up -qC 1
+echo foo >> foo
+hg ci -qm 'change foo again'
+hg up -qC 2
+echo foo >> foo
+hg ci -qm 'change foo again again'
+cd ..
+hg convert --datesort orig new 2>&1 | grep -v 'subversion python bindings could not be loaded'
+
 echo % init broken repository
 hg init broken
 cd broken
--- a/tests/test-convert-hg-source.out	Sat Oct 03 15:57:48 2009 -0500
+++ b/tests/test-convert-hg-source.out	Wed Oct 07 23:25:41 2009 -0500
@@ -20,6 +20,12 @@
 comparing with ../orig
 searching for changes
 no changes found
+% check shamap LF and CRLF handling
+scanning source...
+sorting...
+converting...
+1 change foo again again
+0 change foo again
 % init broken repository
 created new head
 % break it