'Selective' branching of files: is it possible in Mercurial?

Arne Babenhauserheide arne_bab at web.de
Mon Mar 16 10:36:29 CDT 2009


Am Sonntag 15 März 2009 15:21:15 schrieb Vladimir:
> In Borland Starteam, there is a possibility to make some files to be
> identical along different branches, while allowing other files to exist in
> "branched" state. More exactly, for such files one of the branches simply
> contains a link to an object at the another branch - and all changes to
> that file are visible from both branches. Is it possible to get similar
> behavior in Mercurial? Or, if not, how should Alice, Bob and Tom act?
> Moving component.c into a separate repository is not very convenient.

I don't know a way to exactly copy that behaviour, but what I'd do to get as 
close as possible is keeping the diverging changes in component.c in named 
branches (A and B) and only changing them there. 

Then you add a hook and a default in the projects .hg/hgrc (BRANCH is either A 
or B): 

    [hooks]
    update = hg revert -r BRANCH component.c
    
    [defaults]
    commit = -X component.c

This will make sure that the component.c is always the one from the branch, 
but all other files are from your normal work revision. 

If you want to commit a change to component.c you have to pass it explicitely 
on the command line when committing. 

DANGER: If you update your repo before comitting, your changes to the file 
will land in component.c.orig. See hg help revert: 

    Modified files are saved with a .orig suffix before reverting.
    To disable these backups, use --no-backup.

You then change the workflow by saying: 
To commit a change to component.c you first update to branch A or B and commit 
it there. 

If someone violates that workflow, the only problem will be that noone will 
see the change, since the update hook will directly revert back to the version 
in the branch. 

Even a simple commit hook should suffice to make this workflow automatic. 

To make this easier, you could have a default version and a changed version of 
the file, so only people with the changed version need to use the hgrc 
settings for hook and defaults. 

I don't know if that's the best way to do it, but it should work and get close 
to the behaviour you currently have. 

*All below is optional for added convenience:* 

Since this looks quite easy, you should also be able to write a simple 
extension, which manages a list of files and associated branches (for example 
in the tracked file .hgbranchedfiles) and does the steps automatically. 

For an example extension, please have a look at the hello world extension: 
- http://bitbucket.org/ArneBab/hello

To read what you can do with extensions, please see WritingExtensions: 
- http://www.selenic.com/mercurial/wiki/index.cgi/WritingExtensions

Best wishes, 
Arne
-- 
-- Ein Würfel System: http://1w6.org - einfach saubere (Rollenspiel-) Regeln.
-- Infinite Hands: http://infinite-hands.draketo.de - singing a part of the 
history of free software.
-- My stuff: http://draketo.de - stories, songs, poems, programs and stuff :)

-- PGP/GnuPG: http://draketo.de/inhalt/ich/pubkey.txt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://selenic.com/pipermail/mercurial/attachments/20090316/76c63024/attachment.pgp 


More information about the Mercurial mailing list