Commit Graph

1069 Commits

Author SHA1 Message Date
David Soria Parra
9939f03d8e hg: make file view in hgweb working
Summary:
hgweb's file view must determine if the displayed file revision is
the head of the filelog graph. As remotefilelog does not implement file
revision, we have to check if headrevs is implemented.

Reviewed By: DurhamG

Differential Revision: D6954143

fbshipit-source-id: 0657e58110112537dc5baadf743c657d4ecf372a
2018-04-13 21:51:10 -07:00
Jun Wu
f1c575a099 flake8: enable F821 check
Summary:
This check is useful and detects real errors (ex. fbconduit).  Unfortunately
`arc lint` will run it with both py2 and py3 so a lot of py2 builtins will
still be warned.

I didn't find a clean way to disable py3 check. So this diff tries to fix them.
For `xrange`, the change was done by a script:

```
import sys
import redbaron

headertypes = {'comment', 'endl', 'from_import', 'import', 'string',
               'assignment', 'atomtrailers'}

xrangefix = '''try:
    xrange(0)
except NameError:
    xrange = range

'''

def isxrange(x):
    try:
        return x[0].value == 'xrange'
    except Exception:
        return False

def main(argv):
    for i, path in enumerate(argv):
        print('(%d/%d) scanning %s' % (i + 1, len(argv), path))
        content = open(path).read()
        try:
            red = redbaron.RedBaron(content)
        except Exception:
            print('  warning: failed to parse')
            continue
        hasxrange = red.find('atomtrailersnode', value=isxrange)
        hasxrangefix = 'xrange = range' in content
        if hasxrangefix or not hasxrange:
            print('  no need to change')
            continue

        # find a place to insert the compatibility  statement
        changed = False
        for node in red:
            if node.type in headertypes:
                continue
            # node.insert_before is an easier API, but it has bugs changing
            # other "finally" and "except" positions. So do the insert
            # manually.
            # # node.insert_before(xrangefix)
            line = node.absolute_bounding_box.top_left.line - 1
            lines = content.splitlines(1)
            content = ''.join(lines[:line]) + xrangefix + ''.join(lines[line:])
            changed = True
            break

        if changed:
            # "content" is faster than "red.dumps()"
            open(path, 'w').write(content)
            print('  updated')

if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))
```

For other py2 builtins that do not have a py3 equivalent, some `# noqa`
were added as a workaround for now.

Reviewed By: DurhamG

Differential Revision: D6934535

fbshipit-source-id: 546b62830af144bc8b46788d2e0fd00496838939
2018-04-13 21:51:09 -07:00
Jun Wu
2946a1c198 codemod: use single blank line
Summary: This makes test-check-code cleaner.

Reviewed By: ryanmce

Differential Revision: D6937934

fbshipit-source-id: 8f92bc32f75b9792ac67db77bb3a8756b37fa941
2018-04-13 21:51:08 -07:00
Jun Wu
bc139eb86b hgweb: add --port-file flag
Summary:
This allows us to specify `-p 0 --port-file X` to get the port assigned in
an atomic way. So there won't be "server failed to start" caused by race
conditions in tests.

Reviewed By: DurhamG

Differential Revision: D6925397

fbshipit-source-id: 5bbb61b7eb2695f0a673afdb0730d2a61827f8b3
2018-04-13 21:51:07 -07:00
Augie Fackler
eed6eb51f4 merge with stable 2017-12-19 16:27:24 -05:00
Yuya Nishihara
e6f35d04b2 hgweb: disable diff.noprefix option for diffstat
Copied from 62d04dd7ece9.
2017-12-17 18:28:15 +09:00
Anton Shestakov
5cc31b3c35 hgweb: update graph function docstring 2017-12-14 21:30:00 +08:00
Anton Shestakov
7f5566e502 hgweb: render next pages on /graph incrementally
Previously, when user scrolled down to see the next page on /graph, all hgweb
did was re-render everything that would be visible (by simply incrementing
revcount). It was not efficient at all, and this patch makes /graph page behave
similarly to the regular /log: every new page only consists of new changesets,
no duplication, and only jsdata is based on the full set of changesets required
to build accurate graph.

This is achieved by adding "?graphtop=<node>" to the next page URL template,
effectively remembering where the graph started, and using that value to create
the new `tree` that covers the whole visible graph. That variable is then used
to produce jsdata for redrawing graph client-side.

