convert-repo: add option to attempt to sort by date
authorMatt Mackall <mpm@selenic.com>
Fri, 22 Dec 2006 17:59:40 -0600
changeset 3957 2b87d3c5ab8e
parent 3956 558f52943cd2
child 3959 f321d841dce5
convert-repo: add option to attempt to sort by date
contrib/convert-repo
--- a/contrib/convert-repo	Fri Dec 22 17:59:39 2006 -0600
+++ b/contrib/convert-repo	Fri Dec 22 17:59:40 2006 -0600
@@ -434,11 +434,12 @@
     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 @@
             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 @@
         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 @@
         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)