MDN may have intermittent access issues April 18 13:00 - April 19 01:00 UTC. See whistlepig.mozilla.org for all notifications.

mozilla

Revision 353083 of Creating Mercurial User Repositories

  • Revision slug: Creating_Mercurial_User_Repositories
  • Revision title: Creating Mercurial User Repositories
  • Revision id: 353083
  • Created:
  • Creator: cpeterson
  • Is current revision? No
  • Comment Expanded elided username in URL examples

Revision Content

When working with Mercurial, it is often nice to publish your changes on a server as a backup or so others can examine and work with them. If you have Level 1 commit access or higher, then you should have an LDAP account which allows you to push to user repos in the /users directory of hg.mozilla.org.

Configuring ssh

So you don't need to type your username every time, add these lines to ~/.ssh/config:

Host hg.mozilla.org
User your-hg@username.domain

where 'your-hg@username.domain' is simply your LDAP username.

Creating a Repository

To do this, run the following command. Use the same command regardless of whether you want to clone an existing repository or create a new, empty one.

ssh hg.mozilla.org clone my-repo1

my-repo1 is the name of the new repository you want to create, not the repository you are trying to clone from.

Running the above ssh command will run an interactive script, prompting you to make some choices (about which repository you want to clone from). It is by and large self-explanatory. When the script is finished, ssh will exit. After 5-10 minutes, your repository should appear on http://hg.mozilla.org/users/

Editing your personal repository

Once you have created your mercurial repository, you can edit its description. This description will show up when people visit http://hg.mozilla.org/users/your-hg_username.domain. The process is similar to creating a brand new repository, instead of using the clone action, use the "edit" action. The "edit" action also lets you delete your repository. Please note that the delete action is irreversible.

~ $ssh hg.mozilla.org edit my-repo1

0) Exit.
1) Delete the repository.
2) Edit the description.

What would you like to do? 0

Examining Clones Via the Web

The clone will be visible at http://hg.mozilla.org/users/your-hg_username.domain/my-repo1.  It may take a while for it to show up because of some caching mechanisms that have been put in place. It should show up pretty quickly though, and you'll be able to browse history via a web interface.

Others can also pull changes via http:

hg clone http://hg.mozilla.org/users/your-hg_username.domain/my-repo1

Pushing Changes

To push changes, use ssh:

hg push ssh://hg.mozilla.org/users/your-hg_username.domain/my-repo1

You may want to add that path to the repository's hgrc, so you don't have to type it every time. Put something like this in .hg/hgrc:

[paths]
default-push = ssh://hg.mozilla.org/users/your-hg_username.domain/my-repo1

Pulling your changes

You may wish to use this repository to share changes between machines. For this, start by doing the exact same setup on the other machine. In other words, if you have pulled mozilla-central from your first machine, pull it from the second machine. If you have created a queue on the first machine, create a queue on the second machine, etc.

Then, to pull the complete repo:

hg pull ssh://hg.mozilla.org/users/your-hg_username.domain/my-repo1

Mercurial Queue User Repository Workflow

This assumes you have already enabled Mercurial Queues (MQ).

Setup the Repository

  1. Create a new empty repository (say, "my-repo-patches") on hg.mozilla.org, as directed above.
  2. Verify that the repository is visible at http://hg.mozilla.org/users/your-hg_username.domain/my-repo-patches
  3. Initialize a patch queue, if you haven't already, with hg qinit -c (option -c ensures that your patch queue is itself a hg repository)
  4. Create an hgrc file for your patch queue (at .hg/patches/.hg/hgrc) with these contents:
    [paths]
    default = http://hg.mozilla.org/users/your-hg_username.domain/my-repo-patches
    default-push = ssh://hg.mozilla.org/users/your-hg_username.domain/my-repo-patches
    
  5. You can now manipulate your patch repository using most of the usual Mercurial commands (e.g. status, diff, pull, push, etc.) while specifying the --mq argument.  This avoids the need to cd .hg/patches directory whenever you want to perform actions on it.  For example, both of these commands are run from the same working directory but they work on different repositories.
    hg pull      # Pulls changes in your top-level clone
    hg pull --mq # Pulls changes to the Mercurial Queue user repo.
    

