Commit Graph

1004 Commits

Author SHA1 Message Date
Denis Laxalde
675f39ef38 hgweb: remove unused code in annotate web command 2016-06-01 15:16:38 +02:00
timeless
a1cb3173a2 py3: convert to next() function
next(..) was introduced in py2.6 and .next() is not available in py3

https://docs.python.org/2/library/functions.html#next
2016-05-16 21:30:53 +00:00
Yuya Nishihara
2d4abff2d9 hgweb: make log streams compatible with command server
Even though it would be useless to start a web server by a command server,
it should be doable in principle. Also, we can't use sys.stdout/err directly
on Python 3 because they are unicode streams.
2014-06-28 13:13:32 +09:00
Yuya Nishihara
3f981af86b templater: separate function to create templater from map file (API)
New frommapfile() function will make it clear when template aliases will be
loaded. They should be applied to command arguments and templates in hgrc,
but not to map files. Otherwise, our stock styles and web templates
(i.e map-file templates) could be modified unintentionally.

Future patches will add "aliases" argument to __init__(), but not to
frommapfile().
2016-04-03 23:26:48 +09:00
timeless
109fcbc79e pycompat: switch to util.urlreq/util.urlerr for py3 compat 2016-04-06 23:22:12 +00:00
timeless
f77cdcd3b1 pycompat: switch to util.stringio for py3 compat 2016-04-10 20:55:37 +00:00
Anton Shestakov
9f3a77930a hgweb: generate last change date for an empty atom-bookmarks feed (issue5022)
RFC 4287 states that atom feeds must have an <updated> element, so let's add
one even when repo doesn't have a single bookmark.
2016-03-31 15:37:21 +08:00
Anton Shestakov
d9e41fcffc hgweb: sort bookmarks in revlog order of their nodes
Changes, branches and tags are already in revlog order on /summary, /branches
and /tags, let's now make bookmarks be sorted by the same principle. It's more
helpful to show more "recent" bookmarks on top. This will affect /bookmarks
page in all styles, including atom, rss and raw, and also /summary page.

Bookmarks are sorted using a (revision number, bookmark name) tuple.
2016-03-31 15:22:06 +08:00
Anton Shestakov
0741a98a71 hgweb: sort bookmarks early
Let's do the same thing that /tags page does. It gets sorted tags and then if
it needs the latest only, it just slices the first item from the list. Since
it's a slice and not a min(), it doesn't throw an exception if the list is
empty. This fixes HTTP 500 error from issue5022.
2016-03-31 14:23:27 +08:00
Anton Shestakov
e81bf97ae9 hgweb: add parents to json-log (issue5074)
Entries prepared in webutil.changelistentry() skip showing parents in the
trivial case when there's only one parent and it's the previous revision. This
doesn't work well for the json-log template, which is supposed to just dump raw
data in an easy-to-parse format, so let's provide all parents as another
keyword: allparents.

Using a lambda function here means that the performance of templates that don't
use allparents won't be affected (see 88bd6697bfad).
2016-03-31 18:09:09 +08:00
Augie Fackler
b3f8347d29 http: support sending hgargs via POST body instead of in GET or headers
narrowhg (for its narrow spec) and remotefilelog (for its large batch
requests) would like to be able to make requests with argument sets so
absurdly large that they blow out total request size limit on some
http servers. As a workaround, support stuffing args at the start
of the POST body.

We will probably want to leave this behavior off by default in servers
forever, because it makes the old "POSTs are only for writes"
assumption wrong, which might break some of the simpler authentication
configurations.
2016-03-11 11:37:00 -05:00
Yuya Nishihara
2e33bbee20 templatefilters: make json filter be byte-transparent (BC) (issue4926)
This is necessary to preserve filename encoding over JSON. Instead, this
patch inserts "|utf8" where non-ascii local-encoding texts can be passed
to "|json".

See also the commit that introduced "utf8" filter.
2015-12-27 17:59:57 +09:00
Yuya Nishihara
bd35a9a988 hgweb: add option to convert encoding of graphdata()
Because future patches will change "|json" filter to handle input bytes
transparently, i.e. use UTF-8b encoding, "{jsdata}" must keep data in UTF-8
bytes, whereas "{nodes}" are text.

This patch inserts encodestr() where localstr is likely to survive.
2016-01-04 23:05:09 +09:00
Yuya Nishihara
0633dff1e2 hgweb: remove unused argument from graphdata() factory
As graphdata() is wrapped by lambda, there's no reason to pass unused
arguments to it.
2016-01-04 22:55:05 +09:00
Gregory Szorc
a3e59a30b6 hgweb: support rendering a sub-topic
If the requested topic contains a "." we assume a sub-topic is
requested and display it.
2015-12-30 17:15:10 -07:00
Gregory Szorc
a320e743a7 hgweb: support rendering sub-topic indexes
If the requested topic name is the name of a sub-topic, we now render
an index of topics within that sub-topic.
2015-12-30 17:34:51 -07:00
Anton Shestakov
2e206a44b7 hgweb: move entry-preparing code from webcommands to webutils.commonentry()
The new function is used to fill basic information about a ctx, such as
revision number and hash, author, commit message, etc. Before, every webcommand
used to get this basic information on its own using some boilerplate code, and
some things in some places just weren't available.
2015-11-13 14:35:36 +08:00
Yuya Nishihara
9ed442849f hgweb: load server settings from --web-conf (issue4699)
It copies the ui before loading the webconf and passes the copied ui only
to the service. This way, the hgwebdir app can reload configs cleanly.
2015-10-31 22:50:03 +09:00
Yuya Nishihara
5cfcdd71d7 hgweb: make sure command options are set to all ui objects
Before this patch, it was unclear why the httpservice object could read the
server options (e.g. --port) from 'ui'. It just worked because repo.ui is ui.
2015-11-21 13:28:12 +09:00
Yuya Nishihara
8d4fdbd827 hgweb: eliminate duck-typing to select hgweb or hgwebdir by command option
Since createservice() was moved to hgweb and hgweb imports both hgweb_mod and
hgwebdir_mod, we no longer have to force hgweb() function to select one of
them by the type of 'o' variable. Let's be explicit!

This patch does not change hgweb() function because it is the interface of
existing WSGI and CGI scripts.
2015-10-31 22:26:50 +09:00
Anton Shestakov
4f46ce6f31 webcommands: test that fctx is not None in filediff()
A block of code above this one already says "if fctx is not None", and it's
also what this code actually intends to check, so let's be specific as PEP-8
recommends.
2015-11-28 17:06:29 +08:00
Anton Shestakov
7359ceac6b webcommands: stop using ersatz if-else ternary operator for rename variable
c0ebd60607e9 didn't remove it, let's do it now.

