Commit Graph

1048 Commits

Author SHA1 Message Date
Denis Laxalde
f37bd71289 diff: also yield file context objects in patch.trydiff() (API)
And retrieve them in patch.diffhunks(). We'll use these in forthcoming
changesets to filter diff hunks by line range.
2017-10-05 21:20:08 +02:00
Augie Fackler
bcaad82b20 webcommands: replace str(ctx) etc with pycompat.bytestr(ctx) etc
hgweb can now serve the graph view in Python 3.

Differential Revision: https://phab.mercurial-scm.org/D1138
2017-10-16 22:51:58 -04:00
Augie Fackler
45c9441c0e webutil: use pycompat.bytestr() instead of str()
Stops us from choking the templater on Python 3. With this patch
applied, much of hgweb works correctly in Python 3. The notable
exception is the graph page, which chokes because it gets node IDs as
str instead of bytes.

Differential Revision: https://phab.mercurial-scm.org/D1135
2017-10-16 22:44:06 -04:00
Augie Fackler
c6a33e23e1 hgweb: correct an earlier error of mine - start should be bytes
Gets hgweb very close to working with Python 3.

Differential Revision: https://phab.mercurial-scm.org/D1134
2017-10-16 22:43:19 -04:00
Augie Fackler
27aba6c982 hgweb: fix decodevaluefromheaders to always return a bytes value
That's more in line with what we want, and we know it's ASCII data
since that's all HTTP technically allows in headers anyway.

Differential Revision: https://phab.mercurial-scm.org/D1112
2017-10-15 00:43:01 -04:00
Augie Fackler
386ad003ae hgweb: more "headers are native strs" cleanup
I'll fix the decodevaluefromheaders function in an upcoming change.

Differential Revision: https://phab.mercurial-scm.org/D1111
2017-10-15 00:42:25 -04:00
Augie Fackler
db6ecaafd2 hgweb: when unpacking args from request form, convert to bytes
We assume http-originated values are ASCII, which should be safe based
on the RFC.

Differential Revision: https://phab.mercurial-scm.org/D1110
2017-10-15 00:41:34 -04:00
Augie Fackler
22c84078c4 hgweb: more "http headers are native strs" cleanup
Differential Revision: https://phab.mercurial-scm.org/D1108
2017-10-15 00:38:33 -04:00
Augie Fackler
1eb0868158 hgweb: fill in content-type and content-length as native strings
This lets me actually get a capabilities response from hgweb over
http.

Differential Revision: https://phab.mercurial-scm.org/D1087
2017-10-14 11:20:31 -04:00
Augie Fackler
d3a0083e45 hgweb: mimetype guessing needs a unicode path
Differential Revision: https://phab.mercurial-scm.org/D1086
2017-10-14 10:47:29 -04:00
Augie Fackler
dfaf4b98bc hgweb: set sent_headers attr as early as practical
While doing Python 3 porting work, I've seen exceptions happen in
parts of hgweb we normally assume are robust. It won't hurt anything
to set this attribute significantly earlier, so let's do so and save
confusing during the porting process.

Differential Revision: https://phab.mercurial-scm.org/D1085
2017-10-14 15:37:33 -04:00
Augie Fackler
caec472139 hgweb: detect Python 3-era libraries and use modern attribute names
Differential Revision: https://phab.mercurial-scm.org/D1084
2017-10-05 14:53:52 -04:00
Augie Fackler
1f7e395752 server: indent block that's about to get conditionalized
Differential Revision: https://phab.mercurial-scm.org/D1083
2017-10-14 15:53:36 -04:00
Augie Fackler
bc69639184 hgweb: fix logging to use native strings as appropriate
Kind of a tangled mess, but now logging works in both Python 2 and 3.

# no-check-commit because of the interface required by Python's HTTP
server code.

Differential Revision: https://phab.mercurial-scm.org/D1080
2017-10-14 15:43:06 -04:00
Augie Fackler
3327fe780e hgweb: rewrite most obviously-native-strings to be native strings
This clearly won't be everything, but it unblocks a fair amount of
stuff here.

Differential Revision: https://phab.mercurial-scm.org/D1079
2017-10-14 15:42:38 -04:00
Augie Fackler
9f097cd648 hgweb: use native strings consistently for querystring parsing
Differential Revision: https://phab.mercurial-scm.org/D1078
2017-10-05 14:48:52 -04:00
Augie Fackler
4fec03fc61 hgweb: rewrite two X or Y and Z ad-hoc ternaries with Y if X else Z
Just easier to muddle through for my brain now that I don't see the
old pattern much anymore.

Differential Revision: https://phab.mercurial-scm.org/D1077
2017-10-05 14:48:31 -04:00
Augie Fackler
58adac28f6 hgweb: more native string treatment in query string parsing
Differential Revision: https://phab.mercurial-scm.org/D1076
2017-10-05 14:29:51 -04:00
Augie Fackler
a67386352a python3: use our bytes-only version of cgi.escape everywhere
As suggested by Yuya in D965.

