/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: Wouter van Heyst
  • Date: 2006-06-06 12:06:20 UTC
  • mfrom: (1740 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: larstiq@larstiq.dyndns.org-20060606120620-50066b0951e4ef7c
merge bzr.dev 1740

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import bzrlib.branch
28
28
from bzrlib.branch import Branch
29
29
import bzrlib.bzrdir as bzrdir
 
30
from bzrlib.bundle.read_bundle import BundleReader
 
31
from bzrlib.bundle.apply_bundle import merge_bundle
30
32
from bzrlib.commands import Command, display_command
31
 
from bzrlib.revision import common_ancestor
32
33
import bzrlib.errors as errors
33
34
from bzrlib.errors import (BzrError, BzrCheckError, BzrCommandError, 
34
35
                           NotBranchError, DivergedBranches, NotConflicted,
35
36
                           NoSuchFile, NoWorkingTree, FileInWrongBranch,
36
 
                           NotVersionedError)
 
37
                           NotVersionedError, BadBundle)
37
38
from bzrlib.log import show_one_log
38
39
from bzrlib.merge import Merge3Merger
39
40
from bzrlib.option import Option
40
41
import bzrlib.osutils
41
42
from bzrlib.progress import DummyProgress, ProgressPhase
 
43
from bzrlib.revision import common_ancestor
42
44
from bzrlib.revisionspec import RevisionSpec
43
45
import bzrlib.trace
44
46
from bzrlib.trace import mutter, note, log_error, warning, is_quiet
281
283
        added, ignored = bzrlib.add.smart_add(file_list, not no_recurse, 
282
284
                                              action=action)
283
285
        if len(ignored) > 0:
284
 
            for glob in sorted(ignored.keys()):
285
 
                match_len = len(ignored[glob])
286
 
                if verbose:
 
286
            if verbose:
 
287
                for glob in sorted(ignored.keys()):
287
288
                    for path in ignored[glob]:
288
289
                        self.outf.write("ignored %s matching \"%s\"\n" 
289
290
                                        % (path, glob))
290
 
                else:
291
 
                    self.outf.write("ignored %d file(s) matching \"%s\"\n"
292
 
                                    % (match_len, glob))
 
291
            else:
 
292
                match_len = 0
 
293
                for glob, paths in ignored.items():
 
294
                    match_len += len(paths)
 
295
                self.outf.write("ignored %d file(s).\n" % match_len)
293
296
            self.outf.write("If you wish to add some of these files,"
294
297
                            " please add them by name.\n")
295
298
 
545
548
                        if new_transport.base == transport.base:
546
549
                            raise BzrCommandError("Could not create "
547
550
                                                  "path prefix.")
548
 
            dir_to = br_from.bzrdir.clone(location_url)
 
551
            dir_to = br_from.bzrdir.clone(location_url,
 
552
                revision_id=br_from.last_revision())
549
553
            br_to = dir_to.open_branch()
550
 
        old_rh = br_to.revision_history()
551
 
        try:
 
554
            count = len(br_to.revision_history())
 
555
        else:
 
556
            old_rh = br_to.revision_history()
552
557
            try:
553
 
                tree_to = dir_to.open_workingtree()
554
 
            except errors.NotLocalUrl:
555
 
                # TODO: This should be updated for branches which don't have a
556
 
                # working tree, as opposed to ones where we just couldn't 
557
 
                # update the tree.
558
 
                warning('This transport does not update the working '
559
 
                        'tree of: %s' % (br_to.base,))
560
 
                count = br_to.pull(br_from, overwrite)
561
 
            except NoWorkingTree:
562
 
                count = br_to.pull(br_from, overwrite)
563
 
            else:
564
 
                count = tree_to.pull(br_from, overwrite)
565
 
        except DivergedBranches:
566
 
            raise BzrCommandError("These branches have diverged."
567
 
                                  "  Try a merge then push with overwrite.")
 
558
                try:
 
559
                    tree_to = dir_to.open_workingtree()
 
560
                except errors.NotLocalUrl:
 