Placing the added lines into the already existing "if fctx is not None" block
also makes webcommands.comparison() look a bit more like
webcommands.filediff(), which eases possible future refactoring. And fctx is
not None only when path in ctx, so logically it's equivalent.
2015-11-28 16:46:31 +08:00
Anton Shestakov
9f284e62ca webcommands: get correct parents when comparing a removed file (issue4962)
When comparing a file that was removed at the current revision, parents used to
show grandparents instead, due to how fctx was "shifted" from the current
revision to its p1. Let's not do that.

The fix is pretty much copied from webcommands.filediff().
2015-11-28 16:02:22 +08:00
Yuya Nishihara
c64bc024c8 hgweb: extract factory function of httpservice object
The next patch will merge the cmdutil.service() calls of both commandserver
and hgweb. Before doing it, this patch wipes out the code specific to hgweb
from commands.serve().
2015-10-31 22:15:16 +09:00
Yuya Nishihara
4fb8995ece hgweb: move httpservice object from commands module
This avoids the deep import of hgweb.server at the commands module.
2015-10-31 21:57:45 +09:00
Anton Shestakov
5c74a8a582 paper: show current revision on file log page
Most of the pages in paper (and coal) style show the current revision and its
branch, tags and bookmarks. Let's also show all this on file log page.
2015-11-13 18:31:58 +08:00
Yuya Nishihara
47690f822c hgweb: use absolute_import 2015-10-31 22:07:40 +09:00
Yuya Nishihara
6f91677786 hgweb: import wsgicgi at top level
There should be no practical reason to delay the import of wsgicgi.
2015-11-01 15:09:35 +09:00
Yuya Nishihara
3a2ca88d5a hgweb: import BaseHTTPServer as module at top level
This will avoid future warning spotted by the import checker.
2015-11-01 15:07:08 +09:00
Yuya Nishihara
e142543972 hgweb: do not import hgweb_mod.hgweb and .makebreadcrumb as symbol
It will be enforced by the import checker.
2015-11-01 14:23:23 +09:00
Anton Shestakov
53412195f4 webutil: make _siblings into an object with __iter__ and __len__
_siblings is a helper that is used for displaying changeset parents and
children in hgweb. Before, when it was a simple generator, it couldn't tell its
length without being consumed, and that required a special case when preparing
data for changeset template (see 3468fd599ef4).

Let's make it into a class (similar to templatekw._hybrid) that allows len(...)
without side-effects.
2015-11-10 17:22:40 +08:00
Yuya Nishihara
8110fbc21f hgweb: unify import style of error classes
It will be enforced by the import checker.
2015-11-01 14:43:25 +09:00
Yuya Nishihara
01e2649d34 hgweb: do not import templatefilters.revescape and websub as symbol
It will be enforced by the import checker.
2015-11-01 14:00:14 +09:00
Yuya Nishihara
ad55f13658 hgweb: alias ui module as uimod
It will be enforced by the import checker.
2015-11-01 13:58:32 +09:00
Anton Shestakov
90da27730e hgweb: compute changeset parents and children for log pages lazily
Log pages, i.e. changelog, filelog and search results page computed children
and parents for each changeset shown, because spartan hgweb style shows this
info. Turns out, computing all this is heavy and also unnecessary for log pages
in all other hgweb styles.

Luckily, templates allow an easy way to do computations on demand: just pass
the heavy part of code as a callable and it will be only called when needed.

Here are some benchmarks on the mercurial repository (best of 3):

time wget http://127.0.0.1:8021/

before: 0m0.050s
after:  0m0.040s

time wget http://127.0.0.1:8021/?revcount=960

before: 0m1.164s
after:  0m0.389s

time wget http://127.0.0.1:8021/log/tip/mercurial/commands.py

before: 0m0.047s
after:  0m0.042s

time wget http://127.0.0.1:8021/log/tip/mercurial/commands.py?revcount=960

before: 0m0.830s
after:  0m0.434s
2015-11-10 23:02:59 +08:00
Siddharth Agarwal
6b30464363 hgweb.server: drop support for Python 2.4 2015-10-24 16:23:42 -07:00
Anton Shestakov
9b60cbd85f hgweb: replace some str.split() calls by str.partition() or str.rpartition()
Since Python 2.5 str has new methods: partition and rpartition. They are more
specialized than the usual split and rsplit, and they sometimes convey the
intent of code better and also are a bit faster (faster than split/rsplit with
maxsplit specified). Let's use them in appropriate places for a small speedup.

Example performance (partition):

$ python -m timeit 'assert "apple|orange|banana".split("|")[0] == "apple"'
1000000 loops, best of 3: 0.376 usec per loop

$ python -m timeit 'assert "apple|orange|banana".split("|", 1)[0] == "apple"'
1000000 loops, best of 3: 0.327 usec per loop

$ python -m timeit 'assert "apple|orange|banana".partition("|")[0] == "apple"'
1000000 loops, best of 3: 0.214 usec per loop

Example performance (rpartition):

$ python -m timeit 'assert "apple|orange|banana".rsplit("|")[-1] == "banana"'
1000000 loops, best of 3: 0.372 usec per loop

$ python -m timeit 'assert "apple|orange|banana".rsplit("|", 1)[-1] == "banana"'
1000000 loops, best of 3: 0.332 usec per loop

$ python -m timeit 'assert "apple|orange|banana".rpartition("|")[-1] == "banana"'
1000000 loops, best of 3: 0.219 usec per loop
2015-11-02 23:37:49 +08:00
Mads Kiilerich
09567db49a spelling: trivial spell checking 2015-10-17 00:58:46 +02:00
Pierre-Yves David
30913031d4 error: get Abort from 'error' instead of 'util'
The home of 'Abort' is 'error' not 'util' however, a lot of code seems to be
confused about that and gives all the credit to 'util' instead of the
hardworking 'error'. In a spirit of equity, we break the cycle of injustice and
give back to 'error' the respect it deserves. And screw that 'util' poser.

For great justice.
2015-10-08 12:55:45 -07:00
Matt Mackall
5e1b4ad958 urls: bulk-change primary website URLs 2015-09-30 15:43:49 -05:00
Yuya Nishihara
d7b6a95763 hgweb: overwrite cwd to resolve file patterns relative to repo (issue4568)
It's useless to handle file patterns as relative to the cwd of the server
process. The only sensible way in hgweb is to resolve paths relative to the
repository root.

It seems dirstate.getcwd() isn't used to get a real file path, so this patch
won't cause problem.
2015-09-20 20:11:31 +09:00
Gregory Szorc
4e3c6d9b7a hgweb: consume generator inside context manager (issue4756)
If code inside a context manager returns a generator, the context
manager exits before the generator is iterated.

hgweb was using a context manager to control thread safe access to a
localrepository instance. But it was returning a generator, so there was
a race condition between a previous request streaming a response to the
client and a new request obtaining the released but in use repository.
By iterating the generator inside the context manager, we ensure we
don't release the repo instance until after the response has finished.

With this change, hgweb finally appears to have full localrepository
isolation between threads. I can no longer reproduce the 2 exceptions
reported in issue4756.

test-hgweb-non-interactive.t has been modified to consume the output
of calling into a WSGI application. Without this, execution of the WSGI
application stalls because of the added yield statement.
2015-09-12 12:16:39 -07:00
Gregory Szorc
216aba88f8 hg: always create new localrepository instance
cachedlocalrepo.copy() didn't actually create new localrepository
instances. This meant that the new thread isolation code in hgweb wasn't
actually using separate localrepository instances, even though it was
properly using separate cachedlocalrepo instances.

Because the behavior of the API changed, the single caller in hgweb had
to be refactored to always call _webifyrepo() or it may not have used
the proper filter.

I confirmed via print() debugging that id(repo) is in fact different on
each thread. This was not the case before.

For reasons I can't yet explain, this does not fix issue4756. I suspect
there is shared cache somewhere that isn't thread safe.
2015-09-12 11:31:56 -07:00
Matt Mackall
a8c75dcbec hgweb: drop unused import 2015-09-11 12:48:09 -07:00
Gregory Szorc
39247b40e9 hgweb: use separate repo instances per thread
Before this change, multiple threads/requests could share a
localrepository instance. This meant that all of localrepository needed
to be thread safe. Many bugs have been reported telling us that
localrepository isn't actually thread safe.

While making localrepository thread safe is a noble cause, it is a lot
of work. And there is little gain from doing so. Due to Python's GIL,
only 1 thread may be processing Python code at a time. The benefits
to multi-threaded servers are marginal.

Thread safety would be a lot of work for little gain. So, we're not
going to even attempt it.

This patch establishes a pool of repos in hgweb. When a request arrives,
we obtain the most recently used repository from the pool or create a
new one if none is available. When the request has finished, we put that
repo back in the pool.

We start with a pool size of 1. For servers using a single thread, the
pool will only ever be of size 1. For multi-threaded servers, the pool
size will grow to the max number of simultaneous requests the server
processes.

No logic for pruning the pool has been implemented. We assume server
operators either limit the number of threads to something they can
handle or restart the Mercurial process after a certain amount of
requests or time has passed.
2015-08-22 18:43:24 -07:00
Gregory Szorc
83818c1fca hg: establish a cache for localrepository instances
hgweb contained code for determining whether a cached localrepository
instance was up to date. This code was way too low-level to be in
hgweb.

This functionality has been moved to a new "cachedlocalrepo" class
in hg.py. The code has been changed slightly to facilitate use
inside a class. hgweb has been refactored to use the new API.

As part of this refactor, hgweb.repo no longer exists! We're very close
to using a distinct repo instance per thread.

The new cache records state when it is created. This intelligence
prevents an extra localrepository from being created on the first
hgweb request. This is why some redundant output from test-extension.t
has gone away.
2015-08-22 18:54:34 -07:00
Gregory Szorc
2aa478bfd2 hgweb: create function to perform actions on new repo
We perform some common tasks when a new repo instance is obtained. In
preparation for changing how we obtain repo instances, factor this
functionality into a standalone function.
2015-08-22 18:15:42 -07:00
Gregory Szorc
e03cfea13e hgweb: remove proxy to hgweb instance
We were temporarily routing attributes until all request-specific
attributes from hgweb were moved to requestcontext. We have finally
reached that juncture and we can remove the proxy.

At this point, only the repo instance is prone to race conditions
between threads. This will be dealt with shortly.
2015-08-22 17:50:28 -07:00
Gregory Szorc
fc3513ba2d hgweb: assign ctype to requestcontext
The very existence of ctype is a bit hacky. But we roll with it.

Before this patch, there was possibly a race condition between 2
threads handling file requests: 1 thread could set the ctype and
another serving a different file would read and use that potentially
wrong ctype.
2015-08-22 17:08:37 -07:00
Gregory Szorc
e74f9acd5d hgweb: add reponame to requestcontext
We have to use object.__setattr__ until the app proxy is gone.
2015-08-22 17:04:24 -07:00
Gregory Szorc
c3d67d78b9 hgweb: don't access self.repo during request processing
We want all repository accesses to go through requestcontext.repo
so the request is isolated from the application.
2015-08-22 16:54:52 -07:00
Gregory Szorc
29e7feecf4 hgweb: extract _getview to own function
While we're refactoring code, we might as well remove a method that
doesn't need to be a method.
2015-08-22 16:44:36 -07:00
Gregory Szorc
6e97351675 hgweb: regenerate web substitutions when repo is refreshed
Previously, changes to the configuration would not be picked up by a
running server. That feels like a bug. Regenerate the web substitutions
table when the repository changes.
2015-08-22 16:41:02 -07:00
Matt Mackall
9389191839 hgweb: drop unused import 2015-09-09 12:40:57 -07:00
timeless@mozdev.org
096175f16e hgweb.server: fix _httprequesthandlerssl help text 2015-09-08 15:32:20 -04:00
timeless@mozdev.org
9059b84547 hgweb: remove ErrorResponse.message
BaseException.message is deprecated:
https://www.python.org/dev/peps/pep-0352/#retracted-ideas
2015-09-08 14:56:29 -04:00
Gregory Szorc
123302288c hgweb: move templater instantiation to requestcontext
This code needs to access a lot of config options. All our config
lookups have moved to requestcontext. It makes sense to move this
function there.
2015-08-22 16:38:51 -07:00
Matt Mackall
78dbeac869 merge with stable 2015-09-03 18:32:17 -05:00
Matt Mackall
5a89fbd24f hgweb: use latest mtime for caching tag (issue4814)
Previously, we were using the last mtime we saw when reporting the
HTTP cache etag. When we added bookmarks to the end of the list of
files checked, unchanged or missing bookmarks would keep the client
cache from being invalidated.
2015-09-03 12:19:43 -05:00
Matt Mackall
12d69c8e7a hgweb: fix trust of templates path (BC)
Long ago we disabled trust of the templates path with a comment
describing the (insecure) behavior before the change. At some later
refactor, the code was apparently changed back to match the comment,
unaware that the intent of the comment was to describe the behavior to
avoid.

This change disables the trust and updates the comment to explicitly
say not only what the old problem was, but also that it was in fact a
problem and the action taken to prevent it.

