~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_repository/test_reconcile.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-12 03:53:21 UTC
  • mfrom: (4948 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4964.
  • Revision ID: andrew.bennetts@canonical.com-20100112035321-hofpz5p10224ryj3
Merge lp:bzr, resolving conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for reconciliation of repositories."""
18
18
 
47
47
    def checkNoBackupInventory(self, aBzrDir):
48
48
        """Check that there is no backup inventory in aBzrDir."""
49
49
        repo = aBzrDir.open_repository()
50
 
        # Remote repository, and possibly others, do not have 
 
50
        # Remote repository, and possibly others, do not have
51
51
        # _transport.
52
52
        if getattr(repo, '_transport', None) is not None:
53
53
            for path in repo._transport.list_dir('.'):
58
58
 
59
59
    def setUp(self):
60
60
        super(TestsNeedingReweave, self).setUp()
61
 
        
 
61
 
62
62
        t = get_transport(self.get_url())
63
63
        # an empty inventory with no revision for testing with.
64
64
        repo = self.make_repository('inventory_without_revision')
104
104
        # i.e. a ghost.
105
105
        repo = self.make_repository('inventory_one_ghost')
106
106
        add_commit(repo, 'ghost', ['the_ghost'])
107
 
         
 
107
 
108
108
        # a inventory with a ghost that can be corrected now.
109
109
        t.copy_tree('inventory_one_ghost', 'inventory_ghost_present')
110
110
        bzrdir_url = self.get_url('inventory_ghost_present')
231
231
    def test_reweave_inventory_preserves_a_revision_with_ghosts(self):
232
232
        d = bzrlib.bzrdir.BzrDir.open(self.get_url('inventory_one_ghost'))
233
233
        reconciler = d.open_repository().reconcile(thorough=True)
234
 
        # no inconsistent parents should have been found: 
 
234
        # no inconsistent parents should have been found:
235
235
        # the lack of a parent for ghost is normal
236
236
        self.assertEqual(0, reconciler.inconsistent_parents)
237
237
        # and one garbage inventories
240
240
        repo = d.open_repository()
241
241
        repo.get_inventory('ghost')
242
242
        self.assertEqual([None, 'ghost'], repo.get_ancestry('ghost'))
243
 
        
 
243
 
244
244
    def test_reweave_inventory_fixes_ancestryfor_a_present_ghost(self):
245
245
        d = bzrlib.bzrdir.BzrDir.open(self.get_url('inventory_ghost_present'))
246
246
        repo = d.open_repository()
264
264
        self.assertEqual([None, 'the_ghost', 'ghost'], repo.get_ancestry('ghost'))
265
265
        self.assertEqual([None, 'the_ghost'], repo.get_ancestry('the_ghost'))
266
266
 
 
267
    def test_text_from_ghost_revision(self):
 
268
        repo = self.make_repository('text-from-ghost')
 
269
        inv = Inventory(revision_id='final-revid')
 
270
        inv.root.revision = 'root-revid'
 
271
        ie = inv.add_path('bla', 'file', 'myfileid')
 
272
        ie.revision = 'ghostrevid'
 
273
        ie.text_size = 42
 
274
        ie.text_sha1 = "bee68c8acd989f5f1765b4660695275948bf5c00"
 
275
        rev = bzrlib.revision.Revision(timestamp=0,
 
276
                                       timezone=None,
 
277
                                       committer="Foo Bar <foo@example.com>",
 
278
                                       message="Message",
 
279
                                       revision_id='final-revid')
 
280
        repo.lock_write()
 
281
        try:
 
282
            repo.start_write_group()
 
283
            try:
 
284
                repo.add_revision('final-revid', rev, inv)
 
285
                try:
 
286
                    repo.texts.add_lines(('myfileid', 'ghostrevid'),
 
287
                        (('myfileid', 'ghost-text-parent'),),
 
288
                        ["line1\n", "line2\n"])
 
289
                except errors.RevisionNotPresent:
 
290
                    raise TestSkipped("text ghost parents not supported")
 
291
                if repo.supports_rich_root():
 
292
                    root_id = inv.root.file_id
 
293
                    repo.texts.add_lines((inv.root.file_id, inv.root.revision),
 
294
                        [], [])
 
295
            finally:
 
296
                repo.commit_write_group()
 
297
        finally:
 
298
            repo.unlock()
 
299
        repo.reconcile(thorough=True)
 
300
 
267
301
 
268
302
class TestReconcileWithIncorrectRevisionCache(TestReconcile):
269
303
    """Ancestry data gets cached in knits and weaves should be reconcilable.
275
309
    def setUp(self):
276
310
        self.reduceLockdirTimeout()
277
311
        super(TestReconcileWithIncorrectRevisionCache, self).setUp()
278
 
        
 
312
 
279
313
        t = get_transport(self.get_url())
280
314
        # we need a revision with two parents in the wrong order
281
315
        # which should trigger reinsertion.
286
320
        # there is no api to construct a broken knit repository at
287
321
        # this point. if we ever encounter a bad graph in a knit repo
288
322
        # we should add a lower level api to allow constructing such cases.
289
 
        
 
323
 
290
324
        # first off the common logic:
291
325
        tree = self.make_branch_and_tree('wrong-first-parent')
292
326
        second_tree = self.make_branch_and_tree('reversed-secondary-parents')
307
341
        repo.start_write_group()
308
342
        inv = Inventory(revision_id='wrong-first-parent')
309
343
        inv.root.revision = 'wrong-first-parent'
 
344
        if repo.supports_rich_root():
 
345
            root_id = inv.root.file_id
 
346
            repo.texts.add_lines((root_id, 'wrong-first-parent'), [], [])
310
347
        sha1 = repo.add_inventory('wrong-first-parent', inv, ['2', '1'])
311
348
        rev = Revision(timestamp=0,
312
349
                       timezone=None,