/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: Aaron Bentley
  • Date: 2005-10-27 23:14:48 UTC
  • mfrom: (1185.16.130)
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1491.
  • Revision ID: abentley@panoramicfeedback.com-20051027231448-ba0ae9cde819edc9
MergeĀ fromĀ mainline

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
492
509
    aliases = ['rm']
493
510
    
494
511
    def run(self, file_list, verbose=False):
495
 
        b = Branch.open_containing(file_list[0])[0]
496
 
        tree = WorkingTree(b.base, b)
497
 
        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)
498
515
 
499
516
 
500
517
class cmd_file_id(Command):
613
630
    @display_command
614
631
    def run(self, revision=None, file_list=None, diff_options=None):
615
632
        from bzrlib.diff import show_diff
616
 
 
617
 
        if file_list:
618
 
            b = Branch.open_containing(file_list[0])[0]
619
 
            tree = WorkingTree(b.base, b)
620
 
            file_list = [tree.relpath(f) for f in file_list]
621
 
            if file_list == ['']:
622
 
                # just pointing to top-of-tree
623
 
                file_list = None
624
 
        else:
625
 
            b = Branch.open_containing('.')[0]
626
 
 
 
633
        
 
634
        b, file_list = branch_files(file_list)
627
635
        if revision is not None:
628
636
            if len(revision) == 1:
629
637
                show_diff(b, revision[0], specific_files=file_list,
1053
1061
        from bzrlib.status import show_status
1054
1062
        from cStringIO import StringIO
1055
1063
 
1056
 
        b = Branch.open_containing('.')[0]
1057
 
        tree = WorkingTree(b.base, b)
1058
 
        if selected_list:
1059
 
            selected_list = [tree.relpath(s) for s in selected_list]
 
1064
        b, selected_list = branch_files(selected_list)
1060
1065
        if message is None and not file:
1061
1066
            catcher = StringIO()
1062
1067
            show_status(b, specific_files=selected_list,
1376
1381
        elif len(revision) != 1:
1377
1382
            raise BzrCommandError('bzr revert --revision takes exactly 1 argument')
1378
1383
        else:
1379
 
            b = Branch.open_containing('.')[0]
 
1384
            b, file_list = branch_files(file_list)
1380
1385
            revno = revision[0].in_history(b).revno
1381
1386
        merge(('.', revno), parse_spec('.'),
1382
1387
              check_clean=False,
1433
1438
    def run(self, from_branch, to_branch):
1434
1439
        from bzrlib.fetch import Fetcher
1435
1440
        from bzrlib.branch import Branch
1436
 
        from_b = Branch(from_branch)
1437
 
        to_b = Branch(to_branch)
1438
 
        Fetcher(to_b, from_b)
1439
 
        
 
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()
1440
1452
 
1441
1453
 
1442
1454
class cmd_missing(Command):