changeset 3958:2b87d3c5ab8e

convert-repo: add option to attempt to sort by date
author Matt Mackall <mpm@selenic.com>
date Fri, 22 Dec 2006 17:59:40 -0600
parents 558f52943cd2
children f321d841dce5
files contrib/convert-repo
diffstat 1 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/convert-repo
+++ b/contrib/convert-repo
@@ -434,11 +434,12 @@ def converter(path):
     abort("%s: unknown repository type\n" % path)
 
 class convert:
-    def __init__(self, source, dest, mapfile):
+    def __init__(self, source, dest, mapfile, opts):
 
         self.source = source
         self.dest = dest
         self.mapfile = mapfile
+        self.opts = opts
         self.commitcache = {}
 
         self.map = {}
@@ -501,11 +502,24 @@ class convert:
             if not dep:
                 # all n's parents are in the list
                 removed[n] = 1
-                s.append(n)
+                if n not in self.map:
+                    s.append(n)
                 if n in children:
                     for c in children[n]:
                         visit.insert(0, c)
 
+        if opts.get('datesort'):
+            depth = {}
+            for n in s:
+                depth[n] = 0
+                pl = [p for p in self.commitcache[n].parents if p not in self.map]
+                if pl:
+                    depth[n] = max([depth[p] for p in pl]) + 1
+
+            s = [(depth[n], self.commitcache[n].date, n) for n in s]
+            s.sort()
+            s = [e[2] for e in s]
+
         return s
 
     def copy(self, rev):
@@ -532,7 +546,6 @@ class convert:
         parents = self.walktree(heads)
         status("sorting...\n")
         t = self.toposort(parents)
-        t = [n for n in t if n not in self.map]
         num = len(t)
         c = None
 
@@ -580,10 +593,11 @@ def command(src, dest=None, mapfile=None
         except:
             mapfile = os.path.join(destc, "map")
 
-    c = convert(srcc, destc, mapfile)
+    c = convert(srcc, destc, mapfile, opts)
     c.convert()
 
-options = [('q', 'quiet', None, 'suppress output')]
+options = [('q', 'quiet', None, 'suppress output'),
+           ('', 'datesort', None, 'try to sort changesets by date')]
 opts = {}
 args = fancyopts.fancyopts(sys.argv[1:], options, opts)