Patchwork D849: hgweb: query string arguments to control whitespace for annotate

login
register
mail settings
Submitter phabricator
Date Oct. 1, 2017, 10:56 a.m.
Message ID <d428663baf903bbb4bf2f3e4008d39a3@localhost.localdomain>
Download mbox | patch
Permalink /patch/24308/
State Not Applicable
Headers show

Comments

phabricator - Oct. 1, 2017, 10:56 a.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGf6492f482c60: hgweb: query string arguments to control whitespace for annotate (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D849?vs=2174&id=2235

REVISION DETAIL
  https://phab.mercurial-scm.org/D849

AFFECTED FILES
  mercurial/hgweb/webcommands.py
  mercurial/hgweb/webutil.py
  tests/test-hgweb-annotate-whitespace.t

CHANGE DETAILS




To: indygreg, #hg-reviewers, simpkins, durin42
Cc: durin42, simpkins, mercurial-devel

Patch

diff --git a/tests/test-hgweb-annotate-whitespace.t b/tests/test-hgweb-annotate-whitespace.t
--- a/tests/test-hgweb-annotate-whitespace.t
+++ b/tests/test-hgweb-annotate-whitespace.t
@@ -282,7 +282,7 @@ 
     "permissions": ""
   }
 
-ignorews=1 query string argument enables whitespace skipping (not implemented)
+ignorews=1 query string argument enables whitespace skipping
 
   $ get-with-headers.py --json $LOCALIP:$HGPORT 'json-annotate/9d1b2c7db017/foo?ignorews=1'
   200 Script output follows
