~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: abentley
  • Date: 2005-10-14 05:21:43 UTC
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1460.
  • Revision ID: abentley@lappy-20051014052143-2368d04b9caaab2b
Got rid of MergeAdapterTree

Show diffs side-by-side

added added

removed removed

Lines of Context:
197
197
        if not self.ignore_zero:
198
198
            note("%d conflicts encountered.\n" % self.conflicts)
199
199
            
200
 
def get_tree(treespec, temp_root, label, local_branch=None):
 
200
def get_tree(treespec, local_branch=None):
201
201
    location, revno = treespec
202
202
    branch = Branch.open_containing(location)
203
203
    if revno is None:
206
206
        revision = branch.last_revision()
207
207
    else:
208
208
        revision = branch.get_rev_id(revno)
209
 
    return branch, get_revid_tree(branch, revision, temp_root, label,
210
 
                                  local_branch)
 
209
    return branch, get_revid_tree(branch, revision, local_branch)
211
210
 
212
 
def get_revid_tree(branch, revision, temp_root, label, local_branch):
 
211
def get_revid_tree(branch, revision, local_branch):
213
212
    if revision is None:
214
213
        base_tree = branch.working_tree()
215
214
    else:
218
217
            base_tree = local_branch.revision_tree(revision)
219
218
        else:
220
219
            base_tree = branch.revision_tree(revision)
221
 
    temp_path = os.path.join(temp_root, label)
222
 
    os.mkdir(temp_path)
223
 
    return MergeAdapterTree(base_tree, temp_path)
 
220
    return base_tree
224
221
 
225
222
 
226
223
def file_exists(tree, file_id):
227
224
    return tree.has_filename(tree.id2path(file_id))
228
225
    
229
226
 
230
 
class MergeAdapterTree(object):
231
 
    """MergeAdapterTree adapts a normal tree for merge_inner to use.
232
 
 
233
 
    The interface the merge_inner needs is nearly but not quite
234
 
    the same as that of bzrlib.tree.
235
 
    """
236
 
    
237
 
    def __init__(self, tree, tempdir):
238
 
        object.__init__(self)
239
 
        if hasattr(tree, "basedir"):
240
 
            self.basedir = tree.basedir
241
 
        else:
242
 
            self.basedir = None
243
 
        self.tree = tree
244
 
        self.inventory = tree.inventory
245
 
        self.tempdir = tempdir
246
 
        os.mkdir(os.path.join(self.tempdir, "texts"))
247
 
        os.mkdir(os.path.join(self.tempdir, "symlinks"))
248
 
        self.cached = {}
249
 
 
250
 
    def __iter__(self):
251
 
        return self.tree.__iter__()
252
 
 
253
 
    def __contains__(self, file_id):
254
 
        return file_id in self.tree
255
 
 
256
 
    def get_file(self, file_id):
257
 
        return self.tree.get_file(file_id)
258
 
 
259
 
    def get_file_sha1(self, id):
260
 
        return self.tree.get_file_sha1(id)
261
 
 
262
 
    def is_executable(self, id):
263
 
        return self.tree.is_executable(id)
264
 
 
265
 
    def id2path(self, file_id):
266
 
        return self.tree.id2path(file_id)
267
 
 
268
 
    def has_id(self, file_id):
269
 
        return self.tree.has_id(file_id)
270
 
 
271
 
    def has_or_had_id(self, file_id):
272
 
        return self.tree.has_or_had_id(file_id)
273
 
 
274
 
    def kind(self, file_id):
275
 
        return self.tree.kind(file_id)
276
 
 
277
 
    def get_symlink_target(self, file_id):
278
 
        return self.tree.get_symlink_target(file_id)
279
 
 
280
 
    def id2abspath(self, file_id):
281
 
        return self.tree.id2abspath(file_id)
282
 
 
283
 
 
284
227
def build_working_dir(to_dir):
285
228
    """Build a working directory in an empty directory.
286
229
 
330
273
                                    this_branch.basis_tree(), False)
331
274
            if changes.has_changed():
332
275
                raise BzrCommandError("Working tree has uncommitted changes.")
333
 
        other_branch, other_tree = get_tree(other_revision, tempdir, "other",
334
 
                                            this_branch)
 
276
        other_branch, other_tree = get_tree(other_revision, this_branch)
335
277
        if other_revision[1] == -1:
336
278
            other_rev_id = other_branch.last_revision()
337
279
            if other_rev_id is None:
351
293
                                              this_branch)
352
294
            except NoCommonAncestor:
353
295
                raise UnrelatedBranches()
354
 
            base_tree = get_revid_tree(this_branch, base_rev_id, tempdir, 
355
 
                                       "base", None)
 
296
            base_tree = get_revid_tree(this_branch, base_rev_id, None)
356
297
            base_is_ancestor = True
357
298
        else:
358
 
            base_branch, base_tree = get_tree(base_revision, tempdir, "base")
 
299
            base_branch, base_tree = get_tree(base_revision)
359
300
            if base_revision[1] == -1:
360
301
                base_rev_id = base_branch.last_revision()
361
302
            elif base_revision[1] is None:
409
350
            contents_change = BackupBeforeChange(contents_change)
410
351
        return contents_change
411
352
 
412
 
    this_tree = get_tree((this_branch.base, None), tempdir, "this")[1]
 
353
    this_tree = get_tree((this_branch.base, None))[1]
413
354
 
414
355
    def get_inventory(tree):
415
356
        return tree.inventory