/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/interrepository_implementations/test_fetch.py

  • Committer: Martin Pool
  • Date: 2009-06-05 23:21:51 UTC
  • mfrom: (4415 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4416.
  • Revision ID: mbp@sourcefrog.net-20090605232151-luwmyyl95siraqyz
merge trunk

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
 
18
18
import sys
20
20
import bzrlib
21
21
from bzrlib import (
22
22
    errors,
 
23
    inventory,
 
24
    osutils,
23
25
    repository,
24
 
    osutils,
 
26
    versionedfile,
25
27
    )
26
28
from bzrlib.errors import (
27
29
    NoSuchRevision,
51
53
        def check_push_rev1(repo):
52
54
            # ensure the revision is missing.
53
55
            self.assertRaises(NoSuchRevision, repo.get_revision, 'rev1')
54
 
            # fetch with a limit of NULL_REVISION and an explicit progress bar.
 
56
            # fetch with a limit of NULL_REVISION
55
57
            repo.fetch(tree_a.branch.repository,
56
 
                       revision_id=NULL_REVISION,
57
 
                       pb=bzrlib.progress.DummyProgress())
 
58
                       revision_id=NULL_REVISION)
58
59
            # nothing should have been pushed
59
60
            self.assertFalse(repo.has_revision('rev1'))
60
61
            # fetch with a default limit (grab everything)
73
74
        repo_b = self.make_to_repository('b')
74
75
        check_push_rev1(repo_b)
75
76
 
 
77
    def test_fetch_inconsistent_last_changed_entries(self):
 
78
        """If an inventory has odd data we should still get what it references.
 
79
 
 
80
        This test tests that we do fetch a file text created in a revision not
 
81
        being fetched, but referenced from the revision we are fetching when the
 
82
        adjacent revisions to the one being fetched do not reference that text.
 
83
        """
 
84
        tree = self.make_branch_and_tree('source')
 
85
        revid = tree.commit('old')
 
86
        to_repo = self.make_to_repository('to_repo')
 
87
        to_repo.fetch(tree.branch.repository, revid)
 
88
        # Make a broken revision and fetch it.
 
89
        source = tree.branch.repository
 
90
        source.lock_write()
 
91
        self.addCleanup(source.unlock)
 
92
        source.start_write_group()
 
93
        try:
 
94
            # We need two revisions: OLD and NEW. NEW will claim to need a file
 
95
            # 'FOO' changed in 'OLD'. OLD will not have that file at all.
 
96
            source.texts.insert_record_stream([
 
97
                versionedfile.FulltextContentFactory(('foo', revid), (), None,
 
98
                'contents')])
 
99
            basis = source.revision_tree(revid)
 
100
            parent_id = basis.path2id('')
 
101
            entry = inventory.make_entry('file', 'foo-path', parent_id, 'foo')
 
102
            entry.revision = revid
 
103
            entry.text_size = len('contents')
 
104
            entry.text_sha1 = osutils.sha_string('contents')
 
105
            inv_sha1, _ = source.add_inventory_by_delta(revid, [
 
106
                (None, 'foo-path', 'foo', entry)], 'new', [revid])
 
107
            rev = Revision(timestamp=0,
 
108
                           timezone=None,
 
109
                           committer="Foo Bar <foo@example.com>",
 
110
                           message="Message",
 
111
                           inventory_sha1=inv_sha1,
 
112
                           revision_id='new',
 
113
                           parent_ids=[revid])
 
114
            source.add_revision(rev.revision_id, rev)
 
115
        except:
 
116
            source.abort_write_group()
 
117
            raise
 
118
        else:
 
119
            source.commit_write_group()
 
120
        to_repo.fetch(source, 'new')
 
121
        to_repo.lock_read()
 
122
        self.addCleanup(to_repo.unlock)
 
123
        self.assertEqual('contents',
 
124
            to_repo.texts.get_record_stream([('foo', revid)],
 
125
            'unordered', True).next().get_bytes_as('fulltext'))
 
126
 
 
127
    def test_fetch_parent_inventories_at_stacking_boundary(self):
 
128
        """Fetch to a stacked branch copies inventories for parents of
 
129
        revisions at the stacking boundary.
 
130
 
 
131
        This is necessary so that the server is able to determine the file-ids
 
132
        altered by all revisions it contains, which means that it needs both
 
133
        the inventory for any revision it has, and the inventories of all that
 
134
        revision's parents.
 
135
        """
 
136
        to_repo = self.make_to_repository('to')
 
137
        if not to_repo._format.supports_external_lookups:
 
138
            raise TestNotApplicable("Need stacking support in the target.")
 
139
        builder = self.make_branch_builder('branch')
 
140
        builder.start_series()
 
141
        builder.build_snapshot('base', None, [
 
142
            ('add', ('', 'root-id', 'directory', ''))])
 
143
        builder.build_snapshot('left', ['base'], [])
 
144
        builder.build_snapshot('right', ['base'], [])
 
145
        builder.build_snapshot('merge', ['left', 'right'], [])
 
146
        builder.finish_series()
 
147
        branch = builder.get_branch()
 
148
        repo = self.make_to_repository('trunk')
 
149
        trunk = repo.bzrdir.create_branch()
 
150
        trunk.repository.fetch(branch.repository, 'left')
 
151
        trunk.repository.fetch(branch.repository, 'right')
 
152
        repo = self.make_to_repository('stacked')
 
153
        stacked_branch = repo.bzrdir.create_branch()
 
154
        stacked_branch.set_stacked_on_url(trunk.base)
 
155
        stacked_branch.repository.fetch(branch.repository, 'merge')
 
156
        unstacked_repo = stacked_branch.bzrdir.open_repository()
 
157
        unstacked_repo.lock_read()
 
158
        self.addCleanup(unstacked_repo.unlock)
 
159
        self.assertFalse(unstacked_repo.has_revision('left'))
 
160
        self.assertFalse(unstacked_repo.has_revision('right'))
 
161
        self.assertEqual(
 
162
            set([('left',), ('right',), ('merge',)]),
 
163
            unstacked_repo.inventories.keys())
 
164
 
76
165
    def test_fetch_missing_basis_text(self):
77
166
        """If fetching a delta, we should die if a basis is not present."""
78
167
        tree = self.make_branch_and_tree('tree')