/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: Robert Collins
  • Date: 2005-10-27 19:45:18 UTC
  • mfrom: (1185.16.130)
  • Revision ID: robertc@robertcollins.net-20051027194518-58afabc9ab280bb0
MergeĀ fromĀ Martin

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
from bzrlib.workingtree import WorkingTree
36
36
 
37
37
 
 
38
def branch_files(file_list, default_branch='.'):
 
39
    """\
 
40
    Return a branch and list of branch-relative paths.
 
41
    If supplied file_list is empty or None, the branch default will be used,
 
42
    and returned file_list will match the original.
 
43
    """
 
44
    if file_list is None or len(file_list) == 0:
 
45
        return Branch.open_containing(default_branch)[0], file_list
 
46
    b = Branch.open_containing(file_list[0])[0]
 
47
    
 
48
    # note that if this is a remote branch, we would want
 
49
    # relpath against the transport. RBC 20051018
 
50
    # Most branch ops can't meaningfully operate on files in remote branches;
 
51
    # the above comment was in cmd_status.  ADHB 20051026
 
52
    tree = WorkingTree(b.base, b)
 
53
    new_list = []
 
54
    for filename in file_list:
 
55
        try:
 
56
            new_list.append(tree.relpath(filename))
 
57
        except NotBranchError:
 
58
            raise BzrCommandError("%s is not in the same branch as %s" % 
 
59
                                  (filename, file_list[0]))
 
60
    return b, new_list
 
61
 
 
62
 
 
63
# TODO: Make sure no commands unconditionally use the working directory as a
 
64
# branch.  If a filename argument is used, the first of them should be used to
 
65
# specify the branch.  (Perhaps this can be factored out into some kind of
 
66
# Argument class, representing a file in a branch, where the first occurrence
 
67
# opens the branch?)
 
68
 
38
69
class cmd_status(Command):
39
70
    """Display status summary.
40
71
 
86
117
    
87
118
    @display_command
88
119
    def run(self, all=False, show_ids=False, file_list=None, revision=None):
89
 
        if file_list:
90
 
            b, relpath = Branch.open_containing(file_list[0])
91
 
            if relpath == '' and len(file_list) == 1:
92
 
                file_list = None
93
 
            else:
94
 
                # generate relative paths.
95
 
                # note that if this is a remote branch, we would want
96
 
                # relpath against the transport. RBC 20051018
97
 
                tree = WorkingTree(b.base, b)
98
 
                file_list = [tree.relpath(x) for x in file_list]
99
 
        else:
100
 
            b = Branch.open_containing('.')[0]
 
120
        b, file_list = branch_files(file_list)
101
121
            
102
122
        from bzrlib.status import show_status
103
123
        show_status(b, show_unchanged=all, show_ids=show_ids,
266
286
    """
267
287
    takes_args = ['source$', 'dest']
268
288
    def run(self, source_list, dest):
269
 
        b = Branch.open_containing('.')[0]
 
289
        b, source_list = branch_files(source_list)
270
290
 
271
291
        # TODO: glob expansion on windows?
272
292
        tree = WorkingTree(b.base, b)
273
 
        b.move([tree.relpath(s) for s in source_list], tree.relpath(dest))
 
293
        b.move(source_list, tree.relpath(dest))
274
294
 
275
295
 
276
296
class cmd_rename(Command):
290
310
    takes_args = ['from_name', 'to_name']
291
311
    
292
312
    def run(self, from_name, to_name):
293
 
        b = Branch.open_containing('.')[0]
294
 
        tree = WorkingTree(b.base, b)
295
 
        b.rename_one(tree.relpath(from_name), tree.relpath(to_name))
 
313
        b, (from_name, to_name) = branch_files((from_name, to_name))
 
314
        b.rename_one(from_name, to_name)
296
315
 
297
316
 
298
317
class cmd_mv(Command):
312
331
    def run(self, names_list):
313
332
        if len(names_list) < 2:
314
333
            raise BzrCommandError("missing file argument")
315
 
        b = Branch.open_containing(names_list[0])[0]
316
 
        tree = WorkingTree(b.base, b)
317
 
        rel_names = [tree.relpath(x) for x in names_list]
 
334
        b, rel_names = branch_files(names_list)
318
335
        
319
336
        if os.path.isdir(names_list[-1]):
320
337
            # move into existing directory
