1267
1267
self.full_path = full_path
1268
1268
self.stat_result = stat_result
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,
1270
def generate_changeset(tree_a, tree_b, interesting_ids=None):
1271
return ChangesetGenerator(tree_a, tree_b, interesting_ids)()
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
1284
self.inventory_a = tree_a.inventory()
1285
if inventory_b is not None:
1286
self.inventory_b = inventory_b
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
1293
def reverse_inventory(self, inventory):
1295
for entry in inventory.itervalues():
1296
if entry.file_id is None:
1298
r_inventory[entry.file_id] = entry
1280
def iter_both_tree_ids(self):
1281
for file_id in self.tree_a:
1283
for file_id in self.tree_b:
1284
if file_id not in self.tree_a:
1301
1287
def __call__(self):
1302
1288
cset = Changeset()
1303
for entry in self.inventory_a.itervalues():
1304
if entry.file_id is None:
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)
1310
for entry in self.inventory_b.itervalues():
1311
if entry.file_id is None:
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)
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)
1311
def get_entry(self, file_id, tree):
1312
if file_id not in tree:
1314
return tree.tree.inventory[file_id]
1316
def get_entry_parent(self, entry):
1331
1317
if entry is None:
1333
1319
return entry.parent_id
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):
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)
1354
1340
new_path = self.get_path(file_id, self.tree_b)