~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: abentley
  • Date: 2005-10-14 04:32:24 UTC
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1460.
  • Revision ID: abentley@lappy-20051014043224-347635f0e1fbc673
Propogated has_or_had_id to Tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
154
154
    def abs_this_path(self, file_id):
155
155
        """Return the absolute path for a file_id in the this tree."""
156
156
        relpath = self.this_tree.id2path(file_id)
157
 
        return self.this_tree.abspath(relpath)
 
157
        return self.this_tree.tree.abspath(relpath)
158
158
 
159
159
    def add_missing_parents(self, file_id, tree):
160
160
        """If some of the parents for file_id are missing, add them."""
161
 
        entry = tree.inventory[file_id]
 
161
        entry = tree.tree.inventory[file_id]
162
162
        if entry.parent_id not in self.this_tree:
163
163
            return self.create_all_missing(entry.parent_id, tree)
164
164
        else:
166
166
 
167
167
    def create_all_missing(self, file_id, tree):
168
168
        """Add contents for a file_id and all its parents to a tree."""
169
 
        entry = tree.inventory[file_id]
 
169
        entry = tree.tree.inventory[file_id]
170
170
        if entry.parent_id is not None and entry.parent_id not in self.this_tree:
171
171
            abspath = self.create_all_missing(entry.parent_id, tree)
172
172
        else:
198
198
        if not self.ignore_zero:
199
199
            note("%d conflicts encountered.\n" % self.conflicts)
200
200
            
201
 
def get_tree(treespec, local_branch=None):
 
201
def get_tree(treespec, temp_root, label, local_branch=None):
202
202
    location, revno = treespec
203
203
    branch = Branch.open_containing(location)
204
204
    if revno is None:
207
207
        revision = branch.last_revision()
208
208
    else:
209
209
        revision = branch.get_rev_id(revno)
210
 
    return branch, get_revid_tree(branch, revision, local_branch)
 
210
    return branch, get_revid_tree(branch, revision, temp_root, label,
 
211
                                  local_branch)
211
212
 
212
 
def get_revid_tree(branch, revision, local_branch):
 
213
def get_revid_tree(branch, revision, temp_root, label, local_branch):
213
214
    if revision is None:
214
 
        return branch.working_tree()
 
215
        base_tree = branch.working_tree()
215
216
    else:
216
217
        if local_branch is not None:
217
218
            greedy_fetch(local_branch, branch, revision)
218
 
            return local_branch.revision_tree(revision)
 
219
            base_tree = local_branch.revision_tree(revision)
219
220
        else:
220
 
            return branch.revision_tree(revision)
 
221
            base_tree = branch.revision_tree(revision)
 
222
    temp_path = os.path.join(temp_root, label)
 
223
    os.mkdir(temp_path)
 
224
    return MergeAdapterTree(base_tree, temp_path)
221
225
 
222
226
 
223
227
def file_exists(tree, file_id):
234
238
    def __init__(self, tree, tempdir):
235
239
        object.__init__(self)
236
240
        if hasattr(tree, "basedir"):
237
 
            self.root = tree.basedir
 
241
            self.basedir = tree.basedir
238
242
        else:
239
 
            self.root = None
 
243
            self.basedir = None
240
244
        self.tree = tree
241
245
        self.tempdir = tempdir
242
246
        os.mkdir(os.path.join(self.tempdir, "texts"))
265
269
        return self.tree.has_id(file_id)
266
270
 
267
271
    def has_or_had_id(self, file_id):
268
 
        if file_id == self.tree.inventory.root.file_id:
269
 
            return True
270
 
        return self.tree.inventory.has_id(file_id)
 
272
        return self.tree.has_or_had_id(file_id)
271
273
 
272
274
    def kind(self, file_id):
273
275
        return self.tree.kind(file_id)
328
330
                                    this_branch.basis_tree(), False)
329
331
            if changes.has_changed():
330
332
                raise BzrCommandError("Working tree has uncommitted changes.")
331
 
        other_branch, other_tree = get_tree(other_revision, this_branch)
 
333
        other_branch, other_tree = get_tree(other_revision, tempdir, "other",
 
334
                                            this_branch)
332
335
        if other_revision[1] == -1:
333
336
            other_rev_id = other_branch.last_revision()
334
337
            if other_rev_id is None:
348
351
                                              this_branch)
349
352
            except NoCommonAncestor:
350
353
                raise UnrelatedBranches()
351
 
            base_tree = get_revid_tree(this_branch, base_rev_id, None)
 
354
            base_tree = get_revid_tree(this_branch, base_rev_id, tempdir, 
 
355
                                       "base", None)
352
356
            base_is_ancestor = True
353
357
        else:
354
 
            base_branch, base_tree = get_tree(base_revision)
 
358
            base_branch, base_tree = get_tree(base_revision, tempdir, "base")
355
359
            if base_revision[1] == -1:
356
360
                base_rev_id = base_branch.last_revision()
357
361
            elif base_revision[1] is None:
369
373
            for fname in file_list:
370
374
                path = this_branch.relpath(fname)
371
375
                found_id = False
372
 
                for tree in (this_tree, base_tree, other_tree):
 
376
                for tree in (this_tree, base_tree.tree, other_tree.tree):
373
377
                    file_id = tree.inventory.path2id(path)
374
378
                    if file_id is not None:
375
379
                        interesting_ids.add(file_id)
405
409
            contents_change = BackupBeforeChange(contents_change)
406
410
        return contents_change
407
411
 
408
 
    this_tree = get_tree((this_branch.base, None))[1]
 
412
    this_tree = get_tree((this_branch.base, None), tempdir, "this")[1]
409
413
 
410
414
    def get_inventory(tree):
411
 
        return tree.inventory
 
415
        return tree.tree.inventory
412
416
 
413
417
    inv_changes = merge_flex(this_tree, base_tree, other_tree,
414
418
                             generate_changeset, get_inventory,
427
431
            path = path[2:]
428
432
        adjust_ids.append((path, id))
429
433
    if len(adjust_ids) > 0:
430
 
        this_branch.set_inventory(regen_inventory(this_branch,
 
434
        this_branch.set_inventory(regen_inventory(this_branch, 
431
435
                                                  this_tree.basedir,
432
436
                                                  adjust_ids))
433
437