HgWebDirStepByStep - Mercurial

8.1.3. Configuring Apache with mod_wsgi

Using mod_wsgi is recommended over using mod_python. It's one of the faster and more efficient ways of serving hgweb(dir).

You can use the hgwebdir.wsgi script (it lives where other Mercurial scripts live, and works with Mercurial 1.0 and later), which references a hgwebdir.conf file in the CONFIG variable:

from mercurial.hgweb.hgweb_mod import hgweb
from mercurial.hgweb.hgwebdir_mod import hgwebdir

CONFIG = '/var/hg/public.config'
application = hgwebdir(CONFIG)

This is really an ordinary Python module, but it uses a wsgi extension to make it clear what its use is.

You then need to add this to your httpd.conf (or the vhost config):

WSGIScriptAlias / /var/hg/script/public.wsgi
<Directory /var/hg/script>
    Order deny,allow
    Allow from all
</Directory>

Since you're allowing some permissions to the directory the .wsgi script is in, you probably don't want to put the script in a directory that also contains your repositories.

NOTE: the default hgwebdir.wsgi uses 'hgweb.config' as configuration path. This may not be what you expect. If you find yourself with a working but empty installation, try to set this to the full path where your hgweb.config is situated

lighttpd + hgwebdir.fcgi で Mercurial リポジトリを公開する - ursmの日記

バーチャルホストの設定

lighttpd.conf に設定を追加します。先程書いた fastcgi.server = ( ... ) の部分は置き換えちゃってください。

"mod_rewrite" # コメントを解除する

$HTTP["host"] == "hg.example.com" {
  fastcgi.server = (
    "/hgwebdir" => (
      "hgwebdir" => (
        "socket" => "/opt/local/var/run/lighttpd/hgwebdir.sock",
        "bin-path" => "/var/www/fcgi/hgwebdir.fcgi",
        "check-local" => "disable"
      )
    )
  )

  url.rewrite-once = (
    "^/(.*)" => "/hgwebdir/$1"
  )
}

ここの設定が曲者で、/ の位置を間違えるとルートだけリンクが壊れるという不可解な現象で半日悩む羽目になります。sudo lighttpd restart を忘れずに。

上手く行けば http://hg.example.com/ でリポジトリ一覧が見られるようになっているはずです。

ダイジェスト認証の設定

現在 http 経由のコミットは全て弾く設定になっています。認証は lighttpd に任せるので、Mercurial 側のアクセス制限は取っ払ってやります。

% sudo mkdir /etc/mercurial
% sudo cat > /etc/mercurial/hgrc
[web]
push_ssl = false
allow_push = *
^C

続いてダイジェスト認証用のパスワードファイルを作成します。

% mkdir /var/www/auth
% htdigest -c /var/www/auth/hg_push.htdigest "repos" hoge
% sudo vi /opt/local/etc/lighttpd/lighttpd.conf

lighttpd.conf に設定を追加します。$HTTP["host"] == "hg.example.com" { ... } の部分は置き換えです。

"mod_access" # コメントを解除する

$HTTP["host"] == "hg.example.com" {
  fastcgi.server = (
    "/hgwebdir" => (
      "hgwebdir" => (
        "socket" => "/opt/local/var/run/lighttpd/hgwebdir.sock",
        "bin-path" => "/var/www/fcgi/hgwebdir.fcgi",
        "check-local" => "disable"
      )
    )
  )

  url.rewrite-once = (
    "^/(.*)" => "/hgwebdir/$1"
  )

  $HTTP["querystring"] =~ "cmd=unbundle" {
    auth.backend = "htdigest"
    auth.backend.htdigest.userfile = "/var/www/auth/hg_push.htdigest"

    auth.require = (
      "" => (
        "method" => "digest",
        "realm"  => "repos",
        "require" => "valid-user"
      )
    )
  }
}

wsgiの場合もURLはリライトして対応するのかな?

Fedora12にMercurialを入れてみる - tanamonの日記

再度push

pushing to http://192.168.30.46/hg/
searching for changes
1 changesets found
abort: authorization failed
[command interrupted]

またエラー


# vi .hg/hgrc
[web]
push_ssl = false
allow_push = *

誰でもpushできるように設定。


再々度push

pushing to http://192.168.30.46/hg/
searching for changes
1 changesets found
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
[command completed successfully Mon Dec 07 13:31:03 2009]

今度は通った。

Mercurial - torutkの日記

リポジトリの公開(http経由)

hg serveコマンドでhttpによるリポジトリの公開ができます。リポジトリ(.hg)のあるディレクトリで、hg serve とコマンドを実行するだけです。デフォルトで8000ポート、ポート番号はコマンドラインオプション(-p)で指定できるようです。

ssl required

