~ubuntu-branches/ubuntu/intrepid/kdesdk/intrepid-updates

« back to all changes in this revision

Viewing changes to kioslave/svn/svn.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-28 10:11:43 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: james.westby@ubuntu.com-20080528101143-gzc3styjz1b70zxu
Tags: upstream-4.0.80
ImportĀ upstreamĀ versionĀ 4.0.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
   You should have received a copy of the GNU Library General Public License
15
15
   along with this library; see the file COPYING.LIB.  If not, write to
16
 
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
 
   Boston, MA 02111-1307, USA.
 
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
   Boston, MA 02110-1301, USA.
18
18
*/
19
19
 
20
 
#include <qcstring.h>
21
 
#include <qsocket.h>
22
 
#include <qdatetime.h>
23
 
#include <qbitarray.h>
 
20
#include <QDateTime>
 
21
#include <QBitArray>
 
22
#include <QTextStream>
24
23
 
25
24
#include <stdlib.h>
26
25
#include <math.h>
29
28
#include <netinet/in.h>
30
29
#include <netdb.h>
31
30
 
32
 
#include <kapplication.h>
33
31
#include <kdebug.h>
34
32
#include <kmessagebox.h>
35
 
#include <kinstance.h>
 
33
#include <kcomponentdata.h>
36
34
#include <kglobal.h>
37
35
#include <kstandarddirs.h>
38
36
#include <klocale.h>
39
37
#include <kurl.h>
40
 
#include <ksock.h>
41
 
#include <dcopclient.h>
42
 
#include <qcstring.h>
43
 
 
 
38
#include <ksvndinterface.h>
44
39
#include <subversion-1/svn_sorts.h>
45
40
#include <subversion-1/svn_path.h>
46
41
#include <subversion-1/svn_utf.h>
48
43
#include <subversion-1/svn_time.h>
49
44
 
50
45
#include <kmimetype.h>
51
 
#include <qfile.h>
 
46
#include <QFile>
52
47
 
53
48
#include "svn.h"
54
49
#include <apr_portable.h>
93
88
  /* Tack on a made-up filename. */
94
89
  truepath = svn_path_join (truepath, "tempfile", pool);
95
90
 
96
 
  /* Open a unique file;  use APR_DELONCLOSE. */  
 
91
  /* Open a unique file;  use APR_DELONCLOSE. */
97
92
  SVN_ERR (svn_io_open_unique_file (fp, &ignored_filename,
98
 
                                    truepath, ".tmp", TRUE, pool));
 
93
                                    truepath, ".tmp", true, pool));
99
94
 
100
95
  return SVN_NO_ERROR;
101
96
}
111
106
  return svn_path_compare_paths ((const char *)a->key, (const char *)b->key);
112
107
}
113
108
 
114
 
kio_svnProtocol::kio_svnProtocol(const QCString &pool_socket, const QCString &app_socket)
 
109
kio_svnProtocol::kio_svnProtocol(const QByteArray &pool_socket, const QByteArray &app_socket)
115
110
        : SlaveBase("kio_svn", pool_socket, app_socket) {
116
 
                kdDebug(7128) << "kio_svnProtocol::kio_svnProtocol()" << endl;
 
111
                kDebug(7128) << "kio_svnProtocol::kio_svnProtocol()";
117
112
 
118
113
                m_counter = 0;
119
114
 
120
115
                apr_initialize();
121
 
                // CleanUP ctx preventing crash in svn_client_update and other
122
 
                memset(&ctx, 0, sizeof(ctx));
123
116
                pool = svn_pool_create (NULL);
124
 
 
125
117
                svn_error_t *err = svn_client_create_context(&ctx, pool);
126
 
                if ( err ) {
127
 
                        kdDebug(7128) << "kio_svnProtocol::kio_svnProtocol() create_context ERROR" << endl;
128
 
                        error( KIO::ERR_SLAVE_DEFINED, err->message );
129
 
                        return;
130
 
                }
 
118
                if ( err ) {
 
119
                        kDebug(7128) << "kio_svnProtocol::kio_svnProtocol() create_context ERROR";
 
120
                        error( KIO::ERR_SLAVE_DEFINED, err->message );
 
121
                        return;
 
122
                }
131
123
 
132
124
                err = svn_config_ensure (NULL,pool);
133
125
                if ( err ) {
134
 
                        kdDebug(7128) << "kio_svnProtocol::kio_svnProtocol() configensure ERROR" << endl;
 
126
                        kDebug(7128) << "kio_svnProtocol::kio_svnProtocol() configensure ERROR";
135
127
                        error( KIO::ERR_SLAVE_DEFINED, err->message );
136
128
                        return;
137
129
                }
138
 
                svn_config_get_config (&ctx->config, NULL, pool);
 
130
                svn_config_get_config (&ctx->config,NULL,pool);
139
131
 
140
132
                ctx->log_msg_func = kio_svnProtocol::commitLogPrompt;
141
133
                ctx->log_msg_baton = this; //pass this so that we can get a dcopClient from it
159
151
/*              svn_client_get_username_prompt_provider
160
152
 *              (&provider,kio_svnProtocol::checkAuth,this,2,pool);
161
153
                APR_ARRAY_PUSH(providers, svn_auth_provider_object_t*) = provider;*/
162
 
                
 
154
 
163
155
                //SSL disk cache, keep that one, because it does nothing bad :)
164
156
                svn_client_get_ssl_server_trust_file_provider (&provider, pool);
165
157
                APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
167
159
                APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
168
160
                svn_client_get_ssl_client_cert_pw_file_provider (&provider, pool);
169
161
                APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
170
 
                
 
162
 
171
163
                //SSL interactive prompt, where things get hard
172
164
                svn_client_get_ssl_server_trust_prompt_provider (&provider, kio_svnProtocol::trustSSLPrompt, NULL, pool);
173
165
                APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider;
180
172
}
181
173
 
182
174
kio_svnProtocol::~kio_svnProtocol(){
183
 
        kdDebug(7128) << "kio_svnProtocol::~kio_svnProtocol()" << endl;
 
175
        kDebug(7128) << "kio_svnProtocol::~kio_svnProtocol()";
184
176
        svn_pool_destroy(pool);
185
177
        apr_terminate();
186
178
}
190
182
        ctx->notify_func = kio_svnProtocol::notify;
191
183
        struct notify_baton *nb = ( struct notify_baton* )apr_palloc(spool, sizeof( *nb ) );
192
184
        nb->master = this;
193
 
        nb->received_some_change = FALSE;
194
 
        nb->sent_first_txdelta = FALSE;
 
185
        nb->received_some_change = false;
 
186
        nb->sent_first_txdelta = false;
195
187
        nb->is_checkout = is_checkout;
196
188
        nb->is_export = is_export;
197
189
        nb->suppress_final_line = suppress_final_line;
198
 
        nb->in_external = FALSE;
199
 
        nb->had_print_error = FALSE;
 
190
        nb->in_external = false;
 
191
        nb->had_print_error = false;
200
192
        nb->pool = svn_pool_create (spool);
201
193
 
202
194
        ctx->notify_baton = nb;
203
195
}
204
196
 
205
197
svn_error_t* kio_svnProtocol::checkAuth(svn_auth_cred_simple_t **cred, void *baton, const char *realm, const char *username, svn_boolean_t /*may_save*/, apr_pool_t *pool) {
206
 
        kdDebug(7128) << "kio_svnProtocol::checkAuth() for " << realm << endl;
 
198
        kDebug(7128) << "kio_svnProtocol::checkAuth() for " << realm;
207
199
        kio_svnProtocol *p = ( kio_svnProtocol* )baton;
208
200
        svn_auth_cred_simple_t *ret = (svn_auth_cred_simple_t*)apr_pcalloc (pool, sizeof (*ret));
209
 
        
 
201
 
210
202
//      p->info.keepPassword = true;
211
203
        p->info.verifyPath=true;
212
 
        kdDebug(7128 ) << "auth current URL : " << p->myURL.url() << endl;
 
204
        kDebug(7128 ) << "auth current URL : " << p->myURL.url();
213
205
        p->info.url = p->myURL;
214
206
        p->info.username = username; //( const char* )svn_auth_get_parameter( p->ctx->auth_baton, SVN_AUTH_PARAM_DEFAULT_USERNAME );
215
207
//      if ( !p->checkCachedAuthentication( p->info ) ){
216
 
                p->openPassDlg( p->info );
 
208
                p->openPasswordDialog( p->info );
217
209
//      }
218
 
        ret->username = apr_pstrdup(pool, p->info.username.utf8());
219
 
        ret->password = apr_pstrdup(pool, p->info.password.utf8());
 
210
        ret->username = apr_pstrdup(pool, p->info.username.toUtf8());
 
211
        ret->password = apr_pstrdup(pool, p->info.password.toUtf8());
220
212
        ret->may_save = true;
221
213
        *cred = ret;
222
214
        return SVN_NO_ERROR;
223
215
}
224
216
 
225
 
