Problem with Mercurial and Branches

Christian Krebs chrisk at opera.com
Tue Jan 13 17:03:49 UTC 2009


On Tue, 13 Jan 2009 03:50:14 +0100, Paul Franz <theandromedan at gmail.com>  
wrote:

>
>
> Christian Krebs wrote:
>> On Sat, 10 Jan 2009 06:48:55 +0100, Bill Barry  
>> <after.fallout at gmail.com>  wrote:
>>
>>
>>> Christian Krebs wrote:
>>>
>>>> On Fri, 09 Jan 2009 19:51:36 +0100, Benoit Boissinot
>>>> <benoit.boissinot at ens-lyon.org> wrote:
>>>>
>>>>
>>>>
>>>>> On Fri, Jan 09, 2009 at 04:22:51PM +0100, Christian Krebs wrote:
>>>>>
>>>>>
>>>>>> Hi
>>>>>>
>>>>>> i hope we can get some help here for a problem we couldn't solve
>>>>>> ourself.
>>>>>>
>>>>>> We are using Mercurial in the Dragonfly project at Opera.
>>>>>>
>>>>>> We have IMO some serious problem with it.
>>>>>>
>>>>>>
>>>>> Would it be possible to provide a script to reproduce your issue? At
>>>>> least for me it would be more clear.
>>>>>
>>>>> regards,
>>>>>
>>>>> Benoit
>>>>>
>>>>>
>>>>>
>>>> this is the command log if that helps:
>>>>
>>>> local-path>hg init source
>>>>
>>>> local-path>cd source
>>>>
>>>> local-path\source>hg add
>>>> adding file-1.txt
>>>> adding file-2.txt
>>>>
>>>> local-path\source>hg ci -m "added files"
>>>>
>>>> local-path\source>hg branch b1
>>>> marked working directory as branch b1
>>>>
>>>> local-path\source>hg ci -m "created branch b1"
>>>>
>>>> local-path\source>hg branch b2
>>>> marked working directory as branch b2
>>>>
>>>> local-path\source>hg ci -m "created branch b2"
>>>>
>>>> local-path\source>cd ..
>>>>
>>>> local-path>hg clone source copy
>>>> updating working directory
>>>> 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
>>>>
>>>> local-path>cd source
>>>>
>>>> local-path\source>hg up b1
>>>> 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
>>>>
>>>> local-path\source>hg status
>>>> M file-1.txt
>>>>
>>>> local-path\source>hg ci -m "edited file 1 in source in b1"
>>>> created new head
>>>>
>>>> local-path\source>hg up b2
>>>> 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
>>>>
>>>> local-path\source>hg merge b1
>>>> 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
>>>> (branch merge, don't forget to commit)
>>>>
>>>> local-path\source>hg ci -m "merged b1 to b2 in source"
>>>>
>>>> local-path\source>cd ../copy
>>>>
>>>> local-path\copy>hg up b1
>>>> 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
>>>>
>>>> local-path\copy>hg status
>>>> M file-2.txt
>>>>
>>>> local-path\copy>hg ci -m "edited file 2 in copy in b1"
>>>> created new head
>>>>
>>>> local-path\copy>hg up b2
>>>> 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
>>>>
>>>> local-path\copy>hg merge b1
>>>> 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
>>>> (branch merge, don't forget to commit)
>>>>
>>>> local-path\copy>hg ci -m "merged b1 to b2 in copy"
>>>>
>>>> local-path\copy>hg pull
>>>> pulling from local-path\source
>>>> searching for changes
>>>> adding changesets
>>>> adding manifests
>>>> adding file changes
>>>> added 2 changesets with 1 changes to 1 files (+1 heads)
>>>> (run 'hg heads' to see heads, 'hg merge' to merge)
>>>>
>>>> local-path\copy>hg heads
>>>> changeset:   6:9cf3c6bfa8c0
>>>> branch:      b2
>>>> tag:         tip
>>>> parent:      2:42281141b974
>>>> parent:      5:280c7f8ff422
>>>> user:        Christian Krebs <chrisk at opera.com>
>>>> date:        Fri Jan 09 20:06:35 2009 +0100
>>>> summary:     merged b1 to b2 in source
>>>>
>>>> changeset:   4:cc7e9f66181b
>>>> branch:      b2
>>>> parent:      2:42281141b974
>>>> parent:      3:2fbe16571989
>>>> user:        Christian Krebs <chrisk at opera.com>
>>>> date:        Fri Jan 09 20:08:49 2009 +0100
>>>> summary:     merged b1 to b2 in copy
>>>>
>>>>
>>>> local-path\copy>hg merge
>>>> 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
>>>> (branch merge, don't forget to commit)
>>>>
>>>> local-path\copy>hg ci -m "merged the two heads in copy"
>>>>
>>>> local-path\copy>hg up b1
>>>> 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
>>>>
>>>> local-path\copy>cat file-2.txt
>>>>
>>>> local-path\copy>
>>>>
>>>>
>>> Your problem is that you have 2 heads in the b1 branch, try this:
>>> hg up -C -r 5 (head 1 of b1)
>>> hg merge -r 3 (head 2 of b1)
>>> hg ci -m"merged multiple heads of the b1 branch"
>>> hg up -C b2
>>> hg merge
>>> hg ci -m"merged b1 into b2"
>>>
>>
>> Thanks, basically i know how to fix it. The problem is IMO that  
>> Mercurial  does not give any warning when one tries to merge the two  
>> "visible" heads  (the ones you get with hg heads). After pulling from  
>> the source there are  actually four heads, each branch with two. IMO  
>> Mercurial should not allow  in that situation to just merge the two  
>> "visible" heads while disregarding  completely the two other heads of  
>> the non active branch. Either it should  merge per named branch or  
>> display a warning or something, but the current  implementation of  
>> named branches is IMO broken by design, it is too easy  to just "loose"  
>> commits.
>>
> I think the solution is to do a:
>
> hg up b1
> hg merge (which should merge to two branch heads)
> hg ci -m "merged multiple heads of the b1 branch"

Quickly tested, but this does not work. Merging after "hg up b1"  does  
merge the heads of the b2 branch, which is not surprising, because this  
are the two heads in the repo.

>
> Then you will have 2 heads (i.e. changeset that has no children) one for  
> branch b1 and one for b2.

After that merge there is only one head.

> It should not be necessary to merge b2 to b1.
>
> "hg merge" seems to merge only the current branch, which makes sense.  
> Because you can't really merge multiple changesets branches at once.
>
>>> The easiest way to handle this is to have a repository that only ever
>>> contains b1; I think you could do this:
>>> cd local-path
>>> hg clone -r b1 copy b1copy
>>>
>>
>> Yes, thanks, after thinking over the weekend that is probably what we  
>> are  going to do.
>>
>>
>>> (if you cannot do this then I am pretty sure you can do hg init then hg
>>> pull -r b1)
>>>
>>> then when in b1copy, alias hg pull to be hg pull -r b1, and force push
>>> it to copy when you merge it down to one head (then merge it into b2
>>> back in the copy branch).
>>>
>>>
>>>
>
>





More information about the Mercurial mailing list