~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: aaron.bentley at utoronto
  • Date: 2005-08-25 02:10:04 UTC
  • mto: (1092.1.41) (1185.3.4)
  • mto: This revision was merged to the branch mainline in revision 1139.
  • Revision ID: aaron.bentley@utoronto.ca-20050825021004-a7afd22f3dd52b2e
pending merges, common ancestor work properly

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
2
 
 
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
 
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
 
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
 
18
 
import os
 
1
from bzrlib.merge_core import merge_flex, ApplyMerge3, BackupBeforeChange
 
2
from bzrlib.changeset import generate_changeset, ExceptionConflictHandler
 
3
from bzrlib.changeset import Inventory, Diff3Merge
 
4
from bzrlib import find_branch
 
5
import bzrlib.osutils
 
6
from bzrlib.errors import BzrCommandError
 
7
from bzrlib.delta import compare_trees
 
8
from trace import mutter, warning
 
9
import os.path
19
10
import tempfile
20
11
import shutil
21
12
import errno
22
13
from fetch import greedy_fetch
23
14
 
24
 
import bzrlib.osutils
25
 
import bzrlib.revision
26
 
from bzrlib.merge_core import merge_flex, ApplyMerge3, BackupBeforeChange
27
 
from bzrlib.changeset import generate_changeset, ExceptionConflictHandler
28
 
from bzrlib.changeset import Inventory, Diff3Merge
29
 
from bzrlib.branch import find_branch
30
 
from bzrlib.errors import BzrCommandError, UnrelatedBranches, NoCommonAncestor
31
 
from bzrlib.errors import NoCommits
32
 
from bzrlib.delta import compare_trees
33
 
from bzrlib.trace import mutter, warning
34
 
from bzrlib.fetch import greedy_fetch
35
 
from bzrlib.revision import is_ancestor
36
15
 
37
16
# comments from abentley on irc: merge happens in two stages, each
38
17
# of which generates a changeset object
40
19
# stage 1: generate OLD->OTHER,
41
20
# stage 2: use MINE and OLD->OTHER to generate MINE -> RESULT
42
21
 
 
22
class UnrelatedBranches(BzrCommandError):
 
23
    def __init__(self):
 
24
        msg = "Branches have no common ancestor, and no base revision"\
 
25
            " specified."
 
26
        BzrCommandError.__init__(self, msg)
 
27
 
 
28
 
43
29
class MergeConflictHandler(ExceptionConflictHandler):
44
30
    """Handle conflicts encountered while merging.
45
31
 
192
178
    def has_id(self, file_id):
193
179
        return self.tree.has_id(file_id)
194
180
 
195
 
    def has_or_had_id(self, file_id):
196
 
        if file_id == self.tree.inventory.root.file_id:
197
 
            return True
198
 
        return self.tree.inventory.has_id(file_id)
199
 
 
200
 
    def has_or_had_id(self, file_id):
201
 
        if file_id == self.tree.inventory.root.file_id:
202
 
            return True
203
 
        return self.tree.inventory.has_id(file_id)
204
 
 
205
181
    def readonly_path(self, id):
206
182
        if id not in self.tree:
207
183
            return None
227
203
    """Merge changes into a tree.
228
204
 
229
205
    base_revision
230
 
        tuple(path, revision) Base for three-way merge.
 
206
        Base for three-way merge.
231
207
    other_revision
232
 
        tuple(path, revision) Other revision for three-way merge.
 
208
        Other revision for three-way merge.
233
209
    this_dir
234
210
        Directory to merge changes into; '.' by default.
235
211
    check_clean
238
214
    all available ancestors of other_revision and base_revision are
239
215
    automatically pulled into the branch.
240
216
    """
241
 
    from bzrlib.revision import common_ancestor, MultipleRevisionSources
 
217
    from bzrlib.revision import common_ancestor, is_ancestor
 
218
    from bzrlib.revision import MultipleRevisionSources
242
219
    from bzrlib.errors import NoSuchRevision
243
220
    tempdir = tempfile.mkdtemp(prefix="bzr-")
244
221
    try:
257
234
                                            this_branch)
258
235
        if other_revision[1] == -1:
259
236
            other_rev_id = other_branch.last_patch()
260
 
            if other_rev_id is None:
261
 
                raise NoCommits(other_branch)
262
237
            other_basis = other_rev_id
263
238
        elif other_revision[1] is not None:
264
239
            other_rev_id = other_branch.lookup_revision(other_revision[1])
266
241
        else:
267
242
            other_rev_id = None
268
243
            other_basis = other_branch.last_patch()
269
 
            if other_basis is None:
270
 
                raise NoCommits(other_branch)
271
244
        if base_revision == [None, None]:
272
 
            try:
273
 
                base_rev_id = common_ancestor(this_rev_id, other_basis, 
274
 
                                              this_branch)
275
 
            except NoCommonAncestor:
 
245
            base_rev_id = common_ancestor(this_rev_id, other_basis, 
 
246
                                          this_branch)
 
247
            if base_rev_id is None:
276
248
                raise UnrelatedBranches()
277
249
            base_tree = get_revid_tree(this_branch, base_rev_id, tempdir, 
278
250
                                       "base", None)
287
259
                base_rev_id = base_branch.lookup_revision(base_revision[1])
288
260
            if base_rev_id is not None:
289
261
                base_is_ancestor = is_ancestor(this_rev_id, base_rev_id, 
290
 
                                               MultipleRevisionSources(this_branch, 
291
 
                                                                       base_branch))
 
262
                                               MultipleRevisionSources(
 
263
                                               this_branch, 
 
264
                                               base_branch))
292
265
            else:
293
266
                base_is_ancestor = False
294
267
        if file_list is None:
310
283
        merge_inner(this_branch, other_tree, base_tree, tempdir, 
311
284
                    ignore_zero=ignore_zero, backup_files=backup_files, 
312
285
                    merge_type=merge_type, interesting_ids=interesting_ids)
313
 
        if base_is_ancestor and other_rev_id is not None\
314
 
            and other_rev_id not in this_branch.revision_history():
 
286
        if base_is_ancestor and other_rev_id is not None:
315
287
            this_branch.add_pending_merge(other_rev_id)
316
288
    finally:
317
289
        shutil.rmtree(tempdir)
363
335
            if path == '.':
364
336
                path = ''
365
337
            else:
366
 
                assert path.startswith('.' + os.sep), "path is %s" % path
 
338
                assert path.startswith('./'), "path is %s" % path
367
339
            path = path[2:]
368
340
        adjust_ids.append((path, id))
369
341
    if len(adjust_ids) > 0: