~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-12-14 18:03:42 UTC
  • mfrom: (4871.4.2 admin-guide-upgrade)
  • Revision ID: pqm@pqm.ubuntu.com-20091214180342-nk22cwvqcz54e331
(nmb) Add upgrade section to admin-guide

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
1627
1627
                                this_tree=self,
1628
1628
                                pb=pb,
1629
1629
                                change_reporter=change_reporter)
1630
 
                    basis_root_id = basis_tree.get_root_id()
1631
 
                    new_root_id = new_basis_tree.get_root_id()
1632
 
                    if basis_root_id != new_root_id:
1633
 
                        self.set_root_id(new_root_id)
 
1630
                    if (basis_tree.inventory.root is None and
 
1631
                        new_basis_tree.inventory.root is not None):
 
1632
                        self.set_root_id(new_basis_tree.get_root_id())
1634
1633
                finally:
1635
1634
                    pb.finished()
1636
1635
                    basis_tree.unlock()
2192
2191
        """
2193
2192
        raise NotImplementedError(self.unlock)
2194
2193
 
2195
 
    _marker = object()
2196
 
 
2197
 
    def update(self, change_reporter=None, possible_transports=None,
2198
 
               revision=None, old_tip=_marker):
 
2194
    def update(self, change_reporter=None, possible_transports=None):
2199
2195
        """Update a working tree along its branch.
2200
2196
 
2201
2197
        This will update the branch if its bound too, which means we have
2219
2215
        - Merge current state -> basis tree of the master w.r.t. the old tree
2220
2216
          basis.
2221
2217
        - Do a 'normal' merge of the old branch basis if it is relevant.
2222
 
 
2223
 
        :param revision: The target revision to update to. Must be in the
2224
 
            revision history.
2225
 
        :param old_tip: If branch.update() has already been run, the value it
2226
 
            returned (old tip of the branch or None). _marker is used
2227
 
            otherwise.
2228
2218
        """
2229
2219
        if self.branch.get_bound_location() is not None:
2230
2220
            self.lock_write()
2231
 
            update_branch = (old_tip is self._marker)
 
2221
            update_branch = True
2232
2222
        else:
2233
2223
            self.lock_tree_write()
2234
2224
            update_branch = False
2236
2226
            if update_branch:
2237
2227
                old_tip = self.branch.update(possible_transports)
2238
2228
            else:
2239
 
                if old_tip is self._marker:
2240
 
                    old_tip = None
2241
 
            return self._update_tree(old_tip, change_reporter, revision)
 
2229
                old_tip = None
 
2230
            return self._update_tree(old_tip, change_reporter)
2242
2231
        finally:
2243
2232
            self.unlock()
2244
2233
 
2245
2234
    @needs_tree_write_lock
2246
 
    def _update_tree(self, old_tip=None, change_reporter=None, revision=None):
 
2235
    def _update_tree(self, old_tip=None, change_reporter=None):
2247
2236
        """Update a tree to the master branch.
2248
2237
 
2249
2238
        :param old_tip: if supplied, the previous tip revision the branch,
2264
2253
            last_rev = self.get_parent_ids()[0]
2265
2254
        except IndexError:
2266
2255
            last_rev = _mod_revision.NULL_REVISION
2267
 
        if revision is None:
2268
 
            revision = self.branch.last_revision()
2269
 
        else:
2270
 
            if revision not in self.branch.revision_history():
2271
 
                raise errors.NoSuchRevision(self.branch, revision)
2272
 
        if last_rev != _mod_revision.ensure_null(revision):
2273
 
            # merge tree state up to specified revision.
 
2256
        if last_rev != _mod_revision.ensure_null(self.branch.last_revision()):
 
2257
            # merge tree state up to new branch tip.
2274
2258
            basis = self.basis_tree()
2275
2259
            basis.lock_read()
2276
2260
            try:
2277
 
                to_tree = self.branch.repository.revision_tree(revision)
2278
 
                to_root_id = to_tree.get_root_id()
2279
 
                if (basis.inventory.root is None
2280
 
                    or basis.inventory.root.file_id != to_root_id):
2281
 
                    self.set_root_id(to_root_id)
 
2261
                to_tree = self.branch.basis_tree()
 
2262
                if basis.inventory.root is None:
 
2263
                    self.set_root_id(to_tree.get_root_id())
2282
2264
                    self.flush()
2283
2265
                result += merge.merge_inner(
2284
2266
                                      self.branch,
2286
2268
                                      basis,
2287
2269
                                      this_tree=self,
2288
2270
                                      change_reporter=change_reporter)
2289
 
                self.set_last_revision(revision)
2290
2271
            finally:
2291
2272
                basis.unlock()
2292
2273
            # TODO - dedup parents list with things merged by pull ?
2293
2274
            # reuse the tree we've updated to to set the basis:
2294
 
            parent_trees = [(revision, to_tree)]
 
2275
            parent_trees = [(self.branch.last_revision(), to_tree)]
2295
2276
            merges = self.get_parent_ids()[1:]
2296
2277
            # Ideally we ask the tree for the trees here, that way the working
2297
2278
            # tree can decide whether to give us the entire tree or give us a
2327
2308
            #       should be able to remove this extra flush.
2328
2309
            self.flush()
2329
2310
            graph = self.branch.repository.get_graph()
2330
 
            base_rev_id = graph.find_unique_lca(revision, old_tip)
 
2311
            base_rev_id = graph.find_unique_lca(self.branch.last_revision(),
 
2312
                                                old_tip)
2331
2313
            base_tree = self.branch.repository.revision_tree(base_rev_id)
2332
2314
            other_tree = self.branch.repository.revision_tree(old_tip)
2333
2315
            result += merge.merge_inner(