~ubuntu-branches/ubuntu/hardy/pysvn/hardy

« back to all changes in this revision

Viewing changes to Source/pysvn_client.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-06-16 20:18:32 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060616201832-t79622pf2365ab7o
Tags: 1.4.2-1
* New upstream version.
* Convert to new Python policy. Closes: #373507.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
static const char name_notice_ancestry[] = "notice_ancestry";
73
73
static const char name_number[] = "number";
74
74
static const char name_path[] = "path";
 
75
static const char name_password[] = "password";
75
76
static const char name_peg_revision[] = "peg_revision";
76
77
static const char name_prop_name[] = "prop_name";
77
78
static const char name_prop_value[] = "prop_value";
95
96
static const char name_url_or_path[] = "url_or_path";
96
97
static const char name_url_or_path1[] = "url_or_path1";
97
98
static const char name_url_or_path2[] = "url_or_path2";
 
99
static const char name_username[] = "username";
98
100
static const char name_utf8[] = "UTF-8";
99
101
 
100
102
 
161
163
 
162
164
static void set_callable( Py::Object &callback, const Py::Object &value )
163
165
{
164
 
    if( value.is( Py::Nothing() ) || value.isCallable() )
 
166
    if( value.is( Py::None() ) || value.isCallable() )
165
167
        callback = value;
166
168
    else
167
169
        throw Py::AttributeError( "expecting None or a callable object" );
293
295
        throw_client_error( e );
294
296
    }
295
297
 
296
 
    return Py::Nothing();
 
298
    return Py::None();
297
299
}
298
300
 
299
301
class AnnotatedLineInfo
346
348
    apr_pool_t *pool
347
349
    )
348
350
{
 
351
    // There are cases when the author has been passed as NULL
 
352
    // protect against NULL passed for any of the strings
 
353
    if( author == NULL )
 
354
        author = "";
 
355
    if( date == NULL )
 
356
        date = "";
 
357
    if( line == NULL )
 
358
        line = "";
 
359
 
349
360
    std::list<AnnotatedLineInfo> *entries = (std::list<AnnotatedLineInfo> *)baton;
350
361
    entries->push_back( AnnotatedLineInfo( line_no, revision, author, date, line ) );
351
362
 
714
725
        throw_client_error( e );
715
726
    }
716
727
 
717
 
    return Py::Nothing();
 
728
    return Py::None();
718
729
}
719
730
 
720
731
Py::Object pysvn_client::cmd_copy( const Py::Tuple &a_args, const Py::Dict &a_kws )
1363
1374
            throw SvnException( error );
1364
1375
 
1365
1376
        if( entry == NULL )
1366
 
            return Py::Nothing();
 
1377
            return Py::None();
1367
1378
 
1368
1379
        return Py::asObject( new pysvn_entry( entry, m_context ) );
1369
1380
    }
1373
1384
        m_context.checkForError( m_module.client_error );
1374
1385
 
1375
1386
        throw_client_error( e );
1376
 
        return Py::Nothing();       // needed to remove warning about return value missing
 
1387
        return Py::None();       // needed to remove warning about return value missing
1377
1388
    }
1378
1389
}
1379
1390
 
1749
1760
            if( SVN_IS_VALID_REVNUM( change_entry.m_copy_from_revision ) )
1750
1761
                changed_entry_dict[name_copyfrom_revision] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, change_entry.m_copy_from_revision ) );
1751
1762
            else
1752
 
                changed_entry_dict[name_copyfrom_revision] = Py::Nothing();
 
1763
                changed_entry_dict[name_copyfrom_revision] = Py::None();
1753
1764
 
1754
1765
            changed_paths_list.append( changed_entry_dict );
1755
1766
        }
1937
1948
        throw_client_error( e );
1938
1949
    }
1939
1950
 
1940
 
    return Py::Nothing();
 
1951
    return Py::None();
1941
1952
}
1942
1953
 
1943
1954
#ifdef PYSVN_HAS_CLIENT_MERGE_PEG
2006
2017
        throw_client_error( e );
2007
2018
    }
2008
2019
 
2009
 
    return Py::Nothing();
 
2020
    return Py::None();
2010
2021
}
2011
2022
#endif
2012
2023
 
2248
2259
        throw_client_error( e );
2249
2260
    }
2250
2261
 
2251
 
    return Py::Nothing();
 
2262
    return Py::None();