561
                    warning('This transport does not update the working '
 
562
                            'tree of: %s' % (br_to.base,))
 
563
                    count = br_to.pull(br_from, overwrite)
 
564
                except NoWorkingTree:
 
565
                    count = br_to.pull(br_from, overwrite)
 
566
                else:
 
567
                    count = tree_to.pull(br_from, overwrite)
 
568
            except DivergedBranches:
 
569
                raise BzrCommandError("These branches have diverged."
 
570
                                      "  Try a merge then push with overwrite.")
568
571
        note('%d revision(s) pushed.' % (count,))
569
572
 
570
573
        if verbose:
825
828
 
826
829
    This makes bzr stop tracking changes to a versioned file.  It does
827
830
    not delete the working copy.
 
831
 
 
832
    You can specify one or more files, and/or --new.  If you specify --new,
 
833
    only 'added' files will be removed.  If you specify both, then new files
 
834
    in the specified directories will be removed.  If the directories are
 
835
    also new, they will also be removed.
828
836
    """
829
 
    takes_args = ['file+']
830
 
    takes_options = ['verbose']
 
837
    takes_args = ['file*']
 
838
    takes_options = ['verbose', Option('new', help='remove newly-added files')]
831
839
    aliases = ['rm']
832
840
    
833
 
    def run(self, file_list, verbose=False):
 
841
    def run(self, file_list, verbose=False, new=False):
834
842
        tree, file_list = tree_files(file_list)
 
843
        if new is False:
 
844
            if file_list is None:
 
845
                raise BzrCommandError('Specify one or more files to remove, or'
 
846
                                      ' use --new.')
 
847
        else:
 
848
            from bzrlib.delta import compare_trees
 
849
            added = [compare_trees(tree.basis_tree(), tree,
 
850
                                   specific_files=file_list).added]
 
851
            file_list = sorted([f[0] for f in added[0]], reverse=True)
 
852
            if len(file_list) == 0:
 
853
                raise BzrCommandError('No matching files.')
835
854
        tree.remove(file_list, verbose=verbose)
836
855
 
837
856
 
924
943
        tree = WorkingTree.open_containing(u'.')[0]
925
944
        b = tree.branch
926
945
        # FIXME. should be tree.last_revision
927
 
        for revision_id in b.repository.get_ancestry(b.last_revision()):
928
 
            if revision_id is None:
929
 
                continue
930
 
            self.outf.write(revision_id)
931
 
            self.outf.write('\n')
 
946
        revision_ids = b.repository.get_ancestry(b.last_revision())
 
947
        assert revision_ids[0] == None
 
948
        revision_ids.pop(0)
 
949
        for revision_id in revision_ids:
 
950
            self.outf.write(revision_id + '\n')
932
951
 
933
952
 
934
953
class cmd_init(Command):
1441
1460
            igns += '\n'
1442
1461
        igns += name_pattern + '\n'
1443
1462
 
 
1463
        f = AtomicFile(ifn, 'wt')
1444
1464
        try:
1445
 
            f = AtomicFile(ifn, 'wt')
1446
1465
            f.write(igns.encode('utf-8'))
1447
1466
            f.commit()
1448
1467
        finally:
1627
1646
        # TODO: if the commit *does* happen to fail, then save the commit 
1628
1647
        # message to a temporary file where it can be recovered
1629
1648
        tree, selected_list = tree_files(selected_list)
 
1649
        if selected_list == ['']:
 
1650
            # workaround - commit of root of tree should be exactly the same
 
1651
            # as just default commit in that tree, and succeed even though
 
1652
            # selected-file merge commit is not done yet
 
1653
            selected_list = []
 
1654
 
1630
1655
        if local and not tree.branch.get_bound_location():
1631
1656
            raise errors.LocalRequiresBoundBranch()
1632
1657
        if message is None and not file:
1819
1844
                            help='Use a different transport by default '
1820
1845
                                 'throughout the test suite.',
1821
1846
                            type=get_transport_type),
1822
 
                    ]
 
1847
                     Option('benchmark', help='run the bzr bencharks.'),
 
1848
                     Option('lsprof-timed',
 
1849
                            help='generate lsprof output for benchmarked'
 
1850
                                 ' sections of code.'),
 
1851
                     ]
1823
1852
 
1824
 
    def run(self, testspecs_list=None, verbose=False, one=False,
1825
 
            keep_output=False, transport=None):
 
1853
    def run(self, testspecs_list=None, verbose=None, one=False,
 
1854
            keep_output=False, transport=None, benchmark=None,
 
1855
            lsprof_timed=None):
1826
1856
        import bzrlib.ui
1827
1857
        from bzrlib.tests import selftest
 
1858
        import bzrlib.benchmarks as benchmarks
1828
1859
        # we don't want progress meters from the tests to go to the
1829
1860
        # real output; and we don't want log messages cluttering up
1830
1861
        # the real logs.
1831
1862
        save_ui = bzrlib.ui.ui_factory
 
1863
        print '%10s: %s' % ('bzr', bzrlib.osutils.realpath(sys.argv[0]))
 
1864
        print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
 
1865
        print
1832
1866
        bzrlib.trace.info('running tests...')
1833
1867
        try:
1834
1868
            bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1836
1870
                pattern = '|'.join(testspecs_list)
1837
1871
            else:
1838
1872
                pattern = ".*"
 
1873
            if benchmark:
 
1874
                test_suite_factory = benchmarks.test_suite
 
1875
                if verbose is None:
 
1876
                    verbose = True
 
1877
            else:
 
1878
                test_suite_factory = None
 
1879
                if verbose is None:
 
1880
                    verbose = False
1839
1881
            result = selftest(verbose=verbose, 
1840
1882
                              pattern=pattern,
1841
1883
                              stop_on_failure=one, 
1842
1884
                              keep_output=keep_output,
1843
 
                              transport=transport)
 
1885
                              transport=transport,
 
1886
                              test_suite_factory=test_suite_factory,
 
1887
                              lsprof_timed=lsprof_timed)
1844
1888
            if result:
1845
1889
                bzrlib.trace.info('tests passed')
1846
1890
            else:
1875
1919
        print "  nick: %s" % (branch.nick,)
1876
1920
        if rh:
1877
1921
            print "  revid: %s" % (rh[-1],)
 
1922
    print "Using python interpreter:", sys.executable
 
1923
    import site
 
1924
    print "Using python standard library:", os.path.dirname(site.__file__)
 
1925
    print "Using bzrlib:",
 
1926
    if len(bzrlib.__path__) > 1:
 
1927
        # print repr, which is a good enough way of making it clear it's
 
1928
        # more than one element (eg ['/foo/bar', '/foo/bzr'])
 
1929
        print repr(bzrlib.__path__)
 
1930
    else:
 
1931
        print bzrlib.__path__[0]
 
1932
 
 
1933
    print
1878
1934
    print bzrlib.__copyright__
1879
 
    print "http://bazaar-ng.org/"
 
1935
    print "http://bazaar-vcs.org/"
1880
1936
    print
1881
1937
    print "bzr comes with ABSOLUTELY NO WARRANTY.  bzr is free software, and"
1882
1938
    print "you may use, modify and redistribute it under the terms of the GNU"
1975
2031
    
1976
2032
    merge refuses to run if there are any uncommitted changes, unless
1977
2033
    --force is given.
 
2034
 
 
2035
    The following merge types are available:
1978
2036
    """