Impact: prior to this change, if you had a UNIX-based hgweb server
where users can write hgrc files, those users could potentially read
any file readable by the web server.

This is marked as a backwards compatibility issue because people may
have configured templates without proper trust settings. Issue spotted
by Greg Szorc.
2015-09-01 16:08:07 -05:00
Gregory Szorc
8201e17909 hgweb: create websubtable on requestcontext 2015-08-22 16:39:29 -07:00
Gregory Szorc
6d1194795f hgweb: move templatepath to requestcontext
This does change behavior in that the templatepath could change during
the lifetime of the server. But everything else can change, I don't see
why template paths can't.
2015-08-22 16:28:22 -07:00
Gregory Szorc
4b659c309d hgweb: extract web substitutions table generation to own function
It doesn't use any state in hgweb except for the repo instance.
Move it to a standalone function.
2015-08-22 15:40:33 -07:00
Gregory Szorc
fe3df2ac82 hgweb: remove hgweb.configbool
It is redundant with requestcontext.configbool.
2015-08-22 15:32:16 -07:00
Gregory Szorc
1cdb989214 hgweb: move additional state setting outside of refresh
We want refresh() to only be about refreshing repository
instances. This state doesn't belong in requestcontext
because it is shared across multiple threads.
2015-08-22 15:30:39 -07:00
Gregory Szorc
b629be8ff2 hgweb: initialize repostate to None
The initial value is irrelevant since refresh() compares it to
a tuple of tuples of file mtime and size. None != tuple and
None is a better default value than a tuple containing irrelevant
values.
2015-08-22 15:21:45 -07:00
Matt Mackall
58b892a1cb merge with stable 2015-09-01 17:09:00 -05:00
Gregory Szorc
34c68673a7 hgweb: move archive related attributes to requestcontext
As part of this, "archive_specs" was renamed to "archivespecs" to align
with naming conventions.

"archive_specs" didn't technically need to be moved from hgweb. But it
seemed to make sense to have all the archive code in the same class.

As part of this, hgweb.configlist is no longer used, so it was deleted.
2015-08-22 15:12:52 -07:00
Gregory Szorc
820065a592 hgweb: move some config options to requestcontext
Various config options from the repository were stored on the
hgweb instance. While unlikely, there could be race conditions between
a new request updating these values and an in-flight request seeing both
old and new values, leading to weird results.

We move some of options/attributes from hgweb to requestcontext.

As part of this, we establish config* helpers on requestcontext. As
part of the move, we changed int() casts to configint() calls. The
int() usage likely predates the existence of configint().

We also removed config option updating from once every refresh to every
request. I don't believe obtaining config options is expensive enough to
warrant only doing when the repository has changed.

The excessive use of object.__setattr__ is unfortunate. But it will
eventually disappear once the proxy is no longer necessary.
2015-08-22 15:02:41 -07:00
Gregory Szorc
bdb55cdf30 hgweb: establish class for holding per request context
Currently, hgweb applications have many instance variables holding
mutated state. This is somewhat problematic because multiple threads
may race accessing or changing this state.

This patch starts a series that will add more thread safety to
hgweb applications. It will do this by moving mutated state out
of hgweb and into per-request instances of the newly established
"requestcontext" class.

Our new class currently behaves like a proxy to hgweb instances. This
should change once all state is captured in it instead of hgweb. The
effectiveness of this proxy is demonstrated by passing instances of
it - not hgweb instances/self - to various functions.
2015-08-22 14:59:36 -07:00
Gregory Szorc
a8f65a043f hgweb: don't make request optional
The "request" argument has been optional in this code since
it was introduced in bb95879961db in 2009. There are no consumers that
don't pass this argument. So don't make it an optional argument.
2015-08-22 14:22:40 -07:00
Gregory Szorc
962145920a hgweb: add some documentation
It took longer than I wanted to grok how the various parts of hgweb
worked. So I added some class and method documentation to help whoever
hacks on this next.
2015-08-22 13:58:59 -07:00
Anton Shestakov
df9bda4834 hgweb: limit branches shown on summary page to 10
Tags and bookmarks on summary page are already limited to 10, let's limit
branches as well.

Each of the blocks (tags, bookmarks, branches) currently has a link to the full
list.
2015-09-01 23:35:06 +08:00
Anton Shestakov
7e5ab1949a hgweb: use webutil.branchentries for branches on summary page
This allows showing correct status for each branch, which was missing on
/summary. Usually that means that closed branches get the same css class
(resulting in e.g. different color/shade) as they do on /branches page.

The sorting of the branches on summary page also changes and is now the same as
on /branches page: closed branches are now at the end of the list.
2015-09-01 23:29:30 +08:00
Anton Shestakov
3fecbc5edf hgweb: move branchentries code from webcommands to webutil 2015-09-01 22:28:45 +08:00
Gregory Szorc
6e680ddd62 hgweb: make refresh interval configurable
hgwebdir refreshes the set of known repositories periodically. This
is necessary because refreshing on every request could add significant
request latency.

More than once I've found myself wanting to tweak this interval at
Mozilla. I've also wanted the ability to always refresh (often when
writing tests for our replication setup).

This patch makes the refresh interval configurable. Negative values
indicate to always refresh. The default is left unchanged.
2015-08-22 22:59:51 -07:00
Anton Shestakov
3c48ed2bcf style: adjust whitespaces in webutil.py
Turns out, all this came from the single 3ff83729b63f.
2015-08-11 13:19:42 +08:00
Anton Shestakov
939c576f07 templates: introduce revescape filter for escaping symbolic revisions
There needs to be a way to escape symbolic revisions containing forward
slashes, but urlescape filter doesn't escape slashes at all (in fact, it is
used in places where forward slashes must be preserved).

The filter considers @ to be safe just for bookmarks like @ and @default to
look good in urls.
2015-07-12 16:47:56 +08:00
Anton Shestakov
59f182075a hgweb: allow symbolic revisions with forward slashes in urls
It's possible to have a branch/tag/bookmark with all kinds of special
characters, such as {}/\!?. While not very conveniently, symbolic revisions
with such characters work from command line if user correctly quotes the
characters. These characters also work in hgweb, when they are properly
encoded, with one exception: '/' (forward slash, urlencoded as '%2F'), which
was getting decoded before hgweb could parse it as a part of PATH_INFO.
Because of that, hgweb was seeing it as any other forward slash, that is, as
just another url parts separator.

For example, if user wanted to see the content of dir/file at bookmark
'feature/eggs', url could be: '/file/feature%2Feggs/dir/file'. But hgweb tried
to find a revision 'feature' and get contents of 'eggs/dir/file'.

