Mercurial hg serve multiple repositories - mercurial

I am setting up a central mercurial server, and want to host multiple repositories. Every web page I look at about this says to set up a config file that looks like this:
[collections]
repos/ = repos/
Where /repos is the folder and /repos is the path to use in the URL.
My question is which /repos is which??? I may want to use a name that is not the same as the path, as in:
[collections]
A/ = B/
Is A the physical path or the url path? Such a simple question you would think would have been answered, but I could not find any nontrivial examples.

Ok, I got it. This is on Windows, and here is everything that I need in the hg.conf file:
[paths]
foo = C:\Data\repositories-hg/foo-hg
bar = C:\Data\repositories-hg/bar-hg
This lets met access the repo at the location C:\Data\repositories-hg/foo-hg as:
http://server:8000/foo
Therefore A is the url alias and B is the physical path. There's of course more to set up, but this accomplishes what need for now.

Related

How to refer to external SubRepo in the .hgsub file? [duplicate]

Is it possible to create a subrepository using a sibling path?
Subversion is our "chosen" VCS here, but I've already had quite a few issues with out of date commits. It's much more convenient for me to dual version my files under Hg and SVN, and I have had great success with it. However, I've got a few other co-workers using Hg, and we've had no problems there except for one they probably haven't noticed.
Our SVN layout looks like this
Area/
trunk/
Program1/
Program2/
...
Services/
Program1ServiceA/
Program1ServiceB/
branches/
Program/
Program/
...
Services/
Program1ServiceA/
Program1ServiceB/
tags/
Program1/
Program2/
...
Services/
Program1ServiceA/
Program1ServiceB/
Which makes it kind of stupid when you're working on a project, because if your main project is comprised of Program1 and Program2, and a few more services... I can't get all of the changesets in one go, because we've got a repository that matches the directories. So I have to make sure 4 or 5 repos are in sync, especially with some service references.
I've had some good luck using subrepos beneath a single directory:
MainRepo/
Subrepo1/
Subrepo2/
But what I would like to do is specify a relative path so I can use sibling directories to the subrepository, so I could have something like this:
Area/
Project1/
Program1/ (points to ../trunk/Program1)
Program2/ (points to ../trunk/Program2)
Service1/ (... You get the idea)
Service2/
trunk/
Program1/
Program2/
Services/
Service1/
Service2/
But so far it hasn't worked like I expected it to. trunk/Program1 is an Hg repo, and my Project1/.hgsub file contains
Program1 = ../trunk/Program1
I've also tried ../../trunk/Program1
But the result of either of those is that a new directory is created: Area/Program1/Project1 that is empty.
So far, the only search results I've been able to find use http based repositories for subrepos, so I'm not sure where to go from here. Our dev env is Windows 7, so the "easy" answer is to create junctions, but my primary concern is to make things like this easy to do, so the barrier to entry is as low as possible, and even something as easy as mklink /J Program1 ..\trunk\Program1 from an administrator cmd window is one more thing that would prevent people from migrating to a better workflow.
Is it possible to add a subrepository like I want, or is there a better way to do what we're doing?
Subrepositories are always inside another repository. In other words, subrepositories lets you version a collection of repositories where some repositories are nested inside other repositories. Subrepositories can thus not be siblings without creating an outer repository.
The relative paths you're talking about are used when Mercurial needs to figure out where to get a new subrepository from. That is, when you run hg update (or when it's run for you as part of hg clone) and Mercurial notices a .hgsub file, then it needs to create the subrepositories mentioned there. To create the subrepo, Mercurial uses the path on right-hand side:
sub-A = relative/path
sub-B = C:/absolute/path
Here sub-A will be checked out in the root of your working copy using the command
hg clone <default path for main repo>/relative/path sub-A
and sub-B is checked out using the command
hg clone C:/absolute/path sub-B
That's all — it's a very simple mechanism. I've tried to describe this in my subrepository guide and it's also explained in the wiki.
For your case, you can make a thin shell repository for the parts that belong together. This repo will be like Project1 above and have Program1, Program2, Service1, etc as subrepos. The .hgsub will look like this:
Program1 = Program1
Program2 = Program2
Service1 = Service1
Service2 = Service2
By using "trivial subrepo paths" you make things easy: a clone looks just like the clone source and everything is kept together.
A final note: unless you use Program1 or Service1 in other projects, then you should just put everything into a single repository.

Mercurial's authors description

I'm trying to change Mercurial's template.
When I push some files to my repository, the log files list my PC's name, not user's name that is logged in.
I don't want the PC's name, I want logged user's name shows up.
How I do it?
#Praveen-K has the right answer and Lazy Badger and Lasse have the details you're missing. Here it is spelled out, but go pick Praveen's answer:
The user name you're seeing in/on your remote repository are completely unrelated to:
Any settings on your repository/server
The username you use to authenticate to your repository
Instead that string, called 'author' is burned into the changeset (commit) at commit time and is entirely crafted on your "PC". You could set it to anything you want and once you push that commit to the repository that's how it will display.
At your current skill level you're not going to successfully change that string in commits you've already made, but if you dive into a good explanation (not lookup commands) like the hg book you'll come away understanding things.
Make the entry in to your hgrc file. This file should be in your .hg/ directory (it may be in your repo or you can do in your home directory) and if it is not exist make the file with the name of hgrc in that folder.
[ui]
username = Your Name <your#mail>

