~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/fetch.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-11 00:23:23 UTC
  • mfrom: (2070 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061011002323-82ba88c293d7caff
[merge] bzr.dev 2070

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
 
 
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
147
147
        if self._last_revision is NULL_REVISION:
148
148
            # explicit limit of no revisions needed
149
149
            return None
150
 
        if (self._last_revision != None and
 
150
        if (self._last_revision is not None and
151
151
            self.to_repository.has_revision(self._last_revision)):
152
152
            return None
153
153
            
160
160
    def _fetch_weave_texts(self, revs):
161
161
        texts_pb = bzrlib.ui.ui_factory.nested_progress_bar()
162
162
        try:
 
163
            # fileids_altered_by_revision_ids requires reading the inventory
 
164
            # weave, we will need to read the inventory weave again when
 
165
            # all this is done, so enable caching for that specific weave
 
166
            inv_w = self.from_repository.get_inventory_weave()
 
167
            inv_w.enable_cache()
163
168
            file_ids = self.from_repository.fileids_altered_by_revision_ids(revs)
164
169
            count = 0
165
170
            num_file_ids = len(file_ids)
172
177
                    self.from_repository.get_transaction())
173
178
                # we fetch all the texts, because texts do
174
179
                # not reference anything, and its cheap enough
175
 
                to_weave.join(from_weave, version_ids=required_versions) 
 
180
                to_weave.join(from_weave, version_ids=required_versions)
176
181
                # we don't need *all* of this data anymore, but we dont know
177
182
                # what we do. This cache clearing will result in a new read 
178
183
                # of the knit data when we do the checkout, but probably we
205
210
                # corrupt.
206
211
                to_weave.join(from_weave, pb=child_pb, msg='merge inventory',
207
212
                              version_ids=revs)
 
213
                from_weave.clear_cache()
208
214
            finally:
209
215
                child_pb.finished()
210
216
        finally:
275
281
        to_rf.join(from_rf, version_ids=revs)
276
282
 
277
283
 
 
284
class Inter1and2Helper(object):
 
285
    """Helper for operations that convert data from model 1 and 2
 
286
    
 
287
    This is for use by fetchers and converters.
 
288
    """
 
289
 
 
290
    def __init__(self, source, target):
 
291
        """Constructor.
 
292
 
 
293
        :param source: The repository data comes from
 
294
        :param target: The repository data goes to
 
295
        """
 
296
        self.source = source
 
297
        self.target = target
 
298
 
 
299
    def iter_rev_trees(self, revs):
 
300
        """Iterate through RevisionTrees efficiently.
 
301
 
 
302
        Additionally, the inventory's revision_id is set if unset.
 
303
 
 
304
        Trees are retrieved in batches of 100, and then yielded in the order
 
305
        they were requested.
 
306
 
 
307
        :param revs: A list of revision ids
 
308
        """
 
309
        while revs:
 
310
            for tree in self.source.revision_trees(revs[:100]):
 
311
                if tree.inventory.revision_id is None:
 
312
                    tree.inventory.revision_id = tree.get_revision_id()
 
313
                yield tree
 
314
            revs = revs[100:]
 
315
 
 
316
    def generate_root_texts(self, revs):
 
317
        """Generate VersionedFiles for all root ids.
 
318
        
 
319
        :param revs: the revisions to include
 
320
        """
 
321
        inventory_weave = self.source.get_inventory_weave()
 
322
        parent_texts = {}
 
323
        versionedfile = {}
 
324
        to_store = self.target.weave_store
 
325
        for tree in self.iter_rev_trees(revs):
 
326
            revision_id = tree.inventory.root.revision
 
327
            root_id = tree.inventory.root.file_id
 
328
            parents = inventory_weave.get_parents(revision_id)
 
329
            if root_id not in versionedfile:
 
330
                versionedfile[root_id] = to_store.get_weave_or_empty(root_id, 
 
331
                    self.target.get_transaction())
 
332
            parent_texts[root_id] = versionedfile[root_id].add_lines(
 
333
                revision_id, parents, [], parent_texts)
 
334
 
 
335
    def regenerate_inventory(self, revs):
 
336
        """Generate a new inventory versionedfile in target, convertin data.
 
337
        
 
338
        The inventory is retrieved from the source, (deserializing it), and
 
339
        stored in the target (reserializing it in a different format).
 
340
        :param revs: The revisions to include
 
341
        """
 
342
        inventory_weave = self.source.get_inventory_weave()
 
343
        for tree in self.iter_rev_trees(revs):
 
344
            parents = inventory_weave.get_parents(tree.get_revision_id())
 
345
            self.target.add_inventory(tree.get_revision_id(), tree.inventory,
 
346
                                      parents)
 
347
 
 
348
 
 
349
class Model1toKnit2Fetcher(GenericRepoFetcher):
 
350
    """Fetch from a Model1 repository into a Knit2 repository
 
351
    """
 
352
    def __init__(self, to_repository, from_repository, last_revision=None, 
 
353
                 pb=None):
 
354
        self.helper = Inter1and2Helper(from_repository, to_repository)
 
355
        GenericRepoFetcher.__init__(self, to_repository, from_repository,
 
356
                                    last_revision, pb)
 
357
 
 
358
    def _fetch_weave_texts(self, revs):
 
359
        GenericRepoFetcher._fetch_weave_texts(self, revs)
 
360
        # Now generate a weave for the tree root
 
361
        self.helper.generate_root_texts(revs)
 
362
 
 
363
    def _fetch_inventory_weave(self, revs):
 
364
        self.helper.regenerate_inventory(revs)
 
365
 
 
366
 
 
367
class Knit1to2Fetcher(KnitRepoFetcher):
 
368
    """Fetch from a Knit1 repository into a Knit2 repository"""
 
369
 
 
370
    def __init__(self, to_repository, from_repository, last_revision=None, 
 
371
                 pb=None):
 
372
        self.helper = Inter1and2Helper(from_repository, to_repository)
 
373
        KnitRepoFetcher.__init__(self, to_repository, from_repository,
 
374
                                 last_revision, pb)
 
375
 
 
376
    def _fetch_weave_texts(self, revs):
 
377
        KnitRepoFetcher._fetch_weave_texts(self, revs)
 
378
        # Now generate a weave for the tree root
 
379
        self.helper.generate_root_texts(revs)
 
380
 
 
381
    def _fetch_inventory_weave(self, revs):
 
382
        self.helper.regenerate_inventory(revs)
 
383
        
 
384
 
278
385
class Fetcher(object):
279
386
    """Backwards compatibility glue for branch.fetch()."""
280
387