~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commands.py

  • Committer: Martin Pool
  • Date: 2005-05-31 08:10:44 UTC
  • Revision ID: mbp@sourcefrog.net-20050531081044-0f6d28e39b8e19de
- replace Branch.lock(mode) with separate lock_read and lock_write 
  methods

Show diffs side-by-side

added added

removed removed

Lines of Context:
384
384
 
385
385
 
386
386
 
387
 
 
388
 
 
389
 
class cmd_pull(Command):
390
 
    """Pull any changes from another branch into the current one.
391
 
 
392
 
    If the location is omitted, the last-used location will be used.
393
 
    Both the revision history and the working directory will be
394
 
    updated.
395
 
 
396
 
    This command only works on branches that have not diverged.  Branches are
397
 
    considered diverged if both branches have had commits without first
398
 
    pulling from the other.
399
 
 
400
 
    If branches have diverged, you can use 'bzr merge' to pull the text changes
401
 
    from one into the other.
402
 
    """
403
 
    takes_args = ['location?']
404
 
 
405
 
    def run(self, location=None):
406
 
        from bzrlib.merge import merge
407
 
        import errno
408
 
        
409
 
        br_to = Branch('.')
410
 
        stored_loc = None
411
 
        try:
412
 
            stored_loc = br_to.controlfile("x-pull", "rb").read().rstrip('\n')
413
 
        except IOError, e:
414
 
            if errno == errno.ENOENT:
415
 
                raise
416
 
        if location is None:
417
 
            location = stored_loc
418
 
        if location is None:
419
 
            raise BzrCommandError("No pull location known or specified.")
420
 
        from branch import find_branch, DivergedBranches
421
 
        br_from = find_branch(location)
422
 
        location = pull_loc(br_from)
423
 
        old_revno = br_to.revno()
424
 
        try:
425
 
            br_to.update_revisions(br_from)
426
 
        except DivergedBranches:
427
 
            raise BzrCommandError("These branches have diverged.  Try merge.")
428
 
            
429
 
        merge(('.', -1), ('.', old_revno))
430
 
        if location != stored_loc:
431
 
            br_to.controlfile("x-pull", "wb").write(location + "\n")
432
 
 
433
 
 
434
 
 
435
 
class cmd_branch(Command):
436
 
    """Create a new copy of a branch.
437
 
 
438
 
    If the TO_LOCATION is omitted, the last component of the
439
 
    FROM_LOCATION will be used.  In other words,
440
 
    "branch ../foo/bar" will attempt to create ./bar.
441
 
    """
442
 
    takes_args = ['from_location', 'to_location?']
443
 
 
444
 
    def run(self, from_location, to_location=None):
445
 
        import errno
446
 
        from bzrlib.merge import merge
447
 
        
448
 
        if to_location is None:
449
 
            to_location = os.path.basename(from_location)
450
 
            # FIXME: If there's a trailing slash, keep removing them
451
 
            # until we find the right bit
452
 
 
453
 
        try:
454
 
            os.mkdir(to_location)
455
 
        except OSError, e:
456
 
            if e.errno == errno.EEXIST:
457
 
                raise BzrCommandError('Target directory "%s" already exists.' %
458
 
                                      to_location)
459
 
            if e.errno == errno.ENOENT:
460
 
                raise BzrCommandError('Parent of "%s" does not exist.' %
461
 
                                      to_location)
462
 
            else:
463
 
                raise
464
 
        br_to = Branch(to_location, init=True)
465
 
        from branch import find_branch, DivergedBranches
466
 
        try:
467
 
            br_from = find_branch(from_location)
468
 
        except OSError, e:
469
 
            if e.errno == errno.ENOENT:
470
 
                raise BzrCommandError('Source location "%s" does not exist.' %
471
 
                                      to_location)
472
 
            else:
473
 
                raise
474
 
 
475
 
        from_location = pull_loc(br_from)
476
 
        br_to.update_revisions(br_from)
477
 
        merge((to_location, -1), (to_location, 0), this_dir=to_location,
478
 
              check_clean=False)
479
 
        br_to.controlfile("x-pull", "wb").write(from_location + "\n")
480
 
 
481
 
 
482
 
def pull_loc(branch):
483
 
    # TODO: Should perhaps just make attribute be 'base' in
484
 
    # RemoteBranch and Branch?
485
 
    if hasattr(branch, "baseurl"):
486
 
        return branch.baseurl
487
 
    else:
488
 
        return branch.base
489
 
 
490
 
 
491
 
 
492
387
class cmd_renames(Command):
493
388
    """Show list of renamed files.
494
389
 
839
734
 
840
735
 
841
736
class cmd_unknowns(Command):
842
 
    """List unknown files."""
 
737
    """List unknown files"""
843
738
    def run(self):
844
739
        for f in Branch('.').unknowns():
845
740
            print quotefn(f)
847
742
 
848
743
 
849
744
class cmd_ignore(Command):
850
 
    """Ignore a command or pattern.
 
745
    """Ignore a command or pattern
851
746
 
852
747
    To remove patterns from the ignore list, edit the .bzrignore file.
853
748
 
1047
942
 
1048
943
 
1049
944
class cmd_version(Command):
1050
 
    """Show version of bzr."""
 
945
    """Show version of bzr"""
1051
946
    def run(self):
1052
947
        show_version()
1053
948
 
1072
967
        print "it sure does!"
1073
968
 
1074
969
def parse_spec(spec):
1075
 
    """
1076
 
    >>> parse_spec(None)
1077
 
    [None, None]
1078
 
    >>> parse_spec("./")
1079
 
    ['./', None]
1080
 
    >>> parse_spec("../@")
1081
 
    ['..', -1]
1082
 
    >>> parse_spec("../f/@35")
1083
 
    ['../f', 35]
1084
 
    """
1085
 
    if spec is None:
1086
 
        return [None, None]
1087
970
    if '/@' in spec:
1088
971
        parsed = spec.split('/@')
1089
972
        assert len(parsed) == 2
1096
979
        parsed = [spec, None]
1097
980
    return parsed
1098
981
 
1099
 
 
1100
 
 
1101
982
class cmd_merge(Command):
1102
 
    """Perform a three-way merge of trees.
1103
 
    
1104
 
    The SPEC parameters are working tree or revision specifiers.  Working trees
1105
 
    are specified using standard paths or urls.  No component of a directory
1106
 
    path may begin with '@'.
1107
 
    
1108
 
    Working tree examples: '.', '..', 'foo@', but NOT 'foo/@bar'
1109
 
 
1110
 
    Revisions are specified using a dirname/@revno pair, where dirname is the
1111
 
    branch directory and revno is the revision within that branch.  If no revno
1112
 
    is specified, the latest revision is used.
1113
 
 
1114
 
    Revision examples: './@127', 'foo/@', '../@1'
1115
 
 
1116
 
    The OTHER_SPEC parameter is required.  If the BASE_SPEC parameter is
1117
 
    not supplied, the common ancestor of OTHER_SPEC the current branch is used
1118
 
    as the BASE.
1119
 
 
1120
 
    merge refuses to run if there are any uncommitted changes, unless
1121
 
    --force is given.
1122
 
    """
1123
 
    takes_args = ['other_spec', 'base_spec?']
1124
 
    takes_options = ['force']
1125
 
 
1126
 
    def run(self, other_spec, base_spec=None, force=False):
 
983
    """Perform a three-way merge of trees."""
 
984
    takes_args = ['other_spec', 'base_spec']
 
985
 
 
986
    def run(self, other_spec, base_spec):
1127
987
        from bzrlib.merge import merge
1128
 
        merge(parse_spec(other_spec), parse_spec(base_spec),
1129
 
              check_clean=(not force))
1130
 
 
1131
 
 
1132
 
class cmd_revert(Command):
1133
 
    """Reverse all changes since the last commit.
1134
 
 
1135
 
    Only versioned files are affected.
1136
 
 
1137
 
    TODO: Store backups of any files that will be reverted, so
1138
 
          that the revert can be undone.          
1139
 
    """
1140
 
    takes_options = ['revision']
1141
 
 
1142
 
    def run(self, revision=-1):
1143
 
        merge(('.', revision), parse_spec('.'),
1144
 
              check_clean=False,
1145
 
              ignore_zero=True)
1146
 
 
 
988
        merge(parse_spec(other_spec), parse_spec(base_spec))
1147
989
 
1148
990
class cmd_assert_fail(Command):
1149
991
    """Test reporting of assertion failures"""
1184
1026
    'diff-options':           str,
1185
1027
    'help':                   None,
1186
1028
    'file':                   unicode,
1187
 
    'force':                  None,
1188
1029
    'forward':                None,
1189
1030
    'message':                unicode,
1190
1031
    'no-recurse':             None,