1979
2037
    takes_args = ['branch?']
1980
2038
    takes_options = ['revision', 'force', 'merge-type', 'reprocess', 'remember',
1981
2039
                     Option('show-base', help="Show base revision text in "
1982
2040
                            "conflicts")]
1983
2041
 
 
2042
    def help(self):
 
2043
        from merge import merge_type_help
 
2044
        from inspect import getdoc
 
2045
        return getdoc(self) + '\n' + merge_type_help() 
1984
2046
 
1985
2047
    def run(self, branch=None, revision=None, force=False, merge_type=None,
1986
2048
            show_base=False, reprocess=False, remember=False):
1988
2050
            merge_type = Merge3Merger
1989
2051
 
1990
2052
        tree = WorkingTree.open_containing(u'.')[0]
 
2053
 
 
2054
        try:
 
2055
            if branch is not None:
 
2056
                reader = BundleReader(file(branch, 'rb'))
 
2057
            else:
 
2058
                reader = None
 
2059
        except IOError, e:
 
2060
            if e.errno not in (errno.ENOENT, errno.EISDIR):
 
2061
                raise
 
2062
            reader = None
 
2063
        except BadBundle:
 
2064
            reader = None
 
2065
        if reader is not None:
 
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
 
2072
 
1991
2073
        branch = self._get_remembered_parent(tree, branch, 'Merging from')