nextentry is used for the same purpose as on /log page (to format the next page
URL), but it's not a part of the graph.
2017-12-11 15:43:56 +08:00
Anton Shestakov
820b447ff6 hgweb: split graphdata() into jsdata() and nodes()
nodes keyword passed to the template can be any iterator, but jsdata needs to
be a list because it gets JSONified.
2017-12-11 13:47:58 +08:00
Anton Shestakov
4d6d802ec6 hgweb: calculate <canvas> width and height client-side
hgweb determines and passes to templates some variables related to graph
appearance, like bg_height, canvaswidth and canvasheight. bg_height was and
still is used for graph.scale() call in graph.tmpl, and the two latter
variables were used in <canvas> element as width and height properties, and
they were set before JS code got to run. Setting these properties server-side
doesn't make a lot of sense, because a graph that has been scaled should
calculate things like width and height on its own when being rendered.

Let's move (re)sizing <canvas> to JavaScript (to Graph.render function) and
stop parsing HTML with regular expressions just to know new width and height.
That extra loop that only counts cols is required because <canvas> can't
be resized after or in the process of rendering (or it gets cleared).
Incidentally, SVG doesn't have this problem and I'm hoping to switch graph to
using it in future.

There also was truecanvasheight, but according to hg grep --all it was never
used, see f5506d2a674c.
2017-12-10 15:56:22 +08:00
Anton Shestakov
43db6ffb5a hgweb: filter graphmod.colored() output before iterating over it
Consumers in this function use output of graphmod.colored(), but only want
items with type == CHANGESET, so let's filter it early.

This is primarily just a refactoring, but it also fixes a potential small bug
with `rows = len(tree)` (this variable is used for "Rows shown" line in
raw-graph) if there are items of other types.
2017-12-08 21:50:11 +08:00
Anton Shestakov
d2fc494432 hgweb: implement json-graph
It's essentially a copy of json-log with graph-related things added (col, row,
color, edges).
2017-12-07 17:18:29 +08:00
Anton Shestakov
80d803c705 hgweb: rewrite template = A and B or C to be a proper ternary operator 2017-12-08 22:27:14 +08:00
Anton Shestakov
364b5723c5 hgweb: only include graph-related data in jsdata variable on /graph pages (BC)
Historically, client-side graph code was not only rendering the graph itself,
but it was also adding all of the changeset information to the page as well.
It meant that JavaScript code needed to construct valid HTML as a string
(although proper escaping was done server-side). It wasn't too clunky, even
though it meant that a lot of server-side things were duplicated client-side
for no good reason, but the worst thing about it was the data format it used.
It was somewhat future-proof, but not human-friendly, because it was just a
tuple: it was possible to append things to it (as was done in e.g.
4d7cfa1867b5), but you'd then have to remember the indices and reading the
resulting JS code wasn't easy, because cur[8] is not descriptive at all.

So what would need to happen for graph to have more features, such as more
changeset information or a different vertex style (branch-closing, obsolete)?
First you'd need to take some property, process it (e.g. escape and pass
through templatefilters function, and mind the encoding too), append it to
jsdata and remember its index, then go add nearly identical JavaScript code to
4 different hgweb themes that use jsdata to render HTML, and finally try and
forget how brittle it all felt. Oh yeah, and the indices go to double digits if
we add 2 more items, say phase and obsolescence, and there are more to come.
Rendering vertex in a different style would need another property (say,
character "o", "_", or "x"), except if you want to be backwards-compatible, it
would need to go after tags and bookmarks, and that just doesn't feel right.

So here I'm trying to fix both the duplication of code and the data format:

- changesets will be rendered by hgweb templates the same way as changelog and
  other such pages, so jsdata won't need any information that's not needed for
  rendering the graph itself

- jsdata will be a dict, or an Object in JS, which is a lot nicer to humans and
  is a lot more future-proof in the long run, because it doesn't use numeric
  indices

What about hgweb themes? Obviously, this will break all hgweb themes that
render graph in JavaScript, including 3rd-party custom ones. But this will also
reduce the size of client-side code and make it more uniform, so that it can be
shared across hgweb themes, further reducing its size. The next few patches
demonstrate that it's not hard to adapt a theme to these changes. And in a
later series, I'm planning to move duplicate JS code from */graph.tmpl to
mercurial.js and leave only 4 lines of code embedded in those <script>
elements, and even that would be just to allow redefining graph.vertex
function. So adapting a custom 3rd-party theme to these changes would mean:

