// commit.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <fstream>
#include <svn_client.h>
#include <svn_path.h>
#include <svn_utf.h>
#include <svn_pools.h>

#include <apr_tables.h>
#include <apr_pools.h>

using namespace std;

const char* FILEPATH = "\\tmp\\wc\\Form.cs";

void displayErr( svn_error_t* err )
{
    cout << err->message << endl;
    if ( err->child )
        displayErr( err->child );
}


int main(int argc, char* argv[])
{
    apr_initialize();

    ofstream os( FILEPATH );
    os << "Moo" << endl;
    os.close();

    apr_pool_t* pool = svn_pool_create( 0 );

    apr_array_header_t* array = 
        apr_array_make( pool, 1, sizeof( const char* ) );

    const char* utf8path;;
    char* trueNamedTarget;

    apr_filepath_merge( &trueNamedTarget, "", FILEPATH, 
        APR_FILEPATH_TRUENAME, pool );
    svn_path_cstring_to_utf8( &utf8path, trueNamedTarget, pool );
    const char* target = svn_path_canonicalize( utf8path, pool );

    *((const char**)apr_array_push(array)) = target;

    svn_client_commit_info_t* commitInfo;
    svn_client_ctx_t ctx = { 0 };

    svn_error_t* err = svn_client_commit( 
        &commitInfo, array, true, &ctx, pool );
    if ( err ) 
        displayErr( err );
}

