/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 breezy/plugins/fastimport/processors/generic_processor.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
 
99
99
    * count - only import this many commits then exit. If not set
100
100
      or negative, all commits are imported.
101
 
    
 
101
 
102
102
    * checkpoint - automatically checkpoint every n commits over and
103
103
      above any checkpoints contained in the import stream.
104
104
      The default is 10000.
128
128
        ]
129
129
 
130
130
    def __init__(self, bzrdir, params=None, verbose=False, outf=None,
131
 
            prune_empty_dirs=True):
 
131
                 prune_empty_dirs=True):
132
132
        processor.ImportProcessor.__init__(self, params, verbose)
133
133
        self.prune_empty_dirs = prune_empty_dirs
134
134
        self.controldir = bzrdir
147
147
        self._load_info_and_params()
148
148
        if self.total_commits:
149
149
            self.note("Starting import of %d commits ..." %
150
 
                (self.total_commits,))
 
150
                      (self.total_commits,))
151
151
        else:
152
152
            self.note("Starting import ...")
153
153
        self.cache_mgr = cache_manager.CacheManager(self.info, self.verbose,
154
 
            self.inventory_cache_size)
 
154
                                                    self.inventory_cache_size)
155
155
 
156
156
        if self.params.get("import-marks") is not None:
157
 
            mark_info = marks_file.import_marks(self.params.get("import-marks"))
 
157
            mark_info = marks_file.import_marks(
 
158
                self.params.get("import-marks"))
158
159
            if mark_info is not None:
159
160
                self.cache_mgr.marks = mark_info
160
161
            self.skip_total = False
164
165
            self.skip_total = self._init_id_map()
165
166
            if self.skip_total:
166
167
                self.note("Found %d commits already loaded - "
167
 
                    "skipping over these ...", self.skip_total)
 
168
                          "skipping over these ...", self.skip_total)
168
169
        self._revision_count = 0
169
170
 
170
171
        # mapping of tag name to revision_id
178
179
        if isinstance(self.repo, KnitPackRepository):
179
180
            self._original_max_pack_count = \
180
181
                self.repo._pack_collection._max_pack_count
 
182
 
181
183
            def _max_pack_count_for_import(total_revisions):
182
184
                return total_revisions + 1
183
185
            self.repo._pack_collection._max_pack_count = \
226
228
 
227
229
        # Decide how often (# of commits) to automatically checkpoint
228
230
        self.checkpoint_every = int(self.params.get('checkpoint',
229
 
            _DEFAULT_AUTO_CHECKPOINT))
 
231
                                                    _DEFAULT_AUTO_CHECKPOINT))
230
232
 
231
233
        # Decide how often (# of checkpoints) to automatically pack
232
234
        self.checkpoint_count = 0
233
235
        self.autopack_every = int(self.params.get('autopack',
234
 
            _DEFAULT_AUTO_PACK))
 
236
                                                  _DEFAULT_AUTO_PACK))
235
237
 
236
238
        # Decide how big to make the inventory cache
237
239
        cache_size = int(self.params.get('inv-cache', -1))
255
257
            self.max_commits = None
256
258
        if self.info is not None:
257
259
            self.total_commits = int(self.info['Command counts']['commit'])
258
 
            if (self.max_commits is not None and
259
 
                self.total_commits > self.max_commits):
 
260
            if (self.max_commits is not None
 
261
                    and self.total_commits > self.max_commits):
260
262
                self.total_commits = self.max_commits
261
263
        else:
262
264
            self.total_commits = self.max_commits
306
308
 
307
309
        if self.params.get("export-marks") is not None:
308
310
            marks_file.export_marks(self.params.get("export-marks"),
309
 
                self.cache_mgr.marks)
 
311
                                    self.cache_mgr.marks)
310
312
 
311
 
        if self.cache_mgr.reftracker.last_ref == None:
 
313
        if self.cache_mgr.reftracker.last_ref is None:
312
314
            """Nothing to refresh"""
313
315
            return
314
316
 
315
317
        # Update the branches
316
318
        self.note("Updating branch information ...")
317
319
        updater = branch_updater.BranchUpdater(self.repo, self.branch,
318
 
            self.cache_mgr, invert_dictset(
319
 
                self.cache_mgr.reftracker.heads),
320
 
            self.cache_mgr.reftracker.last_ref, self.tags)
 
