1. Arne Babenhauserheide
  2. hg-test-namespaced-bookmarks


hg-test-namespaced-bookmarks / test.py

#!/usr/bin/env python
# encoding: utf-8

"""Manage 100 branches. 

Create 10 repos with 10 branches each, 2 changes per branch to one of 10 random files (0-10).

Then turn the bookmarks into namespaced bookmarks, because FelipeC thinks that necessary for managing branches.

Reason: Take the challenge: http://felipec.wordpress.com/2011/01/16/mercurial-vs-git-its-all-in-the-branches/

from subprocess import call
import os
from random import randint
from mercurial import commands

def test100branches(ui, repo, target=None, **opts):
    """Take the branch rebasing challenge: http://felipec.wordpress.com/2011/01/16/mercurial-vs-git-its-all-in-the-branches/ ; execute in an empty repo."""

    # make sure this repo is empty
    for i in repo.changelog: 
    if commitsexist: 
        ui.warn("the repo is not empty. bailing out. Please create an empty repo with hg init <repo>, cd into it and try again.\n")

    remote = ["bab", "alice", "sober", "matt", "mg", "1337", "durin", "ron", "sam", "kerrigan"]

    for r in remote: 
    # branches
        branchnum = 1
        for branch in range(randint(1,20)): 
            branchnum += randint(1, 3)
            for j in range(randint(1,9)): 
                call("echo " + str(randint(0,9)) + " >> " + str(randint(0,9)), shell=True)
                call(["hg","commit","-qAm","random-commit " +str(randint(0,9))])
            call("hg up null -q".split())
        print "created repo", r

    # prepare my r
    with open(".hg/hgrc","w") as f: 
        for r in remote: 
            f.write(r + " = ../" + r + "\n")

    # use namespaces for bookmarks
    for r in remote: 
        commands.incoming(ui, repo, r, bundle=False, force=True, quiet=True, bookmarks=True)
        marks[r]=[tuple(b.split()) for b in ui.popbuffer().splitlines()[2:]]
        # pull, to make sure that we have all required revs in the repo
        commands.pull(ui, repo, r, force=True)
    ui.debug("remote bookmarks "+ str(marks) + "\n")
    for r, book in marks.items(): 
        for mark, rev in book: 
            commands.bookmark(ui, repo, r+"/"+mark, rev=rev, force=True)

    # show the bookmarks
    commands.bookmark(ui, repo)
    ui.write("Now just use hg rebase -b <bookmark> to rebase the branches.\n")

cmdtable = {
    # "command-name": (function-call, options-list, help-string)
    "test100branches": (test100branches,

if __name__ == "__main__": 
    print """Take the branch rebasing challenge: http://felipec.wordpress.com/2011/01/16/mercurial-vs-git-its-all-in-the-branches/

This is a mercurial extension (now). 

Run it in an empty repo with 

    hg --config extensions.bran=<path/to/test.py> test100branches

Enjoy your time with Mercurial!