/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/builtins.py

  • Committer: Parth Malwankar
  • Date: 2010-03-03 14:55:44 UTC
  • mfrom: (5074 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5092.
  • Revision ID: parth.malwankar@gmail.com-20100303145544-1fwse4q2nv2alxoh
merged trunk. resolved conflict in NEWS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
340
340
    # cat-revision is more for frontends so should be exact
341
341
    encoding = 'strict'
342
342
 
 
343
    def print_revision(self, revisions, revid):
 
344
        stream = revisions.get_record_stream([(revid,)], 'unordered', True)
 
345
        record = stream.next()
 
346
        if record.storage_kind == 'absent':
 
347
            raise errors.NoSuchRevision(revisions, revid)
 
348
        revtext = record.get_bytes_as('fulltext')
 
349
        self.outf.write(revtext.decode('utf-8'))
 
350
 
343
351
    @display_command
344
352
    def run(self, revision_id=None, revision=None):
345
353
        if revision_id is not None and revision is not None:
350
358
                                         ' --revision or a revision_id')
351
359
        b = WorkingTree.open_containing(u'.')[0].branch
352
360
 
353
 
        # TODO: jam 20060112 should cat-revision always output utf-8?
354
 
        if revision_id is not None:
355
 
            revision_id = osutils.safe_revision_id(revision_id, warn=False)
356
 
            try:
357
 
                self.outf.write(b.repository.get_revision_xml(revision_id).decode('utf-8'))
358
 
            except errors.NoSuchRevision:
359
 
                msg = "The repository %s contains no revision %s." % (b.repository.base,
360
 
                    revision_id)
361
 
                raise errors.BzrCommandError(msg)
362
 
        elif revision is not None:
363
 
            for rev in revision:
364
 
                if rev is None:
365
 
                    raise errors.BzrCommandError('You cannot specify a NULL'
366
 
                                                 ' revision.')
367
 
                rev_id = rev.as_revision_id(b)
368
 
                self.outf.write(b.repository.get_revision_xml(rev_id).decode('utf-8'))
 
361
        revisions = b.repository.revisions
 
362
        if revisions is None:
 
363
            raise errors.BzrCommandError('Repository %r does not support '
 
364
                'access to raw revision texts')
369
365
 
 
366
        b.repository.lock_read()
 
367
        try:
 
368
            # TODO: jam 20060112 should cat-revision always output utf-8?
 
369
            if revision_id is not None:
 
370
                revision_id = osutils.safe_revision_id(revision_id, warn=False)
 
371
                try:
 
372
                    self.print_revision(revisions, revision_id)
 
373
                except errors.NoSuchRevision:
 
374
                    msg = "The repository %s contains no revision %s." % (
 
375
                        b.repository.base, revision_id)
 
376
                    raise errors.BzrCommandError(msg)
 
377
            elif revision is not None:
 
378
                for rev in revision:
 
379
                    if rev is None:
 
380
                        raise errors.BzrCommandError(
 
381
                            'You cannot specify a NULL revision.')
 
382
                    rev_id = rev.as_revision_id(b)
 
383
                    self.print_revision(revisions, rev_id)
 
384
        finally:
 
385
            b.repository.unlock()
 
386
        
370
387
 