320
                                               self.cache_mgr, invert_dictset(
 
321
                                                   self.cache_mgr.reftracker.heads),
 
322
                                               self.cache_mgr.reftracker.last_ref, self.tags)
321
323
        branches_updated, branches_lost = updater.update()
322
324
        self._branch_count = len(branches_updated)
323
325
 
325
327
        if branches_lost:
326
328
            if not self.repo.is_shared():
327
329
                self.warning("Cannot import multiple branches into "
328
 
                    "a standalone branch")
 
330
                             "a standalone branch")
329
331
            self.warning("Not creating branches for these head revisions:")
330
332
            for lost_info in branches_lost:
331
333
                head_revision = lost_info[1]
370
372
        if remind_about_update:
371
373
            # This message is explicitly not timestamped.
372
374
            note("To refresh the working tree for other branches, "
373
 
                "use 'bzr update' inside that branch.")
 
375
                 "use 'bzr update' inside that branch.")
374
376
 
375
377
    def _update_working_trees(self, trees):
376
378
        if self.verbose:
434
436
        bc = self._branch_count
435
437
        wtc = self._tree_count
436
438
        self.note("Imported %d %s, updating %d %s and %d %s in %s",
437
 
            rc, helpers.single_plural(rc, "revision", "revisions"),
438
 
            bc, helpers.single_plural(bc, "branch", "branches"),
439
 
            wtc, helpers.single_plural(wtc, "tree", "trees"),
440
 
            time_required)
 
439
                  rc, helpers.single_plural(rc, "revision", "revisions"),
 
440
                  bc, helpers.single_plural(bc, "branch", "branches"),
 
441
                  wtc, helpers.single_plural(wtc, "tree", "trees"),
 
442
                  time_required)
441
443
 
442
444
    def _init_id_map(self):
443
445
        """Load the id-map and check it matches the repository.
489
491
        if self.skip_total and self._revision_count < self.skip_total:
490
492
            self.cache_mgr.reftracker.track_heads(cmd)
491
493
            # Check that we really do know about this commit-id
492
 
            if not self.cache_mgr.marks.has_key(mark):
 
494
            if mark not in self.cache_mgr.marks:
493
495
                raise plugin_errors.BadRestart(mark)
494
496
            self.cache_mgr._blobs = {}
495
497
            self._revision_count += 1
503
505
 
504
506
        # 'Commit' the revision and report progress
505
507
        handler = self.commit_handler_factory(cmd, self.cache_mgr,
506
 
            self.rev_store, verbose=self.verbose,
507
 
            prune_empty_dirs=self.prune_empty_dirs)
 
508
                                              self.rev_store, verbose=self.verbose,
 
509
                                              prune_empty_dirs=self.prune_empty_dirs)
508
510
        try:
509
511
            handler.process()
510
512
        except:
519
521
            self._set_tag(tag_name, cmd.id)
520
522
 
521
523
        # Check if we should finish up or automatically checkpoint
522
 
        if (self.max_commits is not None and
523
 
            self._revision_count >= self.max_commits):
 
524
        if (self.max_commits is not None
 
525
                and self._revision_count >= self.max_commits):
524
526
            self.note("Stopping after reaching requested count of commits")
525
527
            self.finished = True
526
528
        elif self._revision_count % self.checkpoint_every == 0:
527
529
            self.note("%d commits - automatic checkpoint triggered",
528
 
                self._revision_count)
 
530
                      self._revision_count)
529
531
            self.checkpoint_handler(None)
530
532
 
531
533
    def report_progress(self, details=''):
541
543
                rate_str = "at %.0f/minute " % rate
542
544
            else:
543
545
                rate_str = "at %.1f/minute " % rate
544
 
            self.note("%s commits processed %s%s" % (counts, rate_str, details))
 
546
            self.note("%s commits processed %s%s" %
 
547
                      (counts, rate_str, details))
545
548
 
546
549
    def progress_handler(self, cmd):
547
550
        """Process a ProgressCommand."""
558
561
                self._set_tag(tag_name, cmd.from_)
559
562
            elif self.verbose:
560
563
                self.warning("ignoring reset refs/tags/%s - no from clause"
561
 
                    % tag_name)
 
564
                             % tag_name)
562
565
            return
563
566
 
564
567
        if cmd.from_ is not None: