Hosting Mercurial HG via VisualSVN Server - mercurial

I have tried to host a Mercurial HG repository using a Scriptalias.
ScriptAlias /hg/ "htdocs/hgwebdir.cgi"
If I go to Chrome it display the contents of the cgi file. In IE it does render however images and links are not displayed. In either case the repository I want to display is not shown.
Has anyone managed to get this working with VisualSVN? Also will this work if I have windows authentication and https?

Here's a alternative setup using mod_wsgi (fast!), combined repository directory, and you can manage Mercurial repository level access from the VisualSVN Server GUI.
Download mod_wsgi.so for Apache 2.2 Win32 and place in "C:\Program Files\VisualSVN Server\bin".
Copy hgwebdir.wsgi from your Mercurial installation (contrib directory) to "C:\Program Files\VisualSVN Server\". It should look something like this:
import sys
sys.path.insert(0, "C:\Program Files\Mercurial\library")
from mercurial.hgweb.hgwebdir_mod import hgwebdir
application = hgwebdir('hgweb.config')
Create the config file "C:\Program Files\VisualSVN Server\hgweb.config".
[paths]
/ = c:/Repositories/*
Paste the following in "C:\Program Files\VisualSVN Server\conf\httpd-custom.conf". You should adjust the Auth* values based on the section of httpd.conf.
LoadModule wsgi_module bin/mod_wsgi.so
WSGIScriptAlias /hg "hgwebdir.wsgi"
<Location /hg/>
AuthName "Mercurial Repositories"
AuthType VisualSVN
AuthzVisualSVNAccessFile "C:/Repositories/authz-windows"
AuthnVisualSVNBasic on
AuthnVisualSVNIntegrated off
AuthnVisualSVNUPN Off
SVNParentPath "C:/Repositories/"
require valid-user
</Location>
Create a Mercurial repository:
hg init C:\Repositories\hgtest
You should now be able to access /hg through your browser, and manage repository level authorization through the VisualSVN Server tool.

Assuming you have Python 2.6 installed and working, here are the steps that I took.
Obtain "mod_cgi.so" built for Apache 2.2 Win32 and place it in "C:\Program Files\VisualSVN Server\bin".
Paste the following in "C:\Program Files\VisualSVN Server\conf\httpd-custom.conf"
LoadModule cgi_module bin/mod_cgi.so
ScriptAliasMatch ^/hg(.*) "cgi-bin/hgweb.cgi$1"
Create the cgi-bin directory, "C:\Program Files\VisualSVN Server\cgi-bin". And place hgweb.cgi in it. Make sure it looks similar to the following:
#!c:/Python26/python.exe -u
import sys
sys.path.insert(0, "C:\Program Files\Mercurial\library")
import cgitb
cgitb.enable()
from mercurial.hgweb.hgwebdir_mod import hgwebdir
import mercurial.hgweb.wsgicgi as wsgicgi
application = hgwebdir('hgweb.config')
wsgicgi.launch(application)
Create a file called hgweb.config in the cgi-bin directory.
[paths]
/ = c:/HgRepositories/*
Copied "C:\Program Files\Mercurial\templates" to "C:\Program Files\Mercurial\library\templates".
Create "C:\HgRepositories" folder and "hg init c:\HgRepositories\test".
Restart VisualSVN Server, open browser, enjoy your Mercurial repository.

Starting with version 1.6 of Mercurial, the hgwebdir.wsgi script has
been unified with the hgweb.wsgi script. Wherever hgwebdir.wsgi is
referred to in these directions, you can substitute the hgweb.wsgi
script instead.
https://www.mercurial-scm.org/wiki/modwsgi

You can run hgwebdir behind different authentication and https modules just fine, provided your webserver handles them before the REMOTE_USER variable is handed off to the CGI.
I don't know visualsvn, but your ScriptAlias looks a lot like Apache. Do you need an AddHandler line for .cgi?

Related

How to use local paths to repositories on hard disk in hgrc?

I have repository on local machine C:\repo\my_proj
I want add path to my repository for using in TortoiseHG Workbanch
If I type my configurations in file <work_place>\.hg\hgrc
[paths]
C:\repo\my_proj
application is sending an error message:
No valid default remote repositary URL or path has been configured for this repository.
Please type and save a remote repository path on the Sync widget
But all works when I use terminal GIT-BASH on my OS
hg pull /c/repo/my_proj/
How to use right syntax for adding paths to local repositories in hgrc?
About software:
Mercurial Distributed SCM (version 4.9)
Windows 10 x64
Solved. Sample syntax for use on Windows:
[paths]
file:///c:/repo/my_proj/
or
[paths]
repo = file:///c:/repo/my_proj/
UPD:
or
[paths]
default = S:\repo\my_proj

mercurial hgweb.config do not find repositories, path issue

I have a repository set up on an apache web server using the hgweb.cgi script declared in my apache2.conf file as following:
ScriptAlias /hgp "/var/www/hgrepublic/hgweb.cgi"
In my hgweb.cgi script, if I set the config variable as the path to my repository:
config = "/var/www/hgrepublic/fakecake"
it works and I see the history of my repository at http://localhost/hgp
Now if I want to use the hgweb.config file, I set the config variable in the hgweb.cgi script like:
config = "hgweb.config"
whatever the paths I try to use in config file, I cannot see my repository in the web interface (empty repository index). Here are a few examples I tried with absolute and relative paths
[paths]
/ = /var/www/hgrepublic/**
fakecake = /fakecake
fakecake = /var/www/hgrepublic/fakecake
Any idea to help me make it work with the config file? (I would like to have several repositories declared in the config file)
Note: hgweb cgi and config files are in the /var/www/hgrepublic/ folder as well as the fakecake repository folder.
I found a solution to my own question by looking at the source.
I used a dict in the hgweb.cgi file to pass the different repositories I want to show:
config = {'repo1' : '/path/to/repo1', 'repo2' : '/path/to/repo2'}
It works like this, so I think that there might be a parsing problem in hgweb.config file for [paths] section?
The [paths] section converts the URL to the repository path. Try:
hgweb.config
[paths]
/hpg/fakecake = /var/www/hgrepublic/fakecake
/hpg/repo2 = /var/www/hgrepublic/repo2
hgweb.cgi
config = "hgweb.cgi" # or /path/to/hgweb.cgi if not in cwd

Mercurial server running multiple repositories

I'm using TortoiseHg, and I want to run it as a server. I've been able to run the server, pointing it to the root of the repository I've chosen.
http://192.168.1.64:8000 points to c:\myproject
I'm looking for a way to have a folder C:\projects, with multiple repositories inside, pointing my Hg server to that folder, and i would access my repositories like:
http://192.168.1.64:8000/project1 points to c:\projects\project1
http://192.168.1.64:8000/project2 points to c:\projects\project2
Can someone help me please?
While using a full web server for repo hosting, as suggested by Lasse, is a good idea, nothing prevents you from serving multiple repositories using hg serve.
Here's my hgweb.config file:
[paths]
project-a = C:/hg/project-a/
library-b = C:/hg/library-b/
I start hg serve with this command:
hg serve --address 127.0.0.1 --port 8000 --webdir-conf C:/hg/hgweb.config --encoding utf8
you should edit the hgweb.config file, as it is by default of view like:
[web]
style = gitweb
[collections]
<br>
/mercurial/collections = /mercurial/collections
so, assume that record as first /mercurial/collections is the identifier name whereas second (right side from equals sign) stands for physical path of repo.
for example, I have made it like:
[web]
style = gitweb
[collections]
myrepo1 = /mercurial/repositories/hang_over
myrepo2 = /mercurial/repositories/first_repo
myrepo3 = /mercurial/repositories/javaforever
Im making this under linux ubuntu distribution version.
anyways, here mercurial directory is in my root directory and I'm pointing from it to /mercurial/repositories.
hope it helped you.
Sincerely.
For that you need to set up a full web server, either IIS or Apache, and host hgweb, the Python cgi script that Mercurial comes with (you may have to download the source for this.)
See Publishing Repositories with hgwebdir.cgi for more details.

How to config mercurial to push without asking my password through ssh?

I use mercurial in my project, and every time I push new changesets to the server by ssh, it ask me for a password.
Then how to config the mercurial to push with out asking password?
I works on Ubuntu 9.10
On Linux and Mac, use ssh-agent.
Ensure you have an ssh keypair (see man ssh-keygen for details)
Copy your public key (from ~/.ssh/id_dsa.pub) to the remote machine, giving it a unique name (such as myhost_key.pub)
Log in to the remote machine normally and append the public key you just copied to the ~/.ssh/authorized_keys file
Run ssh-add on your local workstation to add your key to the keychain
You can now use any remote hg commands in this session without requiring authentication.
Assuming you're using Windows, have a read of my Mercurial/SSH guide. Down the bottom of the post you'll find info on how to use PuTTy to do this for you.
Edit: -- Here's the part of the post that I'm talking about (bear in mind you'll need to have pageant running with your key already loaded for this to work):
Client: Setting up Mercurial
If you haven't already, make sure you install Mercurial on the client machine using the default settings. Make sure you tell the installer to add the Mercurial path to the system PATH.
The last step of configuration for the client is to tell Mercurial to use the PuTTy tools when using SSH. Mercurial can be configured by a user-specific configuration file called .hgrc. On Windows it can also be called Mercurial.ini. The file is located in your home folder. If you don't know what your home folder is, simply open a command prompt and type echo %USERPROFILE% - this will tell you the path.
If you haven't set up your configuration yet, then chances are the configuration file doesn't exist. So you'll have to create it. Create a file call either .hgrc or Mercurial.ini in your home folder manually, and open it in a text editor. Here is what part of mine looks like:
[ui]
username = OJ Reeves
editor = vim
ssh = plink -ssh -i "C:/path/to/key/id_rsa.ppk" -C -agent
The last line is the key and this is what you need to make sure it set properly. We are telling Mercurial to use the plink program. This also comes with PuTTy and is a command-line version of what the PuTTY program itself does behind the scenes. We also add a few parameters:
-ssh : Indicates that we're using the SSH protocol.
-i "file.ppk" : Specifies the location of the private key file we want to use to log in to the remote server. Change this to point to your local putty-compatible ppk private key. Make sure you user forward-slashes for the path separators as well!
-C : This switch enables compression.
-agent : This tells plink to talk to the pageant utility to get the passphrase for the key instead of asking you for it interactively.
The client is now ready to rock!
Install PuTTY.
If you're on Windows, open projectdir/.hg/hgrc in your favorite text editor. Edit it to look like this:
[paths]
default = ssh://hg#bitbucket.org/name/project
[ui]
username = Your Name <your#email.com>
ssh = "C:\Program Files (x86)\PuTTY\plink.exe" -ssh -i "C:\path\to\your\private_key.ppk" -C -agent
If it's taking forever to push, the server might be trying to ask you a question (but it's not displayed).
Run this:
"C:\Program Files (x86)\PuTTY\plink.exe" -T hg#bitbucket.org -i "C:\Program Files (x86)\PuTTY\plink.exe" -ssh -i "C:\path\to\your\private_key.ppk"
Answer any questions, and then try pushing again.
If you're using Bitbucket, open your private key with puttygen, copy your public key out of the top textbox, and add it to your user account: https://bitbucket.org/account/user/USERNAME/ssh-keys/

Published mercurial repos - links return 404

I am able to publish the list of repositories using hgwebdir.cgi on Tomcat. However none of the links on the published repository work. What should the baseurl be set to? I set it to http://host:port/folder where the cgi-bin is right under the folder. The urls dont form correctly (dont have the hgwebdir.cgi in them) and i have no url rewriting setup. Is there some Tomcat configuration needed to get the urls working?
as far as I know hgwebdir.cgi should be installed via an HTTP Web server like Apache.
It is not possible to run it under Tomcat: for this reason it is not working.
install an apache web server (try XAMPP if you are running under windows)
Install a python interpreter
Put the hgwebdir.cgi under the CGI dir of your apache web server.
Configure the hgwebdir.cgi so it can find python on PATH
You can find more information on the mercurial book http://hgbook.red-bean.com/read/