~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Robert Collins
  • Date: 2006-03-05 02:20:07 UTC
  • mto: This revision was merged to the branch mainline in revision 1590.
  • Revision ID: robertc@robertcollins.net-20060305022007-53e5907d083453e8
Local commits appear to be working properly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1161
1161
 
1162
1162
    @needs_write_lock
1163
1163
    def update(self):
 
1164
        """Update a working tree along its branch.
 
1165
 
 
1166
        This will update the branch if its bound too, which means we have multiple trees involved:
 
1167
        The new basis tree of the master.
 
1168
        The old basis tree of the branch.
 
1169
        The old basis tree of the working tree.
 
1170
        The current working tree state.
 
1171
        pathologically all three may be different, and non ancestors of each other.
 
1172
        Conceptually we want to:
 
1173
        Preserve the wt.basis->wt.state changes
 
1174
        Transform the wt.basis to the new master basis.
 
1175
        Apply a merge of the old branch basis to get any 'local' changes from it into the tree.
 
1176
        Restore the wt.basis->wt.state changes.
 
1177
 
 
1178
        There isn't a single operation at the moment to do that, so we:
 
1179
        Merge current state -> basis tree of the master w.r.t. the old tree basis.
 
1180
        Do a 'normal' merge of the old branch basis if it is relevant.
 
1181
        """
1164
1182
        old_tip = self.branch.update()
 
1183
        if old_tip is not None:
 
1184
            self.add_pending_merge(old_tip)
1165
1185
        self.branch.lock_read()
1166
1186
        try:
1167
 
            if self.last_revision() == self.branch.last_revision():
1168
 
                # no change
1169
 
                return
1170
 
            basis = self.basis_tree()
1171
 
            to_tree = self.branch.basis_tree()
1172
 
            result = merge_inner(self.branch,
1173
 
                                 to_tree,
1174
 
                                 basis,
1175
 
                                 this_tree=self)
1176
 
            self.set_last_revision(self.branch.last_revision())
 
1187
            result = 0
 
1188
            if self.last_revision() != self.branch.last_revision():
 
1189
                # merge tree state up to new branch tip.
 
1190
                basis = self.basis_tree()
 
1191
                to_tree = self.branch.basis_tree()
 
1192
                result += merge_inner(self.branch,
 
1193
                                      to_tree,
 
1194
                                      basis,
 
1195
                                      this_tree=self)
 
1196
                self.set_last_revision(self.branch.last_revision())
 
1197
            if old_tip and old_tip != self.last_revision():
 
1198
                # our last revision was not the prior branch last reivison
 
1199
                # and we have converted that last revision to a pending merge.
 
1200
                # base is somewhere between the branch tip now
 
1201
                # and the now pending merge
 
1202
                from bzrlib.revision import common_ancestor
 
1203
                try:
 
1204
                    base_rev_id = common_ancestor(self.branch.last_revision(),
 
1205
                                                  old_tip,
 
1206
                                                  self.branch.repository)
 
1207
                except errors.NoCommonAncestor:
 
1208
                    base_rev_id = None
 
1209
                base_tree = self.branch.repository.revision_tree(base_rev_id)
 
1210
                other_tree = self.branch.repository.revision_tree(old_tip)
 
1211
                result += merge_inner(self.branch,
 
1212
                                      other_tree,
 
1213
                                      base_tree,
 
1214
                                      this_tree=self)
1177
1215
            return result
1178
1216
        finally:
1179
1217
            self.branch.unlock()