~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Martin Pool
  • Date: 2005-06-27 01:36:22 UTC
  • Revision ID: mbp@sourcefrog.net-20050627013622-0d56be3e3105043e
Merge from aaron:

------------------------------------------------------------
revno: 763
committer: Aaron Bentley <abentley@panoramicfeedback.com>
timestamp: Thu 2005-06-23 17:30:28 -0400
message:
  Copy files in immutable stores directly.
------------------------------------------------------------
revno: 762
committer: Aaron Bentley <abentley@panoramicfeedback.com>
timestamp: Thu 2005-06-23 16:12:33 -0400
message:
  Fixed direct call of get_url in RemoteBranch.get_revision
------------------------------------------------------------
revno: 761
committer: Aaron Bentley <abentley@panoramicfeedback.com>
timestamp: Thu 2005-06-23 12:00:31 -0400
message:
  Added prefetch support to update_revisions
------------------------------------------------------------
revno: 760
committer: Aaron Bentley <abentley@panoramicfeedback.com>
timestamp: Thu 2005-06-23 11:57:54 -0400
message:
  Added cache support to branch and pull
------------------------------------------------------------
revno: 759
committer: Aaron Bentley <abentley@panoramicfeedback.com>
timestamp: Thu 2005-06-23 11:21:37 -0400
message:
  Added find_cached_branch to branch
------------------------------------------------------------
revno: 758
committer: Aaron Bentley <abentley@panoramicfeedback.com>
timestamp: Thu 2005-06-23 11:17:10 -0400
message:
  Added CachedStore type to reduce remote downloads

Show diffs side-by-side

added added

removed removed

Lines of Context:
469
469
 
470
470
    def run(self, location=None):
471
471
        from bzrlib.merge import merge
 
472
        import tempfile
 
473
        from shutil import rmtree
472
474
        import errno
473
475
        
474
476
        br_to = Branch('.')
484
486
            else:
485
487
                print "Using last location: %s" % stored_loc
486
488
                location = stored_loc
487
 
        from branch import find_branch, DivergedBranches
488
 
        br_from = find_branch(location)
489
 
        location = pull_loc(br_from)
490
 
        old_revno = br_to.revno()
 
489
        cache_root = tempfile.mkdtemp()
491
490
        try:
492
 
            br_to.update_revisions(br_from)
493
 
        except DivergedBranches:
494
 
            raise BzrCommandError("These branches have diverged.  Try merge.")
495
 
            
496
 
        merge(('.', -1), ('.', old_revno), check_clean=False)
497
 
        if location != stored_loc:
498
 
            br_to.controlfile("x-pull", "wb").write(location + "\n")
 
491
            from branch import find_cached_branch, DivergedBranches
 
492
            br_from = find_cached_branch(location, cache_root)
 
493
            location = pull_loc(br_from)
 
494
            old_revno = br_to.revno()
 
495
            try:
 
496
                br_to.update_revisions(br_from)
 
497
            except DivergedBranches:
 
498
                raise BzrCommandError("These branches have diverged."
 
499
                    "  Try merge.")
 
500
                
 
501
            merge(('.', -1), ('.', old_revno), check_clean=False)
 
502
            if location != stored_loc:
 
503
                br_to.controlfile("x-pull", "wb").write(location + "\n")
 
504
        finally:
 
505
            rmtree(cache_root)
499
506
 
500
507
 
501
508
 
514
521
    def run(self, from_location, to_location=None, revision=None):
515
522
        import errno
516
523
        from bzrlib.merge import merge
517
 
        from branch import find_branch, DivergedBranches, NoSuchRevision
 
524
        from branch import find_cached_branch, DivergedBranches, NoSuchRevision
518
525
        from shutil import rmtree
519
 
        try:
520
 
            br_from = find_branch(from_location)
521
 
        except OSError, e:
522
 
            if e.errno == errno.ENOENT:
523
 
                raise BzrCommandError('Source location "%s" does not exist.' %
524
 
                                      to_location)
525
 
            else:
526
 
                raise
527
 
 
528
 
        if to_location is None:
529
 
            to_location = os.path.basename(from_location.rstrip("/\\"))
530
 
 
531
 
        try:
532
 
            os.mkdir(to_location)
533
 
        except OSError, e:
534
 
            if e.errno == errno.EEXIST:
535
 
                raise BzrCommandError('Target directory "%s" already exists.' %
536
 
                                      to_location)
537
 
            if e.errno == errno.ENOENT:
538
 
                raise BzrCommandError('Parent of "%s" does not exist.' %
539
 
                                      to_location)
540
 
            else:
541
 
                raise
542
 
        br_to = Branch(to_location, init=True)
543
 
 
544
 
        try:
545
 
            br_to.update_revisions(br_from, stop_revision=revision)
546
 
        except NoSuchRevision:
547
 
            rmtree(to_location)
548
 
            msg = "The branch %s has no revision %d." % (from_location,
549
 
                                                         revision)
550
 
            raise BzrCommandError(msg)
551
 
        merge((to_location, -1), (to_location, 0), this_dir=to_location,
552
 
              check_clean=False, ignore_zero=True)
553
 
        from_location = pull_loc(br_from)
554
 
        br_to.controlfile("x-pull", "wb").write(from_location + "\n")
 
526
        from meta_store import CachedStore
 
527
        import tempfile
 
528
        cache_root = tempfile.mkdtemp()
 
529
        try:
 
530
            try:
 
531
                br_from = find_cached_branch(from_location, cache_root)
 
532
            except OSError, e:
 
533
                if e.errno == errno.ENOENT:
 
534
                    raise BzrCommandError('Source location "%s" does not'
 
535
                                          ' exist.' % to_location)
 
536
                else:
 
537
                    raise
 
538
 
 
539
            if to_location is None:
 
540
                to_location = os.path.basename(from_location.rstrip("/\\"))
 
541
 
 
542
            try:
 
543
                os.mkdir(to_location)
 
544
            except OSError, e:
 
545
                if e.errno == errno.EEXIST:
 
546
                    raise BzrCommandError('Target directory "%s" already'
 
547
                                          ' exists.' % to_location)
 
548
                if e.errno == errno.ENOENT:
 
549
                    raise BzrCommandError('Parent of "%s" does not exist.' %
 
550
                                          to_location)
 
551
                else:
 
552
                    raise
 
553
            br_to = Branch(to_location, init=True)
 
554
 
 
555
            try:
 
556
                br_to.update_revisions(br_from, stop_revision=revision)
 
557
            except NoSuchRevision:
 
558
                rmtree(to_location)
 
559
                msg = "The branch %s has no revision %d." % (from_location,
 
560
                                                             revision)
 
561
                raise BzrCommandError(msg)
 
562
            merge((to_location, -1), (to_location, 0), this_dir=to_location,
 
563
                  check_clean=False, ignore_zero=True)
 
564
            from_location = pull_loc(br_from)
 
565
            br_to.controlfile("x-pull", "wb").write(from_location + "\n")
 
566
        finally:
 
567
            rmtree(cache_root)
555
568
 
556
569
 
557
570
def pull_loc(branch):