# HG changeset patch # User Anton Shestakov # Date 1633415376 -10800 # Node ID b47a952b244a2d4db3f5e7dfdbe30779c1dc27cf # Parent b1a04ff0f99e01c7502827bf96a744d217b815db evolve: refactor _pick_latest_divergent(), rename to _sorted_divergents() diff -r b1a04ff0f99e -r b47a952b244a hgext3rd/evolve/evolvecmd.py --- a/hgext3rd/evolve/evolvecmd.py Wed Sep 22 02:33:50 2021 +0300 +++ b/hgext3rd/evolve/evolvecmd.py Tue Oct 05 09:29:36 2021 +0300 @@ -1127,31 +1127,26 @@ base, others = divergentdata(divergent) othersrevs = [o.rev() for o in others] all_divergents = othersrevs + [divergent.rev()] - pick, discard = _pick_latest_divergent(repo, all_divergents) - res.add(pick) - discarded.update(discard) + all_divergents = _sorted_divergents(repo, all_divergents) + res.update(all_divergents[:1]) + discarded.update(all_divergents[1:]) return res -def _pick_latest_divergent(repo, divergent_revs): - """On the basis of evolution date, pick out the latest evolved revision - from all the `divergent_revs` (which are divergent with each other) +def _sorted_divergents(repo, divergent_revs): + """Sort divergent_revs by latest evolution date, from newest to oldest. - Return a tuple (latest_evolved, others) + Fall back to rev number, but in ascending order, for historical reasons. """ - mapping = [] - for rev in divergent_revs: - led = latest_evolution_date(repo, repo[rev]) + ledmap = { # For purpose of comparing, from `led` which is (unixtime, offset) # we only need `unixtime`. - mapping.append((led[0], rev)) + rev: latest_evolution_date(repo, repo[rev])[0] + for rev in divergent_revs + } # Sorting by negating the `rev` in key func, to fallback to the old way # of selecting revision, in case when `led` is same while comparing. # Old way: was to select the one with minimum revision number - mapping = sorted(mapping, key=lambda v: (v[0], -v[1])) - latest_evolved = mapping[-1][1] - others = mapping[:-1] - others = [val[1] for val in others[:]] - return latest_evolved, others + return sorted(divergent_revs, key=lambda rev: (-ledmap[rev], rev)) def latest_evolution_date(repo, ctx): """Return latest evolution date of a changeset `ctx`"""