2252
2263
}
2253
2264
 
2254
2265
Py::Object pysvn_client::cmd_propget( const Py::Tuple &a_args, const Py::Dict &a_kws )
2529
2540
        throw_client_error( e );
2530
2541
    }
2531
2542
 
2532
 
    return Py::Nothing();
 
2543
    return Py::None();
2533
2544
}
2534
2545
 
2535
2546
Py::Object pysvn_client::cmd_relocate( const Py::Tuple &a_args, const Py::Dict &a_kws )
2580
2591
        throw_client_error( e );
2581
2592
    }
2582
2593
 
2583
 
    return Py::Nothing();
 
2594
    return Py::None();
2584
2595
}
2585
2596
 
2586
2597
Py::Object pysvn_client::cmd_remove( const Py::Tuple &a_args, const Py::Dict &a_kws )
2681
2692
        throw_client_error( e );
2682
2693
    }
2683
2694
 
2684
 
    return Py::Nothing();
 
2695
    return Py::None();
2685
2696
}
2686
2697
 
2687
2698
Py::Object pysvn_client::cmd_revert( const Py::Tuple &a_args, const Py::Dict &a_kws )
2733
2744
        throw Py::TypeError( type_error_message );
2734
2745
    }
2735
2746
 
2736
 
    return Py::Nothing();
 
2747
    return Py::None();
2737
2748
}
2738
2749
 
2739
2750
Py::Object pysvn_client::cmd_revpropdel( const Py::Tuple &a_args, const Py::Dict &a_kws )
2847
2858
    // prop_name that is not in this rev returns a NULL value
2848
2859
    if( propval == NULL )
2849
2860
    {
2850
 
        result[1] = Py::Nothing();
 
2861
        result[1] = Py::None();
2851
2862
    }
2852
2863
    else
2853
2864
    {
3048
3059
        PythonAllowThreads permission( m_context );
3049
3060
 
3050
3061
        svn_revnum_t revnum;
3051
 
        svn_opt_revision_t rev = { svn_opt_revision_head, 0 };
 
3062
        svn_opt_revision_t rev = { svn_opt_revision_head, {0} };
3052
3063
 
3053
3064
        StatusEntriesBaton baton;
3054
3065
 
3344
3355
}
3345
3356
#endif
3346
3357
 
 
3358
Py::Object pysvn_client::helper_boolean_auth_set( FunctionArguments &a_args, const char *a_arg_name, const char *a_param_name )
 
3359
{
 
3360
    a_args.check();
 
3361
 
 
3362
    bool enable( a_args.getBoolean( a_arg_name ) );
 
3363
    try
 
3364
    {
 
3365
        void *param = 0;
 
3366
        if( !enable )
 
3367
            param = (void *)"1";
 
3368
 
 
3369
        svn_auth_set_parameter
 
3370
            (
 
3371
            m_context.ctx()->auth_baton,
 
3372
            a_param_name,
 
3373
            param
 
3374
            );
 
3375
    }
 
3376
    catch( SvnException &e )
 
3377
    {
 
3378
        // use callback error over ClientException
 
3379
        m_context.checkForError( m_module.client_error );
 
3380
 
 
3381
        throw_client_error( e );
 
3382
    }
 
3383
 
 
3384
    return Py::None();
 
3385
}
 
3386
 
 
3387
Py::Object pysvn_client::helper_boolean_auth_get( FunctionArguments &a_args, const char *a_param_name )
 
3388
{
 
3389
    a_args.check();
 
3390
 
 
3391
    char *param = NULL;
 
3392
    try
 
3393
    {
 
3394
        param = (char *)svn_auth_get_parameter
 
3395
            (
 
3396
            m_context.ctx()->auth_baton,
 
3397
            a_param_name
 
3398
            );
 
3399
    }
 
3400
    catch( SvnException &e )
 
3401
    {
 
3402
        // use callback error over ClientException
 
3403
        m_context.checkForError( m_module.client_error );
 
3404
 
 
3405
        throw_client_error( e );
 
3406
    }
 
3407
 
 
3408
    bool not_set = param != NULL && param[0] == '1';
 
3409
    if( not_set )
 
3410
        return Py::Int( 0 );
 
3411
    return Py::Int( 1 );
 
3412
}
 
3413
 
 
3414
Py::Object pysvn_client::helper_string_auth_set
 