To fix this, let's assume forward slashes are doubly-urlencoded (%252F), so
CGI/WSGI server decodes it into %2F. Then we can decode %2F in the revision
part of the url into an actual '/' character.

Making hgweb produce such urls will be done in the next 2 patches.
2015-07-12 16:06:57 +08:00
Pierre-Yves David
d9fec5b798 hgweb: also monitor change to bookmarks
This makes changes to bookmarks visible to hgweb through the official
way. There is no change to tests because there is currently another
hack in place to ensure the same behavior.
2015-06-30 23:55:22 -07:00
Pierre-Yves David
4a96783202 hgweb: also refresh the repo on changes to the obsstore
Before this change, hgweb could miss update to the obsolescence markers store
if that was the only change between two commands.
2015-07-01 01:02:27 -07:00
Pierre-Yves David
8a846f512f hgweb: use an extensible list of files to check for refresh
The refresh feature was explicitly testing if '00changelog.i' and 'phaseroots'
changed. This is overlooking other important information like bookmarks and
obsstore (bookmark have their own hack to work around it).

We move to a more extensible system with a list of files of interest
that will be used to build the repo state. The system should probably
move into a more central place so that the command server and other
systems are able to use it. Extension writers will also be able to add
entries to ensure that changes to extension data are properly detected.

Also the current key (mtime, size) is notably weak for bookmarks and phases
whose files can easily change content without effect on their size.

Still, this patch seems like a valuable minimal first step.
2015-07-01 00:18:50 -07:00
Pierre-Yves David
a6ec11b75b hgweb: drop the default argument for get_stat
This default argument is used twice and is making things confusing. Making it
explicit helps to clarify coming changesets
2015-07-03 10:07:51 -07:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Anton Shestakov
90c74a4812 hgweb: provide symrev (symbolic revision) property to the templates
One of the features of hgweb is that current position in repo history is
remembered between separate requests. That is, links from /rev/<node_hash> lead
to /file/<node_hash> or /log/<node_hash>, so it's easy to dig deep into the
history. However, such links could only use node hashes and local revision
numbers, so while staying at one exact revision is easy, staying on top of the
changes is not, because hashes presumably can't change (local revision numbers
can, but probably not in a way you'd find useful for navigating).

So while you could use 'tip' or 'default' in a url, links on that page would be
permanent. This is not always desired (think /rev/tip or /graph/stable or
/log/@) and is sometimes just confusing (i.e. /log/<not the tip hash>, when
recent history is not displayed). And if user changed url deliberately to say
default instead of <some node hash>, the page ignores that fact and uses node
hash in its links, which means that navigation is, in a way, broken.

This new property, symrev, is used for storing current revision the way it was
specified, so then templates can use it in links and thus "not dereference" the
symbolic revision. It is an additional way to produce links, so not every link
needs to drop {node|short} in favor of {symrev}, many will still use node hash
(log and filelog entries, annotate lines, etc).

Some pages (e.g. summary, tags) always use the tip changeset for their context,
in such cases symrev is set to 'tip'. This is needed in case the pages want to
provide archive links.

highlight extension needs to be updated, since _filerevision now takes an
additional positional argument (signature "web, req, tmpl" is used by most of
webcommands.py functions).

