Bound branch implementation

John A Meinel john at arbash-meinel.com
Sun Nov 13 04:04:46 GMT 2005


Nathaniel McCallum wrote:
> On Sat, 2005-11-12 at 20:50 -0600, John A Meinel wrote:
>> One use case that comes up fairly often is wanting to have a public
>> location where people can download your branches, while still having a
>> local branch that you can use offline.
>> Also, frequently people want to have some sort of centralized
>> development, where they have a shared branch that multiple people can
>> commit to. In this sort of mode, you have to update your local tree
>> before you can commit.
>>
>> So, I think I have an implementation which works. It is built off of
>> Robert's integration branch, and is available from here:
>> http://bzr.arbash-meinel.com/branches/bzr/bound-branch/
>>

...

> 
> Please support this!  I haven't been following much bzr development as
> my wife and I just had a baby.  so... what is the problem with updating
> remote working trees?

Congratulations!!!

> 
> Also, could you give a little demo of how bound branches work?

The wiki page discussing it is available here:
http://bazaar.canonical.com/LockStepDevelopment


The basic flow would be something like:

$ bzr get --bound /path/to/other/branch local_branch
$ cd local_branch
<hack hack>
$ bzr commit -m "Added a new feature"
# At this point, the remote branch will be updated with
# the same commit
<hack some more>
# Someone commits to /path/to/other/branch in the meantime
$ bzr commit -m "Another new feature"
bzr: ERROR: Remote branch has been updated, use bzr pull to update
$ bzr pull
# Review new changes to tree
$ bzr commit -m "Another new feature"
# This time it succeeds.

# Go offline
$ bzr commit -m "Did something"
bzr: ERROR: unable to connect to remote branch
$ bzr unbind
$ bzr commit -m "This is a local commit"
# Come back online
$ bzr bind
# If nothing was committed, this will push your changes
# to the remote tree, and leave you back in the bound state
# Otherwise you will get:
bzr: ERROR: Trees have diverged. You must merge, and push the changes

$ bzr merge
$ bzr commit -m "Joining trees"
$ bzr push # Add the joining revision to the remote tree
$ bzr bind # This should succeed,
           # and set local revision-history = remote revision-history


In general, bound branches are an attempt to bring back some form of
centralized development with bzr. Right now, since each branch is
completely independent, users have to be careful to run "bzr pull"
before a commit, and "bzr push" after a commit. These changes would take
care of some of that for you.
With a bound branch, everything is still recorded locally, so all
history, etc, operations are fast. It is just at pull/commit time that
it makes sure your local tree is up-to-date with the remote tree.

On an implementation detail, I hook into the "set_revision_history"
function since that is the last step before a commit or pull succeeds.
At that point all of the store entries have been updated, so it is a
simple matter of just doing a regular 'pull' type operation from the
remote object, as long as you fake that the local history has been updated.

It does mean that if a commit fails, you end up with an unreferenced
revision in your store, but it doesn't really hurt anything. If people
really care, I might try to hook into pull and commit directly. I just
thought this would be the easiest way to do it, since no matter what the
code path, it eventually calls set_revision_history(), and at that time,
I know I can get everything out of the local store.

Another detail I wanted to mention. Right now, I only set a file called
".bzr/bound" in the tree. Which means that old versions of bzr will
ignore it, and commit as normal.
I would consider changing the ".bzr/branch-format" so that other
versions of bzr which have not been told about bound branches would fail
to read it at all. It means that even though all commands would normally
work, we are forcing them to fail, because we don't want to accidentally
pull or commit on thetree. Do people feel that this is necessary? (I
know while testing I accidentally committed once)

John
=:->


> 
> Nathaniel
> 



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20051112/0688b611/attachment.pgp 


More information about the bazaar mailing list