3415
    (
 
3416
    FunctionArguments &a_args,
 
3417
    const char *a_arg_name,
 
3418
    const char *a_param_name,
 
3419
    std::string &ctx_str
 
3420
    )
 
3421
{
 
3422
    a_args.check();
 
3423
 
 
3424
    const char *param = NULL;
 
3425
    Py::Object param_obj( a_args.getArg( a_arg_name ) );
 
3426
    if( !param_obj.is( Py::None() ) )
 
3427
    {
 
3428
        Py::String param_str( param_obj );
 
3429
        ctx_str = param_str.as_std_string();
 
3430
        param = ctx_str.c_str();
 
3431
    }
 
3432
 
 
3433
    try
 
3434
    {
 
3435
        svn_auth_set_parameter
 
3436
            (
 
3437
            m_context.ctx()->auth_baton,
 
3438
            a_param_name,
 
3439
            param
 
3440
            );
 
3441
    }
 
3442
    catch( SvnException &e )
 
3443
    {
 
3444
        // use callback error over ClientException
 
3445
        m_context.checkForError( m_module.client_error );
 
3446
 
 
3447
        throw_client_error( e );
 
3448
    }
 
3449
 
 
3450
    return Py::None();
 
3451
}
 
3452
 
 
3453
Py::Object pysvn_client::helper_string_auth_get( FunctionArguments &a_args, const char *a_param_name )
 
3454
{
 
3455
    a_args.check();
 
3456
 
 
3457
    char *param = NULL;
 
3458
    try
 
3459
    {
 
3460
        param = (char *)svn_auth_get_parameter
 
3461
            (
 
3462
            m_context.ctx()->auth_baton,
 
3463
            a_param_name
 
3464
            );
 
3465
    }
 
3466
    catch( SvnException &e )
 
3467
    {
 
3468
        // use callback error over ClientException
 
3469
        m_context.checkForError( m_module.client_error );
 
3470
 
 
3471
        throw_client_error( e );
 
3472
    }
 
3473
 
 
3474
    if( param != NULL )
 
3475
        return Py::String( param );
 
3476
 
 
3477
    return Py::None();
 
3478
}
 
3479
 
3347
3480
Py::Object pysvn_client::get_auth_cache( const Py::Tuple &a_args, const Py::Dict &a_kws )
3348
3481
{
3349
3482
    static argument_description args_desc[] =
3351
3484
    { false, NULL }
3352
3485
    };
3353
3486
    FunctionArguments args( "get_auth_cache", args_desc, a_args, a_kws );
3354
 
    args.check();
3355
 
 
3356
 
    char *param = NULL;
3357
 
    try
3358
 
    {
3359
 
        param = (char *)svn_auth_get_parameter
3360
 
            (
3361
 
            m_context.ctx()->auth_baton,
3362
 
            SVN_AUTH_PARAM_NO_AUTH_CACHE
3363
 
            );
3364
 
    }
3365
 
    catch( SvnException &e )
3366
 
    {
3367
 
        // use callback error over ClientException
3368
 
        m_context.checkForError( m_module.client_error );
3369
 
 
3370
 
        throw_client_error( e );
3371
 
    }
3372
 
 
3373
 
    bool no_auth_cache = (param != NULL && param[0] == '1');
3374
 
    if( no_auth_cache )
3375
 
        return Py::Int( 0 );
3376
 
    return Py::Int( 1 );
 
3487
 
 
3488
    return helper_boolean_auth_get( args, SVN_AUTH_PARAM_NO_AUTH_CACHE );
 
3489
}
 
3490
 
 
3491
Py::Object pysvn_client::get_interactive( const Py::Tuple &a_args, const Py::Dict &a_kws )
 
3492
{
 
3493
    static argument_description args_desc[] =
 
3494
    {
 
3495
    { false, NULL }
 
3496
    };
 
3497
    FunctionArguments args( "get_interactive", args_desc, a_args, a_kws );
 
3498
 
 
3499
    return helper_boolean_auth_get( args, SVN_AUTH_PARAM_NON_INTERACTIVE );
 
3500
}
 
3501
 
 
3502
Py::Object pysvn_client::get_store_passwords( const Py::Tuple &a_args, const Py::Dict &a_kws )
 