More references to symbolic revisions and related gripes: issue2296, issue2826,
issue3594, issue3634.
2015-06-16 02:07:25 +08:00
Pierre-Yves David
ff7d1b0e92 hgweb: add some in-code documentation for 'web.view'
This documentation was mostly intended for the user helps. However given the
lack of request for such feature, we should keep it un-documented. We stick the
help text in the code as it could still be useful to fellow contributors.
2013-02-07 00:32:26 +00:00
Pierre-Yves David
2e04e420cc hgewb: disable progress when serving (issue4582)
Before this patch, progress bar could be displayed when serving, creating
hypothetical problems.
2015-06-07 17:14:17 -07:00
Matt Mackall
182254fe57 merge with stable 2015-06-04 17:51:19 -05:00
Matt Harbison
a1a73ad1ab hgwebdir: don't allow the hidden parent of a subrepo to show as a directory
Previously, if a subrepo parent had 'web.hidden=True' set, neither the parent
nor child had a repository entry.  However, the directory entry for the parent
would be listed (it wouldn't have the fancy 'web.name' if configured), and that
link went to the repo's summary page, effectively making it not hidden.

This simply disables the directory processing if a valid repository is present.
Whether or not the subrepo should be hidden is debatable, but this leaves that
behavior unchanged (i.e. it stays hidden).
2015-06-01 18:06:20 -04:00
Matt Harbison
7ed6e6b3e0 hgwebdir: avoid redundant repo and directory entries when 'web.name' is set
Previously, when 'web.name' was set on a subrepo parent and 'web.collapse=True',
the parent repo would show in the list with the configured 'web.name', and a
directory with the parent repo's filesystem name (with a trailing slash) would
also appear.  The subrepo(s) would unexpectedly be excluded from the list of
repositories.  Clicking the directory entry would go right to the repo page.

Now both the parent and the subrepos show up, without the additional directory
entry.

The configured hgweb paths used '**' for finding the repos in this scenario.


A couple of notes about the tests:

- The area where the subrepo was added has a comment that it tests subrepos,
  though none previously existed there.  One now does.

- The 'web.descend' option is required for collapse to work.  I'm not sure what
  the previous expectations were for the test.  Nothing changed with it set,
  prior to adding the code in this patch.  It is however required for this test.

- The only output changes are for the hyperlinks, obviously because of the
  'web.name' parameter.

- Without this code change, there would be an additional diff:

    --- /usr/local/mercurial/tests/test-hgwebdir.t
    +++ /usr/local/mercurial/tests/test-hgwebdir.t.err
    @@ -951,7 +951,7 @@
       /rcoll/notrepo/e/
       /rcoll/notrepo/e/e2/
       /rcoll/notrepo/f/
    -  /rcoll/notrepo/f/f2/
    +  /rcoll/notrepo/f/


     Test repositories inside intermediate directories

I'm not sure why the fancy name doesn't come out, but it is enough to
demonstrate that the parent is not listed redundantly, and the subrepo isn't
skipped.
2015-06-01 14:42:55 -04:00
Matt Mackall
a5b83eed23 merge with stable 2015-06-02 13:24:39 -05:00
Anton Shestakov
aeea04db07 hgweb: remove an extra call to nodebranchnodefault() in changesetentry()
showbranch variable already contains the result of nodebranchnodefault(ctx), so
it can be reused.
2015-05-26 22:58:30 +08:00
Yuya Nishihara
0aa2a7df4d revset: move validation of incomplete parsing to parse() function
revset.parse() should be responsible for all parsing errors. Perhaps it wasn't
because 'revset.parse' was not a real function when the validation code was
added at ac01134d0a40.
2015-04-26 19:42:47 +09:00
Wagner Bruna
7e4e6c79af webcommands: fix description of manifest default behavior 2015-04-27 19:13:55 -03:00
Wagner Bruna
c39301bfdc webcommands: fix typo in changelog documentation 2015-04-27 19:09:54 -03:00
FUJIWARA Katsunori
6d60352ea0 i18n: extract doc string of each web commands as translatable one
Before this patch, doc string of each web commands isn't extracted as
translatable one, even though web commands are listed up in "hg help
hgweb".

This patch adds "mercurial/hgweb/webcommands.py" on to arguments of
"i18n/hggettext". "i18nfunctions" added into "webcommands.py" is used
by "i18n/hggettext" to get the list of functions having translatable
doc string.
2015-04-28 00:38:16 +09:00
Gregory Szorc
07417ade7a hgweb: expose raw line numbers to templates
Surpringly, the templates didn't receive an unmodified version of the
line numbers. Expose it to make implementing the JSON templates easier.

In theory, we could post-process an existing template variable. But
extra string manipulation seems quite wasteful, especially on items that
could occur hundreds or even thousands of times in output.
2015-04-10 22:34:12 -04:00
Gregory Szorc
35a9613552 hgweb: add phase to {changeset} template
It's pretty surprising phase wasn't part of this template call already.
We now expose {phase} to the {changeset} template and we expose this
data to JSON.

This brings JSON output in line with the output from `hg log -Tjson`.
The lone exception is hweb doesn't print the numeric rev. As has been
stated previously, I don't believe hgweb should be exposing these
unstable identifiers. (We can add them later if we really want them.)
There is still work to bring hgweb in parity with --verbose and
--debug output from the CLI.
2015-03-31 22:29:12 -07:00
Augie Fackler
a5b17bd9d1 cleanup: use __builtins__.any instead of util.any
any() is available in all Python versions we support now.
2015-05-16 14:30:07 -04:00
Anton Shestakov
4451d363dd paper: show branch/tags/bookmarks when blaming (issue3559) 2015-05-15 20:04:24 +08:00
Anton Shestakov
fba3cc6630 paper: show branch/tags/bookmarks when comparing (issue3559) 2015-05-15 20:03:42 +08:00
Anton Shestakov
820c8ef46a paper: show branch/tags/bookmarks when diffing (issue3559) 2015-05-15 20:02:41 +08:00
Anton Shestakov
c6733e1dd2 paper: show branch/tags/bookmarks when viewing (issue3559) 2015-05-15 20:00:47 +08:00
Anton Shestakov
1b782eae1b paper: show branch/tags/bookmarks when browsing (issue3559)
Browse (or manifest) action allows browsing the directory structure at some
specified revision. In gitweb and monoblue styles, the revision header already
has branch/tag/bookmark information for the revision, but in paper style this
header was only showing tags. This patch adds branches and bookmarks.

Branch name needs to be obtained in this special way to be consistent with
regular changeset page, where in paper style default branch is never shown.
2015-05-15 18:17:36 +08:00
Matt Mackall
25a97bf622 hgweb: use try/except/finally 2015-05-15 09:56:27 -05:00
Matt Harbison
b55c45c462 hgweb: replace 'ctx._repo' with 'ctx.repo()' 2015-03-12 23:15:06 -04:00
Jordi Gutiérrez Hermoso
8eb132f5ea style: kill ersatz if-else ternary operators
Although Python supports `X = Y if COND else Z`, this was only
introduced in Python 2.5. Since we have to support Python 2.4, it was
a very common thing to write instead `X = COND and Y or Z`, which is a
bit obscure at a glance. It requires some intricate knowledge of
Python to understand how to parse these one-liners.

We change instead all of these one-liners to 4-liners. This was
executed with the following perlism:

    find -name "*.py" -exec perl -pi -e 's,(\s*)([\.\w]+) = \(?(\S+)\s+and\s+(\S*)\)?\s+or\s+(\S*)$,$1if $3:\n$1    $2 = $4\n$1else:\n$1    $2 = $5,' {} \;

I tweaked the following cases from the automatic Perl output:

    prev = (parents and parents[0]) or nullid
    port = (use_ssl and 443 or 80)
    cwd = (pats and repo.getcwd()) or ''
    rename = fctx and webutil.renamelink(fctx) or []
    ctx = fctx and fctx or ctx
    self.base = (mapfile and os.path.dirname(mapfile)) or ''

I also added some newlines wherever they seemd appropriate for readability

There are probably a few ersatz ternary operators still in the code
somewhere, lurking away from the power of a simple regex.
2015-03-13 17:00:06 -04:00
Gregory Szorc
3a90558059 hgweb: extract changeset template mapping generation to own function
Similar in spirit to df435ff00d29, I want to write an extension to
make available extra template keywords so hgweb templates can include
extra data.

To do this today requires monkeypatching the templater, which I think is
the wrong place to perform this modification.

This patch extracts the creation of the templater arguments to a
standalone function - one that can be monkeypatched by extensions.

I would very much like for extensions to be able to inject extra
templater parameters into *any* template. However, I'm not sure the best
way to facilitate this, as hgweb commands invoke the templater before
returning and we want the extensions to have access to rich data
structures like the context instances. We need cooperation inside hgweb
command functions. The use case screams for something like internal-only
"hooks." This is exactly what my (rejected) "events" patch series
provided. Perhaps that feature should be reconsidered...
2015-03-02 15:07:18 -08:00
Anton Shestakov
1b9c15214b hgweb: use introrev() for finding parents (issue4506)
The issue is titled "filtered revision 'XXX' (not in 'served' subset)" and that
is the error message you sometimes get when trying to look at a file (/file or
/annotate) in hgweb. For example:

http://hg.intevation.org/mercurial/crew/file/8414f8487b33/mercurial/cmdutil.py

This happens when a parent revision for a file is hidden, thus it is
not 'served' and isn't accessible in hgweb by default. When hgweb tries to
access such changeset, it produces the error and HTTP status code 404.

Another detail is that the parents() function, that is used in multiple places
in hgweb, sometimes returned changesets that were obsoleted by the current
changeset for the file. For example, when using rebase with evolve and rebasing
a divergent changeset that introduces a file on top of current branch. Or
grafting a change and making the new grafted changeset obsolete the source
(shown in the test case). The result is the same - the obsoleted changeset was
mistakingly returned from parents(), even though it's not a parent and the only
link to the new changeset is an obsoletion marker (and rebase/graft metadata?
not sure it matters).

The problem is fixed by using introrev() instead of linkrev() for finding
parents. This prevents parents() function from returning unrelated obsolete
changesets.

The test case prepares a separate repo because (afaict) all other test cases
never reuse file names, so there are no files that were changed in multiple
changesets. So no previously available files have obsolete changesets in their
history.
2015-02-19 19:32:06 +08:00
Yuya Nishihara
25fac1a15b revset: make match function initiate query from full set by default
This change is intended to avoid exposing the implementation detail to
callers. I'm going to extend fullreposet to support "null" revision, so
these mfunc calls will have to use fullreposet() instead of spanset().
2015-02-02 22:21:07 +09:00
Gregory Szorc
19908c11f2 webcommands: document "graph" web command 2015-02-06 22:25:40 -08:00
Gregory Szorc
84c9e68503 webcommands: document "archive" web command 2015-02-06 22:19:59 -08:00
Gregory Szorc
7a4c38aedb webcommands: document "filelog" web command 2015-02-06 22:11:54 -08:00
Gregory Szorc
164751c7a0 webcommands: document "annotate" web command 2015-02-06 22:08:30 -08:00
Gregory Szorc
46063b9658 webcommands: document "comparison" web command 2015-02-06 22:06:44 -08:00
Gregory Szorc
4543e0b0be webcommands: document "filediff" web command 2015-02-06 22:02:14 -08:00
Gregory Szorc
d8699a97c0 webcommands: document "summary" web command 2015-02-06 21:51:52 -08:00
Gregory Szorc
060baa099d webcommands: document "manifest" web command 2015-02-06 21:48:01 -08:00
Gregory Szorc
2d9a7685cf webcommands: document "changelog" web command 2015-02-06 21:39:15 -08:00
Gregory Szorc
bb7094c895 webcommands: document "file" web command 2015-02-06 21:26:53 -08:00
Gregory Szorc
e4e6ba61d1 webcommands: document "log" web command 2015-02-06 21:13:03 -08:00
Gregory Szorc
7c907b0b4b webcommands: document "shortlog" web command 2015-02-06 20:50:17 -08:00
Gregory Szorc
22d62d80ec webcommands: document "changeset" web command 2015-02-06 20:48:22 -08:00
Gregory Szorc
8ce448377a webcommands: document "tags" web command 2015-02-06 20:44:46 -08:00
Gregory Szorc
2885cfee5f webcommands: document "bookmarks" web command 2015-02-06 20:43:54 -08:00
Gregory Szorc
ece2021397 webcommands: document "branches" web command 2015-02-06 20:44:10 -08:00
Gregory Szorc
896713a026 webcommands: document "help" web command 2015-02-06 20:41:08 -08:00
Gregory Szorc
4498c4489d webcommands: move help import into help command handler
A subsequent patch will introduce an import cycle between mercurial.help
and mercurial.hgweb.webcommands. Break the cycle by moving the import of
mercurial.help into the web command that actually needs it.
2015-02-06 22:47:48 -08:00
Gregory Szorc
11ed5adff7 webcommands: define a dict of available commands
This will be used to hook web commands up to the help system. It also
makes web commands work similarly as CLI commands.
2015-02-06 22:52:40 -08:00
Gregory Szorc
ef80cfae6c webcommands: define web commands using a decorator
Other parts of Mercurial have evolved to use decorators to declare
commands or handlers. This patch gives the same treatment to web
commands.
2015-02-06 19:06:17 -08:00
Yuya Nishihara
b17cf752d2 hgweb: use revset.spanset where appropriate
It is remainder of 8c5f695903af where spanset was introduced.
2015-02-02 22:28:52 +09:00
Gregory Szorc
2eb1a12cad hgweb: extract changelist entry generation into own function
I want to supplement changelist entries (used by shortlog and changelog
endpoints) with custom metadata from an extension. i.e. I have extra
per-changeset metadata that I wish to make available to templates so it
can be rendered on hgweb.

To facilitate this, I've extracted the logic for creating a changeset
data structure into its own function, where it can be wrapped by
extensions.

Ideally, hgweb would use the same templater as the command line and have
full access to templatekw.keywords. But that's a lot of work. This patch
gets us some of the benefit without all the work.

Many other hgweb commands could benefit from similar refactorings. I'm
going to wait to see how this patch is received before I go crazy on
extracting inline functions.
2015-01-06 20:14:52 -08:00
Anton Shestakov
fa59efaa89 hgweb: allow viewing diffs against p1 or p2 for merge commits (issue3904)
This adds UI portion of the feature that has resided in mercurial since 2012.
Back then the interface was added together with the code, but was shortly
backed out because it was deemed "not ready". Code, however, stayed.

For the original feature and its implementation, see issue2810 and
3ff83729b63f.

In short, the backed-out interface had two outstanding issues:
1. it was introducing an entirely new term (baseline) and
2. it was present on every changeset's page, even for changesets with 1 parent
   (or no parents), which didn't make sense

This patch implements a hopefully better interface because:
1. it uses the usual terms (diff) and
2. it only shows up when there actually are 2 parents.
2015-01-03 17:50:21 +08:00
Siddharth Agarwal
ed470d2b63 webcommands.annotate: explicitly only honor whitespace diffopts
The whitespace ones are the only ones the annotate logic cares about anyway, so
there's no visible impact.
2014-11-21 16:16:03 -08:00
Gregory Szorc
9ccf5570f8 hgweb: send proper HTTP response after uncaught exception
This patch fixes a bug where hgweb would send an incomplete HTTP
response.

If an uncaught exception is raised when hgweb is processing a request,
hgweb attempts to send a generic error response and log that exception.

The server defaults to chunked transfer coding. If an uncaught exception
occurred, it was sending the error response string / chunk properly.
However, RFC 7230 Section 4.1 mandates a 0 size last chunk be sent to
indicate end of the entity body. hgweb was failing to send this last
chunk. As a result, properly written HTTP clients would assume more data
was coming and they would likely time out waiting for another chunk to
arrive.

Mercurial's own test harness was paving over the improper HTTP behavior
by not attempting to read the response body if the status code was 500.
This incorrect workaround was added in faced8f5c2af and has been removed
with this patch.
2014-11-28 10:59:02 -08:00
Matt Harbison
eae366b6a1 hgweb: fix a crash when using web.archivesubrepos
A matcher is required when enabling the subrepo option on archival.archive(),
because that calls match.narrowmatcher(), which accesses fields on the object.
It's therefore probably a bad idea to default the matcher to None on archive(),
but that's a fix for default.
2014-11-05 21:33:45 -05:00
Augie Fackler
0e58e63b9c hgweb: disable SSLv3 serving (BC)
Because of recent attacks[0] on SSLv3, let's just drop support entirely.

0: http://googleonlinesecurity.blogspot.com/2014/10/this-poodle-bites-exploiting-ssl-30.html
2014-10-21 17:09:37 -04:00
Mads Kiilerich
374f35aab5 templater: introduce templatepaths for getting paths searched for templates
Avoid function with different return types depending on parameters.
2014-09-28 16:57:37 +02:00
Matt Mackall
275eb5bdd1 merge with stable 2014-09-29 17:23:38 -05:00
Anton Shestakov
1119de7215 hgweb: refresh hgweb.repo on phase change (issue4061)
Make hgweb.refresh() also look at phaseroots file (in addition to 00changelog.i
file) and reload the repo when os.stat returns different mtime or size than
cached, signifying the file was modified.

This way if user changes phase of a changeset (secret <-> draft), there's no
need to restart hg serve to see the change.
2014-09-27 21:59:55 +09:00
Anton Shestakov
20c415845d hgweb: fail if an invalid command was supplied in url path (issue4071)
Traditionally, the way to specify a command for hgweb was to use url query
arguments (e.g. "?cmd=batch"). If the command is unknown to hgweb, it gives an
error (e.g. "400 no such method: badcmd").

But there's also another way to specify a command: as a url path fragment (e.g.
"/graph"). Before, hgweb was made forgiving (looks like it was made in
cd356f4efd91) and user could put any unknown command in the url. If hgweb
couldn't understand it, it would just silently fall back to the default
command, which depends on the actual style (e.g. for paper it's shortlog, for
monoblue it's summary). This was inconsistent and was breaking some tools that
rely on http status codes (as noted in the issue4071). So this patch changes
that behavior to the more consistent one, i.e. hgweb will now return "400 no
such method: badcmd".

So if some tool was relying on having an invalid command return http status
code 200 and also have some information, then it will stop working. That is, if
somebody typed foobar when they really meant shortlog (and the user was lucky
enough to choose a style where the default command is shortlog too), that fact
will now be revealed.

Code-wise, the changed if block is only relevant when there's no "?cmd" query
parameter (i.e. only when command is specified as a url path fragment), and
looks like the removed else branch was there only for falling back to default
command. With that removed, the rest of the code works as expected: it looks at
the command, and if it's not known, raises a proper ErrorResponse exception
with an appropriate message.

Evidently, there were no tests that required the old behavior. But, frankly, I
don't know any way to tell if anyone actually exploited such forgiving behavior
in some in-house tool.
2014-09-22 23:46:38 +09:00
Matt Mackall
dd1fdce87e merge with stable 2014-09-27 14:47:52 -05:00
Matt Mackall
7a68007f38 hgweb: avoid config object race with hgwebdir (issue4326)
Turns out hgwebdir passes full repo objects to each hgweb request
instance, but with a shared baseui. We explicitly break the sharing.
2014-08-10 13:53:36 -05:00
Gregory Szorc
22de18c0d3 hgweb: refresh repository using URL not path (issue4323)
hgweb detects out-of-date repository instances (using a highly
suspect mechanism that should probably be fixed) and obtains a new
repository object if needed.

This patch changes the repository object copy to use the repo URL
(instead of path). This preserves more information about the source
repository and allows bundles to be served through hgweb.

A test verifying that bundles can now be served properly via
`hg serve` has been added.
2014-08-18 12:12:57 -07:00
Mads Kiilerich
5d377a8588 cleanup: avoid local vars shadowing imports
This will mute some pyflakes "import ... shadowed by loop variable" warnings.
2014-08-15 16:20:47 +02:00
Mads Kiilerich
23da6c1d98 cleanup: avoid _ for local unused tmp variables - that is reserved for i18n
_ is usually used for i18n markup but we also used it for I-don't-care
variables.

Instead, name don't-care variables in a slightly descriptive way but use the _
prefix to designate unused variable.

This will mute some pyflakes "import '_' ... shadowed by loop variable"
warnings.
2014-08-15 16:20:47 +02:00
Matt Mackall
0257c423ac hgweb: avoid initialization race (issue4280) 2014-06-16 13:30:46 -05:00
FUJIWARA Katsunori
350af37dc3 hgweb: show revisions and hashes gotten from changelog in "comparison" page
Before this patch, revision numbers and hash values in "comparison"
page are gotten from not changelog but filelog.

Such filelog information is useful only for hgweb debugging, and may
confuse users.

This patch shows revision numbers and hash values gotten from
changelog in "comparison" page.
2014-04-17 09:36:09 +09:00
FUJIWARA Katsunori
62dac3c633 hgweb: show as same parents as "hg parents -r REV FILE" in pages for file
Before this patch, "parents" in pages for file doesn't show as same
parents as "hg parents -r REV FILE", when the specified file is not
modified in the specified revision.

For example, it is assumed that revision A, B and D change file "f".

    changelog   (A) ---> (B) ---> (C) ---> (D)
    filelog "f" (x) ---> (y) ------------> (z)

"/file/D/f" invokes "webutil.parents()" with filectx(z) gotten from
changectx(D), and it returns changectx(B). This is as same result as
"hg parents -r D f".

In the other hand, "/file/C/f" invokes "webutil.parents()" with
filectx(y') gotten from changectx(C), and it returns changectx(A),
because filectx(y') is linked to changectx(B), and works like
filectx(y) in some cases.

In this case, revision B is hidden from users browsing file "f" in
revision C.

This patch shows as same parents as "hg parents -r REV FILE" in pages
for file, by making "webutil.parents()" return:

  - "linkrev()"-ed revision only, if:

    - specified context instance is "filectx" (because
      "webutil.parents()" is invoked with changectx, too), and

    - (1) the revision from which filectx is gotten and (2) the one to
      which filectx is linked are different from each other

  - revision gotten from "ctx.parents()", otherwise
2014-04-17 09:36:08 +09:00
FUJIWARA Katsunori
fc4364cead hgweb: make "comparison" get parent from not filelog but changelog
Before this patch, "comparison" shows unexpected result, when the
specified file is not modified in the specified revision, even though
"diff" shows empty result.

When REV doesn't change specified FILE, "diff" shows:

  "hg diff -c REV FILE"

but "comparison" shows:

  "hg diff -c `hg parents -r REV FILE` FILE"

In other words, the former gets parent from changelog, but the latter
gets one from filelog.

This may confuse users browsing (and switching "diff" and
"comparison" of) files in the specified revision.

This patch makes "comparison" get parent from not filelog but
changelog, to show "hg diff -c REV FILE" in both "diff" and
"comparison" pages.
2014-04-17 09:36:08 +09:00