371
388
class cmd_dump_btree(Command):
372
389
    """Dump the contents of a btree index file to stdout.
682
699
 
683
700
    def run(self, dir_list):
684
701
        for d in dir_list:
685
 
            os.mkdir(d)
686
702
            wt, dd = WorkingTree.open_containing(d)
687
 
            wt.add([dd])
688
 
            self.outf.write('added %s\n' % d)
 
703
            base = os.path.dirname(dd)
 
704
            id = wt.path2id(base)
 
705
            if id != None:
 
706
                os.mkdir(d)
 
707
                wt.add([dd])
 
708
                self.outf.write('added %s\n' % d)
 
709
            else:
 
710
                raise errors.NotVersionedError(path=base)
689
711
 
690
712
 
691
713
class cmd_relpath(Command):
2667
2689
        if old_default_rules is not None:
2668
2690
            # dump the rules and exit
2669
2691
            for pattern in ignores.OLD_DEFAULTS:
2670
 
                print pattern
 
2692
                self.outf.write("%s\n" % pattern)
2671
2693
            return
2672
2694
        if not name_pattern_list:
2673
2695
            raise errors.BzrCommandError("ignore requires at least one "
2689
2711
            if id is not None:
2690
2712
                filename = entry[0]
2691
2713
                if ignored.match(filename):
2692
 
                    matches.append(filename.encode('utf-8'))
 
2714
                    matches.append(filename)
2693
2715
        tree.unlock()
2694
2716
        if len(matches) > 0:
2695
 
            print "Warning: the following files are version controlled and" \
2696
 
                  " match your ignore pattern:\n%s" \
2697
 
                  "\nThese files will continue to be version controlled" \
2698
 
                  " unless you 'bzr remove' them." % ("\n".join(matches),)
 
2717
            self.outf.write("Warning: the following files are version controlled and"
 
2718
                  " match your ignore pattern:\n%s"
 
2719
                  "\nThese files will continue to be version controlled"
 
2720
                  " unless you 'bzr remove' them.\n" % ("\n".join(matches),))
2699
2721
 
2700
2722
 
2701
2723
class cmd_ignored(Command):
2739
2761
        try:
2740
2762
            revno = int(revno)
2741
2763
        except ValueError:
2742
 
            raise errors.BzrCommandError("not a valid revision-number: %r" % revno)
2743
 
 
2744
 
        print WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
 
2764
            raise errors.BzrCommandError("not a valid revision-number: %r"
 
2765
                                         % revno)
 
2766
        revid = WorkingTree.open_containing(u'.')[0].branch.get_rev_id(revno)
 
2767
        self.outf.write("%s\n" % revid)
2745
2768
 
2746
2769
 
2747
2770
class cmd_export(Command):
2894
2917
    hidden = True
2895
2918
    @display_command
2896
2919
    def run(self):
2897
 
        print osutils.local_time_offset()
 
2920
        self.outf.write("%s\n" % osutils.local_time_offset())
2898
2921
 
2899
2922
 
2900
2923
 
3151
3174
            raise errors.BzrCommandError("Commit refused because there are"
3152
3175
                              " unknown files in the working tree.")
3153
3176
        except errors.BoundBranchOutOfDate, e:
3154
 
            raise errors.BzrCommandError(str(e) + "\n"
3155
 
            'To commit to master branch, run update and then commit.\n'
3156
 
            'You can also pass --local to commit to continue working '
3157
 
            'disconnected.')
 
3177
            e.extra_help = ("\n"
 
3178
                'To commit to master branch, run update and then commit.\n'
 
3179
                'You can also pass --local to commit to continue working '
 
3180
                'disconnected.')
 
3181
            raise
3158
3182
 
3159
3183
 
3160
3184
class cmd_check(Command):
3322
3346
 
3323
3347
    @display_command
3324
3348
    def printme(self, branch):
3325
 
        print branch.nick
 
3349
        self.outf.write('%s\n' % branch.nick)
3326
3350
 
3327
3351
 
3328
3352
class cmd_alias(Command):
3602
3626
 
3603
3627
    @display_command
3604
3628
    def run(self):
3605
 
        print "It sure does!"
 
3629
        self.outf.write("It sure does!\n")
3606
3630
 
3607
3631
 
3608
3632
class cmd_find_merge_base(Command):
3628
3652
        graph = branch1.repository.get_graph(branch2.repository)
3629
3653
        base_rev_id = graph.find_unique_lca(last1, last2)
3630
3654
 
3631
 
        print 'merge base is revision %s' % base_rev_id
 
3655
        self.outf.write('merge base is revision %s\n' % base_rev_id)
3632
3656
 
3633
3657
 
3634
3658
class cmd_merge(Command):
4427
4451
                doc = '(no description)'
4428
4452
            result.append((name_ver, doc, plugin.path()))
4429
4453
        for name_ver, doc, path in sorted(result):
4430
 
            print name_ver
4431
 
            print '   ', doc
 
4454
            self.outf.write("%s\n" % name_ver)
 
4455
            self.outf.write("   %s\n" % doc)
4432
4456
            if verbose:
4433
 
                print '   ', path
4434
 
            print
 
4457
                self.outf.write("   %s\n" % path)
 
4458
            self.outf.write("\n")
4435
4459
 
4436
4460
 
4437
4461
class cmd_testament(Command):
4717
4741
                rev_id = b.get_rev_id(revno)
4718
4742
 
4719
4743
        if rev_id is None or _mod_revision.is_null(rev_id):
4720
 
            ui.ui_factory.note('No revisions to uncommit.')
 
4744
            self.outf.write('No revisions to uncommit.\n')
4721
4745
            return 1
4722
4746
 
4723
 
        log_collector = ui.ui_factory.make_output_stream()
4724
4747
        lf = log_formatter('short',
4725
 
                           to_file=log_collector,
 
4748
                           to_file=self.outf,
4726
4749
                           show_timezone='original')
4727
4750
 
4728
4751
        show_log(b,
4733
4756
                 end_revision=last_revno)
4734
4757
 
4735
4758
        if dry_run:
4736
 
            ui.ui_factory.note('Dry-run, pretending to remove the above revisions.')
 
4759
            self.outf.write('Dry-run, pretending to remove'
 
4760
                            ' the above revisions.\n')
4737
4761
        else:
4738
 
            ui.ui_factory.note('The above revision(s) will be removed.')
 
4762
            self.outf.write('The above revision(s) will be removed.\n')
4739
4763
 
4740
4764
        if not force:
4741
 
            if not ui.ui_factory.get_boolean('Are you sure [y/N]? '):
4742
 
                ui.ui_factory.note('Canceled')
 
4765
            if not ui.ui_factory.get_boolean('Are you sure'):
 
4766
                self.outf.write('Canceled')
4743
4767
                return 0
4744
4768
 
4745
4769
        mutter('Uncommitting from {%s} to {%s}',
4746
4770
               last_rev_id, rev_id)
4747
4771
        uncommit(b, tree=tree, dry_run=dry_run, verbose=verbose,
4748
4772
                 revno=revno, local=local)
4749
 
        ui.ui_factory.note('You can restore the old tip by running:\n'
4750
 
             '  bzr pull . -r revid:%s' % last_rev_id)
 
4773
        self.outf.write('You can restore the old tip by running:\n'
 
4774
             '  bzr pull . -r revid:%s\n' % last_rev_id)
4751
4775
 
4752
4776
 
4753
4777
class cmd_break_lock(Command):