convert: default revisions order depends on source
authorPatrick Mezard <pmezard@gmail.com>
Mon, 01 Jun 2009 17:12:41 +0200
changeset 8692 827d4e807d57
parent 8691 a0a541d6fed6
child 8693 68e0a55eee6e
convert: default revisions order depends on source When converting Mercurial repositories you expect the revision numbers to be preserved, while other sources conversions focus on efficiency.
hgext/convert/__init__.py
hgext/convert/convcmd.py
tests/test-convert-clonebranches.out
tests/test-convert-datesort
tests/test-convert-datesort.out
tests/test-convert-hg-source.out
tests/test-convert.out
--- a/hgext/convert/__init__.py	Mon Jun 01 17:12:39 2009 +0200
+++ b/hgext/convert/__init__.py	Mon Jun 01 17:12:41 2009 +0200
@@ -41,6 +41,18 @@
     basename of the source with '-hg' appended. If the destination
     repository doesn't exist, it will be created.
 
+    By default, all sources except Mercurial will use
+    --branchsort. Mercurial uses --sourcesort to preserve original
+    revision numbers order. Sort modes have the following effects:
+      --branchsort: convert from parent to child revision when
+        possible, which means branches are usually converted one after
+        the other. It generates more compact repositories.
+      --datesort: sort revisions by date. Converted repositories have
+        good-looking changelogs but are often an order of magnitude
+        larger than the same ones generated by --branchsort.
+      --sourcesort: try to preserve source revisions order, only
+        supported by Mercurial sources.
+
     If <REVMAP> isn't given, it will be put in a default location
     (<dest>/.hg/shamap by default). The <REVMAP> is a simple text file
     that maps each source commit ID to the destination ID for that
@@ -247,6 +259,7 @@
           ('s', 'source-type', '', _('source repository type')),
           ('', 'splicemap', '', _('splice synthesized history into place')),
           ('', 'branchmap', '', _('change branch names while converting')),
+          ('', 'branchsort', None, _('try to sort changesets by branches')),
           ('', 'datesort', None, _('try to sort changesets by date')),
           ('', 'sourcesort', None, _('preserve source changesets order'))],
          _('hg convert [OPTION]... SOURCE [DEST [REVMAP]]')),
--- a/hgext/convert/convcmd.py	Mon Jun 01 17:12:39 2009 +0200
+++ b/hgext/convert/convcmd.py	Mon Jun 01 17:12:41 2009 +0200
@@ -30,15 +30,15 @@
         return s.decode('utf-8').encode(orig_encoding, 'replace')
 
 source_converters = [
-    ('cvs', convert_cvs),
-    ('git', convert_git),
-    ('svn', svn_source),
-    ('hg', mercurial_source),
-    ('darcs', darcs_source),
-    ('mtn', monotone_source),
-    ('gnuarch', gnuarch_source),
-    ('bzr', bzr_source),
-    ('p4', p4_source),
+    ('cvs', convert_cvs, 'branchsort'),
+    ('git', convert_git, 'branchsort'),
+    ('svn', svn_source, 'branchsort'),
+    ('hg', mercurial_source, 'sourcesort'),
+    ('darcs', darcs_source, 'branchsort'),
+    ('mtn', monotone_source, 'branchsort'),
+    ('gnuarch', gnuarch_source, 'branchsort'),
+    ('bzr', bzr_source, 'branchsort'),
+    ('p4', p4_source, 'branchsort'),
     ]
 
 sink_converters = [
@@ -48,10 +48,10 @@
 
 def convertsource(ui, path, type, rev):
     exceptions = []
-    for name, source in source_converters:
+    for name, source, sortmode in source_converters:
         try:
             if not type or name == type:
-                return source(ui, path, rev)
+                return source(ui, path, rev), sortmode
         except (NoRepo, MissingTool), inst:
             exceptions.append(inst)
     if not ui.quiet:
@@ -364,18 +364,18 @@
     destc = convertsink(ui, dest, opts.get('dest_type'))
 
     try:
-        srcc = convertsource(ui, src, opts.get('source_type'),
-                             opts.get('rev'))
+        srcc, defaultsort = convertsource(ui, src, opts.get('source_type'),
+                                          opts.get('rev'))
     except Exception:
         for path in destc.created:
             shutil.rmtree(path, True)
         raise
 
-    sortmodes = ('datesort', 'sourcesort')
+    sortmodes = ('branchsort', 'datesort', 'sourcesort')
     sortmode = [m for m in sortmodes if opts.get(m)]
     if len(sortmode) > 1:
         raise util.Abort(_('more than one sort mode specified'))
-    sortmode = sortmode and sortmode[0] or 'branchsort'
+    sortmode = sortmode and sortmode[0] or defaultsort
     if sortmode == 'sourcesort' and not srcc.hasnativeorder():
         raise util.Abort(_('--sourcesort is not supported by this data source'))
 
--- a/tests/test-convert-clonebranches.out	Mon Jun 01 17:12:39 2009 +0200
+++ b/tests/test-convert-clonebranches.out	Mon Jun 01 17:12:41 2009 +0200
@@ -3,10 +3,10 @@
 (branch merge, don't forget to commit)
 % convert
 3 adda
-2 addb
+2 changea
+1 addb
 pulling from default into branch0
 1 changesets found
-1 changea
 0 mergeab
 pulling from default into branch0
 1 changesets found
@@ -16,11 +16,11 @@
 (branch merge, don't forget to commit)
 marked working directory as branch branch3
 % incremental conversion
-2 c2
-pulling from branch0 into branch2
+2 c1
+pulling from branch0 into branch1
 2 changesets found
-1 c1
-pulling from branch0 into branch1
+1 c2
+pulling from branch0 into branch2
 2 changesets found
 0 c3
 pulling from branch2 into branch3
--- a/tests/test-convert-datesort	Mon Jun 01 17:12:39 2009 +0200
+++ b/tests/test-convert-datesort	Mon Jun 01 17:12:41 2009 +0200
@@ -38,8 +38,8 @@
 echo % graph converted repo
 hg -R t-datesort glog --template '{rev} "{desc}"\n'
 
-echo % convert with datesort
-hg convert --sourcesort t t-sourcesort
+echo '% convert with datesort (default mode)'
+hg convert t t-sourcesort
 echo % graph converted repo
 hg -R t-sourcesort glog --template '{rev} "{desc}"\n'
 
--- a/tests/test-convert-datesort.out	Mon Jun 01 17:12:39 2009 +0200
+++ b/tests/test-convert-datesort.out	Mon Jun 01 17:12:41 2009 +0200
@@ -39,7 +39,7 @@
 |/
 o  0 "a0"
 
-% convert with datesort
+% convert with datesort (default mode)
 initializing destination t-sourcesort repository
 scanning source...
 sorting...
--- a/tests/test-convert-hg-source.out	Mon Jun 01 17:12:39 2009 +0200
+++ b/tests/test-convert-hg-source.out	Mon Jun 01 17:12:41 2009 +0200
@@ -29,8 +29,8 @@
 converting...
 4 init
 ignoring: data/b.i@1e88685f5dde: no match found
-3 changebagain
-2 changeall
+3 changeall
+2 changebagain
 1 merge
 0 moveb
 checking changesets
--- a/tests/test-convert.out	Mon Jun 01 17:12:39 2009 +0200
+++ b/tests/test-convert.out	Mon Jun 01 17:12:41 2009 +0200
@@ -25,6 +25,18 @@
     basename of the source with '-hg' appended. If the destination
     repository doesn't exist, it will be created.
 
+    By default, all sources except Mercurial will use
+    --branchsort. Mercurial uses --sourcesort to preserve original
+    revision numbers order. Sort modes have the following effects:
+      --branchsort: convert from parent to child revision when
+        possible, which means branches are usually converted one after
+        the other. It generates more compact repositories.
+      --datesort: sort revisions by date. Converted repositories have
+        good-looking changelogs but are often an order of magnitude
+        larger than the same ones generated by --branchsort.
+      --sourcesort: try to preserve source revisions order, only
+        supported by Mercurial sources.
+
     If <REVMAP> isn't given, it will be put in a default location
     (<dest>/.hg/shamap by default). The <REVMAP> is a simple text file
     that maps each source commit ID to the destination ID for that
@@ -209,6 +221,7 @@
  -s --source-type  source repository type
     --splicemap    splice synthesized history into place
     --branchmap    change branch names while converting
+    --branchsort   try to sort changesets by branches
     --datesort     try to sort changesets by date
     --sourcesort   preserve source changesets order