convert/darcs: improve unsupported format detection (
issue2172)
--- a/hgext/convert/darcs.py Fri Sep 24 00:03:58 2010 +0200
+++ b/hgext/convert/darcs.py Fri Sep 24 00:04:07 2010 +0200
@@ -8,7 +8,7 @@
from common import NoRepo, checktool, commandline, commit, converter_source
from mercurial.i18n import _
from mercurial import util
-import os, shutil, tempfile
+import os, shutil, tempfile, re
# The naming drift of ElementTree is fun!
@@ -31,11 +31,8 @@
converter_source.__init__(self, ui, path, rev=rev)
commandline.__init__(self, ui, 'darcs')
- # check for _darcs, ElementTree, _darcs/inventory so that we can
- # easily skip test-convert-darcs if ElementTree is not around
- if not os.path.exists(os.path.join(path, '_darcs', 'inventories')):
- raise NoRepo(_("%s does not look like a darcs repository") % path)
-
+ # check for _darcs, ElementTree so that we can easily skip
+ # test-convert-darcs if ElementTree is not around
if not os.path.exists(os.path.join(path, '_darcs')):
raise NoRepo(_("%s does not look like a darcs repository") % path)
@@ -55,6 +52,15 @@
self.parents = {}
self.tags = {}
+ # Check darcs repository format
+ format = self.format()
+ if format:
+ if format in ('darcs-1.0', 'hashed'):
+ raise NoRepo(_("%s repository format is unsupported, "
+ "please upgrade") % format)
+ else:
+ self.ui.warn(_('failed to detect repository format!'))
+
def before(self):
self.tmppath = tempfile.mkdtemp(
prefix='convert-' + os.path.basename(self.path) + '-')
@@ -91,6 +97,15 @@
self.checkexit(fp.close())
return etree.getroot()
+ def format(self):
+ output, status = self.run('show', 'repo', no_files=True,
+ repodir=self.path)
+ self.checkexit(status)
+ m = re.search(r'^\s*Format:\s*(.*)$', output, re.MULTILINE)
+ if not m:
+ return None
+ return ','.join(sorted(f.strip() for f in m.group(1).split(',')))
+
def manifest(self):
man = []
output, status = self.run('show', 'files', no_directories=True,
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/darcs/darcs1/_darcs/inventory Fri Sep 24 00:04:07 2010 +0200
@@ -0,0 +1,2 @@
+[adda
+test@test.com**20100923184058]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/darcs/darcs1/_darcs/prefs/author Fri Sep 24 00:04:07 2010 +0200
@@ -0,0 +1,1 @@
+test@test.com
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/darcs/darcs1/_darcs/prefs/binaries Fri Sep 24 00:04:07 2010 +0200
@@ -0,0 +1,59 @@
+# Binary file regexps:
+\.png$
+\.PNG$
+\.gz$
+\.GZ$
+\.pdf$
+\.PDF$
+\.jpg$
+\.JPG$
+\.jpeg$
+\.JPEG$
+\.gif$
+\.GIF$
+\.tif$
+\.TIF$
+\.tiff$
+\.TIFF$
+\.pnm$
+\.PNM$
+\.pbm$
+\.PBM$
+\.pgm$
+\.PGM$
+\.ppm$
+\.PPM$
+\.bmp$
+\.BMP$
+\.mng$
+\.MNG$
+\.tar$
+\.TAR$
+\.bz2$
+\.BZ2$
+\.z$
+\.Z$
+\.zip$
+\.ZIP$
+\.jar$
+\.JAR$
+\.so$
+\.SO$
+\.a$
+\.A$
+\.tgz$
+\.TGZ$
+\.mpg$
+\.MPG$
+\.mpeg$
+\.MPEG$
+\.iso$
+\.ISO$
+\.exe$
+\.EXE$
+\.doc$
+\.DOC$
+\.elc$
+\.ELC$
+\.pyc$
+\.PYC$
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/darcs/darcs1/_darcs/prefs/boring Fri Sep 24 00:04:07 2010 +0200
@@ -0,0 +1,49 @@
+# Boring file regexps:
+\.hi$
+\.hi-boot$
+\.o-boot$
+\.o$
+\.o\.cmd$
+# *.ko files aren't boring by default because they might
+# be Korean translations rather than kernel modules.
+# \.ko$
+\.ko\.cmd$
+\.mod\.c$
+(^|/)\.tmp_versions($|/)
+(^|/)CVS($|/)
+\.cvsignore$
+^\.#
+(^|/)RCS($|/)
+,v$
+(^|/)\.svn($|/)
+\.bzr$
+(^|/)SCCS($|/)
+~$
+(^|/)_darcs($|/)
+\.bak$
+\.BAK$
+\.orig$
+\.rej$
+(^|/)vssver\.scc$
+\.swp$
+(^|/)MT($|/)
+(^|/)\{arch\}($|/)
+(^|/).arch-ids($|/)
+(^|/),
+\.prof$
+(^|/)\.DS_Store$
+(^|/)BitKeeper($|/)
+(^|/)ChangeSet($|/)
+\.py[co]$
+\.elc$
+\.class$
+\#
+(^|/)Thumbs\.db$
+(^|/)autom4te\.cache($|/)
+(^|/)config\.(log|status)$
+^\.depend$
+(^|/)(tags|TAGS)$
+#(^|/)\.[^/]
+(^|/|\.)core$
+\.(obj|a|exe|so|lo|la)$
+^\.darcs-temp-mail$
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/darcs/darcs1/_darcs/pristine/a Fri Sep 24 00:04:07 2010 +0200
@@ -0,0 +1,1 @@
+a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/darcs/darcs1/a Fri Sep 24 00:04:07 2010 +0200
@@ -0,0 +1,1 @@
+a
--- a/tests/test-convert-darcs Fri Sep 24 00:03:58 2010 +0200
+++ b/tests/test-convert-darcs Fri Sep 24 00:04:07 2010 +0200
@@ -17,6 +17,9 @@
exit 80
fi
+echo '% try converting darcs1 repository'
+hg convert -s darcs "$TESTDIR/darcs/darcs1" 2>&1 | grep darcs-1.0
+
echo % initialize darcs repo
mkdir darcs-repo
cd darcs-repo
--- a/tests/test-convert-darcs.out Fri Sep 24 00:03:58 2010 +0200
+++ b/tests/test-convert-darcs.out Fri Sep 24 00:04:07 2010 +0200
@@ -1,3 +1,5 @@
+% try converting darcs1 repository
+darcs-1.0 repository format is unsupported, please upgrade
% initialize darcs repo
Finished recording patch 'p0'
% branch and update