~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge.py

  • Committer: Aaron Bentley
  • Date: 2005-09-30 03:59:46 UTC
  • mto: (1393.1.21) (1185.14.1)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: aaron.bentley@utoronto.ca-20050930035945-febfb28a4c499be4
Handled modified files missing from THIS

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
    conflict that are not explicitly handled cause an exception and
48
48
    terminate the merge.
49
49
    """
50
 
    def __init__(self, ignore_zero=False):
 
50
    def __init__(self, this_tree, base_tree, other_tree, ignore_zero=False):
51
51
        ExceptionConflictHandler.__init__(self)
52
52
        self.conflicts = 0
53
53
        self.ignore_zero = ignore_zero
 
54
        self.this_tree = this_tree
 
55
        self.base_tree = base_tree
 
56
        self.other_tree = other_tree
54
57
 
55
58
    def copy(self, source, dest):
56
59
        """Copy the text and mode of a file
135
138
                      filename)
136
139
        return ReplaceContents(this_contents, None)
137
140
 
 
141
    def abs_this_path(self, file_id):
 
142
        """Return the absolute path for a file_id in the this tree."""
 
143
        relpath = self.this_tree.id2path(file_id)
 
144
        return self.this_tree.tree.abspath(relpath)
 
145
 
 
146
    def add_missing_parents(self, file_id, tree):
 
147
        """If some of the parents for file_id are missing, add them."""
 
148
        entry = tree.tree.inventory[file_id]
 
149
        if entry.parent_id not in self.this_tree:
 
150
            return self.create_all_missing(entry.parent_id, tree)
 
151
        else:
 
152
            return self.abs_this_path(entry.parent_id)
 
153
 
 
154
    def create_all_missing(self, file_id, tree):
 
155
        """Add contents for a file_id and all its parents to a tree."""
 
156
        entry = tree.tree.inventory[file_id]
 
157
        if entry.parent_id is not None and entry.parent_id not in self.this_tree:
 
158
            abspath = self.create_all_missing(entry.parent_id, tree)
 
159
        else:
 
160
            abspath = self.abs_this_path(entry.parent_id)
 
161
        entry_path = os.path.join(abspath, entry.name)
 
162
        if not os.path.isdir(entry_path):
 
163
            self.create(file_id, entry_path, tree)
 
164
        return entry_path
 
165
 
 
166
    def create(self, file_id, path, tree, reverse=False):
 
167
        """Uses tree data to create a filesystem object for the file_id"""
 
168
        from merge_core import get_id_contents
 
169
        get_id_contents(file_id, tree)(path, self, reverse)
 
170
 
 
171
    def missing_for_merge(self, file_id, other_path):
 
172
        """The file_id doesn't exist in THIS, but does in OTHER and BASE"""
 
173
        self.conflict("Other branch modified locally deleted file %s" %
 
174
                      other_path)
 
175
        parent_dir = self.add_missing_parents(file_id, self.other_tree)
 
176
        stem = os.path.join(parent_dir, os.path.basename(other_path))
 
177
        self.create(file_id, stem+".OTHER", self.other_tree)
 
178
        self.create(file_id, stem+".BASE", self.base_tree)
 
179
 
138
180
    def finalize(self):
139
181
        if not self.ignore_zero:
140
182
            print "%d conflicts encountered.\n" % self.conflicts
356
398
 
357
399
    inv_changes = merge_flex(this_tree, base_tree, other_tree,
358
400
                             generate_cset_optimized, get_inventory,
359
 
                             MergeConflictHandler(ignore_zero=ignore_zero),
 
401
                             MergeConflictHandler(this_tree, base_tree,
 
402
                             other_tree, ignore_zero=ignore_zero),
360
403
                             merge_factory=merge_factory, 
361
404
                             interesting_ids=interesting_ids)
362
405