# HG changeset patch # User Matt Mackall # Date 1166831980 21600 # Node ID 2b87d3c5ab8e2ac79479c643c30e3949ca64690e # Parent 558f52943cd202c4e73a84b03b260b22553d3eb7 convert-repo: add option to attempt to sort by date diff -r 558f52943cd2 -r 2b87d3c5ab8e 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)