[PATCH] cmdutil: changeset_printer: use methods of filectx/changectx

Greg Ward greg-hg at gerg.ca
Mon Oct 5 22:17:40 UTC 2009


# HG changeset patch
# User Greg Ward <greg-hg at gerg.ca>
# Date 1254781033 14400
# Node ID 1ef07f75983d1169a63517d478a6faade27101d2
# Parent  5287de171d74061b00cf55f3d9224dc76f832d7c
cmdutil: changeset_printer: use methods of filectx/changectx.

This allows extensions that modify changeset metadata (e.g.
description) by overriding methods of changectx to get consistent
behavior from all log-like commands, regardless of whether templates
or styles are used. Without this, overriding changectx methods works
if you use styles or templates, but not with default log format.

This meant adding filectx.extra() for consistency with changectx.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -652,9 +652,8 @@
             return
 
         log = self.repo.changelog
-        changes = log.read(changenode)
-        date = util.datestr(changes[2])
-        extra = changes[5]
+        date = util.datestr(ctx.date())
+        extra = ctx.extra()
         branch = extra.get("branch")
 
         hexfunc = self.ui.debugflag and hex or short
@@ -674,9 +673,10 @@
             self.ui.write(_("parent:      %d:%s\n") % parent)
 
         if self.ui.debugflag:
+            mnode = ctx.manifestnode()
             self.ui.write(_("manifest:    %d:%s\n") %
-                          (self.repo.manifest.rev(changes[0]), hex(changes[0])))
-        self.ui.write(_("user:        %s\n") % changes[1])
+                          (self.repo.manifest.rev(mnode), hex(mnode)))
+        self.ui.write(_("user:        %s\n") % ctx.user())
         self.ui.write(_("date:        %s\n") % date)
 
         if self.ui.debugflag:
@@ -685,8 +685,8 @@
                                   files):
                 if value:
                     self.ui.write("%-12s %s\n" % (key, " ".join(value)))
-        elif changes[3] and self.ui.verbose:
-            self.ui.write(_("files:       %s\n") % " ".join(changes[3]))
+        elif ctx.files() and self.ui.verbose:
+            self.ui.write(_("files:       %s\n") % " ".join(ctx.files()))
         if copies and self.ui.verbose:
             copies = ['%s (%s)' % c for c in copies]
             self.ui.write(_("copies:      %s\n") % ' '.join(copies))
@@ -696,7 +696,7 @@
                 self.ui.write(_("extra:       %s=%s\n")
                               % (key, value.encode('string_escape')))
 
-        description = changes[4].strip()
+        description = ctx.description().strip()
         if description:
             if self.ui.verbose:
                 self.ui.write(_("description:\n"))
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -299,6 +299,7 @@
     def files(self): return self._changectx.files()
     def description(self): return self._changectx.description()
     def branch(self): return self._changectx.branch()
+    def extra(self): return self._changectx.extra()
     def manifest(self): return self._changectx.manifest()
     def changectx(self): return self._changectx
 



More information about the Mercurial-devel mailing list