3503
{
 
3504
    static argument_description args_desc[] =
 
3505
    {
 
3506
    { false, NULL }
 
3507
    };
 
3508
    FunctionArguments args( "get_store_passwords", args_desc, a_args, a_kws );
 
3509
 
 
3510
    return helper_boolean_auth_get( args, SVN_AUTH_PARAM_DONT_STORE_PASSWORDS );
 
3511
}
 
3512
 
 
3513
Py::Object pysvn_client::get_default_username( const Py::Tuple &a_args, const Py::Dict &a_kws )
 
3514
{
 
3515
    static argument_description args_desc[] =
 
3516
    {
 
3517
    { false, NULL }
 
3518
    };
 
3519
    FunctionArguments args( "get_default_username", args_desc, a_args, a_kws );
 
3520
 
 
3521
    return helper_string_auth_get( args, SVN_AUTH_PARAM_DEFAULT_USERNAME );
 
3522
}
 
3523
 
 
3524
Py::Object pysvn_client::get_default_password( const Py::Tuple &a_args, const Py::Dict &a_kws )
 
3525
{
 
3526
    static argument_description args_desc[] =
 
3527
    {
 
3528
    { false, NULL }
 
3529
    };
 
3530
    FunctionArguments args( "get_default_password", args_desc, a_args, a_kws );
 
3531
 
 
3532
    return helper_string_auth_get( args, SVN_AUTH_PARAM_DEFAULT_PASSWORD );
3377
3533
}
3378
3534
 
3379
3535
Py::Object pysvn_client::set_auth_cache( const Py::Tuple &a_args, const Py::Dict &a_kws )
3384
3540
    { false, NULL }
3385
3541
    };
3386
3542
    FunctionArguments args( "set_auth_cache", args_desc, a_args, a_kws );
3387
 
    args.check();
3388
 
 
3389
 
    bool enable( args.getBoolean( name_enable ) );
3390
 
    try
3391
 
    {
3392
 
        void *param = 0;
3393
 
        if( !enable )
3394
 
            param = (void *)"1";
3395
 
 
3396
 
        svn_auth_set_parameter
3397
 
            (
3398
 
            m_context.ctx()->auth_baton,
3399
 
            SVN_AUTH_PARAM_NO_AUTH_CACHE,
3400
 
            param
3401
 
            );
3402
 
    }
3403
 
    catch( SvnException &e )
3404
 
    {
3405
 
        // use callback error over ClientException
3406
 
        m_context.checkForError( m_module.client_error );
3407
 
 
3408
 
        throw_client_error( e );
3409
 
    }
3410
 
 
3411
 
    return Py::Nothing();
 
3543
 
 
3544
    return helper_boolean_auth_set( args, name_enable, SVN_AUTH_PARAM_NO_AUTH_CACHE );
 
3545
}
 
3546
 
 
3547
Py::Object pysvn_client::set_interactive( const Py::Tuple &a_args, const Py::Dict &a_kws )
 
3548
{
 
3549
    static argument_description args_desc[] =
 
3550
    {
 
3551
    { true,  name_enable },
 
3552
    { false, NULL }
 
3553
    };
 
3554
    FunctionArguments args( "set_interactive", args_desc, a_args, a_kws );
 
3555
 
 
3556
    return helper_boolean_auth_set( args, name_enable, SVN_AUTH_PARAM_NON_INTERACTIVE );
 
3557
}
 
3558
 
 
3559
Py::Object pysvn_client::set_store_passwords( const Py::Tuple &a_args, const Py::Dict &a_kws )
 
3560
{
 
3561
    static argument_description args_desc[] =
 
3562
    {
 
3563
    { true,  name_enable },
 
3564
    { false, NULL }
 
3565
    };
 
3566
    FunctionArguments args( "set_store_passwords", args_desc, a_args, a_kws );
 
3567
 
 
3568
    return helper_boolean_auth_set( args, name_enable, SVN_AUTH_PARAM_DONT_STORE_PASSWORDS );
 
3569
}
 
3570
 
 
3571
Py::Object pysvn_client::set_default_username( const Py::Tuple &a_args, const Py::Dict &a_kws )
 
3572
{
 
3573
    static argument_description args_desc[] =
 
3574
    {
 
3575
    { true,  name_username },
 
3576
    { false, NULL }
 
3577
    };
 
3578
    FunctionArguments args( "set_default_username", args_desc, a_args, a_kws );
 
3579
 
 
3580
    return helper_string_auth_set( args, name_username, SVN_AUTH_PARAM_DEFAULT_USERNAME, m_context.m_default_username );
 
3581
}
 
