diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py +++ b/mercurial/hgweb/webcommands.py @@ -930,6 +930,9 @@ def annotate(web, req, tmpl): "linenumber": "% 6d" % (lineno + 1), "revdate": f.date()} + diffopts = webutil.difffeatureopts(req, web.repo.ui, 'annotate') + diffopts = {k: getattr(diffopts, k) for k in diffopts.defaults} + return tmpl("fileannotate", file=f, annotate=annotate, @@ -938,6 +941,7 @@ def annotate(web, req, tmpl): rename=webutil.renamelink(fctx), permissions=fctx.manifest().flags(f), ishead=int(ishead), + diffopts=diffopts, **webutil.commonentry(web.repo, fctx)) @webcommand('filelog') diff --git a/mercurial/templates/gitweb/fileannotate.tmpl b/mercurial/templates/gitweb/fileannotate.tmpl --- a/mercurial/templates/gitweb/fileannotate.tmpl +++ b/mercurial/templates/gitweb/fileannotate.tmpl @@ -62,6 +62,13 @@ annotate |
{desc|strip|escape|websub|nonempty}
+ +{diffoptsform} + + +
+ Ignore whitespace changes - + Everywhere: + + Within whitespace: + + At end of lines: + + + ' diff --git a/mercurial/templates/paper/fileannotate.tmpl b/mercurial/templates/paper/fileannotate.tmpl --- a/mercurial/templates/paper/fileannotate.tmpl +++ b/mercurial/templates/paper/fileannotate.tmpl @@ -65,6 +65,12 @@
+{diffoptsform} + + +
diff --git a/mercurial/templates/paper/map b/mercurial/templates/paper/map --- a/mercurial/templates/paper/map +++ b/mercurial/templates/paper/map @@ -251,3 +251,18 @@ searchform = ' ' searchhint = 'Find changesets by keywords (author, files, the commit message), revision number or hash, or revset expression.' + +diffoptsform = ' + + Ignore whitespace changes - + Everywhere: + + Within whitespace: + + At end of lines: + + ' diff --git a/mercurial/templates/static/mercurial.js b/mercurial/templates/static/mercurial.js --- a/mercurial/templates/static/mercurial.js +++ b/mercurial/templates/static/mercurial.js @@ -434,6 +434,56 @@ function ajaxScrollInit(urlFormat, scrollHandler(); } +function renderDiffOptsForm() { + // We use URLSearchParams for query string manipulation. Old browsers don't + // support this API. + if (!("URLSearchParams" in window)) { + return; + } + + var form = document.getElementById("diffopts-form"); + + var KEYS = [ + "ignorews", + "ignorewsamount", + "ignorewseol", + "ignoreblanklines", + ]; + + var urlParams = new URLSearchParams(window.location.search); + + function updateAndRefresh(e) { + var checkbox = e.target; + var name = checkbox.id.substr(0, checkbox.id.indexOf("-")); + urlParams.set(name, checkbox.checked ? "1" : "0"); + window.location.search = urlParams.toString(); + } + + var allChecked = form.getAttribute("data-ignorews") == "1"; + + for (var i = 0; i < KEYS.length; i++) { + var key = KEYS[i]; + + var checkbox = document.getElementById(key + "-checkbox"); + if (!checkbox) { + continue; + } + + currentValue = form.getAttribute("data-" + key); + checkbox.checked = currentValue != "0"; + + // ignorews implies ignorewsamount and ignorewseol. + if (allChecked && (key == "ignorewsamount" || key == "ignorewseol")) { + checkbox.checked = true; + checkbox.disabled = true; + } + + checkbox.addEventListener("change", updateAndRefresh, false); + } + + form.style.display = 'block'; +} + document.addEventListener('DOMContentLoaded', function() { process_dates(); }, false); diff --git a/mercurial/templates/static/style-gitweb.css b/mercurial/templates/static/style-gitweb.css --- a/mercurial/templates/static/style-gitweb.css +++ b/mercurial/templates/static/style-gitweb.css @@ -97,6 +97,12 @@ div.annotate-info { } div.annotate-info a { color: #0000FF; text-decoration: underline; } td.annotate:hover div.annotate-info { display: inline; } + +#diffopts-form { + padding-left: 8px; + display: none; +} + .linenr { color:#999999; text-decoration:none } div.rss_logo { float: right; white-space: nowrap; } div.rss_logo a { diff --git a/mercurial/templates/static/style-paper.css b/mercurial/templates/static/style-paper.css --- a/mercurial/templates/static/style-paper.css +++ b/mercurial/templates/static/style-paper.css @@ -226,6 +226,13 @@ div.annotate-info { div.annotate-info a { color: #0000FF; } td.annotate:hover div.annotate-info { display: inline; } +#diffopts-form { + font-size: smaller; + color: #424242; + padding-bottom: 10px; + display: none; +} + .source, .sourcefirst { font-family: monospace; white-space: pre; diff --git a/tests/test-hgweb.t b/tests/test-hgweb.t --- a/tests/test-hgweb.t +++ b/tests/test-hgweb.t @@ -340,7 +340,7 @@ static file $ get-with-headers.py --twice localhost:$HGPORT 'static/style-gitweb.css' - date etag server 200 Script output follows - content-length: 9007 + content-length: 9066 content-type: text/css body { font-family: sans-serif; font-size: 12px; border:solid #d9d8d1; border-width:1px; margin:10px; background: white; color: black; } @@ -442,6 +442,12 @@ static file } div.annotate-info a { color: #0000FF; text-decoration: underline; } td.annotate:hover div.annotate-info { display: inline; } + + #diffopts-form { + padding-left: 8px; + display: none; + } + .linenr { color:#999999; text-decoration:none } div.rss_logo { float: right; white-space: nowrap; } div.rss_logo a { diff --git a/tests/test-highlight.t b/tests/test-highlight.t --- a/tests/test-highlight.t +++ b/tests/test-highlight.t @@ -284,6 +284,25 @@ hgweb fileannotate, html
+ +
+ Ignore whitespace changes - + Everywhere: + + Within whitespace: + + At end of lines: + +
+ + +