~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Vincent Ladeuil
  • Date: 2009-04-27 16:10:10 UTC
  • mto: (4310.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4311.
  • Revision ID: v.ladeuil+lp@free.fr-20090427161010-7swfzeagf63cpixd
Fix bug #367726 by reverting some default user handling introduced
while fixing bug #256612.

* bzrlib/transport/ssh.py:
(_paramiko_auth): Explicitly use getpass.getuser() as default
user.

* bzrlib/transport/ftp/_gssapi.py:
(GSSAPIFtpTransport._create_connection): Explicitly use
getpass.getuser() as default user.

* bzrlib/transport/ftp/__init__.py:
(FtpTransport._create_connection): Explicitly use
getpass.getuser() as default user.

* bzrlib/tests/test_sftp_transport.py:
(TestUsesAuthConfig.test_sftp_is_none_if_no_config)
(TestUsesAuthConfig.test_sftp_doesnt_prompt_username): Revert to
None as the default user.

* bzrlib/tests/test_remote.py:
(TestRemoteSSHTransportAuthentication): The really offending one:
revert to None as the default user.

* bzrlib/tests/test_config.py:
(TestAuthenticationConfig.test_username_default_no_prompt): Update
test (and some PEP8).

* bzrlib/smtp_connection.py:
(SMTPConnection._authenticate): Revert to None as the default
user.

* bzrlib/plugins/launchpad/account.py:
(_get_auth_user): Revert default value handling.

* bzrlib/config.py:
(AuthenticationConfig.get_user): Fix doc-string. Leave default
value handling to callers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
            if view_files:
96
96
                file_list = view_files
97
97
                view_str = views.view_display_str(view_files)
98
 
                note("ignoring files outside view: %s" % view_str)
 
98
                note("Ignoring files outside view. View is %s" % view_str)
99
99
    return tree, file_list
100
100
 
101
101
 
151
151
            if view_files:
152
152
                file_list = view_files
153
153
                view_str = views.view_display_str(view_files)
154
 
                note("ignoring files outside view: %s" % view_str)
 
154
                note("Ignoring files outside view. View is %s" % view_str)
155
155
        return tree, file_list
156
156
    tree = WorkingTree.open_containing(osutils.realpath(file_list[0]))[0]
157
157
    return tree, safe_relpath_files(tree, file_list, canonicalize,
722
722
    takes_args = ['names*']
723
723
    takes_options = [Option("after", help="Move only the bzr identifier"
724
724
        " of the file, because the file has already been moved."),
 
725
        Option('auto', help='Automatically guess renames.'),
 
726
        Option('dry-run', help='Avoid making changes when guessing renames.'),
725
727
        ]
726
728
    aliases = ['move', 'rename']
727
729
    encoding_type = 'replace'
728
730
 
729
 
    def run(self, names_list, after=False):
 
731
    def run(self, names_list, after=False, auto=False, dry_run=False):
 
732
        if auto:
 
733
            return self.run_auto(names_list, after, dry_run)
 
734
        elif dry_run:
 
735
            raise errors.BzrCommandError('--dry-run requires --auto.')
730
736
        if names_list is None:
731
737
            names_list = []
732
 
 
733
738
        if len(names_list) < 2:
734
739
            raise errors.BzrCommandError("missing file argument")
735
740
        tree, rel_names = tree_files(names_list, canonicalize=False)
739
744
        finally:
740
745
            tree.unlock()
741
746
 
 
747
    def run_auto(self, names_list, after, dry_run):
 
748
        if names_list is not None and len(names_list) > 1:
 
749
            raise errors.BzrCommandError('Only one path may be specified to'
 
750
                                         ' --auto.')
 
751
        if after:
 
752
            raise errors.BzrCommandError('--after cannot be specified with'
 
753
                                         ' --auto.')
 
754
        work_tree, file_list = tree_files(names_list, default_branch='.')
 
755
        work_tree.lock_write()
 
756
        try:
 
757
            rename_map.RenameMap.guess_renames(work_tree, dry_run)
 
758
        finally:
 
759
            work_tree.unlock()
 
760
 
742
761
    def _run(self, tree, names_list, rel_names, after):
743
762
        into_existing = osutils.isdir(names_list[-1])
744
763
        if into_existing and len(names_list) == 2:
998
1017
        if revision is not None:
999
1018
            revision_id = revision.in_history(br_from).rev_id
1000
1019
        else:
1001
 
            revision_id = br_from.last_revision()
 
1020
            revision_id = None
1002
1021
 
1003
1022
        # Get the stacked_on branch, if any
1004
1023
        if stacked_on is not None:
1301
1320
      basic statistics (like the number of files in the working tree and
1302
1321
      number of revisions in the branch and repository):
1303
1322
 
1304
 
        bzr -v info
 
1323
        bzr info -v
1305
1324
 
1306
1325
      Display the above together with number of committers to the branch:
1307
1326
 
1308
 
        bzr -vv info
 
1327
        bzr info -vv
1309
1328
    """
1310
1329
    _see_also = ['revno', 'working-trees', 'repositories']
1311
1330
    takes_args = ['location?']
1556
1575
                    "\nYou may supply --create-prefix to create all"
1557
1576
                    " leading parent directories."
1558
1577
                    % location)
1559
 
            _create_prefix(to_transport)
 
1578
            to_transport.create_prefix()
1560
1579
 
1561
1580
        try:
1562
1581
            a_bzrdir = bzrdir.BzrDir.open_from_transport(to_transport)
1933
1952
        --show-ids  display revision-ids (and file-ids), not just revnos
1934
1953
 
1935
1954
      Note that the default number of levels to display is a function of the
1936
 
      log format. If the -n option is not used, ``short`` and ``line`` show
1937
 
      just the top level (mainline) while ``long`` shows all levels of merged
1938
 
      revisions.
 
1955
      log format. If the -n option is not used, the standard log formats show
 
1956
      just the top level (mainline).
1939
1957
 
1940
1958
      Status summaries are shown using status flags like A, M, etc. To see
1941
1959
      the changes explained using words like ``added`` and ``modified``
2027
2045
      You may find it useful to add the aliases below to ``bazaar.conf``::
2028
2046
 
2029
2047
        [ALIASES]
2030
 
        tip = log -r-1 -n1
 
2048
        tip = log -r-1
2031
2049
        top = log -l10 --line
2032
 
        show = log -v -p -n1 --long
 
2050
        show = log -v -p
2033
2051
 
2034
2052
      ``bzr tip`` will then show the latest revision while ``bzr top``
2035
2053
      will show the last 10 mainline revisions. To see the details of a
2036
2054
      particular revision X,  ``bzr show -rX``.
2037
2055
 
2038
 
      As many GUI tools and Web interfaces do, you may prefer viewing
2039
 
      history collapsed initially. If you are interested in looking deeper
2040
 
      into a particular merge X, use ``bzr log -n0 -rX``. If you like
2041
 
      working this way, you may wish to either:
2042
 
 
2043
 
      * change your default log format to short (or line)
2044
 
      * add this alias: log = log -n1
 
2056
      If you are interested in looking deeper into a particular merge X,
 
2057
      use ``bzr log -n0 -rX``.
2045
2058
 
2046
2059
      ``bzr log -v`` on a branch with lots of history is currently
2047
2060
      very slow. A fix for this issue is currently under development.
2092
2105
            Option('show-diff',
2093
2106
                   short_name='p',
2094
2107
                   help='Show changes made in each revision as a patch.'),
 
2108
            Option('include-merges',
 
2109
                   help='Show merged revisions like --levels 0 does.'),
2095
2110
            ]
2096
2111
    encoding_type = 'replace'
2097
2112
 
2106
2121
            levels=None,
2107
2122
            message=None,
2108
2123
            limit=None,
2109
 
            show_diff=False):
 
2124
            show_diff=False,
 
2125
            include_merges=False):
2110
2126
        from bzrlib.log import (
2111
2127
            Logger,
2112
2128
            make_log_request_dict,
2113
2129
            _get_info_for_log_files,
2114
2130
            )
2115
2131
        direction = (forward and 'forward') or 'reverse'
 
2132
        if include_merges:
 
2133
            if levels is None:
 
2134
                levels = 0
 
2135
            else:
 
2136
                raise errors.BzrCommandError(
 
2137
                    '--levels and --include-merges are mutually exclusive')
2116
2138
 
2117
2139
        if change is not None:
2118
2140
            if len(change) > 1:
2175
2197
            lf = log_format(show_ids=show_ids, to_file=self.outf,
2176
2198
                            show_timezone=timezone,
2177
2199
                            delta_format=get_verbosity_level(),
2178
 
                            levels=levels)
 
2200
                            levels=levels,
 
2201
                            show_advice=levels is None)
2179
2202
 
2180
2203
            # Choose the algorithm for doing the logging. It's annoying
2181
2204
            # having multiple code paths like this but necessary until
2189
2212
            # evil when adding features", we continue to use the
2190
2213
            # original algorithm - per-file-graph - for the "single
2191
2214
            # file that isn't a directory without showing a delta" case.
 
2215
            partial_history = revision and b.repository._format.supports_chks
2192
2216
            match_using_deltas = (len(file_ids) != 1 or filter_by_dir
2193
 
                or delta_type)
 
2217
                or delta_type or partial_history)
2194
2218
 
2195
2219
            # Build the LogRequest and execute it
2196
2220
            if len(file_ids) == 0:
2284
2308
 
2285
2309
    _see_also = ['status', 'cat']
2286
2310
    takes_args = ['path?']
2287
 
    # TODO: Take a revision or remote path and list that tree instead.
2288
2311
    takes_options = [
2289
2312
            'verbose',
2290
2313
            'revision',
2291
 
            Option('non-recursive',
2292
 
                   help='Don\'t recurse into subdirectories.'),
 
2314
            Option('recursive', short_name='R',
 
2315
                   help='Recurse into subdirectories.'),
2293
2316
            Option('from-root',
2294
2317
                   help='Print paths relative to the root of the branch.'),
2295
2318
            Option('unknown', help='Print unknown files.'),
2306
2329
            ]
2307
2330
    @display_command
2308
2331
    def run(self, revision=None, verbose=False,
2309
 
            non_recursive=False, from_root=False,
 
2332
            recursive=False, from_root=False,
2310
2333
            unknown=False, versioned=False, ignored=False,
2311
2334
            null=False, kind=None, show_ids=False, path=None):
2312
2335
 
2343
2366
            if view_files:
2344
2367
                apply_view = True
2345
2368
                view_str = views.view_display_str(view_files)
2346
 
                note("ignoring files outside view: %s" % view_str)
 
2369
                note("Ignoring files outside view. View is %s" % view_str)
2347
2370
 
2348
2371
        tree.lock_read()
2349
2372
        try:
2350
2373
            for fp, fc, fkind, fid, entry in tree.list_files(include_root=False):
2351
2374
                if fp.startswith(relpath):
2352
 
                    fp = osutils.pathjoin(prefix, fp[len(relpath):])
2353
 
                    if non_recursive and '/' in fp:
 
2375
                    rp = fp[len(relpath):]
 
2376
                    fp = osutils.pathjoin(prefix, rp)
 
2377
                    if not recursive and '/' in rp:
2354
2378
                        continue
2355
2379
                    if not all and not selection[fc]:
2356
2380
                        continue
2953
2977
 
2954
2978
    def run(self, url='.', format=None):
2955
2979
        from bzrlib.upgrade import upgrade
2956
 
        if format is None:
2957
 
            format = bzrdir.format_registry.make_bzrdir('default')
2958
2980
        upgrade(url, format)
2959
2981
 
2960
2982
 
3187
3209
                            ),
3188
3210
                     Option('list-only',
3189
3211
                            help='List the tests instead of running them.'),
 
3212
                     RegistryOption('parallel',
 
3213
                        help="Run the test suite in parallel.",
 
3214
                        lazy_registry=('bzrlib.tests', 'parallel_registry'),
 
3215
                        value_switches=False,
 
3216
                        ),
3190
3217
                     Option('randomize', type=str, argname="SEED",
3191
3218
                            help='Randomize the order of tests using the given'
3192
3219
                                 ' seed or "now" for the current time.'),
3218
3245
            lsprof_timed=None, cache_dir=None,
3219
3246
            first=False, list_only=False,
3220
3247
            randomize=None, exclude=None, strict=False,
3221
 
            load_list=None, debugflag=None, starting_with=None, subunit=False):
 
3248
            load_list=None, debugflag=None, starting_with=None, subunit=False,
 
3249
            parallel=None):
3222
3250
        from bzrlib.tests import selftest
3223
3251
        import bzrlib.benchmarks as benchmarks
3224
3252
        from bzrlib.benchmarks import tree_creator
3228
3256
 
3229
3257
        if cache_dir is not None:
3230
3258
            tree_creator.TreeCreator.CACHE_ROOT = osutils.abspath(cache_dir)
3231
 
        if not list_only:
3232
 
            print 'testing: %s' % (osutils.realpath(sys.argv[0]),)
3233
 
            print '   %s (%s python%s)' % (
3234
 
                    bzrlib.__path__[0],
3235
 
                    bzrlib.version_string,
3236
 
                    bzrlib._format_version_tuple(sys.version_info),
3237
 
                    )
3238
 
        print
3239
3259
        if testspecs_list is not None:
3240
3260
            pattern = '|'.join(testspecs_list)
3241
3261
        else:
3247
3267
                raise errors.BzrCommandError("subunit not available. subunit "
3248
3268
                    "needs to be installed to use --subunit.")
3249
3269
            self.additional_selftest_args['runner_class'] = SubUnitBzrRunner
 
3270
        if parallel:
 
3271
            self.additional_selftest_args.setdefault(
 
3272
                'suite_decorators', []).append(parallel)
3250
3273
        if benchmark:
3251
3274
            test_suite_factory = benchmarks.test_suite
3252
3275
            # Unless user explicitly asks for quiet, be verbose in benchmarks
3278
3301
        finally:
3279
3302
            if benchfile is not None:
3280
3303
                benchfile.close()
3281
 
        if result:
3282
 
            note('tests passed')
3283
 
        else:
3284
 
            note('tests failed')
3285
3304
        return int(not result)
3286
3305
 
3287
3306
 
3393
3412
 
3394
3413
            bzr merge -r 81..82 ../bzr.dev
3395
3414
 
3396
 
        To apply a merge directive contained in in /tmp/merge:
 
3415
        To apply a merge directive contained in /tmp/merge:
3397
3416
 
3398
3417
            bzr merge /tmp/merge
3399
3418
    """
3915
3934
            type=_parse_revision_str,
3916
3935
            help='Filter on local branch revisions (inclusive). '
3917
3936
                'See "help revisionspec" for details.'),
3918
 
        Option('include-merges', 'Show merged revisions.'),
 
3937
        Option('include-merges',
 
3938
               'Show all revisions in addition to the mainline ones.'),
3919
3939
        ]
3920
3940
    encoding_type = 'replace'
3921
3941
 
4561
4581
 
4562
4582
 
4563
4583
class cmd_join(Command):
4564
 
    """Combine a subtree into its containing tree.
 
4584
    """Combine a tree into its containing tree.
4565
4585
 
4566
 
    This command is for experimental use only.  It requires the target tree
4567
 
    to be in dirstate-with-subtree format, which cannot be converted into
4568
 
    earlier formats.
 
4586
    This command requires the target tree to be in a rich-root format.
4569
4587
 
4570
4588
    The TREE argument should be an independent tree, inside another tree, but
4571
4589
    not part of it.  (Such trees can be produced by "bzr split", but also by
4574
4592
    The result is a combined tree, with the subtree no longer an independant
4575
4593
    part.  This is marked as a merge of the subtree into the containing tree,
4576
4594
    and all history is preserved.
4577
 
 
4578
 
    If --reference is specified, the subtree retains its independence.  It can
4579
 
    be branched by itself, and can be part of multiple projects at the same
4580
 
    time.  But operations performed in the containing tree, such as commit
4581
 
    and merge, will recurse into the subtree.
4582
4595
    """
4583
4596
 
4584
4597
    _see_also = ['split']
4585
4598
    takes_args = ['tree']
4586
4599
    takes_options = [
4587
 
            Option('reference', help='Join by reference.'),
 
4600
            Option('reference', help='Join by reference.', hidden=True),
4588
4601
            ]
4589
 
    hidden = True
4590
4602
 
4591
4603
    def run(self, tree, reference=False):
4592
4604
        sub_tree = WorkingTree.open(tree)
4626
4638
    branch.  Commits in the top-level tree will not apply to the new subtree.
4627
4639
    """
4628
4640
 
4629
 
    # join is not un-hidden yet
4630
 
    #_see_also = ['join']
 
4641
    _see_also = ['join']
4631
4642
    takes_args = ['tree']
4632
4643
 
4633
4644
    def run(self, tree):
5266
5277
            urlutils.unescape_for_display(to_branch.base, 'utf-8'))