333
350
class cmd_pull(Command):
334
351
    """Pull any changes from another branch into the current one.
335
352
 
336
 
    If the location is omitted, the last-used location will be used.
337
 
    Both the revision history and the working directory will be
338
 
    updated.
 
353
    If there is no default location set, the first pull will set it.  After
 
354
    that, you can omit the location to use the default.  To change the
 
355
    default, use --remember.
339
356
 
340
357
    This command only works on branches that have not diverged.  Branches are
341
358
    considered diverged if both branches have had commits without first
342
359
    pulling from the other.
343
360
 
344
361
    If branches have diverged, you can use 'bzr merge' to pull the text changes
345
 
    from one into the other.
 
362
    from one into the other.  Once one branch has merged, the other should
 
363
    be able to pull it again.
 
364
 
 
365
    If you want to forget your local changes and just update your branch to
 
366
    match the remote one, use --overwrite.
346
367
    """
347
 
    takes_options = ['remember', 'clobber']
 
368
    takes_options = ['remember', 'overwrite']
348
369
    takes_args = ['location?']
349
370
 
350
 
    def run(self, location=None, remember=False, clobber=False):
 
371
    def run(self, location=None, remember=False, overwrite=False):
351
372
        from bzrlib.merge import merge
352
373
        from shutil import rmtree
353
374
        import errno
362
383
                location = stored_loc
363
384
        br_from = Branch.open(location)
364
385
        try:
365
 
            br_to.working_tree().pull(br_from, remember, clobber)
 
386
            br_to.working_tree().pull(br_from, remember, overwrite)
366
387
        except DivergedBranches:
367
388
            raise BzrCommandError("These branches have diverged."
368
389
                                  "  Try merge.")
488
509
    aliases = ['rm']
489
510
    
490
511
    def run(self, file_list, verbose=False):
491
 
        b = Branch.open_containing(file_list[0])[0]
492
 
        tree = WorkingTree(b.base, b)
493
 
        tree.remove([tree.relpath(f) for f in file_list], verbose=verbose)
 
512
        b, file_list = branch_files(file_list)
 
513
        tree = b.working_tree()
 
514
        tree.remove(file_list, verbose=verbose)
494
515
 
495
516
 
496
517
class cmd_file_id(Command):
569
590
    Recipe for importing a tree of files:
570
591
        cd ~/project
571
592
        bzr init
572
 
        bzr add -v .
 
593
        bzr add .
573
594
        bzr status
574
595
        bzr commit -m 'imported project'
575
596
    """
609
630
    @display_command
610
631
    def run(self, revision=None, file_list=None, diff_options=None):
611
632
        from bzrlib.diff import show_diff
612
 
 
613
 
        if file_list:
614
 
            b = Branch.open_containing(file_list[0])[0]
615
 
            tree = WorkingTree(b.base, b)
616
 
            file_list = [tree.relpath(f) for f in file_list]
617
 
            if file_list == ['']:
618
 
                # just pointing to top-of-tree
619
 
                file_list = None
620
 
        else:
621
 
            b = Branch.open_containing('.')[0]
622
 
 
 
633
        
 
634
        b, file_list = branch_files(file_list)
623
635
        if revision is not None:
624
636
            if len(revision) == 1:
625
637
                show_diff(b, revision[0], specific_files=file_list,
1049
1061
        from bzrlib.status import show_status
1050
1062
        from cStringIO import StringIO
1051
1063
 
1052
 
        b = Branch.open_containing('.')[0]
1053
 
        tree = WorkingTree(b.base, b)
1054
 
        if selected_list:
1055
 
            selected_list = [tree.relpath(s) for s in selected_list]
 
1064
        b, selected_list = branch_files(selected_list)
1056
1065
        if message is None and not file:
1057
1066
            catcher = StringIO()
1058
1067
            show_status(b, specific_files=selected_list,
1372
1381
        elif len(revision) != 1:
1373
1382
            raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1374
1383
        else:
1375
 
            b = Branch.open_containing('.')[0]
 
1384
            b, file_list = branch_files(file_list)
1376
1385
            revno = revision[0].in_history(b).revno
1377
1386
        merge(('.', revno), parse_spec('.'),
1378
1387
              check_clean=False,
1429
1438
    def run(self, from_branch, to_branch):
1430
1439
        from bzrlib.fetch import Fetcher
1431
1440
        from bzrlib.branch import Branch
1432
 
        from_b = Branch(from_branch)
1433
 
        to_b = Branch(to_branch)
1434
 
        Fetcher(to_b, from_b)
1435
 
        
 
1441
        from_b = Branch.open(from_branch)
 
1442
        to_b = Branch.open(to_branch)
 
1443
        from_b.lock_read()
 
1444
        try:
 
1445
            to_b.lock_write()
 
1446
            try:
 
1447
                Fetcher(to_b, from_b)
 
1448
            finally:
 
1449
                to_b.unlock()
 
1450
        finally:
 
1451
            from_b.unlock()
1436
1452
 
1437
1453
 
1438
1454
class cmd_missing(Command):