~lifeless/bzr-git/bug-526133

« back to all changes in this revision

Viewing changes to branch.py

  • Committer: Jelmer Vernooij
  • Date: 2010-02-18 12:04:46 UTC
  • mfrom: (720.1.8 partial-fetch)
  • Revision ID: jelmer@samba.org-20100218120446-lj4y1l8d0s1hyt02
Merge partial fetch support from Michael.

Show diffs side-by-side

added added

removed removed

Lines of Context:
372
372
                not isinstance(target, GitBranch) and
373
373
                (getattr(cls._get_interrepo(source, target), "fetch_objects", None) is not None))
374
374
 
375
 
    def update_revisions(self, stop_revision=None, overwrite=False,
376
 
        graph=None):
377
 
        """See InterBranch.update_revisions()."""
 
375
    def _update_revisions(self, stop_revision=None, overwrite=False,
 
376
        graph=None, limit=None):
 
377
        """Like InterBranch.update_revisions(), but with additions.
 
378
 
 
379
        Compared to the `update_revisions()` below, this function takes a
 
380
        `limit` argument that limits how many git commits will be converted
 
381
        and returns the new git head.
 
382
        """
378
383
        interrepo = self._get_interrepo(self.source, self.target)
379
 
        self._head = None
380
 
        self._last_revid = None
381
384
        def determine_wants(heads):
382
385
            if not self.source.name in heads:
383
386
                raise NoSuchRef(self.source.name, heads.keys())
384
387
            if stop_revision is not None:
385
 
                self._last_revid = stop_revision
386
 
                self._head, mapping = self.source.repository.lookup_bzr_revision_id(
 
388
                last_revid = stop_revision
 
389
                head, mapping = self.source.repository.lookup_bzr_revision_id(
387
390
                    stop_revision)
388
391
            else:
389
 
                self._head = heads[self.source.name]
390
 
                self._last_revid = \
391
 
                    self.source.mapping.revision_id_foreign_to_bzr(self._head)
392
 
            if self.target.repository.has_revision(self._last_revid):
 
392
                head = heads[self.source.name]
 
393
                last_revid = self.source.mapping.revision_id_foreign_to_bzr(
 
394
                    head)
 
395
            if self.target.repository.has_revision(last_revid):
393
396
                return []
394
 
            return [self._head]
395
 
        interrepo.fetch_objects(determine_wants, self.source.mapping)
 
397
            return [head]
 
398
        _, head = interrepo.fetch_objects(
 
399
            determine_wants, self.source.mapping, limit=limit)
 
400
        if head is None:
 
401
            last_revid = self.target.last_revision()
 
402
        else:
 
403
            last_revid = self.source.mapping.revision_id_foreign_to_bzr(head)
396
404
        if overwrite:
397
405
            prev_last_revid = None
398
406
        else:
399
407
            prev_last_revid = self.target.last_revision()
400
 
        self.target.generate_revision_history(self._last_revid, prev_last_revid)
 
408
        self.target.generate_revision_history(last_revid, prev_last_revid)
 
409
        return head
 
410
 
 
411
    def update_revisions(self, stop_revision=None, overwrite=False, graph=None):
 
412
        """See InterBranch.update_revisions()."""
 
413
        self._update_revisions(stop_revision, overwrite, graph)
401
414
 
402
415
    def pull(self, overwrite=False, stop_revision=None,
403
416
             possible_transports=None, _hook_master=None, run_hooks=True,
404
 
             _override_hook_target=None, local=False):
 
417
             _override_hook_target=None, local=False, limit=None):
405
418
        """See Branch.pull.
406
419
 
407
420
        :param _hook_master: Private parameter - set the branch to
411
424
            so it should not run its hooks.
412
425
        :param _override_hook_target: Private parameter - set the branch to be
413
426
            supplied as the target_branch to pull hooks.
 
427
        :param limit: Only import this many revisons.  `None`, the default,
 
428
            means import all revisions.
414
429
        """
415
430
        # This type of branch can't be bound.
416
431
        if local:
426
441
            # We assume that during 'pull' the target repository is closer than
427
442
            # the source one.
428
443
            graph = self.target.repository.get_graph(self.source.repository)
429
 
            result.old_revno, result.old_revid = \
430
 
                self.target.last_revision_info()
431
 
            self.update_revisions(stop_revision, overwrite=overwrite,
432
 
                graph=graph)
433
 
            result.new_git_head = self._head
 
444
            result.old_revno, result.old_revid = self.target.last_revision_info()
 
445
            result.new_git_head = self._update_revisions(
 
446
                stop_revision, overwrite=overwrite, graph=graph, limit=limit)
434
447
            result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
435
448
                overwrite)
436
449
            result.new_revno, result.new_revid = self.target.last_revision_info()
453
466
        result.target_branch = self.target
454
467
        graph = self.target.repository.get_graph(self.source.repository)
455
468
        result.old_revno, result.old_revid = self.target.last_revision_info()
456
 
        self.update_revisions(stop_revision, overwrite=overwrite, graph=graph)
457
 
        result.new_git_head = self._head
 
469
        result.new_git_head = self._update_revisions(
 
470
            stop_revision, overwrite=overwrite, graph=graph)
458
471
        result.tag_conflicts = self.source.tags.merge_to(self.target.tags,
459
472
            overwrite)
460
473
        result.new_revno, result.new_revid = self.target.last_revision_info()