"update -r REVNO" support

Martin Pool mbp at sourcefrog.net
Mon Aug 6 06:25:45 BST 2007


On 8/4/07, Robert Widhopf-Fenk <hack at robf.de> wrote:
> Hi,
>
> "revert -r" was not enough for me, so I tried to implement
> "update -r" and better "bzr st" for outdated working trees.

Thanks, that would be nice to have that in.

Please remember to put '[MERGE]' at the start of your mail subject, so
that Bundle Buggy will see your mail and make sure it gets proper
attention and is not dropped.

> === modified file 'bzrlib/builtins.py'
> --- bzrlib/builtins.py  2007-07-31 20:02:47 +0000
> +++ bzrlib/builtins.py  2007-08-04 02:05:49 +0000
> @@ -1013,9 +1013,10 @@
>
>      _see_also = ['pull', 'working-trees', 'status-flags']
>      takes_args = ['dir?']
> +    takes_options = ['revision']
>      aliases = ['up']
> -
> -    def run(self, dir='.'):
> +
> +    def run(self, revision=None, dir='.'):
>          tree = WorkingTree.open_containing(dir)[0]
>          master = tree.branch.get_master_branch()
>          if master is not None:

I think you should add something to the help message for update
explaining that this is available - also that after update -r you
typically will not be able to commit if you're not at the tip of the
branch?

It might be nice to override the help for -r and keep the other
settings, but that probably needs an improvement to the option system,
eg

  takes_options = [ modified_global_option('revision', help='Update to
this revision')]...

> @@ -1023,10 +1024,18 @@
>          else:
>              tree.lock_tree_write()
>          try:
> +           if revision:
> +               if len(revision) > 1:
> +                   raise errors.BzrCommandError(
> +                       'bzr update --revision takes exactly 1 revision value')
> +               branch_location = osutils.getcwd()
> +               source = Branch.open(branch_location)
> +               to_rev = _mod_revision.ensure_null(revision[0].in_history(source)[1])
> +           else:
> +               to_rev = _mod_revision.ensure_null(tree.branch.last_revision())
>              existing_pending_merges = tree.get_parent_ids()[1:]
> -            last_rev = _mod_revision.ensure_null(tree.last_revision())
> -            if last_rev == _mod_revision.ensure_null(
> -                tree.branch.last_revision()):
> +           last_rev = _mod_revision.ensure_null(tree.last_revision())
> +           if last_rev == to_rev:
>                  # may be up to date, check master too.
>                  if master is None or last_rev == _mod_revision.ensure_null(
>                      master.last_revision()):

Why are you using getcwd rather tree.branch?

Maybe you should add a test for ::

  bzr update -r 3 ../otherbranch

> @@ -1034,7 +1043,8 @@
>                      note("Tree is up to date at revision %d." % (revno,))
>                      return 0
>              conflicts = tree.update(delta._ChangeReporter(
> -                                        unversioned_filter=tree.is_ignored))
> +                                        unversioned_filter=tree.is_ignored),
> +                                   revision and to_rev or None)
>              revno = tree.branch.revision_id_to_revno(
>                  _mod_revision.ensure_null(tree.last_revision()))
>              note('Updated to revision %d.' % (revno,))
>

I'd rather you just set to_rev appropriately rather than the
pseudo-ternary here.

> === modified file 'bzrlib/status.py'
> --- bzrlib/status.py    2007-07-23 14:27:42 +0000
> +++ bzrlib/status.py    2007-08-04 00:14:16 +0000
> @@ -122,7 +122,12 @@
>          new_is_working_tree = True
>          if revision is None:
>              if wt.last_revision() != wt.branch.last_revision():
> -                warning("working tree is out of date, run 'bzr update'")
> +                b_revno = wt.branch.last_revision_info()[0]
> +                wt_revno = wt.branch.revision_id_to_revno(wt.last_revision())
> +                missing = b_revno - wt_revno
> +                warning("Working tree is at revno %d missing %d revision%s!" %
> +                        (wt_revno, missing,
> +                         (missing > 1) and "s" or ""))
>              new = wt
>              old = new.basis_tree()
>          elif len(revision) > 0:

Giving more information here is good.

I don't think you should remove the suggestion to run update.  It
might be even better to say "working tree is out of date with its
branch", or something else that helps  the user understand what's
happening.  Suggestions?

Getting the branch last revision is potentially expensive (for
checkouts), so please just do it once and remember it.

In general we don't put '!' at the end of messages.  Stay calm. :-)

>
> === modified file 'bzrlib/workingtree.py'
> --- bzrlib/workingtree.py       2007-07-25 21:25:00 +0000
> +++ bzrlib/workingtree.py       2007-08-04 02:05:49 +0000
> @@ -2001,7 +2001,7 @@
>          """
>          raise NotImplementedError(self.unlock)
>
> -    def update(self, change_reporter=None):
> +    def update(self, change_reporter=None, to_revision=None):
>          """Update a working tree along its branch.
>
>          This will update the branch if its bound too, which means we have

It's almost obvious but please document the parameter.  Maybe it
should be to_revision_id to be more clear.

I don't think you have a workingtree_implementation test of this new
parameter and you probably need one, to make sure it works with every
kind of tree.

> @@ -2096,6 +2099,8 @@
>                  parent_trees.append(
>                      (old_tip, self.branch.repository.revision_tree(old_tip)))
>              self.set_parent_trees(parent_trees)
> +            if to_revision is not None:
> +                self.set_parent_ids([to_rev])
>              last_rev = parent_trees[0][0]
>          else:
>              # the working tree had the same last-revision as the master
>

Is that needed if we've done set_parent_trees?  I think not?

Could you please update your patch and resubmit.

-- 
Martin



More information about the bazaar mailing list