WindowsマシンからUNIX(Solaris)マシンへpushしたときに、"ssl required"エラーが発生しました。Mercurialのhg serveはデフォルトでSSLを使用するのですが、push側でSSLを使う設定が別途必要なようです。

なお、MercurialのFAQには、SSLを無効にする設定が記載されていました。リポジトリのhgrcファイルに以下を記述します。これはhttpサーバ側(pushされる側)のリポジトリ(.hg/hgrcなど)に記述します。

[web]
push_ssl = false

Ubuntu/Mercurial - TOBY SOFT wiki

もし、下記のようなエラーが出る場合は、

*** failed to import extension hgext.hbisect: No module named hbisect
*** failed to import extension hgext.imerge: No module named imerge

などと出る場合は、以前にaptitudeで入れた古いMercurial(0.9相当)の設定が残っている可能性があります。(hbisect等相当は標準で組み込まれたみたいです)

その場合は、/etc/mercurial/hgrc.d/hgext.rc を修正して、
hgext.hbisect= と hgext.imerge= をコメントアウトしてやればいいみたいです。
例:

sudo vim /etc/mercurial/hgrc.d/hgext.rc

hgext.rc にて、

# Dichotomic search in the DAG of changesets
# add the 'bisect' command
#hgext.hbisect=

 :

# lets you split a merge into pieces
# add the 'imerge' command
#hgext.imerge=

Hg-Git Mercurial Plugin

The Big Idea

The Hg-Git plugin can convert commits/changesets losslessly from one system to another, so you can push via a Mercurial repository and another Mercurial client can pull it and their changeset node ids will be identical - Mercurial data does not get lost in translation.

It is intended that Hg users may wish to use this to collaborate even if no Git users are involved in the project, as it may provide some advantages if you're using Bookmarks (it will transfer bookmarks on push, which Mercurial doesn't do).

Mercurial : virtualenvで apache2のmod_wsgiで動いた。

http://hdknr.posterous.com/mercurial-install-on-a-virtualenv で Mercurialがvirtualenvにすんなりはいったので、
apacheで動かしてみる。

(hg)hdknr@deblen:~/.ve/hg$ mkdir repos
(hg)hdknr@deblen:~/.ve/hg$ ls -al
合計 28
drwxr-xr-x  7 hdknr hdknr 4096 2009-10-23 11:10 .
drwxr-xr-x 10 hdknr hdknr 4096 2009-10-23 11:00 ..
drwxr-xr-x  2 hdknr hdknr 4096 2009-10-23 11:05 bin
drwxr-xr-x  2 hdknr hdknr 4096 2009-10-23 11:00 include
drwxr-xr-x  3 hdknr hdknr 4096 2009-10-23 11:00 lib
drwxr-xr-x  2 hdknr hdknr 4096 2009-10-23 11:10 repos
drwxr-xr-x  3 hdknr hdknr 4096 2009-10-23 11:00 src

レポジトリ初期化。
(hg)hdknr@deblen:~/.ve/hg/repos$ hg init
(hg)hdknr@deblen:~/.ve/hg/repos$ date > readme.txt
(hg)hdknr@deblen:~/.ve/hg/repos$ hg status
? readme.txt
(hg)hdknr@deblen:~/.ve/hg/repos$ hg add readme.txt
(hg)hdknr@deblen:~/.ve/hg/repos$ hg status
A readme.txt
(hg)hdknr@deblen:~/.ve/hg/repos$ hg commit -u hdknr -m "hello"
(hg)hdknr@deblen:~/.ve/hg/repos$ hg status


設定ファイル作成。
(hg)hdknr@deblen:~/.ve/hg$ cat > hgweb.config
[collections]
repos/ = /home/hdknr/.ve/hg/repos/

WSGIスクリプト準備。
(hg)hdknr@deblen:~/.ve/hg$ find src/mercurial-stable/ -name "hgwebdir.*" -print
src/mercurial-stable/contrib/hgwebdir.fcgi
src/mercurial-stable/contrib/hgwebdir.wsgi
src/mercurial-stable/hgwebdir.cgi
src/mercurial-stable/.hg/store/data/contrib/hgwebdir.fcgi.i
src/mercurial-stable/.hg/store/data/contrib/hgwebdir.wsgi.i
src/mercurial-stable/.hg/store/data/hgwebdir.cgi.i

(hg)hdknr@deblen:~/.ve/hg$ cp src/mercurial-stable/contrib/hgwebdir.wsgi .

(hg)hdknr@deblen:~/.ve/hg$ vi hgwebdir.wsgi
#application = hgwebdir('hgweb.config')
# by HDKNR
CONFIG='/home/hdknr/.ve/hg/hgweb.config'
application = hgwebdir(CONFIG)

