mercurial hgweb.config do not find repositories, path issue - mercurial

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

Related

Pylint nested pylintrc : Specify a configuration file

Goal
I want to use pylint without specifying the file path (just run pylint instead of pylint --rcfile=linter/.pylintrc), as I want to save all linter related files in a subfolder linter/.
I thought of adding a .pylintrc file at the root folder only a redirection to the actual config file linter/.pylintrc.
Exploration
The option rcfile seems to be what I look for, it doesn't seems to import the settings from the sub-folder. What am I missing ?
Proposed .pylintrc file for redirection:
[MASTER]
# Specify a configuration file.
rcfile=subfolder/.pylintrc
This is not supported in pylint see this pull request

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.

Hosting Mercurial HG via VisualSVN Server

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?

Mercurial error: abort no username supplied

Problem on WindowsXP (likely will happen on all Win installs), first time using Mercurial. I found the answer in an inobvious place so I'm asking/answering the question myself so others don't have to search like I did.
First time using Mercurial on machine.
Add new repoz:
c:\bla\>hg add
no problem.
Next, commit:
c:\bla\hg commit
error:
abort: no username supplied (see "hg help config")
Solution:
On my Windows install, the Mercurial.ini did not get propagated. It also needs a user email added to it.
Take the default Mercurial.ini file found at in the Mercurial executable install directory (C:\Program Files\Mercurial\Mercurial.ini on my machine)
and copy it to your user home dir (C:\Documents and Settings\myName on winXP).
On a Windows 7 install there is no default .ini, you will need to create a new one in C:\Users\myName.
Then edit that .ini file. Find this area. The username needs an email set. It will be blank--add your email name here.
[ui]
; editor used to enter commit logs, etc. Most text editors will work.
editor = notepad
username = userEmail#domain.example
This fixed the problem for me.
I'm sorry, but why do you call this a problem? Mercurial asks you to see hg help config, and this help text explicitly tells you how to add a username -- I know since I wrote that help text :-)
How should we improve the error message to make this more clear?
However, we've managed to screw this up by making hg help config include help for all config settings. So the nice little example of how to set the username:
[ui]
username = Your Name <your#email.example>
is now lost in the noise (add this to ~/.hgrc, creating the file if necessary). I've opened an issue for this.
On Windows XP I do not see an ini file.
After creating the repository using the command hg init,
I added a file with the name hgrc to the folder .hg
With the following content:
[ui]
editor = notepad
username = zamboni#icemachine.example
no matter Windows or Linux, hg looks the <repo>/.hg/hgrc file for valid configuration. As in "hg help config" says, you only have to add at the end of that file the following lines:
[ui]
username = YOUR NAME <EMAIL#HOST.EXAMPLE>
verbose = true
save and hg commit -m 'test'
If you are using TortoiseHg, you can add [UI] settings easily
Right clicking in any folder Explorer to access the TortoiseHg menu.
From the flyout TortoiseHg menu choose Global Settings
From the interface click the Edit File
Add the [UI] settings to the end
[ui]
username = YourName <YourEmail#SomeAddress.com>
verbose = true
Save and you are done
Here is what worked like a charm for me on Windows XP:
Go to the folder C:\Program Files\Mercurial\hgrc.d assuming you have installed Mercurial to C:\Program Files\Mercurial\.
You should see a Mercurial.RC file in there.
Copy the file to C:\Documents and Settings\ [USERNAME]\
Rename Mercurial.RC to Mercurial.ini.
Edit the [ui] section like so:
[ui]
; editor used to enter commit logs, etc. Most text editors will work.
editor = notepad
verbose = True
username = userEmail#domain.example
I had the same problem. What helped me was to put [ui] and username = firstname lastname on separate lines of the ~/.hgrc file. Putting these two things on one line did not work and led to the error.
This problem still exists. The mercurial.ini file is ignored no matter where you put it.
No mercurial.ini file is created during installation. I created one in the Mercurial install directory, but it had no effect. I copied it to %USERPROFILE% and then to %HOME%, but neither one works.
Putting .hgrc in the HOME directory works.
The documentation ("hg help config") needs to be fixed.
Configure you .hgrc like this:
[ui]
username = your name <youremail#host.example>
verbose = True
NOTE! Do not leave out the [ui] part
This is a problem because in the help file the path to the specified config file does not exist, we have to copy the Mercurial.ini from program files directory to USER directory, maybe this is a problem coming from the installer on windows.
#Kevin Won: you forgot to add the line:
verbose = True

Load multiple .hgrc files - ie, some with machine-specific settings?

I'd like to keep two ~/.hgrc files: ~/.hgrc and ~/.hgrc.local – one with "standard" settings (eg, username), the other with machine-specific settings (eg, setting a graphical merge tool).
How can I do this with hg?
For example, this is how I do it with Vim:
# ~/.vimrc
syntax enable
source ~/.vimrc.local
Then:
# ~/.vimrc.local
let work_code = 'code/work/.*'
if expand('%:p:h') =~ work_code ... fi
There's a not-often used %include directive in mercurial 1.3 and later:
From man hgrc:
A line of the form %include file will include file into the current
configuration file. The inclusion is recursive, which means that
included files can include other files. Filenames are relative to the
configuration file in which the %include directive is found.
so go with:
%include ~/.hgrc.local
and you should be good to go.
I solve this problem for all my "dot files" in a similar way. On login my shell checks a list of files (hgrc, vimrc, ....) and checks if any of them is older than ${that_name}.global or ${that_name}.local. If it is - cat ${that_name}.{global,local} > ${that_name}. Simple and works great so far. While there's a "better" way (using %include) sometimes processing the config files manually has advantages - for example it will work with mercurial pre-1.3.
Mercurial checks for a number of configuration files with a specific priority. This way you can have global, user-specific and repository-specific settings.
Mercurial version >= 1.4 has a hg help config command which describes this in a nice overview:
$ hg help config
Configuration Files
Mercurial reads configuration data from several files, if they exist. Below we list the most specific file first.
On Windows, these configuration files are read:
- "<repo>\.hg\hgrc"
- "%USERPROFILE%\.hgrc"
- "%USERPROFILE%\Mercurial.ini"
- "%HOME%\.hgrc"
- "%HOME%\Mercurial.ini"
- "C:\Mercurial\Mercurial.ini"
- "HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial"
- "<install-dir>\Mercurial.ini"
On Unix, these files are read:
- "<repo>/.hg/hgrc"
- "$HOME/.hgrc"
- "/etc/mercurial/hgrc"
- "/etc/mercurial/hgrc.d/*.rc"
- "<install-root>/etc/mercurial/hgrc"
- "<install-root>/etc/mercurial/hgrc.d/*.rc"
The configuration files for Mercurial use a simple ini-file format. A configuration file consists of sections, led by a "[section]" header and followed by
"name = value" entries:
[ui]
username = Firstname Lastname <firstname.lastname#example.net>
verbose = True
This above entries will be referred to as "ui.username" and "ui.verbose", respectively. Please see the hgrc man page for a full description of the possible
configuration values:
- on Unix-like systems: "man hgrc"
- online: http://www.selenic.com/mercurial/hgrc.5.html
You can list your current settings with hg showconfig.
Mercurial will look in several different locations for hgrc files and will load them if present. For system-wide configuration the standard (on UNIX) would be to use /etc/mercurial/hgrc.
See the files section of the hgrc man page for more information.