Differential Revision: https://phab.mercurial-scm.org/D1067
2017-10-05 14:16:20 -04:00
Yuya Nishihara
a312ee40fa configitems: drop redundant default of web.allow<archtype>
Otherwise develwarn would be sent to stderr. I've added blackbox logging
to capture warnings.
2017-10-13 00:22:54 +09:00
Jun Wu
2ae56b14de codemod: use pycompat.iswindows
This is done by:

  sed -i "s/pycompat\.osname == 'nt'/pycompat.iswindows/" **/*.py
  sed -i "s/pycompat\.osname != 'nt'/not pycompat.iswindows/" **/*.py
  sed -i 's/pycompat.osname == "nt"/pycompat.iswindows/' **/*.py

Differential Revision: https://phab.mercurial-scm.org/D1034
2017-10-12 23:30:46 -07:00
Jun Wu
d91707e2a4 hgweb: do not import uuid immediately to avoid its side effect
With hgdemandimport disabled (chg's case), `import uuid` has an immediate
side effect calling `ctypes.util.find_library` trying to locate the
`libuuid` library.  This happens at `import` time before `dispatch.run()`.
The call trace is like:

  File "hg/hg", line 54, in <module>
    from mercurial import (
  File "hg/mercurial/dispatch.py", line 24, in <module>
    from . import (
  File "hg/mercurial/commands.py", line 23, in <module>
    from . import (
  File "hg/mercurial/help.py", line 33, in <module>
    from .hgweb import (
  File "hg/mercurial/hgweb/__init__.py", line 20, in <module>
    from . import (
  File "hg/mercurial/hgweb/hgweb_mod.py", line 14, in <module>
    from .common import (
  File "hg/mercurial/hgweb/common.py", line 15, in <module>
    import uuid
  File "/usr/lib64/python2.7/uuid.py", line 404, in <module>
    lib = ctypes.CDLL(ctypes.util.find_library(libname))

The problem is, `ctypes.util.find_library` will execute
`sh -c '/sbin/ldconfig -p 2>/dev/null'` on Python <= 2.7.12. The output of
`sh` may pollute the terminal:

  shell-init: error retrieving current directory: getcwd: cannot access
  parent directories: No such file or directory

This patch moves `import uuid` so its side-effect can only happen after the
cwd check in `dispatch._getlocal`. Therefore the terminal won't be
polluted by importing `uuid`.

Differential Revision: https://phab.mercurial-scm.org/D1024
2017-10-11 21:24:32 -07:00
Boris Feld
baa18d572d configitems: register the 'web.logourl' config 2017-10-11 04:16:17 +02:00
Boris Feld
8209e13aaa configitems: register the 'web.logoimg' config 2017-10-11 04:16:05 +02:00
Boris Feld
34bf70b86f configitems: register the 'web.guessmime' config 2017-10-11 04:15:24 +02:00
Boris Feld
c71a63f860 configitems: register the 'web.cache' config 2017-10-11 04:14:33 +02:00
Boris Feld
e45e1468d5 configitems: register the 'web.allowpull' config 2017-10-11 04:12:50 +02:00
Boris Feld
64308038dd configitems: register the 'web.maxchanges' config 2017-10-11 03:41:48 +02:00
Boris Feld
308fd61d70 configitems: register the 'web.maxfiles' config 2017-10-11 03:41:01 +02:00
Boris Feld
6ea0289f11 configitems: register the 'web.maxshortchanges' config 2017-10-11 03:39:21 +02:00
Boris Feld
5c68cc40ee configitems: register the 'web.motd' config 2017-10-11 03:36:44 +02:00
Boris Feld
78e86af2e6 configitems: register the 'web.name' config 2017-10-11 03:32:59 +02:00
Boris Feld
176f52eb1f configitems: register the 'web.push_ssl' config 2017-10-11 03:29:09 +02:00
Boris Feld
abce33cdad configitems: register the 'web.view' config 2017-10-11 03:18:04 +02:00
Augie Fackler
0c9dc5bb90 hgweb: extract function for loading style from request context
Also make it work on Python 3.

Differential Revision: https://phab.mercurial-scm.org/D970
2017-10-05 14:29:13 -04:00
Augie Fackler
0f33c5f4f4 request: coerce content-type to native str
Again, required by WSGI.

Differential Revision: https://phab.mercurial-scm.org/D969
2017-10-05 14:27:21 -04:00
Augie Fackler
437290aeb9 request: use trivial iterator over dictionary keys
Differential Revision: https://phab.mercurial-scm.org/D968
2017-10-05 14:26:09 -04:00
Augie Fackler
02378a67e1 hgweb: when constructing or adding to a wsgi environ dict, use native strs
That's what's required of us to work with the WSGI API on Python 3.

Differential Revision: https://phab.mercurial-scm.org/D967
2017-10-05 14:22:02 -04:00
Augie Fackler
70bdecfdf5 hgweb: produce native string for etag value
Also use %d since we know mtime is numeric.

Differential Revision: https://phab.mercurial-scm.org/D966
2017-10-05 14:17:50 -04:00
Augie Fackler
395bba3900 hgweb: in protocol adapter, look for bytes instances, not str
Differential Revision: https://phab.mercurial-scm.org/D963
2017-10-05 14:13:20 -04:00
Augie Fackler
38c5b420ba hgweb: in protocol adapter, avoid control reaching end of non-void function
This greatly confounded some Python 3 porting work, once it was
managing to get this far.

Differential Revision: https://phab.mercurial-scm.org/D962
2017-10-05 14:12:51 -04:00
Alex Gaynor
88c328dbf9 style: never use a space before a colon or comma
Differential Revision: https://phab.mercurial-scm.org/D954
2017-09-29 15:48:34 +00:00
Siddharth Agarwal
ca691a7bec annotate: introduce attr for storing per-line annotate data
We're going to extend this a bit -- at first by simply adding whether this was
a skipped child. We're well on our way to outgrowing tuples, though -- adding
more and more fields to tuples becomes annoying very quickly.

Differential Revision: https://phab.mercurial-scm.org/D898
2017-10-02 02:34:47 -07:00
Gregory Szorc
348ce9ed24 hgweb: use parsebool for parsing diff query string options
Differential Revision: https://phab.mercurial-scm.org/D875
2017-10-01 12:29:33 +01:00
Gregory Szorc
28b7db089e hgweb: add HTML elements to control whitespace settings for annotate
Building on top of the new URL query string arguments to control
whitespace settings for annotate, this commit adds HTML checkboxes
reflecting the values of these arguments to the paper and gitweb
themes.

The actual diff settings are now exported to the templating layer.
The HTML templates add these as data-* attributes so they are
accessible to the DOM.

A new <form> with various <input> elements is added. The <form>
is initially hidden via CSS. A shared JavaScript function (which
runs after the <form> has been rendered but before the annotate
HTML (because annotate HTML could take a while to load and we want
the form to render quickly) takes care of setting the checked state
of each box from the data-* attributes. It also registers an event
handler to modify the URL and refresh the page whenever the checkbox
state is changed.

I'm using the URLSearchParams interface to perform URL manipulation.
https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams tells
me this may not be supported on older web browsers. Yes, apparently
the web API didn't have a standard API to parse and format query
strings until recently. Hence the check for the presence of this
feature in the JavaScript. If the browser doesn't support the
feature, the <form> will remain hidden and behavior will like it
currently is. We could polyfill this feature or implement our own
query string parsing. But I'm lazy and this could be done as a
follow-up if people miss it.

We could certainly expand this feature to support more diff options
(such as lines of context). That's why the potentially reusable code
is stored in a reusable place. It is also certainly possible to
add diff controls to other pages that display diffs. But since
Mozillians are making noise about controlling which revisions
annotate shows, I figured I'd start there.

.. feature::

   Control whitespace settings for annotation on hgweb

   /annotate URLs on hgweb now accept query string arguments to
   influence how whitespace changes impact results.

   The arguments "ignorews," "ignorewsamount," "ignorewseol," and
   "ignoreblanklines" now have the same meaning as their [annotate]
   config section counterparts. Any provided setting overrides the
   server default.

   HTML checkboxes have been added to the paper and gitweb themes
   to expose current whitespace settings and to easily modify the
   current view.

Differential Revision: https://phab.mercurial-scm.org/D850
2017-09-30 09:01:36 +01:00
Gregory Szorc
0ed01b356d hgweb: query string arguments to control whitespace for annotate
This feature should hopefully be pretty straightforward. We simply
examine some query string arguments to feed into the diff options.

The function to obtain the diff options has been factored into its
own generic function to facilitate an upcoming change to the HTML
interface and to enable diff settings to be controlled via the same
query string arguments on other web commands.

The test output for "ignoreblanklines" didn't change. I'm not sure
why. Our test coverage for --ignore-blank-lines isn't great and I
can't figure out how to make this diff setting do anything meaningful.
On a very brief examination of the code, it is possible the setting
doesn't work because it is operating at the line level and blank lines
detection needs to examine multiple lines. But I'm not an expert in
this code, so I'm not sure.

Differential Revision: https://phab.mercurial-scm.org/D849
2017-09-30 09:08:01 +01:00
Augie Fackler
3519ee0e52 hgweb: remove superfluous pass statements 2017-09-30 07:44:20 -04:00
Yuya Nishihara
e896c6e733 py3: remove use of str() in hgwebdir
'%d' can't be used here since port may be either integer or byte string.
2017-09-27 19:04:32 +09:00
Boris Feld
5d4daea552 hgwebdir: read 'web.template' untrusted
The 'hgweb_mod.py' version of this read it untrusted. For consistency we align
the two versions of this code.
2017-09-15 18:57:50 +02:00
Boris Feld
d6d64df885 configitems: register the 'web.templates' config 2017-06-30 03:45:53 +02:00