#!/usr/bin/python # -*- coding: utf-8 -*- ''' O script em bash para criação da ramificação no Mercurial é lento porque cada comando invoca o Python separadamente. Este programa executando uma única invocação do Python comprova que a execução fica muito mais rápida desta forma ''' from __future__ import print_function import os import shutil import mercurial from mercurial.dispatch import dispatch, request def echo(texto, nome_arq): with open(nome_arq, 'a') as f: f.write(texto) return def hg(*args): return dispatch(request(list(args))) path = '/tmp/hg-named-branches' if os.path.isdir(path): shutil.rmtree(path) hg('init', path) os.chdir(path) echo('zero', 'default.txt') hg('commit', '-Am', 'zero') hg('branch', 'stable') echo('um', 'stable.txt') hg('add') hg('commit', '-m', 'um') echo('dois', 'stable.txt') hg('commit', '-m', 'dois') hg('update', 'default') echo('três', 'default.txt') hg('commit', '-m', 'tres') hg('merge', 'stable') hg('commit', '-m', 'quatro') hg('update', '3') hg('branch', 'bug') echo('cinco', 'bug.txt') hg('add') hg('commit', '-m', 'cinco') echo('seis', 'bug.txt') hg('commit', '-m', 'seis') hg('update', 'default') hg('merge', 'bug') hg('commit', '-m', 'sete') hg('up', '0') hg('branch', 'feature') echo('oito', 'feature.txt') hg('add') hg('commit', '-m', 'oito') hg('merge', 'bug') hg('commit', '-m', 'nove') print('\n\n========\ndefault\n========') hg('log', '-Gqb', 'default') print('\n\n=======\nfeature\n=======') hg('log', '-Gqb', 'feature') print('\n\n===\nbug\n===') hg('log', '-Gqb', 'bug') print('\n\n======\nstable\n======') hg('log', '-Gqb', 'stable')