Patchwork hgweb: make fctx.annotate a separated function so it could be wrapped

login
register
mail settings
Submitter Jun Wu
Date Oct. 8, 2016, 3:17 p.m.
Message ID <30141bc03ab8608b04aa.1475939833@x1c>
Download mbox | patch
Permalink /patch/16933/
State Accepted
Headers show

Comments

Jun Wu - Oct. 8, 2016, 3:17 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1475939434 -3600
#      Sat Oct 08 16:10:34 2016 +0100
# Node ID 30141bc03ab8608b04aa717e4dee46046c00f5d6
# Parent  cd7276f7ea8308df2c5d8874d335d73247d0f357
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 30141bc03ab8
hgweb: make fctx.annotate a separated function so it could be wrapped

This patch moves "fctx.annotate" used by the "annotate" webcommand, along
with the diffopts to a separated function which takes a ui and a fctx.
So it could be replaced by other implementations which don't want to replace
the core "fctx.annotate" directly.
Augie Fackler - Oct. 8, 2016, 4:56 p.m.
On Sat, Oct 08, 2016 at 04:17:13PM +0100, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1475939434 -3600
> #      Sat Oct 08 16:10:34 2016 +0100
> # Node ID 30141bc03ab8608b04aa717e4dee46046c00f5d6
> # Parent  cd7276f7ea8308df2c5d8874d335d73247d0f357
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 30141bc03ab8
> hgweb: make fctx.annotate a separated function so it could be wrapped

Queued with enthusiasm for our faster annotation overlords.

>
> This patch moves "fctx.annotate" used by the "annotate" webcommand, along
> with the diffopts to a separated function which takes a ui and a fctx.
> So it could be replaced by other implementations which don't want to replace
> the core "fctx.annotate" directly.
>
> diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
> --- a/mercurial/hgweb/webcommands.py
> +++ b/mercurial/hgweb/webcommands.py
> @@ -32,5 +32,4 @@ from .. import (
>      error,
>      graphmod,
> -    patch,
>      revset,
>      scmutil,
> @@ -862,6 +861,4 @@ def annotate(web, req, tmpl):
>      f = fctx.path()
>      parity = paritygen(web.stripecount)
> -    diffopts = patch.difffeatureopts(web.repo.ui, untrusted=True,
> -                                     section='annotate', whitespace=True)
>
>      def parents(f):
> @@ -878,6 +875,6 @@ def annotate(web, req, tmpl):
>              lines = [((fctx.filectx(fctx.filerev()), 1), '(binary:%s)' % mt)]
>          else:
> -            lines = fctx.annotate(follow=True, linenumber=True,
> -                                  diffopts=diffopts)
> +            lines = webutil.annotate(fctx, web.repo.ui)
> +
>          previousrev = None
>          blockparitygen = paritygen(1)
> diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
> --- a/mercurial/hgweb/webutil.py
> +++ b/mercurial/hgweb/webutil.py
> @@ -165,4 +165,9 @@ class _siblings(object):
>          return len(self.siblings)
>
> +def annotate(fctx, ui):
> +    diffopts = patch.difffeatureopts(ui, untrusted=True,
> +                                     section='annotate', whitespace=True)
> +    return fctx.annotate(follow=True, linenumber=True, diffopts=diffopts)
> +
>  def parents(ctx, hide=None):
>      if isinstance(ctx, context.basefilectx):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -32,5 +32,4 @@  from .. import (
     error,
     graphmod,
-    patch,
     revset,
     scmutil,
@@ -862,6 +861,4 @@  def annotate(web, req, tmpl):
     f = fctx.path()
     parity = paritygen(web.stripecount)
-    diffopts = patch.difffeatureopts(web.repo.ui, untrusted=True,
-                                     section='annotate', whitespace=True)
 
     def parents(f):
@@ -878,6 +875,6 @@  def annotate(web, req, tmpl):
             lines = [((fctx.filectx(fctx.filerev()), 1), '(binary:%s)' % mt)]
         else:
-            lines = fctx.annotate(follow=True, linenumber=True,
-                                  diffopts=diffopts)
+            lines = webutil.annotate(fctx, web.repo.ui)
+
         previousrev = None
         blockparitygen = paritygen(1)
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -165,4 +165,9 @@  class _siblings(object):
         return len(self.siblings)
 
+def annotate(fctx, ui):
+    diffopts = patch.difffeatureopts(ui, untrusted=True,
+                                     section='annotate', whitespace=True)
+    return fctx.annotate(follow=True, linenumber=True, diffopts=diffopts)
+
 def parents(ctx, hide=None):
     if isinstance(ctx, context.basefilectx):