Commit and push your patches:

hg st --mq                          # Show the changes to your .hg/patches directory to be committed
hg commit --mq -m "Some message"    # Commit the patch changes
hg push --mq                        # Push them to your public repository

Pulling changes

hg qpop -a        # Pop all currently applied patches.  This is required before pulling.
hg pull --mq -u   # Pull and update the patch repository.  
hg merge --mq     # If there are conflicts you may need to merge with your working copy.
hg qpush foo      # Apply patches to continue working.

Revision Source

<p>When working with <a href="/en/Mercurial" title="en/Mercurial">Mercurial</a>, it is often nice to publish your changes on a server as a backup or so others can examine and work with them. If you have Level 1 <a class="link-https" href="https://www.mozilla.org/hacking/commit-access-policy/#Summary" title="https://www.mozilla.org/hacking/commit-access-policy/#Summary">commit access</a> or higher, then you should have an LDAP account which allows you to push to user repos in the <a class="link-https" href="https://hg.mozilla.org/users/" title="https://hg.mozilla.org/users/"><code>/users</code></a> directory of <code>hg.mozilla.org</code>.</p>
<h3 id="Configuring_ssh" name="Configuring_ssh">Configuring <code>ssh</code></h3>
<p>So you don't need to type your username every time, add these lines to <code>~/.ssh/config</code>:</p>
<pre>
Host hg.mozilla.org
User <em>your-hg@username.domain</em>
</pre>
<p>where '<em><a class="link-mailto" href="mailto:your-hg@username.domain" rel="freelink">your-hg@username.domain</a></em>' is simply your LDAP username.</p>
<h3 id="Creating_a_Repository" name="Creating_a_Repository">Creating a Repository</h3>
<p>To do this, run the following command. Use the same command regardless of whether you want to clone an existing repository or create a new, empty one.</p>
<pre class="eval">
ssh hg.mozilla.org clone <em>my-repo1</em>
</pre>
<p><em><code>my-repo1</code></em> is the name of the <strong>new repository you want to create</strong>, not the repository you are trying to clone from.</p>
<p>Running the above ssh command will run an interactive script, prompting you to make some choices (about which repository you want to clone from). It is by and large self-explanatory. When the script is finished, ssh will exit. After 5-10 minutes, your repository should appear on <a class="external" href="http://hg.mozilla.org/users/" title="http://hg.mozilla.org/users/"><code>http://hg.mozilla.org/users/</code></a></p>
<h3 id="Editing_your_personal_repository" name="Editing_your_personal_repository">Editing your personal repository</h3>
<p>Once you have created your mercurial repository, you can edit its description. This description will show up when people visit <a class="external" href="http://hg.mozilla.org/users/your-hg_username.domain" rel="freelink">http://hg.mozilla.org/users/your-hg_username.domain</a>. The process is similar to creating a brand new repository, instead of using the clone action, use the "edit" action. The "edit" action also lets you delete your repository. Please note that the delete action is irreversible.</p>
<pre>
~ $ssh hg.mozilla.org edit <em>my-repo1</em>

0) Exit.
1) Delete the repository.
2) Edit the description.

