# HG changeset patch # User Boris Feld # Date 1533250330 -7200 # Node ID 35b2d201eb71fdfcd25de88f2d0c722d8749f340 # Parent b627e165ad2046dd34c8002303164abd1579be11 compat: fix obslog compatiblity with 4.3 Due to the way of how successor sets are retrieved in new Mercurial version, retrieving it again in 4.3 way would be a performance hit and complexify the code too much. Don't retrieve markers of successor sets which makes obslog filtered output more limited in 4.3. diff -r b627e165ad20 -r 35b2d201eb71 hgext3rd/evolve/compat.py --- a/hgext3rd/evolve/compat.py Thu Aug 02 16:54:40 2018 +0300 +++ b/hgext3rd/evolve/compat.py Fri Aug 03 00:52:10 2018 +0200 @@ -11,6 +11,7 @@ from mercurial import ( context, copies, + encoding, mdiff, obsolete, obsutil, @@ -701,5 +702,85 @@ if util.safehasattr(copies, '_fullcopytracing'): copies._fullcopytracing = fixedcopytracing elif util.safehasattr(copies, 'mergecopies'): - # comapt fix for hg <= 4.3 + # compat fix for hg <= 4.3 copies.mergecopies = fixoldmergecopies + +if not util.safehasattr(obsutil, "_succs"): + class _succs(list): + """small class to represent a successors with some metadata about it""" + + def __init__(self, *args, **kwargs): + super(_succs, self).__init__(*args, **kwargs) + self.markers = set() + + def copy(self): + new = _succs(self) + new.markers = self.markers.copy() + return new + + @util.propertycache + def _set(self): + # immutable + return set(self) + + def canmerge(self, other): + return self._set.issubset(other._set) +else: + from mercurial.obsutil import _succs + +def wrap_succs(succs): + """ Wrap old data format of successorsets (tuple) only if if's not yet a + _succs instance + """ + + if not util.safehasattr(succs, "markers"): + return _succs(succs) + else: + return succs + +if not util.safehasattr(obsutil, "markersdates"): + MARKERS_DATE_COMPAT = True +else: + MARKERS_DATE_COMPAT = False + +def markersdates(markers): + """returns the list of dates for a list of markers + """ + if MARKERS_DATE_COMPAT is False: + return obsutil.markersdates(markers) + + return [m[4] for m in markers] + +if not util.safehasattr(obsutil, "markersusers"): + MARKERS_USERS_COMPAT = True +else: + MARKERS_USERS_COMPAT = False + +def markersusers(markers): + """ Returns a sorted list of markers users without duplicates + """ + if MARKERS_USERS_COMPAT is False: + return obsutil.markersusers(markers) + + markersmeta = [dict(m[3]) for m in markers] + users = set(encoding.tolocal(meta['user']) for meta in markersmeta + if meta.get('user')) + + return sorted(users) + +if not util.safehasattr(obsutil, "markersoperations"): + MARKERS_OPERATIONS_COMPAT = True +else: + MARKERS_OPERATIONS_COMPAT = False + +def markersoperations(markers): + """ Returns a sorted list of markers operations without duplicates + """ + if MARKERS_OPERATIONS_COMPAT is False: + return obsutil.markersoperations(markers) + + markersmeta = [dict(m[3]) for m in markers] + operations = set(meta.get('operation') for meta in markersmeta + if meta.get('operation')) + + return sorted(operations) diff -r b627e165ad20 -r 35b2d201eb71 hgext3rd/evolve/obshistory.py --- a/hgext3rd/evolve/obshistory.py Thu Aug 02 16:54:40 2018 +0300 +++ b/hgext3rd/evolve/obshistory.py Fri Aug 03 00:52:10 2018 +0200 @@ -107,7 +107,7 @@ fullsuccessorsets = [] # successor set + markers for sset in ssets: if sset: - fullsuccessorsets.append(sset) + fullsuccessorsets.append(compat.wrap_succs(sset)) else: # successorsset return an empty set() when ctx or one of its # successors is pruned. @@ -123,11 +123,11 @@ for mark in succsmap.get(ctx.node(), ()): if not mark[1]: foundany = True - sset = obsutil._succs() + sset = compat._succs() sset.markers.add(mark) fullsuccessorsets.append(sset) if not foundany: - fullsuccessorsets.append(obsutil._succs()) + fullsuccessorsets.append(compat._succs()) values = [] for sset in fullsuccessorsets: @@ -673,7 +673,7 @@ label="evolve.node") # Operations - operations = obsutil.markersoperations(markers) + operations = compat.markersoperations(markers) if operations: fm.plain(' using ') fm.write('operation', '%s', ", ".join(operations), label="evolve.operation") @@ -681,13 +681,13 @@ fm.plain(' by ') # Users - users = obsutil.markersusers(markers) + users = compat.markersusers(markers) fm.write('user', '%s', ", ".join(users), label="evolve.user") fm.plain(' ') # Dates - dates = obsutil.markersdates(markers) + dates = compat.markersdates(markers) if dates: min_date = min(dates) max_date = max(dates)