How do I use the [subpaths] section in .hgsub to remap a local subrepo for use in bitbucket

NOTE: Since I'm new they won't let me post links, which means all the config files will have improperly formatted URLs. This is simply to get around stackoverflow's limitations, I have used the correct URL in practice.
I tried to setup a subrepo, let's call it A/B. So that cloning works properly, I wanted a normal relative path to put it inside the repository, so logically I had .hgsub:
A/B = A/B
However when trying to push this into bitbucket I get the usual 404 (NOT FOUND) error because on bitbucket B cannot be local, and is actually another project (http s://username#bitbucket.org/username/B)
So then I said, OK just to make bitbucket work I can put .hgsub:
A/B = https://username#bitbucket.org/username/B
However, I recently found out that supposedly there was a workaround here: https://www.mercurial-scm.org/wiki/Subrepository where you use the [subpaths] section so that cloning locally works normal, but bitbucket will request the special path for the project.
So I tried copying their instructions. .hgsub:
A/B = A/B
[subpaths]
https://username#bitbucket.org/username/project/A/B = https://username#bitbucket.org/username/B
But I get the same 404 error. Supposedly whenever it sees https://username#bitbucket.org/username/project/A/B, it will instead remap to the latter https://username#bitbucket.org/username/B which will work. However, this doesn't appear to be the case. I have also tried without putting the username# at the beginning.
Any help would be much appreciated. :)
Turns out I think I was testing at a different repo so it wasn't grabbing the match. Here's the working config for all those interested:
.hgsub:
A/B = A/B
[subpaths]
bitbucket\.org/username/projectname/A/B = bitbucket.org/username/B
It looks like your subpaths config is incorrect. The string on the left side must be a pattern that matches an entry in your .hgsub. I think you want something like:
[subpaths]
A/B = https://username#bitbucket.org/username/B
More info may be found in:
SubrepoRemappingPlan
The subpaths section of hg help hgrc:
Here is an excerpt from the hgrc help:
Defines subrepositories source locations rewriting rules of the form:
<pattern> = <replacement>
Where "pattern" is a regular expression matching the source and
"replacement" is the replacement string used to rewrite it. Groups can be
matched in "pattern" and referenced in "replacements". For instance:
http://server/(.*)-hg/ = http://hg.server/\1/
rewrites "http://server/foo-hg/" into "http://hg.server/foo/".

Mercurial workflow with subrepositories and offline clones?

I'm offline a lot.
So normally, I use one local clone as a "hub" for features, bugs, etc.
hg clone local-hub bug-123
Works offline. Cool.
Can I use a similar workflow if that project contains remote subrepositories?
Because, if .hgsub says
sub/shared = http://server/hg/shared
hg clone says
abort: error: getaddrinfo failed
Note that once the clone is created (while connected), push and pull will use the path in the subrepo's hgrc (instead of the location in .hgsub). So I can point this to a local clone and everything is cool.
But clone looks at .hgsub (as it's supposed to). So if the "blessed" subrepo is on a server, I can't create new clones offline, even though the files I need are right there.
This is a problem, right?
Ideally whomever set up the project uses relative URLs in their .hgsub file like this:
sub/shared = ../shared
and then, of course, actually makes shared a sibling of the main repo. Then as long as you have cloned down the main repo and the subs (as siblings) then everything will work out.
If they've used absolute URLs in their .hgsub file you can work around it using the subpaths section in your .hgrc like this:
[subpaths]
http://server/hg/shared = ../shared
which provides a translation layer in your client.
The canonical way to use subrepositories is to have X = X paths in the .hgsub file:
sub/shared = sub/shared
That way a clone will structurally look just like the original -- and so you can use the clone to make further (local!) clones.
However, this is not always possible, for example, Bitbucket wont let you create the nested repositories on their server. In that case, the ../X style paths in the .hgsub file is better, and you can use the subpaths configuration section to translate these paths into paths you can use locally.

How to use a relative pathname to a Mercurial hook

I have a script that is in the top level of my working copy and would like to use it as a Mercurial hook. If I use an absolute pathname to the hook then everything is fine, but I want a relative pathname so the whole thing can be easily moved around, used in other working copies and other developers can copy the hgrc as is.
/space/project/.hg/hgrc contains
[hooks]
update = genid
The genid script is at /space/project/genid
The hook is invoked just fine if I am in /space/project but if my current directory is /space/project/src/tools then 'hg update' will give an error as the hook cannot be found.
Python hooks cannot use a relative path. Script hooks can like this:
[hooks]
update = ./genid
In certain cases, environment variables are expanded in mercurial configuration. So you can check out if you can use a environment variable.
[hooks]
update = $MercurialHooks/genid
See Faq (12) in https://www.mercurial-scm.org/wiki/TipsAndTricks
I had the same problem and couldnt resolve it. The workaround was easy though! I versioned the file in the repo and just copied it to my .hg folder! Not ideal but it isnt that likely to change and other repo users can still get a copy of the file