/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to object_store.py

Cope with no-change merges.

Show diffs side-by-side

added added

removed removed

Lines of Context:
128
128
    except IndexError:
129
129
        base_tree = tree._repository.revision_tree(NULL_REVISION)
130
130
        other_parent_trees = []
 
131
    def find_unchanged_parent_ie(ie, parent_trees):
 
132
        assert ie.kind in ("symlink", "file")
 
133
        for ptree in parent_trees:
 
134
            try:
 
135
                pie = ptree.inventory[ie.file_id]
 
136
            except errors.NoSuchId:
 
137
                pass
 
138
            else:
 
139
                if (pie.text_sha1 == ie.text_sha1 and 
 
140
                    pie.kind == ie.kind and
 
141
                    pie.symlink_target == ie.symlink_target):
 
142
                    return pie
 
143
        raise KeyError
131
144
    for (file_id, path, changed_content, versioned, parent, name, kind,
132
145
         executable) in tree.iter_changes(base_tree):
133
146
        if kind[1] == "file":
134
147
            ie = tree.inventory[file_id]
135
148
            if changed_content:
136
 
                # Content changed, find the correct revision id to use
137
 
                for ptree in other_parent_trees:
138
 
                    try:
139
 
                        pie = ptree.inventory[file_id]
140
 
                    except errors.NoSuchId:
141
 
                        pass
142
 
                    else:
143
 
                        if (pie.text_sha1 == ie.text_sha1 and 
144
 
                            pie.kind == ie.kind):
145
 
                            shamap[ie.file_id] = idmap.lookup_blob_id(
146
 
                                pie.file_id, pie.revision)
147
 
                            break
 
149
                
 
150
                try:
 
151
                    pie = find_unchanged_parent_ie(ie, other_parent_trees)
 
152
                except KeyError:
 
153
                    pass
 
154
                else:
 
155
                    shamap[ie.file_id] = idmap.lookup_blob_id(
 
156
                        pie.file_id, pie.revision)
148
157
            if not file_id in shamap:
149
158
                new_blobs.append((path[1], ie))
150
159
            new_trees[urlutils.dirname(path[1])] = parent[1]
152
161
            ie = tree.inventory[file_id]
153
162
            if changed_content:
154
163
                blob = symlink_to_blob(ie)
155
 
                for ptree in other_parent_trees:
156
 
                    try:
157
 
                        pie = ptree.inventory[file_id]
158
 
                    except errors.NoSuchId:
159
 
                        pass
160
 
                    else:
161
 
                        if (ie.kind == pie.kind and
162
 
                            ie.symlink_target == pie.symlink_target):
163
 
                            break
164
 
            else:
165
 
                yield path[1], blob, ie
166
 
            shamap[file_id] = blob.id
 
164
                shamap[file_id] = blob.id
 
165
                try:
 
166
                    find_unchanged_parent_ie(ie, other_parent_trees)
 
167
                except KeyError:
 
168
                    yield path[1], blob, ie
167
169
            new_trees[urlutils.dirname(path[1])] = parent[1]
168
170
        elif kind[1] not in (None, "directory"):
169
171
            raise AssertionError(kind[1])
200
202
            return shamap[ie.file_id]
201
203
        except KeyError:
202
204
            if ie.kind in ("file", "symlink"):
203
 
                return idmap.lookup_blob_id(ie.file_id, ie.revision)
 
205
                try:
 
206
                    return idmap.lookup_blob_id(ie.file_id, ie.revision)
 
207
                except KeyError:
 
208
                    # no-change merge ?
 
209
                    blob = Blob()
 
210
                    blob.data = tree.get_file_text(ie.file_id)
 
211
                    return blob.id
204
212
            elif ie.kind == "directory":
205
213
                # Not all cache backends store the tree information, 
206
214
                # calculate again from scratch
335
343
        for (fileid, revision, expected_sha), chunks in stream:
336
344
            blob = Blob()
337
345
            blob.chunked = chunks
338
 
            if blob.id != expected_sha:
 
346
            if blob.id != expected_sha and blob.data == "":
339
347
                # Perhaps it's a symlink ?
340
348
                tree = self.tree_cache.revision_tree(revision)
341
349
                entry = tree.inventory[fileid]
342
 
                assert entry.kind == 'symlink'
343
 
                blob = symlink_to_blob(entry)
 
350
                if entry.kind == 'symlink':
 
351
                    blob = symlink_to_blob(entry)
344
352
            _check_expected_sha(expected_sha, blob)
345
353
            yield blob
346
354
 
364
372
                    else:
365
373
                        return obj.id
366
374
            elif entry.kind in ("file", "symlink"):
367
 
                return self._cache.idmap.lookup_blob_id(entry.file_id,
368
 
                    entry.revision)
 
375
                try:
 
376
                    return self._cache.idmap.lookup_blob_id(entry.file_id,
 
377
                        entry.revision)
 
378
                except KeyError:
 
379
                    # no-change merge?
 
380
                    return self._reconstruct_blobs(
 
381
                        [(entry.file_id, entry.revision, None)]).next().id
369
382
            else:
370
383
                raise AssertionError("unknown entry kind '%s'" % entry.kind)
371
384
        tree = directory_to_tree(inv[fileid], get_ie_sha1, unusual_modes)