~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Martin Pool
  • Date: 2005-09-05 05:35:25 UTC
  • mfrom: (974.1.55)
  • Revision ID: mbp@sourcefrog.net-20050905053525-2112bac069dbe331
- merge various bug fixes from aaron

aaron.bentley@utoronto.ca-20050905020131-a2d5b7711dd6cd98

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
 
18
import os.path
 
19
import tempfile
 
20
import shutil
 
21
import errno
 
22
from fetch import greedy_fetch
 
23
 
 
24
import bzrlib.osutils
 
25
import bzrlib.revision
18
26
from bzrlib.merge_core import merge_flex, ApplyMerge3, BackupBeforeChange
19
27
from bzrlib.changeset import generate_changeset, ExceptionConflictHandler
20
28
from bzrlib.changeset import Inventory, Diff3Merge
21
29
from bzrlib.branch import find_branch
22
 
import bzrlib.osutils
23
30
from bzrlib.errors import BzrCommandError, UnrelatedBranches
24
31
from bzrlib.delta import compare_trees
25
 
from trace import mutter, warning
26
 
import os.path
27
 
import tempfile
28
 
import shutil
29
 
import errno
30
 
from fetch import greedy_fetch
31
 
 
 
32
from bzrlib.trace import mutter, warning
 
33
from bzrlib.fetch import greedy_fetch
 
34
from bzrlib.revision import is_ancestor
32
35
 
33
36
# comments from abentley on irc: merge happens in two stages, each
34
37
# of which generates a changeset object
193
196
            return True
194
197
        return self.tree.inventory.has_id(file_id)
195
198
 
 
199
    def has_or_had_id(self, file_id):
 
200
        if file_id == self.tree.inventory.root.file_id:
 
201
            return True
 
202
        return self.tree.inventory.has_id(file_id)
 
203
 
196
204
    def readonly_path(self, id):
197
205
        if id not in self.tree:
198
206
            return None
218
226
    """Merge changes into a tree.
219
227
 
220
228
    base_revision
221
 
        Base for three-way merge.
 
229
        tuple(path, revision) Base for three-way merge.
222
230
    other_revision
223
 
        Other revision for three-way merge.
 
231
        tuple(path, revision) Other revision for three-way merge.
224
232
    this_dir
225
233
        Directory to merge changes into; '.' by default.
226
234
    check_clean
256
264
            other_rev_id = None
257
265
            other_basis = other_branch.last_patch()
258
266
        if base_revision == [None, None]:
259
 
            if other_revision[1] == -1:
260
 
                o_revno = None
261
 
            else:
262
 
                o_revno = other_revision[1]
 
267
            base_rev_id = common_ancestor(this_rev_id, other_basis, 
 
268
                                          this_branch)
 
269
            if base_rev_id is None:
263
270
                raise UnrelatedBranches()
264
 
            try:
265
 
                base_revision = this_branch.get_revision(base_rev_id)
266
 
                base_branch = this_branch
267
 
            except NoSuchRevision:
268
 
                base_branch = other_branch
269
 
            base_tree = get_revid_tree(base_branch, base_rev_id, tempdir, 
270
 
                                       "base")
 
271
            base_tree = get_revid_tree(this_branch, base_rev_id, tempdir, 
 
272
                                       "base", None)
271
273
            base_is_ancestor = True
272
274
        else:
273
275
            base_branch, base_tree = get_tree(base_revision, tempdir, "base")
279
281
                base_rev_id = base_branch.lookup_revision(base_revision[1])
280
282
            if base_rev_id is not None:
281
283
                base_is_ancestor = is_ancestor(this_rev_id, base_rev_id, 
282
 
                                               MultipleRevisionSources(
283
 
                                               this_branch, 
284
 
                                               base_branch))
 
284
                                               MultipleRevisionSources(this_branch, 
 
285
                                                                       base_branch))
285
286
            else:
286
287
                base_is_ancestor = False
287
288
        if file_list is None:
303
304
        merge_inner(this_branch, other_tree, base_tree, tempdir, 
304
305
                    ignore_zero=ignore_zero, backup_files=backup_files, 
305
306
                    merge_type=merge_type, interesting_ids=interesting_ids)
306
 
        if base_is_ancestor and other_rev_id is not None:
 
307
        if base_is_ancestor and other_rev_id is not None\
 
308
            and other_rev_id not in this_branch.revision_history():
307
309
            this_branch.add_pending_merge(other_rev_id)
308
310
    finally:
309
311
        shutil.rmtree(tempdir)