1992
2074
 
 
2075
        if tree.branch.get_parent() is None or remember:
 
2076
            tree.branch.set_parent(branch)
 
2077
 
1993
2078
        if revision is None or len(revision) < 1:
1994
2079
            base = [None, None]
1995
2080
            other = [branch, -1]
2058
2143
 
2059
2144
class cmd_remerge(Command):
2060
2145
    """Redo a merge.
2061
 
    """
 
2146
 
 
2147
    Use this if you want to try a different merge technique while resolving
 
2148
    conflicts.  Some merge techniques are better than others, and remerge 
 
2149
    lets you try different ones on different files.
 
2150
 
 
2151
    The options for remerge have the same meaning and defaults as the ones for
 
2152
    merge.  The difference is that remerge can (only) be run when there is a
 
2153
    pending merge, and it lets you specify particular files.
 
2154
 
 
2155
    Examples:
 
2156
    $ bzr remerge --show-base
 
2157
        Re-do the merge of all conflicted files, and show the base text in
 
2158
        conflict regions, in addition to the usual THIS and OTHER texts.
 
2159
 
 
2160
    $ bzr remerge --merge-type weave --reprocess foobar
 
2161
        Re-do the merge of "foobar", using the weave merge algorithm, with
 
2162
        additional processing to reduce the size of conflict regions.
 
2163
    
 
2164
    The following merge types are available:"""
2062
2165
    takes_args = ['file*']
2063
2166
    takes_options = ['merge-type', 'reprocess',
2064
2167
                     Option('show-base', help="Show base revision text in "
2065
2168
                            "conflicts")]
2066
2169
 
 
2170
    def help(self):
 
2171
        from merge import merge_type_help
 
2172
        from inspect import getdoc
 
2173
        return getdoc(self) + '\n' + merge_type_help() 
 
2174
 
2067
2175
    def run(self, file_list=None, merge_type=None, show_base=False,
2068
2176
            reprocess=False):
2069
2177
        from bzrlib.merge import merge_inner, transform_tree
2451
2559
class cmd_uncommit(bzrlib.commands.Command):
2452
2560
    """Remove the last committed revision.
2453
2561
 
2454
 
    By supplying the --all flag, it will not only remove the entry 
2455
 
    from revision_history, but also remove all of the entries in the
2456
 
    stores.
2457
 
 
2458
2562
    --verbose will print out what is being removed.
2459
2563
    --dry-run will go through all the motions, but not actually
2460
2564
    remove anything.
2461
2565
    
2462
 
    In the future, uncommit will create a changeset, which can then
 
2566
    In the future, uncommit will create a revision bundle, which can then
2463
2567
    be re-applied.
2464
2568
    """
2465
2569
 
2619
2723
# aliases.  ideally we would avoid loading the implementation until the
2620
2724
# details were needed.
2621
2725
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
 
2726
from bzrlib.bundle.commands import cmd_bundle_revisions
2622
2727
from bzrlib.sign_my_commits import cmd_sign_my_commits
2623
2728
from bzrlib.weave_commands import cmd_weave_list, cmd_weave_join, \
2624
2729
        cmd_weave_plan_merge, cmd_weave_merge_text