« Novos rumos: EBCEspertinho esse paster não? »

Micro Tutorial de Mercurial

22/04/2008

Creio que a primeira vez que li algo sobre controle de versão distribuído foi no blog do Thiago Arrais . Até falei sobre isso um tempo atrás .

Eu comecei a utilizar o mercurial. Daí, até descobrir o assembla, foi um pulo. Pensei em fazer um tutorial sobre o mercurial, mas sempre esbarrei na preguiça.

Então, veio a comunidade rails, com seu discurso de três letras: git, git, git! O Fábio Akita publicou um micro tutorial de git, e eu resolvi segui-lo, traduzindo os comandos para o mercurial.

Pra começar a história: nem todas as opções que o git suporta são suportadas pelo mercurial. Algumas são tratáveis pelo uso de extensões, outras estão planejadas para serem adicionadas no futuro.

Para começar, após instalar o mercurial, vamos fazer uma configuração básica e habilitar os plugins necessários. O arquivo é o .hgrc, no $HOME do usuário.

[extensions]
record=
shelve=/home/digo/shelve.py
transplant=

[ui]
username = Walter Cruz <waltercruz@gmail.com>
ignore = ~/.hgignore

e o artigo .hgignore, que configura quais são os padrões de arquivos a serem ignorados.

# use glob syntax.
syntax: glob

*.elc
*.pyc
*~
.*.swp

# switch to regexp syntax.
syntax: regexp
^\.pc/

Isso feito, vamos partir para a nossa exploração. Acompanhem junto com o artigo original do Akita. Nem tudo se traduz numa equivalência 100%, e tenho algumas considerações a fazer no final:

Clone da suíte de testes dos microformats

digo@ubuntu:~/devel$ hg clone http://hg.microformats.org/tests microformats_tests
requesting all changes
adding changesets
adding manifests
adding file changes
added 359 changesets with 1249 changes to 384 files
updating working directory
223 files updated, 0 files merged, 0 files removed, 0 files unresolved

digo@ubuntu:~/devel/microformats_tests$ hg branches
default                        358:302778d2f672

Manipulando Branches Locais

digo@ubuntu:~/devel/microformats_tests$ hg branch working
marked working directory as branch working

digo@ubuntu:~/devel/microformats_tests$ hg ci -m working

digo@ubuntu:~/devel/microformats_tests$ hg branch
working

digo@ubuntu:~/devel/microformats_tests$ hg branches
working                        359:e2d6b4522602
default                        358:302778d2f672 (inactive)

digo@ubuntu:~/devel/microformats_tests$ hg status
M README.web
M TODO
? walter.txt

digo@ubuntu:~/devel/microformats_tests$ hg add
adding walter.txt

digo@ubuntu:~/devel/microformats_tests$ hg ci -m "Primeiro commit"

digo@ubuntu:~/devel/microformats_tests$ hg branches
working                        359:445e4b41d270
default                        358:302778d2f672 (inactive)

digo@ubuntu:~/devel/microformats_tests$ hg update -C default
2 files updated, 0 files merged, 1 files removed, 0 files unresolved

digo@ubuntu:~/devel/microformats_tests$ hg branch meufix
marked working directory as branch meufix

digo@ubuntu:~/devel/microformats_tests$ hg ci -m meufix
created new head

digo@ubuntu:~/devel/microformats_tests$ hg ci -m "minha correcao"

digo@ubuntu:~/devel/microformats_tests$ hg branch
meufix

Merges Triviais

digo@ubuntu:~/devel/microformats_tests$ hg update -C default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

digo@ubuntu:~/devel/microformats_tests$ hg merge meufix
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)

digo@ubuntu:~/devel/microformats_tests$ hg update -C working
3 files updated, 0 files merged, 0 files removed, 0 files unresolved

Merge vs Rebase

digo@ubuntu:~/devel/microformats_tests$ hg shelve

digo@ubuntu:~/devel/microformats_tests$ hg transplant default

digo@ubuntu:~/devel/microformats_tests$ hg unshelve
unshelve completed

digo@ubuntu:~/devel/microformats_tests$ hg status
M Rakefile

digo@ubuntu:~/devel/microformats_tests$ hg ci -m "mais um commit"

Reusando e Resincronizando seus Repositórios

digo@ubuntu:~/devel/microformats_tests$ cd ..
digo@ubuntu:~/devel$ hg clone microformats_tests/ mf_tests
updating working directory
223 files updated, 0 files merged, 0 files removed, 0 files unresolved

digo@ubuntu:~/devel/mf_tests$ hg status
M TODO