5267
5278
 
5268
5279
 
5269
 
class cmd_guess_renames(Command):
5270
 
    """Guess which files have been have been renamed, based on their content.
5271
 
 
5272
 
    Only versioned files which have been deleted are candidates for rename
5273
 
    detection, and renames to ignored files will not be detected.
5274
 
    """
5275
 
 
5276
 
    def run(self):
5277
 
        work_tree, file_list = tree_files(None, default_branch='.')
5278
 
        work_tree.lock_write()
5279
 
        try:
5280
 
            rename_map.RenameMap.guess_renames(work_tree)
5281
 
        finally:
5282
 
            work_tree.unlock()
5283
 
 
5284
 
 
5285
5280
class cmd_view(Command):
5286
5281
    """Manage filtered views.
5287
5282
 
5588
5583
                   dry_run=dry_run, no_prompt=force)
5589
5584
 
5590
5585
 
5591
 
def _create_prefix(cur_transport):
5592
 
    needed = [cur_transport]
5593
 
    # Recurse upwards until we can create a directory successfully
5594
 
    while True:
5595
 
        new_transport = cur_transport.clone('..')
5596
 
        if new_transport.base == cur_transport.base:
5597
 
            raise errors.BzrCommandError(
5598
 
                "Failed to create path prefix for %s."
5599
 
                % cur_transport.base)
5600
 
        try:
5601
 
            new_transport.mkdir('.')
5602
 
        except errors.NoSuchFile:
5603
 
            needed.append(new_transport)
5604
 
            cur_transport = new_transport
5605
 
        else:
5606
 
            break
5607
 
    # Now we only need to create child directories
5608
 
    while needed:
5609
 
        cur_transport = needed.pop()
5610
 
        cur_transport.ensure_base()
5611
 
 
5612
 
 
5613
5586
# these get imported and then picked up by the scan for cmd_*
5614
5587
# TODO: Some more consistent way to split command definitions across files;
5615
5588
# we do need to load at least some information about them to know of
5620
5593
from bzrlib.bundle.commands import (
5621
5594
    cmd_bundle_info,
5622
5595
    )
 
5596
from bzrlib.foreign import cmd_dpush
5623
5597
from bzrlib.sign_my_commits import cmd_sign_my_commits
5624
5598
from bzrlib.weave_commands import cmd_versionedfile_list, \
5625
5599
        cmd_weave_plan_merge, cmd_weave_merge_text