hg.deb というapache仮想サーバーを作成
(hg)hdknr@deblen:~/.ve/hg$ tree apache/
apache/
|-- conf
|   |-- httpd.conf
|   `-- httpd.conf.d
|       |-- hg.conf
|       `-- wsgi.def
|-- logs
|   |-- access.log
|   `-- error.log
`-- www
    `-- index.html
にして、
(hg)hdknr@deblen:~/.ve/hg$ ls -l /etc/apache2/sites-enabled/hg.deb.conf
lrwxrwxrwx 1 root root 41 2009-10-23 11:48 /etc/apache2/sites-enabled/hg.deb.conf -> /home/hdknr/.ve/hg/apache/conf/httpd.conf

とする。

wsgi プロセスをapacheに認識させる。

(hg)hdknr@deblen:~/.ve/hg$ vi apache/conf/httpd.conf
<VirtualHost *:80>
#Basic
    ServerAdmin admin@hg.deb
    ServerName hg.deb
    DocumentRoot /home/hdknr/.ve/hg/apache/www/

#Log
    ErrorLog /home/hdknr/.ve/hg/apache/logs/error.log
    LogLevel warn
    CustomLog /home/hdknr/.ve/hg/apache/logs/access.log combined

# Virtual Directories and Others
    Include /home/hdknr/.ve/hg/apache/conf/httpd.conf.d/wsgi.def
    Include /home/hdknr/.ve/hg/apache/conf/httpd.conf.d/*.conf

</VirtualHost>

こんな感じで、プロセス名は "v_hg"。
(hg)hdknr@deblen:~/.ve/hg$ vi apache/conf/httpd.conf.d/wsgi.def  
WSGIDaemonProcess v_hg user=www-data group=www-data threads=25  ¥
    python-path=/home/hdknr/.ve/hg/lib/python2.5/site-packages/:/home/hdknr/.ve/hg/bin

/hg という仮想ディレクトリをWSGIScriptAliasで定義。
(hg)hdknr@deblen:~/.ve/hg$ vi apache/conf/httpd.conf.d/hg.conf

WSGIScriptAlias /hg /home/hdknr/.ve/hg/hgwebdir.wsgi
<Location /hg >
    WSGIReloadMechanism Process
    WSGIProcessGroup v_hg
    WSGIApplicationGroup %{SERVER}
   Options All
</Location>

apacheリロード。

ブラウザで確認。          

_1

ホストのMac OSからチェックアウト。
wolf:Desktop hide$ hg clone http://hg.deb/hg/home/hdknr/.ve/hg/repos/
destination directory: repos
requesting all changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
updating working directory
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
wolf:Desktop hide$ date >>repos/readme.txt
wolf:Desktop hide$ hg status repos/
M repos/readme.txt
wolf:Desktop hide$ hg commit repos -u hdknr -m "now"
wolf:Desktop hide$ hg push repos
pushing to repos
searching for changes
新たなチェンジセットはありません
wolf:Desktop hide$ cd repos/
wolf:repos hide$ hg push
pushing to http://hg.deb/hg/home/hdknr/.ve/hg/repos/
searching for changes
ssl required

                                            SSLが必要? これは後で調べてみる。                                                                                    

HgWebDirStepByStep - Mercurial

8.1.3. Configuring Apache with mod_wsgi

Using mod_wsgi is recommended over using mod_python. It's one of the faster and more efficient ways of serving hgweb(dir).

You can use the hgwebdir.wsgi script (it lives where other Mercurial scripts live, and works with Mercurial 1.0 and later), which references a hgwebdir.conf file in the CONFIG variable:

from mercurial.hgweb.hgweb_mod import hgweb
from mercurial.hgweb.hgwebdir_mod import hgwebdir

CONFIG = '/var/hg/public.config'
application = hgwebdir(CONFIG)

This is really an ordinary Python module, but it uses a wsgi extension to make it clear what its use is.

You then need to add this to your httpd.conf (or the vhost config):

WSGIScriptAlias / /var/hg/script/public.wsgi
<Directory /var/hg/script>
    Order deny,allow
    Allow from all
</Directory>

Since you're allowing some permissions to the directory the .wsgi script is in, you probably don't want to put the script in a directory that also contains your repositories.

分散バージョン管理Git/Mercurial/Bazaar徹底比較 (5/5) - @IT

 分散バージョン管理システムを利用した場合でも、成果物を共有するよりどころとして中央リポジトリは必要となります。現時点では、中央リポジトリとしてSVNを利用し、各自の作業を行うローカルリポジトリに分散バージョン管理システムを利用するのがベストだと筆者は考えています。各自のローカルリポジトリを管理するツールを変更するのであれば、中央リポジトリへは影響を与えないので、後々ツールを変更してもオーバーヘッドにはなりません。