digo@ubuntu:~/devel/mf_tests$ hg ci -m "modificacao no projeto"

digo@ubuntu:~/devel/mf_tests$ hg push
pushing to /home/digo/devel/microformats_tests
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files

digo@ubuntu:~/devel/mf_tests$ cd ../microformats_tests/

digo@ubuntu:~/devel/microformats_tests$ hg update -C default
3 files updated, 0 files merged, 1 files removed, 0 files unresolved

digo@ubuntu:~/devel/microformats_tests$ hg update -C working
4 files updated, 0 files merged, 0 files removed, 0 files unresolved

digo@ubuntu:~/devel/microformats_tests$ hg ci -A -m "Novo arquivo"

adding todo
removing TODO

Renomeando arquivos

digo@ubuntu:~/devel/microformats_tests$ hg update -C default
3 files updated, 0 files merged, 2 files removed, 0 files unresolved

digo@ubuntu:~/devel/microformats_tests$ hg update -C working
4 files updated, 0 files merged, 1 files removed, 0 files unresolved

digo@ubuntu:~/devel/microformats_tests$ hg mv Rakefile rakefile

conteúdo do rakefile (branch working):

# Walter Cruz
# a rakefile for working with these microformats test files. Maintained by ryan king <ryan@theryanking.com>.

digo@ubuntu:~/devel/microformats_tests$ hg update -C default
3 files updated, 0 files merged, 3 files removed, 0 files unresolved

conteúdo do rakefile (branch default):

# a rakefile for working with these microformats test files. Maintained by ryan king <ryan@theryanking.com>.
# tutorial mercurial
digo@ubuntu:~/devel/microformats_tests$ hg merge working
abort: outstanding uncommitted changes

digo@ubuntu:~/devel/microformats_tests$ hg merge -f working
3 files updated, 1 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)

conteúdo após merge:

# Walter Cruz
# a rakefile for working with these microformats test files. Maintained by ryan king <ryan@theryanking.com>.
# tutorial mercurial

Considerações:

Finda a jornada, alguns pontos:

  • Atualmente o git oferece mais opções que o mercurial. O stash é bacana, e a adição iterativa de arquivos é interessante também. Algumas dessas coisas puderam ser resolvidas pelo uso de extensões, mas ainda assim não trazem uma equivalência total. Por exemplo, no mercurial, não é possível remover um branch.
  • Eu gosto dos comandos do mercurial :) - A principal diferença em relação ao git está na área dos branches.
  • Gostaria de ler em algum lugar sobre as diferenças internas de implementação entre ambos.
  • Não sei ainda qual é o padrão para trabalhar com um repositório mercurial sincronizando com um subversion. O que tenho feito até agora é migrar meus antigos repositórios.
  • Eu não gosto de CVS (Sim, o artigo não tem nada a ver com CVS, mas o código do b2evolution está no CVS, e eu tenho de usá-lo de vez em quando).
  • O git pode ser publicado na web usando o gitweb. O mercurial pode ser publicado facilmente na web também.
  • Gostei do mercurial me avisar ao tentar fazer um merge sem ter comitado as coisas antes.
  • Atualmente, me parece que o git tem coisas que o mercurial não tem. Não sei do inverso.

Enquanto eu escrevia esse texto, o Akita publicou uma entrevista com Chris Wanstrath com uma frase interessante: "As far as other solutions go, it’s Rails vs Django all over again. If you use Mercurial, that’s fine. The two are so similar (yes, Git does work great on Windows) that as long as people move to distributed source control, it’s still a win."

Sobre a questão de hospedagem para mercurial, eu sugiro uma olhada no assembla.


Email por Walter Cruz em scm, mercurial
Tags: git, mercurial

Endereço de trackback para este post

Trackback URL (clique direito e copie atalho/localização do link)

Sem feedback para esse post ainda

Deixe seu comentário


Seu endereço de e-mail não será revelado nesse site.

Sua URL será exibida.
PobreExcelente
=> :!: :?: :idea: :) :D :p B) ;) :> :roll: :oops: :| :-/ :( >:( :'( |-| :>> ;D :P :)) 88| :. :no: XX( :lalala: :crazy: >:XX
(Quebras de linha se tornam <br />)
(Nome, e-mail & website)
(Permitir que usuários o contatem através de um formulário eletrônico (seu e-mail não será exibido.))

You can just use your OpenID to provide your name, e-mail and url.

Busca

Recomendações

Tambores de Minas

Estatísticas

Esse blog tem 165 posts e 536 comentários, com posts publicados no período de 15/08/2005 a 21/07/2008.

powered by b2evolution free blog software