~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Martin Pool
  • Date: 2005-09-16 07:38:10 UTC
  • Revision ID: mbp@sourcefrog.net-20050916073810-1f358be198c9ed91
- fix bug in committing files that are renamed but not modified

- add test for this

Show diffs side-by-side

added added

removed removed

Lines of Context:
155
155
        allow_pointless -- If true (default), commit even if nothing
156
156
            has changed and no merges are recorded.
157
157
        """
158
 
        self.any_changes = False
 
158
        mutter('preparing to commit')
159
159
 
160
160
        self.branch = branch
161
161
        self.weave_store = branch.weave_store
321
321
    def _find_file_parents(self, file_id):
322
322
        """Return the text versions and hashes for all file parents.
323
323
 
324
 
        Returned as a map from text version to text sha1.
 
324
        Returned as a map from text version to inventory entry.
325
325
 
326
326
        This is a set containing the file versions in all parents
327
327
        revisions containing the file.  If the file is new, the set
333
333
                assert ie.kind == 'file'
334
334
                assert ie.file_id == file_id
335
335
                if ie.text_version in r:
336
 
                    assert r[ie.text_version] == ie.text_sha1
 
336
                    assert r[ie.text_version] == ie
337
337
                else:
338
 
                    r[ie.text_version] = ie.text_sha1
 
338
                    r[ie.text_version] = ie
339
339
        return r            
340
340
 
341
341
 
357
357
            if new_ie.kind != 'file':
358
358
                self._commit_nonfile(file_id)
359
359
                continue
 
360
            
360
361
            file_parents = self._find_file_parents(file_id)
361
 
            wc_sha1 = self.work_tree.get_file_sha1(file_id)
362
 
            if (len(file_parents) == 1
363
 
                and file_parents.values()[0] == wc_sha1):
364
 
                # not changed or merged
365
 
                self._carry_file(file_id)
366
 
                continue
 
362
            if len(file_parents) == 1:
 
363
                parent_ie = file_parents.values()[0]
 
364
                wc_sha1 = self.work_tree.get_file_sha1(file_id)
 
365
                if parent_ie.text_sha1 == wc_sha1:
 
366
                    # text not changed or merged
 
367
                    self._commit_old_text(file_id, parent_ie)
 
368
                    continue
367
369
 
368
370
            mutter('parents of %s are %r', path, file_parents)
369
371
 
383
385
 
384
386
 
385
387
    def _carry_file(self, file_id):
386
 
        """Keep a file in the same state as in the basis."""
 
388
        """Carry the file unchanged from the basis revision."""
387
389
        if self.basis_inv.has_id(file_id):
388
390
            self.new_inv.add(self.basis_inv[file_id].copy())
389
391
 
390
392
 
 
393
    def _commit_old_text(self, file_id, parent_ie):
 
394
        """Keep the same text as last time, but possibly a different name."""
 
395
        ie = self.work_inv[file_id].copy()
 
396
        ie.text_version = parent_ie.text_version
 
397
        ie.text_size = parent_ie.text_size
 
398
        ie.text_sha1 = parent_ie.text_sha1
 
399
        self.new_inv.add(ie)
 
400
 
 
401
 
391
402
    def _report_deletes(self):
392
403
        for file_id in self.basis_inv:
393
404
            if file_id not in self.new_inv: