~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2006-06-20 05:32:16 UTC
  • mfrom: (1797 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1798.
  • Revision ID: mbp@sourcefrog.net-20060620053216-817857d7ca3e9d1f
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
import bzrlib
26
26
from bzrlib.branch import Branch, BranchReferenceFormat
27
 
from bzrlib import (branch, bzrdir, errors, osutils, ui, config,
 
27
from bzrlib import (bundle, branch, bzrdir, errors, osutils, ui, config,
28
28
    repository, log)
29
29
from bzrlib.bundle.read_bundle import BundleReader
30
 
from bzrlib.bundle.apply_bundle import merge_bundle
 
30
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
31
31
from bzrlib.commands import Command, display_command
32
32
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError, 
33
33
                           NotBranchError, DivergedBranches, NotConflicted,
126
126
    modified
127
127
        Text has changed since the previous revision.
128
128
 
129
 
    unchanged
130
 
        Nothing about this file has changed since the previous revision.
131
 
        Only shown with --all.
132
 
 
133
129
    unknown
134
130
        Not versioned and not matching an ignore pattern.
135
131
 
148
144
    # TODO: --no-recurse, --recurse options
149
145
    
150
146
    takes_args = ['file*']
151
 
    takes_options = ['all', 'show-ids', 'revision']
 
147
    takes_options = ['show-ids', 'revision']
152
148
    aliases = ['st', 'stat']
153
149
 
154
150
    encoding_type = 'replace'
155
151
    
156
152
    @display_command
157
 
    def run(self, all=False, show_ids=False, file_list=None, revision=None):
 
153
    def run(self, show_ids=False, file_list=None, revision=None):
158
154
        from bzrlib.status import show_tree_status
159
155
 
160
156
        tree, file_list = tree_files(file_list)
161
157
            
162
 
        show_tree_status(tree, show_unchanged=all, show_ids=show_ids,
 
158
        show_tree_status(tree, show_ids=show_ids,
163
159
                         specific_files=file_list, revision=revision,
164
160
                         to_file=self.outf)
165
161
 
413
409
 
414
410
    If there is no default location set, the first pull will set it.  After
415
411
    that, you can omit the location to use the default.  To change the
416
 
    default, use --remember.
 
412
    default, use --remember. The value will only be saved if the remote
 
413
    location can be accessed.
417
414
    """
418
415
 
419
416
    takes_options = ['remember', 'overwrite', 'revision', 'verbose']
428
425
        except NoWorkingTree:
429
426
            tree_to = None
430
427
            branch_to = Branch.open_containing(u'.')[0]
 
428
 
 
429
        reader = None
 
430
        if location is not None:
 
431
            try:
 
432
                reader = bundle.read_bundle_from_url(location)
 
433
            except NotABundle:
 
434
                pass # Continue on considering this url a Branch
 
435
 
431
436
        stored_loc = branch_to.get_parent()
432
437
        if location is None:
433
438
            if stored_loc is None:
438
443
                self.outf.write("Using saved location: %s\n" % display_url)
439
444
                location = stored_loc
440
445
 
441
 
        branch_from = Branch.open(location)
442
 
 
443
 
        if branch_to.get_parent() is None or remember:
444
 
            branch_to.set_parent(branch_from.base)
445
 
 
 
446
 
 
447
        if reader is not None:
 
448
            install_bundle(branch_to.repository, reader)
 
449
            branch_from = branch_to
 
450
        else:
 
451
            branch_from = Branch.open(location)
 
452
 
 
453
            if branch_to.get_parent() is None or remember:
 
454
                branch_to.set_parent(branch_from.base)
 
455
 
 
456
        rev_id = None
446
457
        if revision is None:
447
 
            rev_id = None
 
458
            if reader is not None:
 
459
                rev_id = reader.info.target
448
460
        elif len(revision) == 1:
449
461
            rev_id = revision[0].in_history(branch_from).rev_id
450
462
        else:
488
500
 
489
501
    If there is no default push location set, the first push will set it.
490
502
    After that, you can omit the location to use the default.  To change the
491
 
    default, use --remember.
 
503
    default, use --remember. The value will only be saved if the remote
 
504
    location can be accessed.
492
505
    """
493
506
 
494
507
    takes_options = ['remember', 'overwrite', 'verbose',
512
525
            else:
513
526
                display_url = urlutils.unescape_for_display(stored_loc,
514
527
                        self.outf.encoding)
515
 
                self.outf.write("Using saved location: %s" % display_url)
 
528
                self.outf.write("Using saved location: %s\n" % display_url)
516
529
                location = stored_loc
517
530
 
518
531
        transport = get_transport(location)
519
532
        location_url = transport.base
520
 
        if br_from.get_push_location() is None or remember:
521
 
            br_from.set_push_location(location_url)
522
533
 
523
534
        old_rh = []
524
535
        try:
554
565
                revision_id=br_from.last_revision())
555
566
            br_to = dir_to.open_branch()
556
567
            count = len(br_to.revision_history())
 
568
            # We successfully created the target, remember it
 
569
            if br_from.get_push_location() is None or remember:
 
570
                br_from.set_push_location(br_to.base)
557
571
        else:
 
572
            # We were able to connect to the remote location, so remember it
 
573
            # we don't need to successfully push because of possible divergence.
 
574
            if br_from.get_push_location() is None or remember:
 
575
                br_from.set_push_location(br_to.base)
558
576
            old_rh = br_to.revision_history()
559
577
            try:
560
578
                try:
922
940
 
923
941
 
924
942
class cmd_revision_history(Command):
925
 
    """Display list of revision ids on this branch."""
 
943
    """Display the list of revision ids on a branch."""
 
944
    takes_args = ['location?']
 
945
 
926
946
    hidden = True
927
947
 
928
948
    @display_command
929
 
    def run(self):
930
 
        branch = WorkingTree.open_containing(u'.')[0].branch
931
 
        for patchid in branch.revision_history():
932
 
            self.outf.write(patchid)
 
949
    def run(self, location="."):
 
950
        branch = Branch.open_containing(location)[0]
 
951
        for revid in branch.revision_history():
 
952
            self.outf.write(revid)
933
953
            self.outf.write('\n')
934
954
 
935
955
 
936
956
class cmd_ancestry(Command):
937
957
    """List all revisions merged into this branch."""
 
958
    takes_args = ['location?']
 
959
 
938
960
    hidden = True
939
961
 
940
962
    @display_command
941
 
    def run(self):
942
 
        tree = WorkingTree.open_containing(u'.')[0]
943
 
        b = tree.branch
944
 
        # FIXME. should be tree.last_revision
945
 
        revision_ids = b.repository.get_ancestry(b.last_revision())
 
963
    def run(self, location="."):
 
964
        try:
 
965
            wt = WorkingTree.open_containing(location)[0]
 
966
        except errors.NoWorkingTree:
 
967
            b = Branch.open(location)
 
968
            last_revision = b.last_revision()
 
969
        else:
 
970
            b = wt.branch
 
971
            last_revision = wt.last_revision()
 
972
 
 
973
        revision_ids = b.repository.get_ancestry(last_revision)
946
974
        assert revision_ids[0] == None
947
975
        revision_ids.pop(0)
948
976
        for revision_id in revision_ids:
1993
2021
 
1994
2022
    If there is no default branch set, the first merge will set it. After
1995
2023
    that, you can omit the branch to use the default.  To change the
1996
 
    default, use --remember.
 
2024
    default, use --remember. The value will only be saved if the remote
 
2025
    location can be accessed.
1997
2026
 
1998
2027
    Examples:
1999
2028
 
2028
2057
 
2029
2058
        tree = WorkingTree.open_containing(u'.')[0]
2030
2059
 
2031
 
        try:
2032
 
            if branch is not None:
2033
 
                reader = BundleReader(file(branch, 'rb'))
2034
 
            else:
2035
 
                reader = None
2036
 
        except IOError, e:
2037
 
            if e.errno not in (errno.ENOENT, errno.EISDIR):
2038
 
                raise
2039
 
            reader = None
2040
 
        except NotABundle:
2041
 
            reader = None
2042
 
        if reader is not None:
2043
 
            conflicts = merge_bundle(reader, tree, not force, merge_type,
2044
 
                                        reprocess, show_base)
2045
 
            if conflicts == 0:
2046
 
                return 0
2047
 
            else:
2048
 
                return 1
 
2060
        if branch is not None:
 
2061
            try:
 
2062
                reader = bundle.read_bundle_from_url(branch)
 
2063
            except NotABundle:
 
2064
                pass # Continue on considering this url a Branch
 
2065
            else:
 
2066
                conflicts = merge_bundle(reader, tree, not force, merge_type,
 
2067
                                            reprocess, show_base)
 
2068
                if conflicts == 0:
 
2069
                    return 0
 
2070
                else:
 
2071
                    return 1
2049
2072
 
2050
2073
        branch = self._get_remembered_parent(tree, branch, 'Merging from')
2051
2074
 
2392
2415
 
2393
2416
class cmd_testament(Command):
2394
2417
    """Show testament (signing-form) of a revision."""
2395
 
    takes_options = ['revision', 'long']
 
2418
    takes_options = ['revision', 'long', 
 
2419
                     Option('strict', help='Produce a strict testament')]
2396
2420
    takes_args = ['branch?']
2397
2421
    @display_command
2398
 
    def run(self, branch=u'.', revision=None, long=False):
2399
 
        from bzrlib.testament import Testament
 
2422
    def run(self, branch=u'.', revision=None, long=False, strict=False):
 
2423
        from bzrlib.testament import Testament, StrictTestament
 
2424
        if strict is True:
 
2425
            testament_class = StrictTestament
 
2426
        else:
 
2427
            testament_class = Testament
2400
2428
        b = WorkingTree.open_containing(branch)[0].branch
2401
2429
        b.lock_read()
2402
2430
        try:
2404
2432
                rev_id = b.last_revision()
2405
2433
            else:
2406
2434
                rev_id = revision[0].in_history(b).rev_id
2407
 
            t = Testament.from_revision(b.repository, rev_id)
 
2435
            t = testament_class.from_revision(b.repository, rev_id)
2408
2436
            if long:
2409
2437
                sys.stdout.writelines(t.as_text_lines())
2410
2438
            else: