Add urlhost option

Martin Geisler mg at aragost.com
Fri Nov 4 04:46:48 CDT 2011


<Schueler.external at lantiq.com> writes:

> Add an option to make host used for RSS and Atom links configurable
>
> This patch is useful if you want your links to point to a different
> server than the one the repo is hosted on. In our setup, the repos are
> hosted on backend servers, while access to them is through a frontend
> server, so the links for RSS and Atom were wrong, they pointed to the
> backend server instead of the frontend. The reason for this is that
> the URLs were composed from the SERVERNAME which always contains the
> name of the server on which the repo is hosted.

Okay -- that should go into the commit message. I also think you mean
SERVER_NAME above, as in the code below. (I word wrapped your message
above and I suggest you do the same.)

> We introduced an additional config setting, urlhost, that allows you
> to specify the server to which the links should point.
>
> We implemented this as an option, so if you do not use the option,
> nothing is changed.
>
> The option can be set in all configuration files.


> The patch contains a test for the feature.
>
>
>
> # HG changeset patch
> # User Nikolaus Schüler <schueler.external at lantiq.com<mailto:schueler.external at lantiq.com>>
> # Date 1315488931 -7200
> # Branch lantiq
> # Node ID ee716084dd9a6a1272488f2fc6a21846e06cbc9c
> # Parent  1cde17ebe5ced1e873f0048cf67b3169987f8df8
> HGSUP-203: Adding code change, docu addition and test to this head.

We don't use internal Lantiq issue numbers in Mercurial :-)

> diff --git a/mercurial/help/config.txt b/mercurial/help/config.txt
> --- a/mercurial/help/config.txt
> +++ b/mercurial/help/config.txt
> @@ -1291,3 +1291,7 @@ The full set of options is:
>
>  ``templates``
>      Where to find the HTML templates. Default is install path.
> +
> +``urlhost``
> +   Name of the host that is used in ``urlbase``. If not specified, it defaults
> +   to ``SERVER_NAME``.
> diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
> --- a/mercurial/hgweb/hgweb_mod.py
> +++ b/mercurial/hgweb/hgweb_mod.py
> @@ -233,7 +233,11 @@ class hgweb(object):
>
>          port = req.env["SERVER_PORT"]
>          port = port != default_port and (":" + port) or ""
> -        urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port)
> +        urlhost = self.config('web', 'urlhost')
> +        if urlhost is None:
> +            urlhost = req.env['SERVER_NAME']

You can just use the default argument to self.config.

> +
> +        urlbase = '%s://%s%s' % (proto, urlhost, port)
>          logourl = self.config("web", "logourl", "http://mercurial.selenic.com/")
>          staticurl = self.config("web", "staticurl") or req.url + 'static/'
>          if not staticurl.endswith('/'):
> diff --git a/tests/test-hgweb-urlhost.t b/tests/test-hgweb-urlhost.t
> new file mode 100644
> --- /dev/null
> +++ b/tests/test-hgweb-urlhost.t

There must be an existing test that you can reuse. Just add the
two-three lines to that instead. Yes, this makes the tests more
difficult to understand, but the test suite is already very slow and we
prefer to concentrate tests over making new tests that repeat 'hg init',
'hg add', ...

> @@ -0,0 +1,59 @@

> +Prove that a config setting for the server in fact lets this server
> appear in RSS links

The line should be wrapped to less than 80 characters. I use 72 since
that's the default in Emacs and it allows for quoting the lines a couple
of times in email discussions like this one.

> +
> +  $ hg init test
> +  $ cd test
> +  $ echo b > b
> +  $ hg ci -Am "b"
> +  adding b
> +  $ echo a > a
> +  $ hg ci -Am "first a"
> +  adding a
> +  $ hg rm a
> +  $ hg ci -m "del a"
> +  $ echo b > a
> +  $ hg ci -Am "second a"
> +  adding a
> +  $ hg rm a
> +  $ hg ci -m "del2 a"
> +  $ hg mv b c
> +  $ hg ci -m "mv b"
> +  $ echo c >> c
> +  $ hg ci -m "change c"
> +  $ hg serve -n test -p $HGPORT -d --pid-file=hg.pid -E errors.log --config web.urlhost=example.org
> +  $ cat hg.pid >> $DAEMON_PIDS
> +
> +rss log with server setting honored in RSS links
> +
> +  $ ("$TESTDIR/get-with-headers.py" localhost:$HGPORT '/rss-log/tip/a')
> +  200 Script output follows
> +
> +  <?xml version="1.0" encoding="ascii"?>
> +  <rss version="2.0">
> +    <channel>
> +      <link>http://*:$HGPORT/</link> (glob)
> +      <language>en-us</language>
> +
> +      <title>test: a history</title>
> +      <description>a revision history</description>
> +      <item>
> +      <title>second a</title>
> +      <link>http://example.org:$HGPORT/log01de2d66a28d/a</link> (glob)
> +      <description><![CDATA[second a]]></description>
> +      <author>test</author>
> +      <pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>
> +  </item>
> +  <item>
> +      <title>first a</title>
> +      <link>http://example.org:$HGPORT/log5ed941583260/a</link> (glob)
> +      <description><![CDATA[first a]]></description>
> +      <author>test</author>
> +      <pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>
> +  </item>
> +
> +    </channel>
> +  </rss>
> +
> +
> +errors
> +
> +  $ cat errors.log
>
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

-- 
Martin Geisler

aragost Trifork
Professional Mercurial support
http://mercurial.aragost.com/kick-start/


More information about the Mercurial-devel mailing list