What would you like to do? 0
</pre>
<h3 id="Examining_Clones_Via_the_Web">Examining Clones Via the Web</h3>
<p>The clone will be visible at <code><a class="external" href="http://hg.mozilla.org/users/" rel="freelink">http://hg.mozilla.org/users/</a><em>your-hg_username.domain/my-repo1</em></code>.&nbsp; It may take a while for it to show up because of some caching mechanisms that have been put in place. It should show up pretty quickly though, and you'll be able to browse history via a web interface.</p>
<p>Others can also pull changes via http:</p>
<pre>
hg clone http://hg.mozilla.org/users/<em>your-hg_username.domain/my-repo1</em>
</pre>
<h3 id="Pushing_Changes" name="Pushing_Changes">Pushing Changes</h3>
<p>To push changes, use ssh:</p>
<pre class="eval">
hg push <a class="external" href="ssh://hg.mozilla.org/users/your-hg_username.domain/my-repo1" rel="freelink">ssh://hg.mozilla.org/users/your-hg_username.domain/my-repo1</a>
</pre>
<p>You may want to add that path to the repository's hgrc, so you don't have to type it every time. Put something like this in <code>.hg/hgrc</code>:</p>
<pre class="eval">
[paths]
default-push = <a class="external" href="ssh://hg.mozilla.org/users/your-hg_username.domain/my-repo1" rel="freelink">ssh://hg.mozilla.org/users/your-hg_username.domain/my-repo1</a>
</pre>
<h3 id="Pulling_your_changes">Pulling your changes</h3>
<p>You may wish to use this repository to share changes between machines. For this, start by doing the exact same setup on the other machine. In other words, if you have pulled mozilla-central from your first machine, pull it from the second machine. If you have created a queue on the first machine, create a queue on the second machine, etc.</p>
<p>Then, to pull the complete repo:</p>
<pre class="eval">
hg pull <a class="external" href="ssh://hg.mozilla.org/users/your-hg_username.domain/my-repo1" rel="freelink">ssh://hg.mozilla.org/users/your-hg_username.domain/my-repo1</a>
</pre>
<h3 id="Mercurial_Queue_User_Repository_Workflow">Mercurial Queue User Repository Workflow</h3>
<p>This assumes you have already enabled <a href="/en/Mercurial_Queues#Introduction" title="Mercurial Queues">Mercurial Queues (MQ)</a>.</p>
<h4 id="Creating_an_Mq_Patch_Queue_Repository" name="Creating_an_Mq_Patch_Queue_Repository">Setup the Repository</h4>
<ol>
  <li>Create a new empty repository (say, "<code>my-repo-patches</code>") on hg.mozilla.org, <a href="/en/Creating_Mercurial_User_Repositories#Creating_a_Repository" title="Creating Mercurial User Repositories">as directed above</a>.</li>
  <li>Verify that the repository is visible at <code><a class="external" href="http://hg.mozilla.org/users/" rel="freelink">http://hg.mozilla.org/users/</a><em>your-hg_username.domain/my-repo-patches</em></code></li>
  <li>Initialize a patch queue, if you haven't already, with <code>hg qinit -c </code>(option <code>-c</code> ensures that your patch queue is itself a hg repository)</li>
  <li>Create an <code>hgrc</code> file for your patch queue (at <code>.hg/patches/.hg/hgrc</code>) with these contents:
    <pre>
[paths]
default = http://hg.mozilla.org/users/<em>your-hg_username.domain/my-repo-patches</em>
default-push = <strong>ssh</strong>://hg.mozilla.org/users/<em>your-hg_username.domain/my-repo-patches</em>
</pre>
  </li>
  <li>You can now manipulate your patch repository using most of the usual Mercurial commands (e.g. <code>status</code>, <code>diff</code>, <code>pull</code>, <code>push</code>, etc.) while specifying the <strong><code>--mq</code></strong> argument.&nbsp; This avoids the need to <code>cd</code><code> .hg/patches</code> directory whenever you want to perform actions on it.&nbsp; For example, both of these commands are run from the same working directory but they work on different repositories.<br />
    <pre>
hg pull&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Pulls changes in your top-level clone
hg pull <strong>--mq</strong> # Pulls changes to the Mercurial Queue user repo.
</pre>
  </li>
</ol>
<h4 id="Examining_Clones_Via_the_Web" name="Examining_Clones_Via_the_Web">Commit and push your patches:</h4>
<pre class="eval">
hg st <strong>--mq</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Show the changes to your <code>.hg/patches</code> directory to be committed
hg commit <strong>--mq</strong> -m "Some message"&nbsp;&nbsp;&nbsp; # Commit the patch changes
hg push <strong>--mq</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Push them to your public repository
</pre>
<h4 id="Pulling_changes">Pulling changes</h4>
<pre>
hg qpop -a&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;# Pop all currently applied patches.  This is required before pulling.
hg pull <strong>--mq</strong> -u &nbsp;&nbsp;# Pull and update the patch repository.  
hg merge <strong>--mq</strong>&nbsp;&nbsp;&nbsp;&nbsp; # If there are conflicts you may need to merge with your working copy.
hg qpush <em>foo</em>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;# Apply patches to continue working.
</pre>
Revert to this revision