/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/workingtree.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-11-19 19:46:23 UTC
  • mfrom: (7524.2.5 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20201119194623-5tfi4z6ktdzo0z3y
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/394038

Show diffs side-by-side

added added

removed removed

Lines of Context:
1075
1075
        """
1076
1076
        raise NotImplementedError(self.unlock)
1077
1077
 
1078
 
    _marker = object()
1079
 
 
1080
1078
    def update(self, change_reporter=None, possible_transports=None,
1081
 
               revision=None, old_tip=_marker, show_base=False):
 
1079
               revision=None, old_tip=None, show_base=False):
1082
1080
        """Update a working tree along its branch.
1083
1081
 
1084
1082
        This will update the branch if its bound too, which means we have
1110
1108
            returned (old tip of the branch or None). _marker is used
1111
1109
            otherwise.
1112
1110
        """
1113
 
        if self.branch.get_bound_location() is not None:
1114
 
            self.lock_write()
1115
 
            update_branch = (old_tip is self._marker)
1116
 
        else:
1117
 
            self.lock_tree_write()
1118
 
            update_branch = False
1119
 
        try:
1120
 
            if update_branch:
1121
 
                old_tip = self.branch.update(possible_transports)
1122
 
            else:
1123
 
                if old_tip is self._marker:
1124
 
                    old_tip = None
1125
 
            return self._update_tree(old_tip, change_reporter, revision, show_base)
1126
 
        finally:
1127
 
            self.unlock()
1128
 
 
1129
 
    def _update_tree(self, old_tip=None, change_reporter=None, revision=None,
1130
 
                     show_base=False):
1131
 
        """Update a tree to the master branch.
1132
 
 
1133
 
        :param old_tip: if supplied, the previous tip revision the branch,
1134
 
            before it was changed to the master branch's tip.
1135
 
        """
1136
 
        # here if old_tip is not None, it is the old tip of the branch before
1137
 
        # it was updated from the master branch. This should become a pending
1138
 
        # merge in the working tree to preserve the user existing work.  we
1139
 
        # cant set that until we update the working trees last revision to be
1140
 
        # one from the new branch, because it will just get absorbed by the
1141
 
        # parent de-duplication logic.
1142
 
        #
1143
 
        # We MUST save it even if an error occurs, because otherwise the users
1144
 
        # local work is unreferenced and will appear to have been lost.
1145
 
        #
1146
 
        with self.lock_tree_write():
1147
 
            nb_conflicts = 0
1148
 
            try:
1149
 
                last_rev = self.get_parent_ids()[0]
1150
 
            except IndexError:
1151
 
                last_rev = _mod_revision.NULL_REVISION
1152
 
            if revision is None:
1153
 
                revision = self.branch.last_revision()
1154
 
 
1155
 
            old_tip = old_tip or _mod_revision.NULL_REVISION
1156
 
 
1157
 
            if not _mod_revision.is_null(old_tip) and old_tip != last_rev:
1158
 
                # the branch we are bound to was updated
1159
 
                # merge those changes in first
1160
 
                base_tree = self.basis_tree()
1161
 
                other_tree = self.branch.repository.revision_tree(old_tip)
1162
 
                nb_conflicts = merge.merge_inner(self.branch, other_tree,
1163
 
                                                 base_tree, this_tree=self,
1164
 
                                                 change_reporter=change_reporter,
1165
 
                                                 show_base=show_base)
1166
 
                if nb_conflicts:
1167
 
                    self.add_parent_tree((old_tip, other_tree))
1168
 
                    note(gettext('Rerun update after fixing the conflicts.'))
1169
 
                    return nb_conflicts
1170
 
 
1171
 
            if last_rev != _mod_revision.ensure_null(revision):
1172
 
                # the working tree is up to date with the branch
1173
 
                # we can merge the specified revision from master
1174
 
                to_tree = self.branch.repository.revision_tree(revision)
1175
 
                to_root_id = to_tree.path2id('')
1176
 
 
1177
 
                basis = self.basis_tree()
1178
 
                with basis.lock_read():
1179
 
                    if (basis.path2id('') is None or basis.path2id('') != to_root_id):
1180
 
                        self.set_root_id(to_root_id)
1181
 
                        self.flush()
1182
 
 
1183
 
                # determine the branch point
1184
 
                graph = self.branch.repository.get_graph()
1185
 
                base_rev_id = graph.find_unique_lca(self.branch.last_revision(),
1186
 
                                                    last_rev)
1187
 
                base_tree = self.branch.repository.revision_tree(base_rev_id)
1188
 
 
1189
 
                nb_conflicts = merge.merge_inner(self.branch, to_tree, base_tree,
1190
 
                                                 this_tree=self,
1191
 
                                                 change_reporter=change_reporter,
1192
 
                                                 show_base=show_base)
1193
 
                self.set_last_revision(revision)
1194
 
                # TODO - dedup parents list with things merged by pull ?
1195
 
                # reuse the tree we've updated to to set the basis:
1196
 
                parent_trees = [(revision, to_tree)]
1197
 
                merges = self.get_parent_ids()[1:]
1198
 
                # Ideally we ask the tree for the trees here, that way the working
1199
 
                # tree can decide whether to give us the entire tree or give us a
1200
 
                # lazy initialised tree. dirstate for instance will have the trees
1201
 
                # in ram already, whereas a last-revision + basis-inventory tree
1202
 
                # will not, but also does not need them when setting parents.
1203
 
                for parent in merges:
1204
 
                    parent_trees.append(
1205
 
                        (parent, self.branch.repository.revision_tree(parent)))
1206
 
                if not _mod_revision.is_null(old_tip):
1207
 
                    parent_trees.append(
1208
 
                        (old_tip, self.branch.repository.revision_tree(old_tip)))
1209
 
                self.set_parent_trees(parent_trees)
1210
 
                last_rev = parent_trees[0][0]
1211
 
            return nb_conflicts
 
1111
        raise NotImplementedError(self.update)
1212
1112
 
1213
1113
    def set_conflicts(self, arg):
1214
1114
        raise errors.UnsupportedOperation(self.set_conflicts, self)