3582
 
 
3583
Py::Object pysvn_client::set_default_password( const Py::Tuple &a_args, const Py::Dict &a_kws )
 
3584
{
 
3585
    static argument_description args_desc[] =
 
3586
    {
 
3587
    { true,  name_password },
 
3588
    { false, NULL }
 
3589
    };
 
3590
    FunctionArguments args( "set_default_password", args_desc, a_args, a_kws );
 
3591
 
 
3592
    return helper_string_auth_set( args, name_password, SVN_AUTH_PARAM_DEFAULT_PASSWORD, m_context.m_default_password );
3412
3593
}
3413
3594
 
3414
3595
Py::Object pysvn_client::get_auto_props( const Py::Tuple &a_args, const Py::Dict &a_kws )
3486
3667
        throw_client_error( e );
3487
3668
    }
3488
3669
 
3489
 
    return Py::Nothing();
 
3670
    return Py::None();
3490
3671
}
3491
3672
 
3492
3673
Py::Object pysvn_client::is_url( const Py::Tuple &a_args, const Py::Dict &a_kws )
3539
3720
    add_keyword_method("copy", &pysvn_client::cmd_copy, pysvn_client_copy_doc );
3540
3721
    add_keyword_method("diff", &pysvn_client::cmd_diff, pysvn_client_diff_doc );
3541
3722
    add_keyword_method("export", &pysvn_client::cmd_export, pysvn_client_export_doc );
 
3723
    add_keyword_method("get_auth_cache", &pysvn_client::get_auth_cache, pysvn_client_get_auth_cache_doc );
 
3724
    add_keyword_method("get_auto_props", &pysvn_client::get_auto_props, pysvn_client_get_auto_props_doc );
 
3725
    add_keyword_method("get_default_password", &pysvn_client::get_default_password, pysvn_client_get_default_password_doc );
 
3726
    add_keyword_method("get_default_username", &pysvn_client::get_default_username, pysvn_client_get_default_username_doc );
 
3727
    add_keyword_method("get_interactive", &pysvn_client::get_interactive, pysvn_client_get_interactive_doc );
 
3728
    add_keyword_method("get_store_passwords", &pysvn_client::get_store_passwords, pysvn_client_get_store_passwords_doc );
3542
3729
    add_keyword_method("import_", &pysvn_client::cmd_import, pysvn_client_import__doc );
3543
3730
    add_keyword_method("info", &pysvn_client::cmd_info, pysvn_client_info_doc );
3544
3731
 
3566
3753
    add_keyword_method("revpropget", &pysvn_client::cmd_revpropget, pysvn_client_revpropget_doc );
3567
3754
    add_keyword_method("revproplist", &pysvn_client::cmd_revproplist, pysvn_client_revproplist_doc );
3568
3755
    add_keyword_method("revpropset", &pysvn_client::cmd_revpropset, pysvn_client_revpropset_doc );
3569
 
    add_keyword_method("get_auth_cache", &pysvn_client::get_auth_cache, pysvn_client_get_auth_cache_doc );
3570
3756
    add_keyword_method("set_auth_cache", &pysvn_client::set_auth_cache, pysvn_client_set_auth_cache_doc );
3571
 
    add_keyword_method("get_auto_props", &pysvn_client::get_auto_props, pysvn_client_get_auto_props_doc );
3572
3757
    add_keyword_method("set_auto_props", &pysvn_client::set_auto_props, pysvn_client_set_auto_props_doc );
 
3758
    add_keyword_method("set_default_password", &pysvn_client::set_default_password, pysvn_client_set_default_password_doc );
 
3759
    add_keyword_method("set_default_username", &pysvn_client::set_default_username, pysvn_client_set_default_username_doc );
 
3760
    add_keyword_method("set_interactive", &pysvn_client::set_interactive, pysvn_client_set_interactive_doc );
 
3761
    add_keyword_method("set_store_passwords", &pysvn_client::set_store_passwords, pysvn_client_set_store_passwords_doc );
3573
3762
    add_keyword_method("status", &pysvn_client::cmd_status, pysvn_client_status_doc );
3574
3763
    add_keyword_method("switch", &pysvn_client::cmd_switch, pysvn_client_switch_doc );
3575
3764
#ifdef PYSVN_HAS_CLIENT_LOCK