Commits

Angel Ezquerra  committed bd9d90d

revdetails: show the obsolete precursors and successors on the revision panel

Note that csinfo does not have knowledge of these new fields. It is assumed that
these are only interesting when viewing the revision details.

This changeset adds a new file, obsoleteutil.py, which contains a few functions
copied from hgview util.py.

  • Participants
  • Parent commits 621ff8c

Comments (0)

Files changed (2)

File tortoisehg/hgqt/revpanel.py

 
 from mercurial import error
 
-from tortoisehg.util import hglib
+from tortoisehg.util import hglib, obsoleteutil
 from tortoisehg.hgqt.i18n import _
 from tortoisehg.hgqt import csinfo, qtlib
 
         return _('Child:')
     elif item == 'patch':
         return _('Patch:')
+    elif item == 'precursors':
+        return _('Precursors:')
+    elif item == 'successors':
+        return _('Successors:')
     raise csinfo.UnknownItem(item)
 
 def revid_markup(revid, **kargs):
             return ctx
         desc = ctx.description()
         return (str(ctx.rev()), str(ctx), summary_line(desc), hl, branch)
+    def format_ctxlist(ctxlist):
+        if not ctxlist:
+            return None
+        return [revline_data(ctx)[:3] for ctx in ctxlist]
     if item == 'cset':
         return revline_data(ctx)
     elif item == 'branch':
         if ctx.rev() is None:
             ctx = ctx.p1()
         return ctx.extra().get('close') is not None
+    elif item == 'precursors':
+        ctxlist = obsoleteutil.first_known_precursors(ctx)
+        return format_ctxlist(ctxlist)
+    elif item == 'successors':
+        ctxlist = obsoleteutil.first_known_successors(ctx)
+        return format_ctxlist(ctxlist)
+
     raise csinfo.UnknownItem(item)
 
 def markup_func(widget, item, value):
         if isinstance(value, basestring):
             return revid_markup(value)
         return revline_markup(link=link, *value)
-    elif item in ('parents', 'children'):
+    elif item in ('parents', 'children', 'precursors', 'successors'):
         csets = []
         for cset in value:
             if isinstance(cset, basestring):
                            markup=markup_func)
     style = csinfo.panelstyle(contents=('cset', 'branch', 'obsolete', 'close', 'user',
                    'dateage', 'parents', 'children', 'tags', 'graft', 'transplant',
+                   'precursors', 'successors',
                    'p4', 'svn', 'converted'), selectable=True,
                    expandable=True)
     return csinfo.create(repo, style=style, custom=custom)

File tortoisehg/util/obsoleteutil.py

+# obsolete related util functions (taken from hgview)
+#
+# The functions in this file have been taken from hgview's util.py file
+# (http://hg.logilab.org/review/hgview/file/default/hgviewlib/util.py)
+#
+# Copyright (C) 2009-2012 Logilab. All rights reserved.
+#
+# This software may be used and distributed according to the terms
+# of the GNU General Public License, incorporated herein by reference.
+def precursorsmarkers(obsstore, node):
+    return obsstore.precursors.get(node, ())
+
+def successorsmarkers(obsstore, node):
+    return obsstore.successors.get(node, ())
+
+def first_known_precursors(ctx, excluded=()):
+    obsstore = getattr(ctx._repo, 'obsstore', None)
+    startnode = ctx.node()
+    nm = ctx._repo.changelog.nodemap
+    if obsstore is not None:
+        markers = precursorsmarkers(obsstore, startnode)
+        # consider all precursors
+        candidates = set(mark[0] for mark in markers)
+        seen = set(candidates)
+        if startnode in candidates:
+            candidates.remove(startnode)
+        else:
+            seen.add(startnode)
+        while candidates:
+            current = candidates.pop()
+            # is this changeset in the displayed set ?
+            crev = nm.get(current)
+            if crev is not None and crev not in excluded:
+                yield ctx._repo[crev]
+            else:
+                for mark in precursorsmarkers(obsstore, current):
+                    if mark[0] not in seen:
+                        candidates.add(mark[0])
+                        seen.add(mark[0])
+
+def first_known_successors(ctx, excluded=()):
+    obsstore = getattr(ctx._repo, 'obsstore', None)
+    startnode = ctx.node()
+    nm = ctx._repo.changelog.nodemap
+    if obsstore is not None:
+        markers = successorsmarkers(obsstore, startnode)
+        # consider all precursors
+        candidates = set()
+        for mark in markers:
+            candidates.update(mark[1])
+        seen = set(candidates)
+        if startnode in candidates:
+            candidates.remove(startnode)
+        else:
+            seen.add(startnode)
+        while candidates:
+            current = candidates.pop()
+            # is this changeset in the displayed set ?
+            crev = nm.get(current)
+            if crev is not None and crev not in excluded:
+                yield ctx._repo[crev]
+            else:
+                for mark in successorsmarkers(obsstore, current):
+                    for succ in mark[1]:
+                        if succ not in seen:
+                            candidates.add(succ)
+                            seen.add(succ)