void kio_svnProtocol::recordCurrentURL(const KURL& url) {
 
217
void kio_svnProtocol::recordCurrentURL(const KUrl& url) {
226
218
        myURL = url;
227
219
}
228
220
 
229
221
//don't implement mimeType() until we don't need to download the whole file
230
222
 
231
 
void kio_svnProtocol::get(const KURL& url ){
232
 
        kdDebug(7128) << "kio_svn::get(const KURL& url)" << endl ;
 
223
void kio_svnProtocol::get(const KUrl& url ){
 
224
        kDebug(7128) << "kio_svn::get(const KUrl& url)";
233
225
 
234
226
        QString remoteServer = url.host();
235
 
        infoMessage(i18n("Looking for %1...").arg( remoteServer ) );
 
227
        infoMessage(i18n("Looking for %1...", remoteServer ) );
236
228
 
237
229
        apr_pool_t *subpool = svn_pool_create (pool);
238
230
        kbaton *bt = (kbaton*)apr_pcalloc(subpool, sizeof(*bt));
241
233
        svn_stream_set_write(bt->string_stream,write_to_string);
242
234
 
243
235
        QString target = makeSvnURL( url );
244
 
        kdDebug(7128) << "SvnURL: " << target << endl;
245
 
        recordCurrentURL( KURL( target ) );
246
 
        
 
236
        kDebug(7128) << "SvnURL: " << target;
 
237
        recordCurrentURL( KUrl( target ) );
 
238
 
247
239
        //find the requested revision
248
240
        svn_opt_revision_t rev;
249
241
        svn_opt_revision_t endrev;
250
 
        int idx = target.findRev( "?rev=" );
 
242
        int idx = target.lastIndexOf( "?rev=" );
251
243
        if ( idx != -1 ) {
252
244
                QString revstr = target.mid( idx+5 );
253
245
#if 0
254
 
                kdDebug(7128) << "revision string found " << revstr  << endl;
 
246
                kDebug(7128) << "revision string found " << revstr;
255
247
                if ( revstr == "HEAD" ) {
256
248
                        rev.kind = svn_opt_revision_head;
257
 
                        kdDebug(7128) << "revision searched : HEAD" << endl;
 
249
                        kDebug(7128) << "revision searched : HEAD";
258
250
                } else {
259
251
                        rev.kind = svn_opt_revision_number;
260
252
                        rev.value.number = revstr.toLong();
261
 
                        kdDebug(7128) << "revision searched : " << rev.value.number << endl;
 
253
                        kDebug(7128) << "revision searched : " << rev.value.number;
262
254
                }
263
255
#endif
264
 
                svn_opt_parse_revision( &rev, &endrev, revstr.utf8(), subpool );
 
256
                svn_opt_parse_revision( &rev, &endrev, revstr.toUtf8(), subpool );
265
257
                target = target.left( idx );
266
 
                kdDebug(7128) << "new target : " << target << endl;
 
258
                kDebug(7128) << "new target : " << target;
267
259
        } else {
268
 
                kdDebug(7128) << "no revision given. searching HEAD " << endl;
 
260
                kDebug(7128) << "no revision given. searching HEAD ";
269
261
                rev.kind = svn_opt_revision_head;
270
262
        }
271
263
        initNotifier(false, false, false, subpool);
272
264
 
273
 
        svn_error_t *err = svn_client_cat (bt->string_stream, svn_path_canonicalize( target.utf8(),subpool ),&rev,ctx, subpool);
 
265
        svn_error_t *err = svn_client_cat (bt->string_stream, svn_path_canonicalize( target.toUtf8(),subpool ),&rev,ctx, subpool);
274
266
        if ( err ) {
275
267
                error( KIO::ERR_SLAVE_DEFINED, err->message );
276
268
                svn_pool_destroy( subpool );
280
272
        // Send the mimeType as soon as it is known
281
273
        QByteArray *cp = new QByteArray();
282
274
        cp->setRawData( bt->target_string->data, bt->target_string->len );
283
 
        KMimeType::Ptr mt = KMimeType::findByContent(*cp);
284
 
        kdDebug(7128) << "KMimeType returned : " << mt->name() << endl;
 
275
        KMimeType::Ptr mt = KMimeType::findByNameAndContent(url.fileName(), *cp);
 
276
        kDebug(7128) << "KMimeType returned : " << mt->name();
285
277
        mimeType( mt->name() );
286
278
 
287
279
        totalSize(bt->target_string->len);
294
286
        svn_pool_destroy (subpool);
295
287
}
296
288
 
297
 
void kio_svnProtocol::stat(const KURL & url){
298
 
        kdDebug(7128) << "kio_svn::stat(const KURL& url) : " << url.url() << endl ;
 
289
void kio_svnProtocol::stat(const KUrl & url){
 
290
        kDebug(7128) << "kio_svn::stat(const KUrl& url) : " << url.url();
299
291
 
300
292
        void *ra_baton, *session;
301
293
        svn_ra_plugin_t *ra_lib;
303
295
        apr_pool_t *subpool = svn_pool_create (pool);
304
296
 
305
297
        QString target = makeSvnURL( url);
306
 
        kdDebug(7128) << "SvnURL: " << target << endl;
307
 
        recordCurrentURL( KURL( target ) );
308
 
        
 
298
        kDebug(7128) << "SvnURL: " << target;
 
299
        recordCurrentURL( KUrl( target ) );
 
300
 
309
301
        //find the requested revision
310
302
        svn_opt_revision_t rev;
311
303
        svn_opt_revision_t endrev;
312
 
        int idx = target.findRev( "?rev=" );
 
304
        int idx = target.lastIndexOf( "?rev=" );
313
305
        if ( idx != -1 ) {
314
306
                QString revstr = target.mid( idx+5 );
315
307
#if 0
316
 
                kdDebug(7128) << "revision string found " << revstr  << endl;
 
308
                kDebug(7128) << "revision string found " << revstr;
317
309
                if ( revstr == "HEAD" ) {
318
310
                        rev.kind = svn_opt_revision_head;
319
 
                        kdDebug(7128) << "revision searched : HEAD" << endl;
 
311
                        kDebug(7128) << "revision searched : HEAD";
320
312
                } else {
321
313
                        rev.kind = svn_opt_revision_number;
322
314
                        rev.value.number = revstr.toLong();
323
 
                        kdDebug(7128) << "revision searched : " << rev.value.number << endl;
 
315
                        kDebug(7128) << "revision searched : " << rev.value.number;
324
316
                }
325
317
#endif
326
 
                svn_opt_parse_revision( &rev, &endrev, revstr.utf8( ), subpool );
 
318
                svn_opt_parse_revision( &rev, &endrev, revstr.toUtf8( ), subpool );
327
319
                target = target.left( idx );
328
 
                kdDebug(7128) << "new target : " << target << endl;
 
320
                kDebug(7128) << "new target : " << target;
329
321
        } else {
330
 
                kdDebug(7128) << "no revision given. searching HEAD " << endl;
 
322
                kDebug(7128) << "no revision given. searching HEAD ";
331
323
                rev.kind = svn_opt_revision_head;
332
324
        }
333
325
 
334
326
        //init
335
327
        svn_error_t *err = svn_ra_init_ra_libs(&ra_baton,subpool);
336
328
        if ( err ) {
337
 
                kdDebug(7128) << "init RA libs failed : " << err->message << endl;
 
329
                kDebug(7128) << "init RA libs failed : " << err->message;
338
330
                return;
339
331
        }
340
332
        //find RA libs
341
 
        err = svn_ra_get_ra_library(&ra_lib,ra_baton,svn_path_canonicalize( target.utf8(), subpool ),subpool);
 
333
        err = svn_ra_get_ra_library(&ra_lib,ra_baton,svn_path_canonicalize( target.toUtf8(), subpool ),subpool);
342
334
        if ( err ) {
343
 
                kdDebug(7128) << "RA get libs failed : " << err->message << endl;
 
335
                kDebug(7128) << "RA get libs failed : " << err->message;
344
336
                return;
345
337
        }
346
 
        kdDebug(7128) << "RA init completed" << endl;
347
 
        
 
338
        kDebug(7128) << "RA init completed";
 
339
 
348
340
        //start session
349
 
        svn_ra_callbacks_t *cbtable = (svn_ra_callbacks_t*)apr_pcalloc(subpool, sizeof(*cbtable));      
 
341
        svn_ra_callbacks_t *cbtable = (svn_ra_callbacks_t*)apr_pcalloc(subpool, sizeof(*cbtable));
350
342
        kio_svn_callback_baton_t *callbackbt = (kio_svn_callback_baton_t*)apr_pcalloc(subpool, sizeof( *callbackbt ));
351
343
 
352
344
        cbtable->open_tmp_file = open_tmp_file;
355
347
        cbtable->push_wc_prop = NULL;
356
348
        cbtable->auth_baton = ctx->auth_baton;
357
349
 
358
 
        callbackbt->base_dir = target.utf8();
 
350
        callbackbt->base_dir = target.toUtf8();
359
351
        callbackbt->pool = subpool;
360
352
        callbackbt->config = ctx->config;
361
 
        
362
 
        err = ra_lib->open(&session,svn_path_canonicalize( target.utf8(), subpool ),cbtable,callbackbt,ctx->config,subpool);
 
353
 
 
354
        err = ra_lib->open(&session,svn_path_canonicalize( target.toUtf8(), subpool ),cbtable,callbackbt,ctx->config,subpool);
363
355
        if ( err ) {
364
 
                kdDebug(7128)<< "Open session " << err->message << endl;
 
356
                kDebug(7128)<< "Open session " << err->message;
365
357
                return;
366
358
        }
367
 
        kdDebug(7128) << "Session opened to " << target << endl;
 
359
        kDebug(7128) << "Session opened to " << target;
368
360
        //find number for HEAD
369
361
        if (rev.kind == svn_opt_revision_head) {
370
362
                err = ra_lib->get_latest_revnum(session,&rev.value.number,subpool);
371
363
                if ( err ) {
372
 
                        kdDebug(7128)<< "Latest RevNum " << err->message << endl;
 
364
                        kDebug(7128)<< "Latest RevNum " << err->message;
373
365
                        return;
374
366
                }
375
 
                kdDebug(7128) << "Got rev " << rev.value.number << endl;
 
367
                kDebug(7128) << "Got rev " << rev.value.number;
376
368
        }
377
 
        
 
369
 
378
370
        //get it
379
371
        ra_lib->check_path(session,"",rev.value.number,&kind,subpool);
380
 
        kdDebug(7128) << "Checked Path" << endl;
 
372
        kDebug(7128) << "Checked Path";
381
373
        UDSEntry entry;
382
374
        switch ( kind ) {
383
375
                case svn_node_file:
384
 
                        kdDebug(7128) << "::stat result : file" << endl;
385
 
                        createUDSEntry(url.filename(),"",0,false,0,entry);
 
376
                        kDebug(7128) << "::stat result : file";
 
377
                        createUDSEntry(url.fileName(),"",0,false,0,entry);
386
378
                        statEntry( entry );
387
379
                        break;
388
380
                case svn_node_dir:
389
 
                        kdDebug(7128) << "::stat result : directory" << endl;
390
 
                        createUDSEntry(url.filename(),"",0,true,0,entry);
 
381
                        kDebug(7128) << "::stat result : directory";
 
382
                        createUDSEntry(url.fileName(),"",0,true,0,entry);
391
383
                        statEntry( entry );
392
384
                        break;
393
385
                case svn_node_unknown:
394
386
                case svn_node_none:
395
387
                        //error XXX
396
388
                default:
397
 
                        kdDebug(7128) << "::stat result : UNKNOWN ==> WOW :)" << endl;
 
389
                        kDebug(7128) << "::stat result : UNKNOWN ==> WOW :)";
398
390
                        ;
399
391
        }
400
392
        finished();
401
393
        svn_pool_destroy( subpool );
402
394
}
403
395
 
404
 
void kio_svnProtocol::listDir(const KURL& url){
405
 
        kdDebug(7128) << "kio_svn::listDir(const KURL& url) : " << url.url() << endl ;
 
396
void kio_svnProtocol::listDir(const KUrl& url){
 
397
        kDebug(7128) << "kio_svn::listDir(const KUrl& url) : " << url.url();
406
398
 
407
399
        apr_pool_t *subpool = svn_pool_create (pool);
408
400
        apr_hash_t *dirents;
409
401
 
410
402
        QString target = makeSvnURL( url);
411
 
        kdDebug(7128) << "SvnURL: " << target << endl;
412
 
        recordCurrentURL( KURL( target ) );
413
 
        
 
403
        kDebug(7128) << "SvnURL: " << target;
 
404
        recordCurrentURL( KUrl( target ) );
 
405
 
414
406
        //find the requested revision
415
407
        svn_opt_revision_t rev;
416
408
        svn_opt_revision_t endrev;
417
 
        int idx = target.findRev( "?rev=" );
 
409
        int idx = target.lastIndexOf( "?rev=" );
418
410
        if ( idx != -1 ) {
419
411
                QString revstr = target.mid( idx+5 );
420
 
                svn_opt_parse_revision( &rev, &endrev, revstr.utf8(), subpool );
 
412
                svn_opt_parse_revision( &rev, &endrev, revstr.toUtf8(), subpool );
421
413
#if 0
422
 
                kdDebug(7128) << "revision string found " << revstr  << endl;
 
414
                kDebug(7128) << "revision string found " << revstr;
423
415
                if ( revstr == "HEAD" ) {
424
416
                        rev.kind = svn_opt_revision_head;
425
 
                        kdDebug(7128) << "revision searched : HEAD" << endl;
 
417
                        kDebug(7128) << "revision searched : HEAD";
426
418
                } else {
427
419
                        rev.kind = svn_opt_revision_number;
428
420
                        rev.value.number = revstr.toLong();
429
 
                        kdDebug(7128) << "revision searched : " << rev.value.number << endl;
 
421
                        kDebug(7128) << "revision searched : " << rev.value.number;
430
422
                }
431
423
#endif
432
424
                target = target.left( idx );
433
 
                kdDebug(7128) << "new target : " << target << endl;
 
425
                kDebug(7128) << "new target : " << target;
434
426
        } else {
435
 
                kdDebug(7128) << "no revision given. searching HEAD " << endl;
 
427
                kDebug(7128) << "no revision given. searching HEAD ";
436
428
                rev.kind = svn_opt_revision_head;
437
429
        }
438
430
 
439
431
        initNotifier(false, false, false, subpool);
440
 
        svn_error_t *err = svn_client_ls (&dirents, svn_path_canonicalize( target.utf8(), subpool ), &rev, false, ctx, subpool);
 
432
        svn_error_t *err = svn_client_ls (&dirents, svn_path_canonicalize( target.toUtf8(), subpool ), &rev, false, ctx, subpool);
441
433
        if ( err ) {
442
434
                error( KIO::ERR_SLAVE_DEFINED, err->message );
443
435
                svn_pool_destroy( subpool );
448
440
  int i;
449
441
 
450
442
  array = svn_sort__hash (dirents, compare_items_as_paths, subpool);
451
 
  
 
443
 
452
444
  UDSEntry entry;
453
445
  for (i = 0; i < array->nelts; ++i) {
454
446
          entry.clear();
455
447
      const char *utf8_entryname, *native_entryname;
456
448
      svn_dirent_t *dirent;
457
449
      svn_sort__item_t *item;
458
 
     
 
450
 
459
451
      item = &APR_ARRAY_IDX (array, i, svn_sort__item_t);
460
452
 
461
453
      utf8_entryname = (const char*)item->key;
487
479
}
488
480
 
489
481
bool kio_svnProtocol::createUDSEntry( const QString& filename, const QString& user, long long int size, bool isdir, time_t mtime, UDSEntry& entry) {
490
 
        kdDebug(7128) << "MTime : " << ( long )mtime << endl;
491
 
        kdDebug(7128) << "UDS filename : " << filename << endl;
492
 
        UDSAtom atom;
493
 
        atom.m_uds = KIO::UDS_NAME;
494
 
        atom.m_str = filename;
495
 
        entry.append( atom );
496
 
 
497
 
        atom.m_uds = KIO::UDS_FILE_TYPE;
498
 
        atom.m_long = isdir ? S_IFDIR : S_IFREG;
499
 
        entry.append( atom );
500
 
 
501
 
        atom.m_uds = KIO::UDS_SIZE;
502
 
        atom.m_long = size;
503
 
        entry.append( atom );
504
 
        
505
 
        atom.m_uds = KIO::UDS_MODIFICATION_TIME;
506
 
        atom.m_long = mtime;
507
 
        entry.append( atom );
508
 
        
509
 
        atom.m_uds = KIO::UDS_USER;
510
 
        atom.m_str = user;
511
 
        entry.append( atom );
 
482
        kDebug(7128) << "MTime : " << ( long )mtime;
 
483
        kDebug(7128) << "UDS filename : " << filename;
 
484
        entry.insert(KIO::UDSEntry::UDS_NAME,filename);
 
485
 
 
486
        entry.insert(KIO::UDSEntry::UDS_FILE_TYPE,isdir ? S_IFDIR : S_IFREG);
 
487
 
 
488
        entry.insert(KIO::UDSEntry::UDS_SIZE,size);
 
489
 
 
490
        entry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME,mtime);
 
491
 
 
492
        entry.insert(KIO::UDSEntry::UDS_USER,user);
512
493
 
513
494
        return true;
514
495
}
515
496
 
516
 
void kio_svnProtocol::copy(const KURL & src, const KURL& dest, int /*permissions*/, bool /*overwrite*/) {
517
 
        kdDebug(7128) << "kio_svnProtocol::copy() Source : " << src.url() << " Dest : " << dest.url() << endl;
518
 
        
 
497
void kio_svnProtocol::copy(const KUrl & src, const KUrl& dest, int /*permissions*/, KIO::JobFlags) {
 
498
        kDebug(7128) << "kio_svnProtocol::copy() Source : " << src.url() << " Dest : " << dest.url();
 
499
 
519
500
        apr_pool_t *subpool = svn_pool_create (pool);
520
501
        svn_client_commit_info_t *commit_info = NULL;
521
502
 
522
 
        KURL nsrc = src;
523
 
        KURL ndest = dest;
 
503
        KUrl nsrc = src;
 
504
        KUrl ndest = dest;
524
505
        nsrc.setProtocol( chooseProtocol( src.protocol() ) );
525
506
        ndest.setProtocol( chooseProtocol( dest.protocol() ) );
526
507
        QString srcsvn = nsrc.url();
527
508
        QString destsvn = ndest.url();
528
 
        
 
509
 
529
510
        recordCurrentURL( nsrc );
530
511
 
531
512
        //find the requested revision
532
513
        svn_opt_revision_t rev;
533
 
        int idx = srcsvn.findRev( "?rev=" );
 
514
        int idx = srcsvn.lastIndexOf( "?rev=" );
534
515
        if ( idx != -1 ) {
535
516
                QString revstr = srcsvn.mid( idx+5 );
536
 
                kdDebug(7128) << "revision string found " << revstr  << endl;
 
517
                kDebug(7128) << "revision string found " << revstr;
537
518
                if ( revstr == "HEAD" ) {
538
519
                        rev.kind = svn_opt_revision_head;
539
 
                        kdDebug(7128) << "revision searched : HEAD" << endl;
 
520
                        kDebug(7128) << "revision searched : HEAD";
540
521
                } else {
541
522
                        rev.kind = svn_opt_revision_number;
542
523
                        rev.value.number = revstr.toLong();
543
 
                        kdDebug(7128) << "revision searched : " << rev.value.number << endl;
 
524
                        kDebug(7128) << "revision searched : " << rev.value.number;
544
525
                }
545
526
                srcsvn = srcsvn.left( idx );
546
 
                kdDebug(7128) << "new src : " << srcsvn << endl;
 
527
                kDebug(7128) << "new src : " << srcsvn;
547
528
        } else {
548
 
                kdDebug(7128) << "no revision given. searching HEAD " << endl;
 
529
                kDebug(7128) << "no revision given. searching HEAD ";
549
530
                rev.kind = svn_opt_revision_head;
550
531
        }
551
532
 
552
533
        initNotifier(false, false, false, subpool);
553
 
        svn_error_t *err = svn_client_copy(&commit_info, srcsvn.utf8(), &rev, destsvn.utf8(), ctx, subpool);
 
534
        svn_error_t *err = svn_client_copy(&commit_info, srcsvn.toUtf8(), &rev, destsvn.toUtf8(), ctx, subpool);
554
535
        if ( err ) {
555
536
                error( KIO::ERR_SLAVE_DEFINED, err->message );
556
537
        }
557
 
        
 
538
 
558
539
        finished();
559
540
        svn_pool_destroy (subpool);
560
541
}
561
542
 
562
 
void kio_svnProtocol::mkdir( const KURL::List& list, int /*permissions*/ ) {
563
 
        kdDebug(7128) << "kio_svnProtocol::mkdir(LIST) : " << list << endl;
564
 
        
 
543
void kio_svnProtocol::mkdir( const KUrl::List& list, int /*permissions*/ ) {
 
544
        kDebug(7128) << "kio_svnProtocol::mkdir(LIST) : " << list;
 
545
 
565
546
        apr_pool_t *subpool = svn_pool_create (pool);
566
547
        svn_client_commit_info_t *commit_info = NULL;
567
548
 
568
549
        recordCurrentURL( list[ 0 ] );
569
 
        
 
550
 
570
551
        apr_array_header_t *targets = apr_array_make(subpool, list.count()+1, sizeof(const char *));
571
552
 
572
 
        KURL::List::const_iterator it = list.begin(), end = list.end();
 
553
        KUrl::List::const_iterator it = list.begin(), end = list.end();
573
554
        for ( ; it != end; ++it ) {
574
555
                QString cur = makeSvnURL( *it );
575
 
                kdDebug( 7128 ) << "kio_svnProtocol::mkdir raw url for subversion : " << cur << endl;
576
 
                const char *_target = apr_pstrdup( subpool, svn_path_canonicalize( apr_pstrdup( subpool, cur.utf8() ), subpool ) );
 
556
                kDebug( 7128 ) << "kio_svnProtocol::mkdir raw url for subversion : " << cur;
 
557
                const char *_target = apr_pstrdup( subpool, svn_path_canonicalize( apr_pstrdup( subpool, cur.toUtf8() ), subpool ) );
577
558
                (*(( const char ** )apr_array_push(( apr_array_header_t* )targets)) ) = _target;
578
559
        }
579
560
 
582
563
        if ( err ) {
583
564
                error( KIO::ERR_COULD_NOT_MKDIR, err->message );
584
565
        }
585
 
        
 
566
 
586
567
        finished();
587
568
        svn_pool_destroy (subpool);
588
569
}
589
570
 
590
 
void kio_svnProtocol::mkdir( const KURL& url, int /*permissions*/ ) {
591
 
        kdDebug(7128) << "kio_svnProtocol::mkdir() : " << url.url() << endl;
592
 
        
 
571
void kio_svnProtocol::mkdir( const KUrl& url, int /*permissions*/ ) {
 
572
        kDebug(7128) << "kio_svnProtocol::mkdir() : " << url.url();
 
573
 
593
574
        apr_pool_t *subpool = svn_pool_create (pool);
594
575
        svn_client_commit_info_t *commit_info = NULL;
595
576
 
596
577
        QString target = makeSvnURL( url);
597
 
        kdDebug(7128) << "SvnURL: " << target << endl;
598
 
        recordCurrentURL( KURL( target ) );
599
 
        
 
578
        kDebug(7128) << "SvnURL: " << target;
 
579
        recordCurrentURL( KUrl( target ) );
 
580
 
600
581
        apr_array_header_t *targets = apr_array_make(subpool, 2, sizeof(const char *));
601
 
        (*(( const char ** )apr_array_push(( apr_array_header_t* )targets)) ) = apr_pstrdup( subpool, target.utf8() );
 
582
        (*(( const char ** )apr_array_push(( apr_array_header_t* )targets)) ) = apr_pstrdup( subpool, target.toUtf8() );
602
583
 
603
584
        initNotifier(false, false, false, subpool);
604
585
        svn_error_t *err = svn_client_mkdir(&commit_info,targets,ctx,subpool);
605
586
        if ( err ) {
606
587
                error( KIO::ERR_COULD_NOT_MKDIR, err->message );
607
588
        }
608
 
        
 
589
 
609
590
        finished();
610
591
        svn_pool_destroy (subpool);
611
592
}
612
593
 
613
 
void kio_svnProtocol::del( const KURL& url, bool /*isfile*/ ) {
614
 
        kdDebug(7128) << "kio_svnProtocol::del() : " << url.url() << endl;
615
 
        
 
594
void kio_svnProtocol::del( const KUrl& url, bool /*isfile*/ ) {
 
595
        kDebug(7128) << "kio_svnProtocol::del() : " << url.url();
 
596
 
616
597
        apr_pool_t *subpool = svn_pool_create (pool);
617
598
        svn_client_commit_info_t *commit_info = NULL;
618
599
 
619
600
        QString target = makeSvnURL(url);
620
 
        kdDebug(7128) << "SvnURL: " << target << endl;
621
 
        recordCurrentURL( KURL( target ) );
622
 
        
 
601
        kDebug(7128) << "SvnURL: " << target;
 
602
        recordCurrentURL( KUrl( target ) );
 
603
 
623
604
        apr_array_header_t *targets = apr_array_make(subpool, 2, sizeof(const char *));
624
 
        (*(( const char ** )apr_array_push(( apr_array_header_t* )targets)) ) = apr_pstrdup( subpool, target.utf8() );
 
605
        (*(( const char ** )apr_array_push(( apr_array_header_t* )targets)) ) = apr_pstrdup( subpool, target.toUtf8() );
625
606
 
626
607
        initNotifier(false, false, false, subpool);
627
608
        svn_error_t *err = svn_client_delete(&commit_info,targets,false/*force remove locally modified files in wc*/,ctx,subpool);
628
609
        if ( err ) {
629
610
                error( KIO::ERR_CANNOT_DELETE, err->message );
630
611
        }
631
 
        
 
612
 
632
613
        finished();
633
614
        svn_pool_destroy (subpool);
634
615
}
635
616
 
636
 
void kio_svnProtocol::rename(const KURL& src, const KURL& dest, bool /*overwrite*/) {
637
 
        kdDebug(7128) << "kio_svnProtocol::rename() Source : " << src.url() << " Dest : " << dest.url() << endl;
638
 
        
 
617
void kio_svnProtocol::rename(const KUrl& src, const KUrl& dest, KIO::JobFlags) {
 
618
        kDebug(7128) << "kio_svnProtocol::rename() Source : " << src.url() << " Dest : " << dest.url();
 
619
 
639
620
        apr_pool_t *subpool = svn_pool_create (pool);
640
621
        svn_client_commit_info_t *commit_info = NULL;
641
622
 
642
 
        KURL nsrc = src;
643
 
        KURL ndest = dest;
 
623
        KUrl nsrc = src;
 
624
        KUrl ndest = dest;
644
625
        nsrc.setProtocol( chooseProtocol( src.protocol() ) );
645
626
        ndest.setProtocol( chooseProtocol( dest.protocol() ) );
646
627
        QString srcsvn = nsrc.url();
647
628
        QString destsvn = ndest.url();
648
 
        
 
629
 
649
630
        recordCurrentURL( nsrc );
650
631
 
651
632
        //find the requested revision
652
633
        svn_opt_revision_t rev;
653
 
        int idx = srcsvn.findRev( "?rev=" );
 
634
        int idx = srcsvn.lastIndexOf( "?rev=" );
654
635
        if ( idx != -1 ) {
655
636
                QString revstr = srcsvn.mid( idx+5 );
656
 
                kdDebug(7128) << "revision string found " << revstr  << endl;
 
637
                kDebug(7128) << "revision string found " << revstr;
657
638
                if ( revstr == "HEAD" ) {
658
639
                        rev.kind = svn_opt_revision_head;
659
 
                        kdDebug(7128) << "revision searched : HEAD" << endl;
 
640
                        kDebug(7128) << "revision searched : HEAD";
660
641
                } else {
661
642
                        rev.kind = svn_opt_revision_number;
662
643
                        rev.value.number = revstr.toLong();
663
 
                        kdDebug(7128) << "revision searched : " << rev.value.number << endl;
 
644
                        kDebug(7128) << "revision searched : " << rev.value.number;
664
645
                }
665
646
                srcsvn = srcsvn.left( idx );
666
 
                kdDebug(7128) << "new src : " << srcsvn << endl;
 
647
                kDebug(7128) << "new src : " << srcsvn;
667
648
        } else {
668
 
                kdDebug(7128) << "no revision given. searching HEAD " << endl;
 
649
                kDebug(7128) << "no revision given. searching HEAD ";
669
650
                rev.kind = svn_opt_revision_head;
670
651
        }
671
652
 
672
653
        initNotifier(false, false, false, subpool);
673
 
        svn_error_t *err = svn_client_move(&commit_info, srcsvn.utf8(), &rev, destsvn.utf8(), false/*force remove locally modified files in wc*/, ctx, subpool);
 
654
        svn_error_t *err = svn_client_move(&commit_info, srcsvn.toUtf8(), &rev, destsvn.toUtf8(), false/*force remove locally modified files in wc*/, ctx, subpool);
674
655
        if ( err ) {
675
656
                error( KIO::ERR_CANNOT_RENAME, err->message );
676
657
        }
677
 
        
 
658
 
678
659
        finished();
679
660
        svn_pool_destroy (subpool);
680
661
}
681
662
 
682
663
void kio_svnProtocol::special( const QByteArray& data ) {
683
 
        kdDebug(7128) << "kio_svnProtocol::special" << endl;
 
664
        kDebug(7128) << "kio_svnProtocol::special";
684
665
 
685
 
        QDataStream stream(data, IO_ReadOnly);
 
666
        QByteArray tmpData(data);
 
667
        QDataStream stream(&tmpData, QIODevice::ReadOnly);
686
668
        int tmp;
687
669
 
688
670
        stream >> tmp;
689
 
        kdDebug(7128) << "kio_svnProtocol::special " << tmp << endl;
 
671
        kDebug(7128) << "kio_svnProtocol::special " << tmp;
690
672
 
691
673
        switch ( tmp ) {
692
 
                case SVN_CHECKOUT: 
 
674
                case SVN_CHECKOUT:
693
675
                        {
694
 
                                KURL repository, wc;
 
676
                                KUrl repository, wc;
695
677
                                int revnumber;
696
678
                                QString revkind;
697
679
                                stream >> repository;
698
680
                                stream >> wc;
699
681
                                stream >> revnumber;
700
682
                                stream >> revkind;
701
 
                                kdDebug(7128) << "kio_svnProtocol CHECKOUT from " << repository.url() << " to " << wc.url() << " at " << revnumber << " or " << revkind << endl;
 
683
                                kDebug(7128) << "kio_svnProtocol CHECKOUT from " << repository.url() << " to " << wc.url() << " at " << revnumber << " or " << revkind;
702
684
                                checkout( repository, wc, revnumber, revkind );
703
685
                                break;
704
686
                        }
705
 
                case SVN_UPDATE: 
 
687
                case SVN_UPDATE:
706
688
                        {
707
 
                                KURL wc;
 
689
                                KUrl wc;
708
690
                                int revnumber;
709
691
                                QString revkind;
710
692
                                stream >> wc;
711
693
                                stream >> revnumber;
712
694
                                stream >> revkind;
713
 
                                kdDebug(7128) << "kio_svnProtocol UPDATE " << wc.url() << " at " << revnumber << " or " << revkind << endl;
 
695
                                kDebug(7128) << "kio_svnProtocol UPDATE " << wc.url() << " at " << revnumber << " or " << revkind;
714
696
                                update(wc, revnumber, revkind );
715
697
                                break;
716
698
                        }
717
 
                case SVN_COMMIT: 
 
699
                case SVN_COMMIT:
718
700
                        {
719
 
                                KURL::List wclist;
 
701
                                KUrl::List wclist;
720
702
                                while ( !stream.atEnd() ) {
721
 
                                        KURL tmp;
 
703
                                        KUrl tmp;
722
704
                                        stream >> tmp;
723
705
                                        wclist << tmp;
724
706
                                }
725
 
                                kdDebug(7128) << "kio_svnProtocol COMMIT" << endl;
 
707
                                kDebug(7128) << "kio_svnProtocol COMMIT";
726
708
                                commit( wclist );
727
709
                                break;
728
710
                        }
729
 
                case SVN_LOG: 
 
711
                case SVN_LOG:
730
712
                        {
731
 
                                kdDebug(7128) << "kio_svnProtocol LOG" << endl;
 
713
                                kDebug(7128) << "kio_svnProtocol LOG";
732
714
                                int revstart, revend;
733
715
                                QString revkindstart, revkindend;
734
 
                                KURL::List targets;
 
716
                                KUrl::List targets;
735
717
                                stream >> revstart;
736
718
                                stream >> revkindstart;
737
719
                                stream >> revend;
738
720
                                stream >> revkindend;
739
721
                                while ( !stream.atEnd() ) {
740
 
                                        KURL tmp;
 
722
                                        KUrl tmp;
741
723
                                        stream >> tmp;
742
724
                                        targets << tmp;
743
725
                                }
744
726
                                svn_log( revstart, revkindstart, revend, revkindend, targets );
745
727
                                break;
746
728
                        }
747
 
                case SVN_IMPORT: 
 
729
                case SVN_IMPORT:
748
730
                        {
749
 
                                KURL wc,repos;
 
731
                                KUrl wc,repos;
750
732
                                stream >> repos;
751
733
                                stream >> wc;
752
 
                                kdDebug(7128) << "kio_svnProtocol IMPORT" << endl;
 
734
                                kDebug(7128) << "kio_svnProtocol IMPORT";
753
735
                                import(repos,wc);
754
736
                                break;
755
737
                        }
756
 
                case SVN_ADD: 
 
738
                case SVN_ADD:
757
739
                        {
758
 
                                KURL wc;
 
740
                                KUrl wc;
759
741
                                stream >> wc;
760
 
                                kdDebug(7128) << "kio_svnProtocol ADD" << endl;
 
742
                                kDebug(7128) << "kio_svnProtocol ADD";
761
743
                                add(wc);
762
744
                                break;
763
745
                        }
764
 
                case SVN_DEL: 
 
746
                case SVN_DEL:
765
747
                        {
766
 
                                KURL::List wclist;
 
748
                                KUrl::List wclist;
767
749
                                while ( !stream.atEnd() ) {
768
 
                                        KURL tmp;
 
750
                                        KUrl tmp;
769
751
                                        stream >> tmp;
770
752
                                        wclist << tmp;
771
753
                                }
772
 
                                kdDebug(7128) << "kio_svnProtocol DEL" << endl;
 
754
                                kDebug(7128) << "kio_svnProtocol DEL";
773
755
                                wc_delete(wclist);
774
756
                                break;
775
757
                        }
776
 
                case SVN_REVERT: 
 
758
                case SVN_REVERT:
777
759
                        {
778
 
                                KURL::List wclist;
 
760
                                KUrl::List wclist;
779
761
                                while ( !stream.atEnd() ) {
780
 
                                        KURL tmp;
 
762
                                        KUrl tmp;
781
763
                                        stream >> tmp;
782
764
                                        wclist << tmp;
783
765
                                }
784
 
                                kdDebug(7128) << "kio_svnProtocol REVERT" << endl;
 
766
                                kDebug(7128) << "kio_svnProtocol REVERT";
785
767
                                wc_revert(wclist);
786
768
                                break;
787
769
                        }
788
 
                case SVN_STATUS: 
 
770
                case SVN_STATUS:
789
771
                        {
790
 
                                KURL wc;
 
772
                                KUrl wc;
791
773
                                int checkRepos=false;
792
774
                                int fullRecurse=false;
793
775
                                stream >> wc;
794
776
                                stream >> checkRepos;
795
777
                                stream >> fullRecurse;
796
 
                                kdDebug(7128) << "kio_svnProtocol STATUS" << endl;
 
778
                                kDebug(7128) << "kio_svnProtocol STATUS";
797
779
                                wc_status(wc,checkRepos,fullRecurse);
798
780
                                break;
799
781
                        }
800
782
                case SVN_MKDIR:
801
783
                        {
802
 
                                KURL::List list;
 
784
                                KUrl::List list;
803
785
                                stream >> list;
804
 
                                kdDebug(7128) << "kio_svnProtocol MKDIR" << endl;
 
786
                                kDebug(7128) << "kio_svnProtocol MKDIR";
805
787
                                mkdir(list,0);
806
788
                                break;
807
789
                        }
808
790
                case SVN_RESOLVE:
809
791
                        {
810
 
                                KURL url;
 
792
                                KUrl url;
811
793
                                bool recurse;
812
794
                                stream >> url;
813
795
                                stream >> recurse;
814
 
                                kdDebug(7128) << "kio_svnProtocol RESOLVE" << endl;
 
796
                                kDebug(7128) << "kio_svnProtocol RESOLVE";
815
797
                                wc_resolve(url,recurse);
816
798
                                break;
817
799
                        }
818
800
                case SVN_SWITCH:
819
801
                        {
820
 
                                KURL wc,url;
 
802
                                KUrl wc,url;
821
803
                                bool recurse;
822
804
                                int revnumber;
823
805
                                QString revkind;
826
808
                                stream >> recurse;
827
809
                                stream >> revnumber;
828
810
                                stream >> revkind;
829
 
                                kdDebug(7128) << "kio_svnProtocol SWITCH" << endl;
 
811
                                kDebug(7128) << "kio_svnProtocol SWITCH";
830
812
                                svn_switch(wc,url,revnumber,revkind,recurse);
831
813
                                break;
832
814
                        }
833
815
                case SVN_DIFF:
834
816
                        {
835
 
                                KURL url1,url2;
 
817
                                KUrl url1,url2;
836
818
                                int rev1, rev2;
837
819
                                bool recurse;
838
820
                                QString revkind1, revkind2;
843
825
                                stream >> rev2;
844
826
                                stream >> revkind2;
845
827
                                stream >> recurse;
846
 
                                kdDebug(7128) << "kio_svnProtocol DIFF" << endl;
 
828
                                kDebug(7128) << "kio_svnProtocol DIFF";
847
829
                                svn_diff(url1,url2,rev1,rev2,revkind1,revkind2,recurse);
848
830
                                break;
849
831
                        }
850
832
                default:
851
833
                        {
852
 
                                kdDebug(7128) << "kio_svnProtocol DEFAULT" << endl;
 
834
                                kDebug(7128) << "kio_svnProtocol DEFAULT";
853
835
                                break;
854
836
                        }
855
837
        }
856
838
}
857
839
 
858
840
void kio_svnProtocol::popupMessage( const QString& message ) {
859
 
        QByteArray params;
860
 
        QDataStream stream(params, IO_WriteOnly);
861
 
        stream << message;      
 
841
#ifdef __GNUC__
 
842
#warning "kde4: port dbus stuff"
 
843
#endif
 
844
#if 0
 
845
    QByteArray params;
 
846
        QDataStream stream(&params, QIODevice::WriteOnly);
 
847
        stream << message;
862
848
 
863
849
        if ( !dcopClient()->send( "kded","ksvnd","popupMessage(QString)", params ) )
864
 
                kdWarning() << "Communication with KDED:KSvnd failed" << endl;
 
850
                kWarning() << "Communication with KDED:KSvnd failed";
 
851
#endif
865
852
}
866
853
 
867
 
void kio_svnProtocol::svn_log( int revstart, const QString& revkindstart, int revend, const QString& revkindend, const KURL::List& targets ) {
868
 
        kdDebug(7128) << "kio_svn::log : " << targets << " from revision " << revstart << " or " << revkindstart << " to "
 
854
void kio_svnProtocol::svn_log( int revstart, const QString& revkindstart, int revend, const QString& revkindend, const KUrl::List& targets ) {
 
855
        kDebug(7128) << "kio_svn::log : " << targets << " from revision " << revstart << " or " << revkindstart << " to "
869
856
                " revision " << revend << " or " << revkindend
870
857
                << endl;
871
858
 
890
877
                result.kind = svn_opt_revision_working;
891
878
        } else if ( revkind == "BASE" ) {
892
879
                result.kind = svn_opt_revision_base;
893
 
        } else if ( !revkind.isNull() ) {
894
 
                svn_opt_parse_revision(&result,&endrev,revkind.utf8(),pool);
895
 
        }
 
880
        } else if ( revkind == "HEAD" ) {
 
881
        result.kind = svn_opt_revision_head;
 
882
    } else if ( revkind == "COMMITTED" ) {
 
883
        result.kind = svn_opt_revision_committed;
 
884
    } else if ( revkind == "PREV" ) {
 
885
        result.kind = svn_opt_revision_previous;
 
886
    }
 
887
 
 
888
    else if ( !revkind.isNull() ) {
 
889
                svn_opt_parse_revision(&result,&endrev,revkind.toUtf8(),pool);
 
890
        }else {
 
891
        result.kind = svn_opt_revision_unspecified;
 
892
    }
896
893
        return result;
897
894
}
898
895
 
899
 
void kio_svnProtocol::svn_diff(const KURL & url1, const KURL& url2,int rev1, int rev2,const QString& revkind1,const QString& revkind2,bool recurse) {
900
 
        kdDebug(7128) << "kio_svn::diff : " << url1.path() << " at revision " << rev1 << " or " << revkind1 << " with "
 
896
void kio_svnProtocol::svn_diff(const KUrl & url1, const KUrl& url2,int rev1, int rev2,const QString& revkind1,const QString& revkind2,bool recurse) {
 
897
        kDebug(7128) << "kio_svn::diff : " << url1.path() << " at revision " << rev1 << " or " << revkind1 << " with "
901
898
                << url2.path() << " at revision " << rev2 << " or " << revkind2
902
899
                << endl ;
903
 
        
 
900
 
904
901
        apr_pool_t *subpool = svn_pool_create (pool);
905
 
        apr_array_header_t *options = svn_cstring_split( "", "\t\r\n", TRUE, subpool );
 
902
        apr_array_header_t *options = svn_cstring_split( "", "\t\r\n", true, subpool );
906
903
 
907
 
        KURL nurl1 = url1;
908
 
        KURL nurl2 = url2;
 
904
        KUrl nurl1 = url1;
 
905
        KUrl nurl2 = url2;
909
906
        nurl1.setProtocol( chooseProtocol( url1.protocol() ) ); //svn+https -> https for eg
910
907
        nurl2.setProtocol( chooseProtocol( url2.protocol() ) );
911
908
        recordCurrentURL( nurl1 );
912
909
        QString source = makeSvnURL( nurl1 );
913
910
        QString target = makeSvnURL( nurl2 );
914
911
 
915
 
        const char *path1 = svn_path_canonicalize( apr_pstrdup( subpool, source.utf8() ), subpool );
916
 
        const char *path2 = svn_path_canonicalize( apr_pstrdup( subpool, target.utf8() ), subpool );
 
912
        const char *path1 = svn_path_canonicalize( apr_pstrdup( subpool, source.toUtf8() ), subpool );
 
913
        const char *path2 = svn_path_canonicalize( apr_pstrdup( subpool, target.toUtf8() ), subpool );
917
914
        //remove file:/// so we can diff for working copies, needs a better check (so we support URL for file:/// _repositories_ )
918
915
        if ( nurl1.protocol() == "file" ) {
919
 
                path1 = svn_path_canonicalize( apr_pstrdup( subpool, nurl1.path().utf8() ), subpool );
 
916
                path1 = svn_path_canonicalize( apr_pstrdup( subpool, nurl1.path().toUtf8() ), subpool );
920
917
        }
921
918
        if ( nurl2.protocol() == "file" ) {
922
 
                path2 = svn_path_canonicalize( apr_pstrdup( subpool, nurl2.path().utf8() ), subpool );
 
919
                path2 = svn_path_canonicalize( apr_pstrdup( subpool, nurl2.path().toUtf8() ), subpool );
923
920
        }
924
 
        kdDebug( 7128 ) << "1 : " << path1 << " 2: " << path2 << endl;
 
921
        kDebug( 7128 ) << "1 : " << path1 << " 2: " << path2;
925
922
 
926
923
        svn_opt_revision_t revision1,revision2;
927
924
        revision1 = createRevision(rev1, revkind1, subpool);
940
937
        QStringList tmp;
941
938
        apr_file_close(outfile);
942
939
        QFile file(templ);
943
 
        if ( file.open(  IO_ReadOnly ) ) {
 
940
        if ( file.open(  QIODevice::ReadOnly ) ) {
944
941
                QTextStream stream(  &file );
945
942
                QString line;
946
943
                while ( !stream.atEnd() ) {
950
947
                file.close();
951
948
        }
952
949
        for ( QStringList::Iterator itt = tmp.begin(); itt != tmp.end(); itt++ ) {
953
 
                setMetaData(QString::number( m_counter ).rightJustify( 10,'0' )+ "diffresult", ( *itt ) );
 
950
                setMetaData(QString::number( m_counter ).rightJustified( 10,'0' )+ "diffresult", ( *itt ) );
954
951
                m_counter++;
955
952
        }
956
953
        //delete temp file
960
957
        svn_pool_destroy (subpool);
961
958
}
962
959
 
963
 
void kio_svnProtocol::svn_switch( const KURL& wc, const KURL& repos, int revnumber, const QString& revkind, bool recurse) {
964
 
        kdDebug(7128) << "kio_svn::switch : " << wc.path() << " at revision " << revnumber << " or " << revkind << endl ;
 
960
void kio_svnProtocol::svn_switch( const KUrl& wc, const KUrl& repos, int revnumber, const QString& revkind, bool recurse) {
 
961
        kDebug(7128) << "kio_svn::switch : " << wc.path() << " at revision " << revnumber << " or " << revkind;
965
962
 
966
963
        apr_pool_t *subpool = svn_pool_create (pool);
967
964
 
968
 
        KURL nurl = repos;
969
 
        KURL dest = wc;
 
965
        KUrl nurl = repos;
 
966
        KUrl dest = wc;
970
967
        nurl.setProtocol( chooseProtocol( repos.protocol() ) );
971
968
        dest.setProtocol( "file" );
972
969
        recordCurrentURL( nurl );
973
970
        QString source = dest.path();
974
971
        QString target = makeSvnURL( repos );
975
972
 
976
 
        const char *path = svn_path_canonicalize( apr_pstrdup( subpool, source.utf8() ), subpool );
977
 
        const char *url = svn_path_canonicalize( apr_pstrdup( subpool, target.utf8() ), subpool );
 
973
        const char *path = svn_path_canonicalize( apr_pstrdup( subpool, source.toUtf8() ), subpool );
 
974
        const char *url = svn_path_canonicalize( apr_pstrdup( subpool, target.toUtf8() ), subpool );
978
975
 
979
976
        svn_opt_revision_t rev = createRevision( revnumber, revkind, subpool );
980
 
        
 
977
 
981
978
        initNotifier(false, false, false, subpool);
982
979
        svn_error_t *err = svn_client_switch (NULL/*result revision*/, path, url, &rev, recurse, ctx, subpool);
983
980
        if ( err )
987
984
        svn_pool_destroy (subpool);
988
985
}
989
986
 
990
 
void kio_svnProtocol::update( const KURL& wc, int revnumber, const QString& revkind ) {
991
 
        kdDebug(7128) << "kio_svn::update : " << wc.path() << " at revision " << revnumber << " or " << revkind << endl ;
 
987
void kio_svnProtocol::update( const KUrl& wc, int revnumber, const QString& revkind ) {
 
988
        kDebug(7128) << "kio_svn::update : " << wc.path() << " at revision " << revnumber << " or " << revkind;
992
989
 
993
990
        apr_pool_t *subpool = svn_pool_create (pool);
994
 
        KURL dest = wc;
 
991
        KUrl dest = wc;
995
992
        dest.setProtocol( "file" );
996
993
        QString target = dest.path();
997
994
        recordCurrentURL( dest );
998
 
        
 
995
 
999
996
        svn_opt_revision_t rev = createRevision( revnumber, revkind, subpool );
1000
997
 
1001
998
        initNotifier(false, false, false, subpool);
1002
 
        svn_error_t *err = svn_client_update (NULL, svn_path_canonicalize( target.utf8(), subpool ), &rev, true, ctx, subpool);
1003
 
        if ( err ) 
 
999
        svn_error_t *err = svn_client_update (NULL, svn_path_canonicalize( target.toUtf8(), subpool ), &rev, true, ctx, subpool);
 
1000
        if ( err )
1004
1001
                error( KIO::ERR_SLAVE_DEFINED, err->message );
1005
1002
 
1006
1003
        finished();
1007
1004
        svn_pool_destroy (subpool);
1008
1005
}
1009
1006
 
1010
 
void kio_svnProtocol::import( const KURL& repos, const KURL& wc ) {
1011
 
        kdDebug(7128) << "kio_svnProtocol::import() : " << wc.url() << " into " << repos.url() << endl;
1012
 
        
 
1007
void kio_svnProtocol::import( const KUrl& repos, const KUrl& wc ) {
 
1008
        kDebug(7128) << "kio_svnProtocol::import() : " << wc.url() << " into " << repos.url();
 
1009
 
1013
1010
        apr_pool_t *subpool = svn_pool_create (pool);
1014
1011
        svn_client_commit_info_t *commit_info = NULL;
1015
1012
        bool nonrecursive = false;
1016
1013
 
1017
 
        KURL nurl = repos;
1018
 
        KURL dest = wc;
 
1014
        KUrl nurl = repos;
 
1015
        KUrl dest = wc;
1019
1016
        nurl.setProtocol( chooseProtocol( repos.protocol() ) );
1020
1017
        dest.setProtocol( "file" );
1021
1018
        recordCurrentURL( nurl );
1022
 
        dest.cleanPath( true ); // remove doubled '/'
1023
 
        QString source = dest.path(-1);
 
1019
        dest.cleanPath( KUrl::SimplifyDirSeparators ); // remove doubled '/'
 
1020
        QString source = dest.path( KUrl::RemoveTrailingSlash );
1024
1021
        QString target = makeSvnURL( repos );
1025
1022
 
1026
 
        const char *path = svn_path_canonicalize( apr_pstrdup( subpool, source.utf8() ), subpool );
1027
 
        const char *url = svn_path_canonicalize( apr_pstrdup( subpool, target.utf8() ), subpool );
 
1023
        const char *path = svn_path_canonicalize( apr_pstrdup( subpool, source.toUtf8() ), subpool );
 
1024
        const char *url = svn_path_canonicalize( apr_pstrdup( subpool, target.toUtf8() ), subpool );
1028
1025
 
1029
1026
        initNotifier(false, false, false, subpool);
1030
1027
        svn_error_t *err = svn_client_import(&commit_info,path,url,nonrecursive,ctx,subpool);
1031
1028
        if ( err )
1032
1029
                error( KIO::ERR_SLAVE_DEFINED, err->message );
1033
 
        
 
1030
 
1034
1031
        finished();
1035
1032
        svn_pool_destroy (subpool);
1036
1033
}
1037
1034
 
1038
 
void kio_svnProtocol::checkout( const KURL& repos, const KURL& wc, int revnumber, const QString& revkind ) {
1039
 
        kdDebug(7128) << "kio_svn::checkout : " << repos.url() << " into " << wc.path() << " at revision " << revnumber << " or " << revkind << endl ;
 
1035
void kio_svnProtocol::checkout( const KUrl& repos, const KUrl& wc, int revnumber, const QString& revkind ) {
 
1036
        kDebug(7128) << "kio_svn::checkout : " << repos.url() << " into " << wc.path() << " at revision " << revnumber << " or " << revkind;
1040
1037
 
1041
1038
        apr_pool_t *subpool = svn_pool_create (pool);
1042
 
        KURL nurl = repos;
1043
 
        KURL dest = wc;
 
1039
        KUrl nurl = repos;
 
1040
        KUrl dest = wc;
1044
1041
        nurl.setProtocol( chooseProtocol( repos.protocol() ) );
1045
1042
        dest.setProtocol( "file" );
1046
1043
        QString target = makeSvnURL( repos );
1047
1044
        recordCurrentURL( nurl );
1048
1045
        QString dpath = dest.path();
1049
 
        
 
1046
 
1050
1047
        //find the requested revision
1051
1048
        svn_opt_revision_t rev = createRevision( revnumber, revkind, subpool );
1052
1049
 
1053
1050
        initNotifier(true, false, false, subpool);
1054
 
        svn_error_t *err = svn_client_checkout (NULL/* rev actually checkedout */, svn_path_canonicalize( target.utf8(), subpool ), svn_path_canonicalize ( dpath.utf8(), subpool ), &rev, true, ctx, subpool);
 
1051
        svn_error_t *err = svn_client_checkout (NULL/* rev actually checkedout */, svn_path_canonicalize( target.toUtf8(), subpool ), svn_path_canonicalize ( dpath.toUtf8(), subpool ), &rev, true, ctx, subpool);
1055
1052
        if ( err )
1056
1053
                error( KIO::ERR_SLAVE_DEFINED, err->message );
1057
1054
 
1059
1056
        svn_pool_destroy (subpool);
1060
1057
}
1061
1058
 
1062
 
void kio_svnProtocol::commit(const KURL::List& wc) {
1063
 
        kdDebug(7128) << "kio_svnProtocol::commit() : " << wc << endl;
1064
 
        
 
1059
void kio_svnProtocol::commit(const KUrl::List& wc) {
 
1060
        kDebug(7128) << "kio_svnProtocol::commit() : " << wc;
 
1061
 
1065
1062
        apr_pool_t *subpool = svn_pool_create (pool);
1066
1063
        svn_client_commit_info_t *commit_info = NULL;
1067
1064
        bool nonrecursive = false;
1068
1065
 
1069
1066
        apr_array_header_t *targets = apr_array_make(subpool, 1+wc.count(), sizeof(const char *));
1070
1067
 
1071
 
        for ( QValueListConstIterator<KURL> it = wc.begin(); it != wc.end() ; ++it ) {
1072
 
                KURL nurl = *it;
 
1068
        for ( QList<KUrl>::const_iterator it = wc.begin(); it != wc.end() ; ++it ) {
 
1069
                KUrl nurl = *it;
1073
1070
                nurl.setProtocol( "file" );
1074
1071
                recordCurrentURL( nurl );
1075
 
                (*(( const char ** )apr_array_push(( apr_array_header_t* )targets)) ) = svn_path_canonicalize( nurl.path().utf8(), subpool );
 
1072
                (*(( const char ** )apr_array_push(( apr_array_header_t* )targets)) ) = svn_path_canonicalize( nurl.path().toUtf8(), subpool );
1076
1073
        }
1077
1074
 
1078
1075
        initNotifier(false, false, false, subpool);
1081
1078
                error( KIO::ERR_SLAVE_DEFINED, err->message );
1082
1079
 
1083
1080
        if ( commit_info ) {
1084
 
                for ( QValueListConstIterator<KURL> it = wc.begin(); it != wc.end() ; ++it ) {
1085
 
                        KURL nurl = *it;
 
1081
                for ( QList<KUrl>::const_iterator it = wc.begin(); it != wc.end() ; ++it ) {
 
1082
                        KUrl nurl = *it;
1086
1083
                        nurl.setProtocol( "file" );
1087
1084
 
1088
1085
                        QString userstring = i18n ( "Nothing to commit." );
1089
1086
                        if ( SVN_IS_VALID_REVNUM( commit_info->revision ) )
1090
 
                                userstring = i18n( "Committed revision %1." ).arg(commit_info->revision);
1091
 
                        setMetaData(QString::number( m_counter ).rightJustify( 10,'0' )+ "path", nurl.path() );
1092
 
                        setMetaData(QString::number( m_counter ).rightJustify( 10,'0' )+ "action", "0" ); 
1093
 
                        setMetaData(QString::number( m_counter ).rightJustify( 10,'0' )+ "kind", "0" );
1094
 
                        setMetaData(QString::number( m_counter ).rightJustify( 10,'0' )+ "mime_t", "" );
1095
 
                        setMetaData(QString::number( m_counter ).rightJustify( 10,'0' )+ "content", "0" );
1096
 
                        setMetaData(QString::number( m_counter ).rightJustify( 10,'0' )+ "prop", "0" );
1097
 
                        setMetaData(QString::number( m_counter ).rightJustify( 10,'0' )+ "rev" , QString::number( commit_info->revision ) );
1098
 
                        setMetaData(QString::number( m_counter ).rightJustify( 10,'0' )+ "string", userstring );
 
1087
                                userstring = i18n( "Committed revision %1." , commit_info->revision);
 
1088
                        setMetaData(QString::number( m_counter ).rightJustified( 10,'0' )+ "path", nurl.path() );
 
1089
                        setMetaData(QString::number( m_counter ).rightJustified( 10,'0' )+ "action", "0" );
 
1090
                        setMetaData(QString::number( m_counter ).rightJustified( 10,'0' )+ "kind", "0" );
 
1091
                        setMetaData(QString::number( m_counter ).rightJustified( 10,'0' )+ "mime_t", "" );
 
1092
                        setMetaData(QString::number( m_counter ).rightJustified( 10,'0' )+ "content", "0" );
 
1093
                        setMetaData(QString::number( m_counter ).rightJustified( 10,'0' )+ "prop", "0" );
 
1094
                        setMetaData(QString::number( m_counter ).rightJustified( 10,'0' )+ "rev" , QString::number( commit_info->revision ) );
 
1095
                        setMetaData(QString::number( m_counter ).rightJustified( 10,'0' )+ "string", userstring );
1099
1096
                        m_counter++;
1100
1097
                }
1101
1098
        }
1104
1101
        svn_pool_destroy (subpool);
1105
1102
}
1106
1103
 
1107
 
void kio_svnProtocol::add(const KURL& wc) {
1108
 
        kdDebug(7128) << "kio_svnProtocol::add() : " << wc.url() << endl;
1109
 
        
 
1104
void kio_svnProtocol::add(const KUrl& wc) {
 
1105
        kDebug(7128) << "kio_svnProtocol::add() : " << wc.url();
 
1106
 
1110
1107
        apr_pool_t *subpool = svn_pool_create (pool);
1111
1108
        bool nonrecursive = false;
1112
1109
 
1113
 
        KURL nurl = wc;
 
1110
        KUrl nurl = wc;
1114
1111
        nurl.setProtocol( "file" );
1115
1112
        QString target = nurl.url();
1116
1113
        recordCurrentURL( nurl );
1117
1114
 
1118
1115
        initNotifier(false, false, false, subpool);
1119
 
        svn_error_t *err = svn_client_add(svn_path_canonicalize( nurl.path().utf8(), subpool ),nonrecursive,ctx,subpool);
 
1116
        svn_error_t *err = svn_client_add(svn_path_canonicalize( nurl.path().toUtf8(), subpool ),nonrecursive,ctx,subpool);
1120
1117
        if ( err )
1121
1118
                error( KIO::ERR_SLAVE_DEFINED, err->message );
1122
 
        
 
1119
 
1123
1120
        finished();
1124
1121
        svn_pool_destroy (subpool);
1125
1122
}
1126
1123
 
1127
 
void kio_svnProtocol::wc_delete(const KURL::List& wc) {
1128
 
        kdDebug(7128) << "kio_svnProtocol::wc_delete() : " << wc << endl;
1129
 
        
 
1124
void kio_svnProtocol::wc_delete(const KUrl::List& wc) {
 
1125
        kDebug(7128) << "kio_svnProtocol::wc_delete() : " << wc;
 
1126
 
1130
1127
        apr_pool_t *subpool = svn_pool_create (pool);
1131
1128
        svn_client_commit_info_t *commit_info = NULL;
1132
1129
        bool nonrecursive = false;
1133
1130
 
1134
1131
        apr_array_header_t *targets = apr_array_make(subpool, 1+wc.count(), sizeof(const char *));
1135
1132
 
1136
 
        for ( QValueListConstIterator<KURL> it = wc.begin(); it != wc.end() ; ++it ) {
1137
 
                KURL nurl = *it;
 
1133
        for ( QList<KUrl>::const_iterator it = wc.begin(); it != wc.end() ; ++it ) {
 
1134
                KUrl nurl = *it;
1138
1135
                nurl.setProtocol( "file" );
1139
1136
                recordCurrentURL( nurl );
1140
 
                (*(( const char ** )apr_array_push(( apr_array_header_t* )targets)) ) = svn_path_canonicalize( nurl.path().utf8(), subpool );
 
1137
                (*(( const char ** )apr_array_push(( apr_array_header_t* )targets)) ) = svn_path_canonicalize( nurl.path().toUtf8(), subpool );
1141
1138
        }
1142
1139
 
1143
1140
        initNotifier(false, false, false, subpool);
1145
1142
 
1146
1143
        if ( err )
1147
1144
                error( KIO::ERR_SLAVE_DEFINED, err->message );
1148
 
        
 
1145
 
1149
1146
        finished();
1150
1147
        svn_pool_destroy (subpool);
1151
1148
}
1152
1149
 
1153
 
void kio_svnProtocol::wc_revert(const KURL::List& wc) {
1154
 
        kdDebug(7128) << "kio_svnProtocol::revert() : " << wc << endl;
1155
 
        
 
1150
void kio_svnProtocol::wc_revert(const KUrl::List& wc) {
 
1151
        kDebug(7128) << "kio_svnProtocol::revert() : " << wc;
 
1152
 
1156
1153
        apr_pool_t *subpool = svn_pool_create (pool);
1157
1154
        bool nonrecursive = false;
1158
1155
 
1159
1156
        apr_array_header_t *targets = apr_array_make(subpool, 1 + wc.count(), sizeof(const char *));
1160
1157
 
1161
 
        for ( QValueListConstIterator<KURL> it = wc.begin(); it != wc.end() ; ++it ) {
1162
 
                KURL nurl = *it;
 
1158
        for ( QList<KUrl>::const_iterator it = wc.begin(); it != wc.end() ; ++it ) {
 
1159
                KUrl nurl = *it;
1163
1160
                nurl.setProtocol( "file" );
1164
1161
                recordCurrentURL( nurl );
1165
 
                (*(( const char ** )apr_array_push(( apr_array_header_t* )targets)) ) = svn_path_canonicalize( nurl.path().utf8(), subpool );
 
1162
                (*(( const char ** )apr_array_push(( apr_array_header_t* )targets)) ) = svn_path_canonicalize( nurl.path().toUtf8(), subpool );
1166
1163
        }
1167
1164
 
1168
1165
        initNotifier(false, false, false, subpool);
1169
1166
        svn_error_t *err = svn_client_revert(targets,nonrecursive,ctx,subpool);
1170
1167
        if ( err )
1171
1168
                error( KIO::ERR_SLAVE_DEFINED, err->message );
1172
 
        
 
1169
 
1173
1170
        finished();
1174
1171
        svn_pool_destroy (subpool);
1175
1172
}
1176
1173
 
1177
 
void kio_svnProtocol::wc_status(const KURL& wc, bool checkRepos, bool fullRecurse, bool getAll, int revnumber, const QString& revkind) {
1178
 
        kdDebug(7128) << "kio_svnProtocol::status() : " << wc.url() << endl;
1179
 
        
 
1174
void kio_svnProtocol::wc_status(const KUrl& wc, bool checkRepos, bool fullRecurse, bool getAll, int revnumber, const QString& revkind) {
 
1175
        kDebug(7128) << "kio_svnProtocol::status() : " << wc.url();
 
1176
 
1180
1177
        apr_pool_t *subpool = svn_pool_create (pool);
1181
1178
        svn_revnum_t result_rev;
1182
 
        bool no_ignore = FALSE;
 
1179
        bool no_ignore = false;
1183
1180
 
1184
 
        KURL nurl = wc;
 
1181
        KUrl nurl = wc;
1185
1182
        nurl.setProtocol( "file" );
1186
1183
        recordCurrentURL( nurl );
1187
1184
 
1188
1185
        svn_opt_revision_t rev = createRevision( revnumber, revkind, subpool );
1189
1186
 
1190
1187
        initNotifier(false, false, false, subpool);
1191
 
 
1192
 
        svn_error_t *err = svn_client_status(&result_rev, svn_path_canonicalize( nurl.path().utf8(), subpool ), &rev, kio_svnProtocol::status, this, fullRecurse, getAll, checkRepos, no_ignore, ctx, subpool);
1193
 
 
 
1188
        svn_error_t *err = svn_client_status(&result_rev, svn_path_canonicalize( nurl.path().toUtf8(), subpool ), &rev, kio_svnProtocol::status, this, fullRecurse, getAll, checkRepos, no_ignore, ctx, subpool);
1194
1189
        if ( err )
1195
1190
                error( KIO::ERR_SLAVE_DEFINED, err->message );
1196
 
        
 
1191
 
1197
1192
        finished();
1198
1193
        svn_pool_destroy (subpool);
1199
1194
}
1200
1195
 
1201
1196
//change the proto and remove trailing /
1202
 
//remove double / also 
1203
 
QString kio_svnProtocol::makeSvnURL ( const KURL& url ) const {
 
1197
//remove double / also
 
1198
QString kio_svnProtocol::makeSvnURL ( const KUrl& url ) const {
1204
1199
        QString kproto = url.protocol();
1205
 
        KURL tpURL = url;
1206
 
        tpURL.cleanPath( true );
 
1200
        KUrl tpURL = url;
 
1201
        tpURL.cleanPath( KUrl::SimplifyDirSeparators );
1207
1202
        QString svnUrl;
1208
1203
        if ( kproto == "svn+http" ) {
1209
 
                kdDebug(7128) << "http:/ " << url.url() << endl;
 
1204
                kDebug(7128) << "http:/ " << url.url();
1210
1205
                tpURL.setProtocol("http");
1211
 
                svnUrl = tpURL.url(-1);
 
1206
                svnUrl = tpURL.url( KUrl::RemoveTrailingSlash );
1212
1207
                return svnUrl;
1213
1208
        }
1214
1209
        else if ( kproto == "svn+https" ) {
1215
 
                kdDebug(7128) << "https:/ " << url.url() << endl;
 
1210
                kDebug(7128) << "https:/ " << url.url();
1216
1211
                tpURL.setProtocol("https");
1217
 
                svnUrl = tpURL.url(-1);
 
1212
                svnUrl = tpURL.url( KUrl::RemoveTrailingSlash );
1218
1213
                return svnUrl;
1219
1214
        }
1220
1215
        else if ( kproto == "svn+ssh" ) {
1221
 
                kdDebug(7128) << "svn+ssh:/ " << url.url() << endl;
 
1216
                kDebug(7128) << "svn+ssh:/ " << url.url();
1222
1217
                tpURL.setProtocol("svn+ssh");
1223
 
                svnUrl = tpURL.url(-1);
 
1218
                svnUrl = tpURL.url( KUrl::RemoveTrailingSlash );
1224
1219
                return svnUrl;
1225
1220
        }
1226
1221
        else if ( kproto == "svn" ) {
1227
 
                kdDebug(7128) << "svn:/ " << url.url() << endl;
 
1222
                kDebug(7128) << "svn:/ " << url.url();
1228
1223
                tpURL.setProtocol("svn");
1229
 
                svnUrl = tpURL.url(-1);
 
1224
                svnUrl = tpURL.url( KUrl::RemoveTrailingSlash );
1230
1225
                return svnUrl;
1231
1226
        }
1232
1227
        else if ( kproto == "svn+file" ) {
1233
 
                kdDebug(7128) << "file:/ " << url.url() << endl;
 
1228
                kDebug(7128) << "file:/ " << url.url();
1234
1229
                tpURL.setProtocol("file");
1235
 
                svnUrl = tpURL.url(-1);
 
1230
                svnUrl = tpURL.url( KUrl::RemoveTrailingSlash );
1236
1231
                //hack : add one more / after file:/
1237
 
                int idx = svnUrl.find("/");
 
1232
                int idx = svnUrl.indexOf('/');
1238
1233
                svnUrl.insert( idx, "//" );
1239
1234
                return svnUrl;
1240
1235
        }
1241
 
        return tpURL.url(-1);
 
1236
        return tpURL.url( KUrl::RemoveTrailingSlash );
1242
1237
}
1243
1238
 
1244
1239
QString kio_svnProtocol::chooseProtocol ( const QString& kproto ) const {
1253
1248
svn_error_t *kio_svnProtocol::trustSSLPrompt(svn_auth_cred_ssl_server_trust_t **cred_p, void *, const char */*realm*/, apr_uint32_t /*failures*/, const svn_auth_ssl_server_cert_info_t */*cert_info*/, svn_boolean_t /*may_save*/, apr_pool_t *pool) {
1254
1249
        //when ksvnd is ready make it prompt for the SSL certificate ... XXX
1255
1250
        *cred_p = (svn_auth_cred_ssl_server_trust_t*)apr_pcalloc (pool, sizeof (**cred_p));
1256
 
        (*cred_p)->may_save = FALSE;
 
1251
        (*cred_p)->may_save = false;
1257
1252
        return SVN_NO_ERROR;
1258
1253
}
1259
1254
 
1270
1265
}
1271
1266
 
1272
1267
svn_error_t *kio_svnProtocol::commitLogPrompt( const char **log_msg, const char **/*file*/, apr_array_header_t *commit_items, void *baton, apr_pool_t *pool ) {
1273
 
        QCString replyType;
1274
 
        QByteArray params;
1275
 
        QByteArray reply;
1276
1268
        QString result;
1277
1269
        QStringList slist;
1278
1270
        kio_svnProtocol *p = ( kio_svnProtocol* )baton;
1308
1300
                list += prop_mod;
1309
1301
                list += "  ";
1310
1302
                list += path;
1311
 
                kdDebug(7128) << " Commiting items : " << list << endl;
 
1303
                kDebug(7128) << " Committing items : " << list;
1312
1304
                slist << list;
1313
1305
        }
1314
 
 
1315
 
        QDataStream stream(params, IO_WriteOnly);
1316
 
        stream << slist.join("\n");     
1317
 
 
1318
 
        if ( !p->dcopClient()->call( "kded","ksvnd","commitDialog(QString)", params, replyType, reply ) ) {
1319
 
                kdWarning() << "Communication with KDED:KSvnd failed" << endl;
1320
 
                return SVN_NO_ERROR;
1321
 
        }
1322
 
 
1323
 
        if ( replyType != "QString" ) {
1324
 
                kdWarning() << "Unexpected reply type" << endl;
1325
 
                return SVN_NO_ERROR;
1326
 
        }
1327
 
        
1328
 
        QDataStream stream2 ( reply, IO_ReadOnly );
1329
 
        stream2 >> result;
1330
 
        
 
1306
        OrgKdeKsvndInterface ksvndInterface( "org.kde.kded", "/modules/ksvnd", QDBusConnection::sessionBus() );
 
1307
        if(!ksvndInterface.isValid())
 
1308
        {
 
1309
           kWarning() << "Communication with KDED:KSvnd failed";
 
1310
           return SVN_NO_ERROR;
 
1311
        }
 
1312
 
 
1313
        QString lst = slist.join("\n");
 
1314
        QDBusReply<QString> reply = ksvndInterface.commitDialog(lst);
 
1315
        if ( !reply.isValid() ) 
 
1316
        {
 
1317
                kWarning() << "Unexpected reply type";
 
1318
                return SVN_NO_ERROR;
 
1319
        }
 
1320
        result = reply;
1331
1321
        if ( result.isNull() ) { //cancelled
1332
1322
                *log_msg = NULL;
1333
1323
                return SVN_NO_ERROR;
1334
1324
        }
1335
 
                
1336
 
        message = svn_stringbuf_create( result.utf8(), pool );
 
1325
        message = svn_stringbuf_create( result.toUtf8(), pool );
1337
1326
        *log_msg = message->data;
1338
 
 
1339
1327
        return SVN_NO_ERROR;
1340
1328
}
1341
1329
 
1342
1330
void kio_svnProtocol::notify(void *baton, const char *path, svn_wc_notify_action_t action, svn_node_kind_t kind, const char *mime_type, svn_wc_notify_state_t content_state, svn_wc_notify_state_t prop_state, svn_revnum_t revision) {
1343
 
        kdDebug(7128) << "NOTIFY : " << path << " updated at revision " << revision << " action : " << action << ", kind : " << kind << " , content_state : " << content_state << ", prop_state : " << prop_state << endl;
 
1331
        kDebug(7128) << "NOTIFY : " << path << " updated at revision " << revision << " action : " << action << ", kind : " << kind << " , content_state : " << content_state << ", prop_state : " << prop_state;
1344
1332
 
1345
1333
        QString userstring;
1346
1334
        struct notify_baton *nb = ( struct notify_baton* ) baton;
1349
1337
        switch ( action ) {
1350
1338
                case svn_wc_notify_add : //add
1351
1339
                        if (mime_type && (svn_mime_type_is_binary (mime_type)))
1352
 
                                userstring = i18n( "A (bin) %1" ).arg( path );
 
1340
                                userstring = i18n( "A (bin) %1", path );
1353
1341
                        else
1354
 
                                userstring = i18n( "A %1" ).arg( path );
 
1342
                                userstring = i18n( "A %1", path );
1355
1343
                        break;
1356
1344
                case svn_wc_notify_copy: //copy
1357
1345
                        break;
1358
1346
                case svn_wc_notify_delete: //delete
1359
 
                        nb->received_some_change = TRUE;
1360
 
                        userstring = i18n( "D %1" ).arg( path );
 
1347
                        nb->received_some_change = true;
 
1348
                        userstring = i18n( "D %1", path );
1361
1349
                        break;
1362
1350
                case svn_wc_notify_restore : //restore
1363
 
                        userstring=i18n( "Restored %1." ).arg( path );
 
1351
                        userstring=i18n( "Restored %1.", path );
1364
1352
                        break;
1365
1353
                case svn_wc_notify_revert : //revert
1366
 
                        userstring=i18n( "Reverted %1." ).arg( path );
 
1354
                        userstring=i18n( "Reverted %1.", path );
1367
1355
                        break;
1368
1356
                case svn_wc_notify_failed_revert: //failed revert
1369
 
                        userstring=i18n( "Failed to revert %1.\nTry updating instead." ).arg( path );
 
1357
                        userstring=i18n( "Failed to revert %1.\nTry updating instead.", path );
1370
1358
                        break;
1371
1359
                case svn_wc_notify_resolved: //resolved
1372
 
                        userstring=i18n( "Resolved conflicted state of %1." ).arg( path );
 
1360
                        userstring=i18n( "Resolved conflicted state of %1.", path );
1373
1361
                        break;
1374
1362
                case svn_wc_notify_skip: //skip
1375
1363
                        if ( content_state == svn_wc_notify_state_missing )
1376
 
                                userstring=i18n("Skipped missing target %1.").arg( path );
1377
 
                        else 
1378
 
                                userstring=i18n("Skipped  %1.").arg( path );
 
1364
                                userstring=i18n("Skipped missing target %1.", path );
 
1365
                        else
 
1366
                                userstring=i18n("Skipped  %1.", path );
1379
1367
                        break;
1380
1368
                case svn_wc_notify_update_delete: //update_delete
1381
 
                        nb->received_some_change = TRUE;
1382
 
                        userstring=i18n( "D %1" ).arg( path );
 
1369
                        nb->received_some_change = true;
 
1370
                        userstring=i18n( "D %1", path );
1383
1371
                        break;
1384
1372
                case svn_wc_notify_update_add: //update_add
1385
 
                        nb->received_some_change = TRUE;
1386
 
                        userstring=i18n( "A %1" ).arg( path );
 
1373
                        nb->received_some_change = true;
 
1374
                        userstring=i18n( "A %1", path );
1387
1375
                        break;
1388
1376
                case svn_wc_notify_update_update: //update_update
1389
1377
                        {
1394
1382
                                                        && ((prop_state == svn_wc_notify_state_inapplicable)
1395
1383
                                                                || (prop_state == svn_wc_notify_state_unknown)
1396
1384
                                                                || (prop_state == svn_wc_notify_state_unchanged)))) {
1397
 
                                        nb->received_some_change = TRUE;
 
1385
                                        nb->received_some_change = true;
1398
1386
 
1399
1387
                                        if (kind == svn_node_file) {
1400
1388
                                                if (content_state == svn_wc_notify_state_conflicted)
1427
1415
                                if (! nb->suppress_final_line) {
1428
1416
                                        if (SVN_IS_VALID_REVNUM (revision)) {
1429
1417
                                                if (nb->is_export) {
1430
 
                                                        if ( nb->in_external ) 
1431
 
                                                                userstring = i18n("Exported external at revision %1.").arg( revision );
1432
 
                                                        else 
1433
 
                                                                userstring = i18n("Exported revision %1.").arg( revision );
 
1418
                                                        if ( nb->in_external )
 
1419
                                                                userstring = i18n("Exported external at revision %1.", revision );
 
1420
                                                        else
 
1421
                                                                userstring = i18n("Exported revision %1.", revision );
1434
1422
                                                } else if (nb->is_checkout) {
1435
1423
                                                        if ( nb->in_external )
1436
 
                                                                userstring = i18n("Checked out external at revision %1.").arg( revision );
 
1424
                                                                userstring = i18n("Checked out external at revision %1.", revision );
1437
1425
                                                        else
1438
 
                                                                userstring = i18n("Checked out revision %1.").arg( revision);
 
1426
                                                                userstring = i18n("Checked out revision %1.", revision);
1439
1427
                                                } else {
1440
1428
                                                        if (nb->received_some_change) {
1441
1429
                                                                if ( nb->in_external )
1442
 
                                                                        userstring=i18n("Updated external to revision %1.").arg( revision );
1443
 
                                                                else 
1444
 
                                                                        userstring = i18n("Updated to revision %1.").arg( revision);
 
1430
                                                                        userstring=i18n("Updated external to revision %1.", revision );
 
1431
                                                                else
 
1432
                                                                        userstring = i18n("Updated to revision %1.", revision);
1445
1433
                                                        } else {
1446
1434
                                                                if ( nb->in_external )
1447
 
                                                                        userstring = i18n("External at revision %1.").arg( revision );
 
1435
                                                                        userstring = i18n("External at revision %1.", revision );
1448
1436
                                                                else
1449
 
                                                                        userstring = i18n("At revision %1.").arg( revision);
 
1437
                                                                        userstring = i18n("At revision %1.", revision);
1450
1438
                                                        }
1451
1439
                                                }
1452
1440
                                        } else  /* no revision */ {
1470
1458
                                }
1471
1459
                        }
1472
1460
                        if (nb->in_external)
1473
 
                                nb->in_external = FALSE;
 
1461
                                nb->in_external = false;
1474
1462
                        break;
1475
1463
                case svn_wc_notify_update_external: //update_external
1476
 
                        nb->in_external = TRUE;
1477
 
                        userstring = i18n("Fetching external item into %1." ).arg( path );
 
1464
                        nb->in_external = true;
 
1465
                        userstring = i18n("Fetching external item into %1.", path );
1478
1466
                        break;
1479
1467
                case svn_wc_notify_status_completed: //status_completed
1480
1468
                        if (SVN_IS_VALID_REVNUM (revision))
1481
 
                                userstring = i18n( "Status against revision: %1.").arg( revision );
 
1469
                                userstring = i18n( "Status against revision: %1.", revision );
1482
1470
                        break;
1483
1471
                case svn_wc_notify_status_external: //status_external
1484
 
             userstring = i18n("Performing status on external item at %1.").arg( path ); 
 
1472
             userstring = i18n("Performing status on external item at %1.", path );
1485
1473
                        break;
1486
1474
                case svn_wc_notify_commit_modified: //commit_modified
1487
 
                        userstring = i18n( "Sending %1").arg( path );
 
1475
                        userstring = i18n( "Sending %1", path );
1488
1476
                        break;
1489
1477
                case svn_wc_notify_commit_added: //commit_added
1490
1478
                        if (mime_type && svn_mime_type_is_binary (mime_type)) {
1491
 
                                userstring = i18n( "Adding (bin) %1.").arg( path );
 
1479
                                userstring = i18n( "Adding (bin) %1.", path );
1492
1480
                        } else {
1493
 
                                userstring = i18n( "Adding %1.").arg( path );
 
1481
                                userstring = i18n( "Adding %1.", path );
1494
1482
                        }
1495
1483
                        break;
1496
1484
                case svn_wc_notify_commit_deleted: //commit_deleted
1497
 
                        userstring = i18n( "Deleting %1.").arg( path );
1498
 
                        break; 
 
1485
                        userstring = i18n( "Deleting %1.", path );
 
1486
                        break;
1499
1487
                case svn_wc_notify_commit_replaced: //commit_replaced
1500
 
                        userstring = i18n( "Replacing %1.").arg( path );
 
1488
                        userstring = i18n( "Replacing %1.", path );
1501
1489
                        break;
1502
1490
                case svn_wc_notify_commit_postfix_txdelta: //commit_postfix_txdelta
1503
1491
                        if (! nb->sent_first_txdelta) {
1504
 
                                nb->sent_first_txdelta = TRUE;
 
1492
                                nb->sent_first_txdelta = true;
1505
1493
                                userstring=i18n("Transmitting file data ");
1506
1494
                        } else {
1507
1495
                                userstring=".";
1518
1506
 
1519
1507
        kio_svnProtocol *p = ( kio_svnProtocol* )nb->master;
1520
1508
 
1521
 
        p->setMetaData(QString::number( p->counter() ).rightJustify( 10,'0' )+ "path" , QString::fromUtf8( path ));
1522
 
        p->setMetaData(QString::number( p->counter() ).rightJustify( 10,'0' )+ "action", QString::number( action ));
1523
 
        p->setMetaData(QString::number( p->counter() ).rightJustify( 10,'0' )+ "kind", QString::number( kind ));
1524
 
        p->setMetaData(QString::number( p->counter() ).rightJustify( 10,'0' )+ "mime_t", QString::fromUtf8( mime_type ));
1525
 
        p->setMetaData(QString::number( p->counter() ).rightJustify( 10,'0' )+ "content", QString::number( content_state ));
1526
 
        p->setMetaData(QString::number( p->counter() ).rightJustify( 10,'0' )+ "prop", QString::number( prop_state ));
1527
 
        p->setMetaData(QString::number( p->counter() ).rightJustify( 10,'0' )+ "rev", QString::number( revision ));
1528
 
        p->setMetaData(QString::number( p->counter() ).rightJustify( 10,'0' )+ "string", userstring );
 
1509
        p->setMetaData(QString::number( p->counter() ).rightJustified( 10,'0' )+ "path" , QString::fromUtf8( path ));
 
1510
        p->setMetaData(QString::number( p->counter() ).rightJustified( 10,'0' )+ "action", QString::number( action ));
 
1511
        p->setMetaData(QString::number( p->counter() ).rightJustified( 10,'0' )+ "kind", QString::number( kind ));
 
1512
        p->setMetaData(QString::number( p->counter() ).rightJustified( 10,'0' )+ "mime_t", QString::fromUtf8( mime_type ));
 
1513
        p->setMetaData(QString::number( p->counter() ).rightJustified( 10,'0' )+ "content", QString::number( content_state ));
 
1514
        p->setMetaData(QString::number( p->counter() ).rightJustified( 10,'0' )+ "prop", QString::number( prop_state ));
 
1515
        p->setMetaData(QString::number( p->counter() ).rightJustified( 10,'0' )+ "rev", QString::number( revision ));
 
1516
        p->setMetaData(QString::number( p->counter() ).rightJustified( 10,'0' )+ "string", userstring );
1529
1517
        p->incCounter();
1530
1518
}
1531
1519
 
1532
1520
void kio_svnProtocol::status(void *baton, const char *path, svn_wc_status_t *status) {
1533
 
        kdDebug(7128) << "STATUS : " << path << ", wc text status : " << status->text_status 
 
1521
        kDebug(7128) << "STATUS : " << path << ", wc text status : " << status->text_status
1534
1522
                                                                         << ", wc prop status : " << status->prop_status
1535
1523
                                                                         << ", repos text status : " << status->repos_text_status
1536
 
                                                                         << ", repos prop status : " << status->repos_prop_status 
 
1524
                                                                         << ", repos prop status : " << status->repos_prop_status
1537
1525
                                                                         << endl;
1538
1526
 
1539
1527
        QByteArray params;
1540
1528
        kio_svnProtocol *p = ( kio_svnProtocol* )baton;
1541
1529
 
1542
 
        QDataStream stream(params, IO_WriteOnly);
 
1530
        QDataStream stream(&params, QIODevice::WriteOnly);
1543
1531
        long int rev = status->entry ? status->entry->revision : 0;
1544
 
        stream << QString::fromUtf8( path ) << status->text_status << status->prop_status << status->repos_text_status << status->repos_prop_status << rev;
 
1532
        stream << QString::fromUtf8( path ) << QString::number( status->text_status ) << QString::number( status->prop_status ) << QString::number( status->repos_text_status ) << QString::number( status->repos_prop_status ) << QString::number( rev );
1545
1533
 
1546
 
        p->setMetaData(QString::number( p->counter() ).rightJustify( 10,'0' )+ "path", QString::fromUtf8( path ));
1547
 
        p->setMetaData(QString::number( p->counter() ).rightJustify( 10,'0' )+ "text", QString::number( status->text_status ));
1548
 
        p->setMetaData(QString::number( p->counter() ).rightJustify( 10,'0' )+ "prop", QString::number( status->prop_status ));
1549
 
        p->setMetaData(QString::number( p->counter() ).rightJustify( 10,'0' )+ "reptxt", QString::number( status->repos_text_status ));
1550
 
        p->setMetaData(QString::number( p->counter() ).rightJustify( 10,'0' )+ "repprop", QString::number( status->repos_prop_status ));
1551
 
        p->setMetaData(QString::number( p->counter() ).rightJustify( 10,'0' )+ "rev", QString::number( rev ));
 
1534
        p->setMetaData(QString::number( p->counter() ).rightJustified( 10,'0' )+ "path", QString::fromUtf8( path ));
 
1535
        p->setMetaData(QString::number( p->counter() ).rightJustified( 10,'0' )+ "text", QString::number( status->text_status ));
 
1536
        p->setMetaData(QString::number( p->counter() ).rightJustified( 10,'0' )+ "prop", QString::number( status->prop_status ));
 
1537
        p->setMetaData(QString::number( p->counter() ).rightJustified( 10,'0' )+ "reptxt", QString::number( status->repos_text_status ));
 
1538
        p->setMetaData(QString::number( p->counter() ).rightJustified( 10,'0' )+ "repprop", QString::number( status->repos_prop_status ));
 
1539
        p->setMetaData(QString::number( p->counter() ).rightJustified( 10,'0' )+ "rev", QString::number( rev ));
1552
1540
        p->incCounter();
1553
1541
}
1554
1542
 
1555
1543
 
1556
 
void kio_svnProtocol::wc_resolve( const KURL& wc, bool recurse ) {
1557
 
        kdDebug(7128) << "kio_svnProtocol::wc_resolve() : " << wc.url() << endl;
1558
 
        
 
1544
void kio_svnProtocol::wc_resolve( const KUrl& wc, bool recurse ) {
 
1545
        kDebug(7128) << "kio_svnProtocol::wc_resolve() : " << wc.url();
 
1546
 
1559
1547
        apr_pool_t *subpool = svn_pool_create (pool);
1560
1548
 
1561
 
        KURL nurl = wc;
 
1549
        KUrl nurl = wc;
1562
1550
        nurl.setProtocol( "file" );
1563
1551
        recordCurrentURL( nurl );
1564
1552
 
1565
1553
        initNotifier(false, false, false, subpool);
1566
 
        svn_error_t *err = svn_client_resolved(svn_path_canonicalize( nurl.path().utf8(), subpool ), recurse,ctx,subpool);
 
1554
        svn_error_t *err = svn_client_resolved(svn_path_canonicalize( nurl.path().toUtf8(), subpool ), recurse,ctx,subpool);
1567
1555
        if ( err )
1568
1556
                error( KIO::ERR_SLAVE_DEFINED, err->message );
1569
 
        
 
1557
 
1570
1558
        finished();
1571
1559
        svn_pool_destroy (subpool);
1572
1560
}
1574
1562
extern "C"
1575
1563
{
1576
1564
        KDE_EXPORT int kdemain(int argc, char **argv)    {
1577
 
                KInstance instance( "kio_svn" );
 
1565
                KComponentData componentData( "kio_svn" );
1578
1566
 
1579
 
                kdDebug(7128) << "*** Starting kio_svn " << endl;
 
1567
                kDebug(7128) << "*** Starting kio_svn ";
1580
1568
 
1581
1569
                if (argc != 4) {
1582
 
                        kdDebug(7128) << "Usage: kio_svn  protocol domain-socket1 domain-socket2" << endl;
 
1570
                        kDebug(7128) << "Usage: kio_svn  protocol domain-socket1 domain-socket2";
1583
1571
                        exit(-1);
1584
1572
                }
1585
1573
 
1586
1574
                kio_svnProtocol slave(argv[2], argv[3]);
1587
1575
                slave.dispatchLoop();
1588
1576
 
1589
 
                kdDebug(7128) << "*** kio_svn Done" << endl;
 
1577
                kDebug(7128) << "*** kio_svn Done";
1590
1578
                return 0;
1591
1579
        }
1592
1580
}