- creating or copying graphnode.tmpl and adding it to the map file (if a theme
  doesn't already use __base__)

- modifying one line in graph.tmpl and simply removing the bigger part of
  JavaScript code from there

Making these changes in this patch and not updating every hgweb theme that uses
jsdata at the same time is a bit of a cheat to make this series more
manageable: /graph pages that use jsdata are broken by this patch, but since
there are no tests that would detect this, bisect works fine; and themes are
updated separately, in the next 4 patches of this series to ease reviewing.
2017-12-01 16:00:40 +08:00
Anton Shestakov
296ab8c247 hgweb: rename the main attribute of instabilities
Let's make "instabilities" list contain items with "instability" key as opposed
to "name" key. This way it's more explicit and more consistent with the log
command-line template.
2017-11-26 13:29:18 +08:00
Anton Shestakov
8859c1494a hgweb: use webutil.commonentry() for nodes (but not for jsdata yet) in /graph
This makes graphdata() simpler by using existing code that gets common
changeset properties for showing in hgweb. graphdata() is a nested function in
graph() that prepares entries for /graph view, but there are two different
lists of changesets prepared: "jsdata" for JavaScript-rendered graph and
"nodes" for everything else.

For "jsdata", properties "node", "user", "age" and "desc" are passed through
various template filters because we don't have these filters in JavaScript, so
the data has to be prepared server-side. But now that commonentry() is used for
producing "nodes" list (and it doesn't apply any filters), these filters need
to be added to the appropriate templates (only raw at this moment, everything
else either doesn't implement graph or uses JavaScript).

This is a bit of refactoring that will hopefully simplify future patches. The
end result is to have /graph that only renders the actual graph with nodes and
vertices in JavaScript, and the rest is done server-side. This way server-side
code can focus on showing a list of changesets, which is easy because we
already have /log, /shortlog, etc, and JavaScript code can be simplified,
making it easier to add obsolescence graph and other features.
2017-11-20 21:59:00 +08:00
Anton Shestakov
feae76d15e hgweb: check changeset's original branch in graphdata()
This piece of code checks if a changeset is the tip of its branch, but as can
be seen above in the context, "branch" was prepared for being displayed in
hgweb by making it unicode and passing it through url.escape. It's better to
use the original ctx.branch().
2017-11-20 21:47:11 +08:00
Anton Shestakov
ac68d5ffe4 context: add instabilities() method to basefilectx
This method is now used in webutils.commonentry(), which adds common data items
(commit hash, author, date, etc) for rendering changesets in hgweb. Usually,
commonentry() is given a changectx as ctx; but in views related to files (e.g.
file view, diff, annotate) it's replaced by a filectx, so the latter also needs
to have instabilities() method.
2017-11-19 13:18:54 +08:00
Anton Shestakov
bc9b6ce350 context: add obsolete() method to basefilectx
This method is now used in webutils.commonentry(), which adds common data items
(commit hash, author, date, etc) for rendering changesets in hgweb. Usually,
commonentry() is given a changectx as ctx; but in views related to files (e.g.
file view, diff, annotate) it's replaced by a filectx, so the latter also needs
to have obsolete() method.
2017-11-18 11:58:57 +08:00
David Demelier
15d6fd309d config: rename allow_push to allow-push
As part of ConfigConsolidationPlan [1], rename the option according to
the new UI guidelines [2] and add an alias for backward compatibility.

[1]: https://www.mercurial-scm.org/wiki/ConfigConsolidationPlan
[2]: https://www.mercurial-scm.org/wiki/UIGuideline#adding_new_options
2017-10-19 11:46:41 +02:00
David Demelier
d3338e9bad config: rename allowpull to allow-pull
As part of ConfigConsolidationPlan [1], rename the option according to
the new UI guidelines [2] and add an alias for backward compatibility.

[1]: https://www.mercurial-scm.org/wiki/ConfigConsolidationPlan
[2]: https://www.mercurial-scm.org/wiki/UIGuideline#adding_new_options
2017-10-19 11:43:19 +02:00
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