~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/changeset.py

  • Committer: Aaron Bentley
  • Date: 2005-08-10 17:39:16 UTC
  • mto: (1092.1.41) (1185.3.4) (974.1.47)
  • mto: This revision was merged to the branch mainline in revision 1110.
  • Revision ID: abentley@panoramicfeedback.com-20050810173916-77580019d21a0e82
Removed MergeTree.inventory

Show diffs side-by-side

added added

removed removed

Lines of Context:
1267
1267
        self.full_path = full_path
1268
1268
        self.stat_result = stat_result
1269
1269
 
1270
 
def generate_changeset(tree_a, tree_b, inventory_a=None, inventory_b=None, 
1271
 
                       interesting_ids=None):
1272
 
    return ChangesetGenerator(tree_a, tree_b, inventory_a, inventory_b, 
1273
 
                              interesting_ids)()
 
1270
def generate_changeset(tree_a, tree_b, interesting_ids=None):
 
1271
    return ChangesetGenerator(tree_a, tree_b, interesting_ids)()
1274
1272
 
1275
1273
class ChangesetGenerator(object):
1276
 
    def __init__(self, tree_a, tree_b, inventory_a=None, inventory_b=None, 
1277
 
                 interesting_ids=None):
 
1274
    def __init__(self, tree_a, tree_b, interesting_ids=None):
1278
1275
        object.__init__(self)
1279
1276
        self.tree_a = tree_a
1280
1277
        self.tree_b = tree_b
1281
 
        if inventory_a is not None:
1282
 
            self.inventory_a = inventory_a
1283
 
        else:
1284
 
            self.inventory_a = tree_a.inventory()
1285
 
        if inventory_b is not None:
1286
 
            self.inventory_b = inventory_b
1287
 
        else:
1288
 
            self.inventory_b = tree_b.inventory()
1289
 
        self.r_inventory_a = self.reverse_inventory(self.inventory_a)
1290
 
        self.r_inventory_b = self.reverse_inventory(self.inventory_b)
1291
1278
        self._interesting_ids = interesting_ids
1292
1279
 
1293
 
    def reverse_inventory(self, inventory):
1294
 
        r_inventory = {}
1295
 
        for entry in inventory.itervalues():
1296
 
            if entry.file_id is None:
1297
 
                continue
1298
 
            r_inventory[entry.file_id] = entry
1299
 
        return r_inventory
 
1280
    def iter_both_tree_ids(self):
 
1281
        for file_id in self.tree_a:
 
1282
            yield file_id
 
1283
        for file_id in self.tree_b:
 
1284
            if file_id not in self.tree_a:
 
1285
                yield file_id
1300
1286
 
1301
1287
    def __call__(self):
1302
1288
        cset = Changeset()
1303
 
        for entry in self.inventory_a.itervalues():
1304
 
            if entry.file_id is None:
1305
 
                continue
1306
 
            cs_entry = self.make_entry(entry.file_id)
 
1289
        for file_id in self.iter_both_tree_ids():
 
1290
            cs_entry = self.make_entry(file_id)
1307
1291
            if cs_entry is not None and not cs_entry.is_boring():
1308
1292
                cset.add_entry(cs_entry)
1309
1293
 
1310
 
        for entry in self.inventory_b.itervalues():
1311
 
            if entry.file_id is None:
1312
 
                continue
1313
 
            if not self.r_inventory_a.has_key(entry.file_id):
1314
 
                cs_entry = self.make_entry(entry.file_id)
1315
 
                if cs_entry is not None and not cs_entry.is_boring():
1316
 
                    cset.add_entry(cs_entry)
1317
1294
        for entry in list(cset.entries.itervalues()):
1318
1295
            if entry.parent != entry.new_parent:
1319
1296
                if not cset.entries.has_key(entry.parent) and\
1327
1304
                    cset.add_entry(parent_entry)
1328
1305
        return cset
1329
1306
 
1330
 
    def get_entry_parent(self, entry, inventory):
 
1307
    def iter_inventory(self, tree):
 
1308
        for file_id in tree:
 
1309
            yield self.get_entry(file_id, tree)
 
1310
 
 
1311
    def get_entry(self, file_id, tree):
 
1312
        if file_id not in tree:
 
1313
            return None
 
1314
        return tree.tree.inventory[file_id]
 
1315
 
 
1316
    def get_entry_parent(self, entry):
1331
1317
        if entry is None:
1332
1318
            return None
1333
1319
        return entry.parent_id
1342
1328
            return path
1343
1329
 
1344
1330
    def make_basic_entry(self, file_id, only_interesting):
1345
 
        entry_a = self.r_inventory_a.get(file_id)
1346
 
        entry_b = self.r_inventory_b.get(file_id)
 
1331
        entry_a = self.get_entry(file_id, self.tree_a)
 
1332
        entry_b = self.get_entry(file_id, self.tree_b)
1347
1333
        if only_interesting and not self.is_interesting(entry_a, entry_b):
1348
1334
            return None
1349
 
        parent = self.get_entry_parent(entry_a, self.inventory_a)
 
1335
        parent = self.get_entry_parent(entry_a)
1350
1336
        path = self.get_path(file_id, self.tree_a)
1351
1337
        cs_entry = ChangesetEntry(file_id, parent, path)
1352
 
        new_parent = self.get_entry_parent(entry_b, self.inventory_b)
 
1338
        new_parent = self.get_entry_parent(entry_b)
1353
1339
 
1354
1340
        new_path = self.get_path(file_id, self.tree_b)
1355
1341