[PATCH 1 of 4] log: add an extensionsfields method to changeset_printer

Pierre-Yves David pierre-yves.david at ens-lyon.org
Sat Jun 11 07:31:59 CDT 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1307795142 -7200
# Node ID 877d353a386690bb6b744ad7a6630ccf87617040
# Parent  0980239cb20c409a3eaee6b91fb6a6a3fb86c7f2
log: add an extensionsfields method to changeset_printer

This function meant to be wrapped by extension. The goal is to help them to add
additional field for default changeset display.

Extensions adding field should consider adding template keyword too.

diff -r 0980239cb20c -r 877d353a3866 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Fri Jun 10 20:38:02 2011 +0200
+++ b/mercurial/cmdutil.py	Sat Jun 11 14:25:42 2011 +0200
@@ -650,6 +650,15 @@
         self.ui.write(_("date:        %s\n") % date,
                       label='log.date')
 
+        for extentry in self.extensionsfields(ctx, copies, matchfn, props):
+            fieldname = extentry[0]
+            msg = _("%-13s%%s\n" % (fieldname + ':')) % _(extentry[1])
+            if len(extentry) > 2:
+                label = extentry[2]
+            else:
+                label = "log." + fieldname
+            self.ui.write(msg, label=label)
+
         if self.ui.debugflag:
             files = self.repo.status(log.parents(changenode)[0], changenode)[:3]
             for key, value in zip([_("files:"), _("files+:"), _("files-:")],
@@ -721,6 +730,36 @@
                 parents = [parents[0]]
         return parents
 
+    def extensionsfields(self, ctx, copies, matchfn, props):
+        """A function meant to be overwriten by extension.
+
+        The goal is to help extension to add additional field for default
+        changeset display.
+
+        This function should returns iterable of 2 or 3 tuple as bellow
+
+            (field-name, value, [, label])
+
+        Such tuple will be will be displayed as standard field in this format:
+
+            "<field-name>: %s\n"
+
+        * Enought space will be added to respect the standard padding used by
+          standard field.
+        * Field-name is expected to be shorter than 11 chard.
+        * Field-name will be internationalized.
+        * If label is not provided it will be log.<field-name>
+
+        Extention are responsible to read self.ui to decide if they message
+        should be issued
+
+        Extensions wrapping this function should consider adding template
+        keyword too.
+
+        The function  does return anything by default of course."""
+
+        return []
+
 
 class changeset_templater(changeset_printer):
     '''format changeset information.'''


More information about the Mercurial-devel mailing list