194
195
self._gather_parents()
196
any_deletions = self._remove_deleted()
197
self.new_inv = self.work_inv.copy()
198
any_changes = self._store_files()
197
self.new_inv = Inventory()
199
199
self._report_deletes()
201
# TODO: update hashcache
202
201
if not (self.allow_pointless
205
or len(self.parents) != 1):
202
or len(self.parents) != 1
203
or self.new_inv != self.basis_inv):
206
204
raise PointlessCommit()
209
self.branch._write_inventory(self.work_inv)
210
206
self._record_inventory()
211
207
self._record_ancestry()
212
208
self._make_revision()
315
311
inventory, with deleted/removed files already cut out. So
316
312
this code only needs to deal with setting text versions, and
317
313
possibly recording new file texts."""
319
for path, new_ie in self.new_inv.iter_entries():
314
for path, new_ie in self.work_inv.iter_entries():
315
file_id = new_ie.file_id
316
mutter('check %s {%s}', path, new_ie.file_id)
320
317
if self.specific_files:
321
318
if not is_inside_any(self.specific_files, path):
324
mutter('check %s {%s}', path, new_ie.file_id)
319
mutter('%s not selected for commit', path)
320
self._carry_file(file_id)
325
322
if new_ie.kind != 'file':
326
# only regular files have texts to update
323
self._commit_nonfile(file_id)
328
file_id = new_ie.file_id
329
325
file_parents = self._find_file_parents(file_id)
330
326
wc_sha1 = self.work_tree.get_file_sha1(file_id)
331
wc_len = self.work_tree.get_file_size(file_id)
332
327
if (len(file_parents) == 1
333
328
and file_parents.values()[0] == wc_sha1):
334
# same as the single previous version, can reuse that
335
text_version = file_parents.keys()[0]
329
# not changed or merged
330
self._carry_file(file_id)
333
mutter('parents of %s are %r', path, file_parents)
335
# file is either new, or a file merge; need to record
337
if len(file_parents) > 1:
338
note('merged %s', path)
339
elif len(file_parents) == 0:
340
note('added %s', path)
337
# file is either new, or a file merge; need to record
339
if len(file_parents) > 1:
340
note('merged %s', path)
341
elif len(file_parents) == 0:
342
note('added %s', path)
344
note('modified %s', path)
345
self._store_text(file_id, file_parents)
346
text_version = self.rev_id
348
new_ie.text_version = text_version
349
new_ie.text_sha1 = wc_sha1
350
new_ie.text_size = wc_len
342
note('modified %s', path)
343
self._commit_file(new_ie, file_id, file_parents)
346
def _commit_nonfile(self, file_id):
347
self.new_inv.add(self.work_inv[file_id].copy())
350
def _carry_file(self, file_id):
351
"""Keep a file in the same state as in the basis."""
352
if self.basis_inv.has_id(file_id):
353
self.new_inv.add(self.basis_inv[file_id].copy())
354
356
def _report_deletes(self):
357
359
note('deleted %s', self.basis_inv.id2path(file_id))
360
def _store_text(self, file_id, file_parents):
362
def _commit_file(self, new_ie, file_id, file_parents):
361
363
mutter('store new text for {%s} in revision {%s}',
362
364
file_id, self.rev_id)
363
365
new_lines = self.work_tree.get_file(file_id).readlines()
364
366
self._add_text_to_weave(file_id, new_lines, file_parents)
367
new_ie.text_version = self.rev_id
368
new_ie.text_sha1 = sha_strings(new_lines)
369
new_ie.text_size = sum(map(len, new_lines))
370
self.new_inv.add(new_ie)
367
373
def _add_text_to_weave(self, file_id, new_lines, parents):