[MERGE][RFC] switch for heavyweight checkouts

Ian Clatworthy ian.clatworthy at internode.on.net
Wed Dec 5 13:56:29 GMT 2007


The attached patch extends switch to support heavyweight checkouts. I've
marked this as RFC because I'm happy with it semantically but I
appreciate that others might not be.

Here's the NEWS item as it currently stands:

   * ``switch`` can now be used on heavyweight checkouts as well as
     lightweight ones. After switching a heavyweight checkout, the
     local branch is a mirror/cache of the new bound branch and
     uncommitted changes in the working tree are merged. As a safety
     check, if there are local commits in a checkout which have not
     been committed to the previously bound branch, then ``switch``
     fails unless the ``--force`` option is given.

So the contentious issue is whether the local branch ought to be truly a
mirror of the new bound branch or a superset of some kind. In order to
behave the same for light vs heavy, I think it needs to be a mirror. (My
only concern is that Robert indicated on IRC that "pull --overwrite" was
not the right thing for switch. I'm struggling to understand why but I'm
happy to learn.)

In case it helps add some context, Matthew Fuller explained in a recent
email thread that bound branches and checkouts can be intentionally
different depending on your point of view ...

> Well, they're very similar concepts, but there are subtle differences.
> When you use a 'bound branch', what you mean is 'keep this branch in
> sync with that other one'.  But when you use a checkout, heavy or
> light, what you mean is 'give me a working tree to work on this
> branch'; in the heavy case, you mean 'and cache everything locally too
> so I don't have to hit the network except to commit/update'.

The difference indeed becomes important when switching a heavyweight
checkout. My view is that, excluding uncommitted changes in the working
tree which ought to be merged in, switching a checkout should have the
same effect as removing the current checkout and creating a new one. In
other words, the local branch ought to be made a mirror of the branch
you're switching to. The risk with this is that local commits could be
lost. As explained in the NEWS item, the code explicitly checks for
those and fails if any are detected, so I feel it is safe. You can
override this using --force if required.

I'd also like feedback on behaviour when the existing reference branch
cannot be reached. The existing switch code silently handles this for
checkouts so users can switch to a branch that is accessible instead.
Now that we have a --force option, my thinking is that silently handling
this is wrong and that --force ought to be required in this scenario.
Does anyone have an opinion on this?

I'm happy to add more tests if required as well. With or without these,
the patch ought to be good enough for users keen for this functionality
to give it a test and to confirm it helps their workflow.

Ian C.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: switch-heavy-checkouts.patch
Type: text/x-patch
Size: 19252 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20071205/285b5f50/attachment-0001.bin 


More information about the bazaar mailing list