📜 ⬆️ ⬇️

Mercurial on Windows Server 2003

You may be embarrassed by such archaic figures in the title, however, I think, I’m not the only one who still use w2k3 and mssql2000 in my work. The reason is trivial: why buy something when it is purchased and works. The discussion about the disadvantages / advantages of w2k3 and w2008 I propose to omit. On the other hand, I am no stranger to progress, and lately I have been using mercurial in my work closely. And so it became necessary to raise the internal server, while at the same time there is just one of the title. The discussion here goes not about hg serve, but about full-fledged hgweb. The article arose due to the fact that it took a whole day to make it work; however, step-by-step instructions were not found in Russian. And the English are not a dime a dozen.

Note. All manipulations relate to Mercurial 1.8.3, Python 2.6.6, and x86 architectures. For other versions of mercurial, you need to take the version of Python for which it is compiled (see on the mercurial website).

Installation

  1. Download and install Mercurial ;
  2. Download and install Python ;
  3. Get hgweb.cgi . There are two ways:
    • download the source from the site Mercurial
    • or get a copy of the source
        hg clone http://selenic.com/repo/hg 
    The file we need is in the root directory:
    Location hgweb.cgi

  4. Create a folder in which Mercurial will be located. In my case, this is C:\Inetpub\hg ;
  5. Unzip the library.zip file from this directory into which this folder is installed (default is C:\Program Files\Mercurial\library.zip );
  6. From there, copy the Templates folder (by default, C:\Program Files\Mercurial\Templates );
  7. And finally, copy the hgweb.cgi file to this directory.

Customization


Now you need to allow python to execute .cgi:
  1. Open IIS Manager;
  2. Click "Add new web services extension ...";
  3. In the window that opens, enter the name of the extension. I called it Python;
  4. Click the "Add" button and in the opened window enter the path to the executable file C:\Python26\python.exe -u "%s" "%s" ;
  5. Set the checkbox “Set extension status as“ Allowed ””;
    Adding a new web extension
  6. As a result, we have a web extension Python
    Web extension added
Next, you need to create a virtual directory for the folder where Mercurial is located — with installing the “Execute (for example ISAPI or CGI applications)” checkbox and allow it to execute .cgi scripts. For this you need:
  1. In the properties of the virtual directory on the "Virtual Directory" tab in the "Application Settings" section, click the "Settings" button;
    Setting up a virtual directory
  2. In the window that opens, click the top button "Add ...";
  3. In the window that opens, enter the path to the executable file C:\Python26\python.exe -u "%s" "%s" , the extension name .cgi , reduce the command to GET,HEAD,POST , make sure that the Script Handler is checked ;
    Adding .cgi
    The .cgi extension has .cgi added:
    .Cgi extension added
  4. Click all Okey.
Now you can test the performance of Python. Create a script:
 print 'Status: 200 OK' print 'Content-type: text/html' print print '<html><head><title>Python test</title></head>' print '<body><h1>!</h1></body>' print '</html>' 
and save it to the folder with Mercurial, for example, as test.cgi ( C:\Inetpub\hg\test.cgi ). Open the browser and look:
Python check

Configuring Mercurial


Now you need to configure Mercurial itself. Create a hgweb.config file in the folder where hgweb.cgi is located.
Note. hgweb.cgi has earned from me only with the ANSI encoding hgweb.config . At UTF-8, a parsing error crashed.

Next you need to open in the hgweb.cgi editor and specify the path to the configuration file:
  # Path to repo or hgweb config to serve (see 'hg help hgweb')
 config = "/ path / to / repo / or / config" 
In our case, the file is nearby and we write simply:
  # Path to repo or hgweb config to serve (see 'hg help hgweb')
 config = "hgweb.config" 

To view errors that may occur, you can uncomment the line:
  # Uncomment to send python tracebacks to the browser if an error occurs occurs:
 import cgitb;  cgitb.enable () 

Now open our hgweb.config in the editor and add the following to it:
  [web]
 allow_push = *
 push_ssl = false 
These lines, we allowed to add changes to all users without using ssl.
Look in the browser:
Check hgweb.cgi
Mercurial works! But there is not a single repository ...
')

Adding Repositories


Everything is simple: you need to create a directory on the disk where the repositories will be located, and create a directory for each repository in it. We do it via the command line:
  C: \ Documents and Settings \ admin> cd .. \ ..
 C: \> mkdir Repos
 C: \> cd repos
 C: \ Repos> mkdir test
 C: \ Repos> hg init test 

Now in hgweb.config you need to specify the path to our repository. To do this, add:
  [paths]
 Test = C: \ Repos \ test 
F5 in the browser and see our repository:
Check hgweb.cgi

In order not to manually add repository paths each time, you can specify the path to the collection:
  [collections]
 C: / Repos = C: / Repos 
Then all repositories from the Repos directory will be displayed automatically.

For beauty, add a web page design:
  [web]
 style = monoblue
 allow_push = *
 push_ssl = false 
Monoblue is one of the templates that are in the folder C:\Inetpub\hg\Templates . Initially, there are only four templates in the folder - coal, gitweb, monoblue, paper. But you can easily create your own. You can read about mercurial templates here .

A bit of pampering and you can already see something:
Test Test Revision Count

Beautiful URL


I confess to do it in part I got ...
  http: //localhost/hg/hgweb.cgi/Test/ 
Looks non-kosher. Therefore, we download the free version of Helicon's ISAPI Rewriter 3, install it and open the ISAPI Rewrite manager, click the “Edit” button.
ISAPI Rewrite manager
and add the rule RewriteRule /hg/(.*) /hg/hgweb.cgi/$1 [I,O]
Although the rule worked and the URL became beautiful, the page html was beautiful
  <link rel = "stylesheet" href = "/ hg / hgweb.cgi / Test / static / style-monoblue.css" type = "text / css"> 
and, accordingly, the style was not applied ... I did not overcome it.

Conclusion


As a result, we have an internal Mercurial server. However, after several days of use, another question arose - managing repositories ... At the moment, you have to go to the server, create directories for the repositories and register them in hgweb.config , which is acceptable for our company, but it's not very convenient. Ideally, it’s a bitbucket.org web client.

Links


1. Running Mercurial on Windows - simple, but small; old article, dated June 7, 2009
2. Setting up and configuring Mercurial in a Windows / IIS / Active Directory environment is a good, but stingy collection of four articles: 1) installation, 2) decoration of Url, 3) screwing Active Directory, and 4) changing the web page template.
3. Setting up a Mercurial server under IIS7 on Windows Server 2008 R2 is an article for Windows Server 2008, but it turned out to be very useful.

Source: https://habr.com/ru/post/119330/


All Articles