@@ -293,107 +293,6 @@ 
       {
         "abspath": "foo",
         "author": "test",
-        "desc": "commit 4 (intra whitespace on line 0)",
-        "line": "line  0\n",
-        "lineno": 1,
-        "node": "08adbe269f24cf22d975eadeec16790c5b22f558",
-        "revdate": [
-          0.0,
-          0
-        ],
-        "targetline": 1
-      },
-      {
-        "abspath": "foo",
-        "author": "test",
-        "desc": "commit 5 (add blank line between line 0 and 1)",
-        "line": "\n",
-        "lineno": 2,
-        "node": "400ef1d404706cfb48afd2b78ce6addf641ced25",
-        "revdate": [
-          0.0,
-          0
-        ],
-        "targetline": 2
-      },
-      {
-        "abspath": "foo",
-        "author": "test",
-        "desc": "commit 6 (add another blank line between line 0 and 1)",
-        "line": "\n",
-        "lineno": 3,
-        "node": "9d1b2c7db0175870a950f8c48c9c4ead1058f2c5",
-        "revdate": [
-          0.0,
-          0
-        ],
-        "targetline": 3
-      },
-      {
-        "abspath": "foo",
-        "author": "test",
-        "desc": "commit 1",
-        "line": "line 1 modified by 1\n",
-        "lineno": 4,
-        "node": "23e1e37387dcfca4c0ed0cc568d1e4b9bfed241a",
-        "revdate": [
-          0.0,
-          0
-        ],
-        "targetline": 2
-      },
-      {
-        "abspath": "foo",
-        "author": "test",
-        "desc": "commit 2 (leading whitespace on line 2)",
-        "line": "    line 2\n",
-        "lineno": 5,
-        "node": "6bdb694e7b8cebb68d5b6b27b4bcc2a49d62c602",
-        "revdate": [
-          0.0,
-          0
-        ],
-        "targetline": 3
-      },
-      {
-        "abspath": "foo",
-        "author": "test",
-        "desc": "commit 3 (trailing whitespace on line 3)",
-        "line": "line 3    \n",
-        "lineno": 6,
-        "node": "dcb62cfbfc9b3ab995a5cbbaff6e1971c3e4f865",
-        "revdate": [
-          0.0,
-          0
-        ],
-        "targetline": 4
-      }
-    ],
-    "author": "test",
-    "children": [],
-    "date": [
-      0.0,
-      0
-    ],
-    "desc": "commit 6 (add another blank line between line 0 and 1)",
-    "node": "9d1b2c7db0175870a950f8c48c9c4ead1058f2c5",
-    "parents": [
-      "400ef1d404706cfb48afd2b78ce6addf641ced25"
-    ],
-    "permissions": ""
-  }
-
-ignorews=0 query string argument disables when config defaults to enabled (not implemented)
-
-  $ get-with-headers.py --json $LOCALIP:$HGPORT1 'json-annotate/9d1b2c7db017/foo?ignorews=0'
-  200 Script output follows
-  
-  {
-    "abspath": "foo",
-    "annotate": [
-      {
-        "abspath": "foo",
-        "author": "test",
         "desc": "commit 0",
         "line": "line  0\n",
         "lineno": 1,
@@ -484,9 +383,9 @@ 
     "permissions": ""
   }
 
-ignorewsamount=1 query string enables whitespace amount skipping (not implemented)
+ignorews=0 query string argument disables when config defaults to enabled
 
-  $ get-with-headers.py --json $LOCALIP:$HGPORT 'json-annotate/9d1b2c7db017/foo?ignorewsamount=1'
+  $ get-with-headers.py --json $LOCALIP:$HGPORT1 'json-annotate/9d1b2c7db017/foo?ignorews=0'
   200 Script output follows
   
   {
@@ -585,7 +484,108 @@ 
     "permissions": ""
   }
 
-ignorewseol=1 query string enables whitespace end of line skipping (not implemented)
+ignorewsamount=1 query string enables whitespace amount skipping
+
+  $ get-with-headers.py --json $LOCALIP:$HGPORT 'json-annotate/9d1b2c7db017/foo?ignorewsamount=1'
+  200 Script output follows
+  
+  {
+    "abspath": "foo",
+    "annotate": [
+      {
+        "abspath": "foo",
+        "author": "test",
+        "desc": "commit 0",
+        "line": "line  0\n",
+        "lineno": 1,
+        "node": "b9c578134d72b3a9d26afde8ddd76c0a93c5adbc",
+        "revdate": [
+          0.0,
+          0
+        ],
+        "targetline": 1
+      },
+      {
+        "abspath": "foo",
+        "author": "test",
+        "desc": "commit 5 (add blank line between line 0 and 1)",
+        "line": "\n",
+        "lineno": 2,
+        "node": "400ef1d404706cfb48afd2b78ce6addf641ced25",
+        "revdate": [
+          0.0,
+          0
+        ],
+        "targetline": 2
+      },
+      {
+        "abspath": "foo",
+        "author": "test",
+        "desc": "commit 6 (add another blank line between line 0 and 1)",
+        "line": "\n",
+        "lineno": 3,
+        "node": "9d1b2c7db0175870a950f8c48c9c4ead1058f2c5",
+        "revdate": [
+          0.0,
+          0
+        ],
+        "targetline": 3
+      },
+      {
+        "abspath": "foo",
+        "author": "test",
+        "desc": "commit 1",
+        "line": "line 1 modified by 1\n",
+        "lineno": 4,
+        "node": "23e1e37387dcfca4c0ed0cc568d1e4b9bfed241a",
+        "revdate": [
+          0.0,
+          0
+        ],
+        "targetline": 2
+      },
+      {
+        "abspath": "foo",
+        "author": "test",
+        "desc": "commit 2 (leading whitespace on line 2)",
+        "line": "    line 2\n",
+        "lineno": 5,
+        "node": "6bdb694e7b8cebb68d5b6b27b4bcc2a49d62c602",
+        "revdate": [
+          0.0,
+          0
+        ],
+        "targetline": 3
+      },
+      {
+        "abspath": "foo",
+        "author": "test",
+        "desc": "commit 0",
+        "line": "line 3    \n",
+        "lineno": 6,
+        "node": "b9c578134d72b3a9d26afde8ddd76c0a93c5adbc",
+        "revdate": [
+          0.0,
+          0
+        ],
+        "targetline": 4
+      }
+    ],
+    "author": "test",
+    "children": [],
+    "date": [
+      0.0,
+      0
+    ],
+    "desc": "commit 6 (add another blank line between line 0 and 1)",
+    "node": "9d1b2c7db0175870a950f8c48c9c4ead1058f2c5",
+    "parents": [
+      "400ef1d404706cfb48afd2b78ce6addf641ced25"
+    ],
+    "permissions": ""
+  }
+
+ignorewseol=1 query string enables whitespace end of line skipping
 
   $ get-with-headers.py --json $LOCALIP:$HGPORT 'json-annotate/9d1b2c7db017/foo?ignorewseol=1'
   200 Script output follows
@@ -661,10 +661,10 @@ 
       {
         "abspath": "foo",
         "author": "test",
-        "desc": "commit 3 (trailing whitespace on line 3)",
+        "desc": "commit 0",
         "line": "line 3    \n",
         "lineno": 6,
-        "node": "dcb62cfbfc9b3ab995a5cbbaff6e1971c3e4f865",
+        "node": "b9c578134d72b3a9d26afde8ddd76c0a93c5adbc",
         "revdate": [
           0.0,
           0
@@ -686,7 +686,7 @@ 
     "permissions": ""
   }
 
-ignoreblanklines=1 query string enables whitespace blank line skipping (not implemented)
+ignoreblanklines=1 query string enables whitespace blank line skipping
 
   $ get-with-headers.py --json $LOCALIP:$HGPORT 'json-annotate/9d1b2c7db017/foo?ignoreblanklines=1'
   200 Script output follows
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -170,9 +170,24 @@ 
     def __len__(self):
         return len(self.siblings)
 
-def annotate(fctx, ui):
+def difffeatureopts(req, ui, section):
     diffopts = patch.difffeatureopts(ui, untrusted=True,
-                                     section='annotate', whitespace=True)
+                                     section=section, whitespace=True)
+
+    for k in ('ignorews', 'ignorewsamount', 'ignorewseol', 'ignoreblanklines'):
+        v = req.form.get(k, [None])[0]
+        if v is not None:
+            try:
+                v = bool(int(v))
+            except ValueError:
+                v = True
+
+            setattr(diffopts, k, v)
+
+    return diffopts
+
+def annotate(req, fctx, ui):
+    diffopts = difffeatureopts(req, ui, 'annotate')
     return fctx.annotate(follow=True, linenumber=True, diffopts=diffopts)
 
 def parents(ctx, hide=None):
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -863,6 +863,12 @@ 
 
     Show changeset information for each line in a file.
 
+    The ``ignorews``, ``ignorewsamount``, ``ignorewseol``, and
+    ``ignoreblanklines`` query string arguments have the same meaning as
+    their ``[annotate]`` config equivalents. A value of ``0`` sets the
+    whitespace option to false. All other values are true. If not defined,
+    the server default settings are used.
+
     The ``fileannotate`` template is rendered.
     """
     fctx = webutil.filectx(web.repo, req)
@@ -895,7 +901,7 @@ 
                   or 'application/octet-stream')
             lines = [((fctx.filectx(fctx.filerev()), 1), '(binary:%s)' % mt)]
         else:
-            lines = webutil.annotate(fctx, web.repo.ui)
+            lines = webutil.annotate(req, fctx, web.repo.ui)
 
         previousrev = None
         blockparitygen = paritygen(1)