summaryrefslogtreecommitdiffstats
path: root/vcs/subversion/subversion_fileinfo.cpp
blob: c41ff9efb19c78e657928b2b361218f31f7cca57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
/**
	 Copyright (C) 2004-2005 Mickael Marchand <[email protected]>

	 This program is free software; you can redistribute it and/or
	 modify it under the terms of the GNU General Public
	 License as published by the Free Software Foundation; either
	 version 2 of the License, or (at your option) any later version.

	 This program is distributed in the hope that it will be useful,
	 but WITHOUT ANY WARRANTY; without even the implied warranty of
	 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	 General Public License for more details.

	 You should have received a copy of the GNU General Public License
	 along with this program; see the file COPYING.  If not, write to
	 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
	 Boston, MA 02110-1301, USA.
	 */

#include "subversion_fileinfo.h"
#include "subversion_core.h"
#include <kdebug.h>
#include <tqfileinfo.h>
#include <tqdir.h>
#include <tdevproject.h>
#include <unistd.h>
#include <tdeapplication.h>
#include <tdevmainwindow.h>
#include <tdemainwindow.h>
#include <tqregexp.h>

#include <tdeio/netaccess.h>
#include <tdelocale.h>

SVNFileInfoProvider::SVNFileInfoProvider(subversionPart *parent, const char *name)
    : TDevVCSFileInfoProvider( parent, "svnfileinfoprovider" ),
	m_cachedDirEntries( 0 ), m_recursiveDirEntries(0) {
	Q_UNUSED(name);
	m_part = parent;
}

SVNFileInfoProvider::~SVNFileInfoProvider() {
	delete m_cachedDirEntries;
	m_cachedDirEntries = 0;
	delete m_recursiveDirEntries;
 	m_recursiveDirEntries = 0;
}

//synchronous
const VCSFileInfoMap *SVNFileInfoProvider::status( const TQString &dirPath ) {
	if ( !m_cachedDirEntries )
		m_cachedDirEntries = new VCSFileInfoMap;
//	return m_cachedDirEntries;

	kdDebug(9036) << "svn provider : status " << dirPath << endl;

	if ( dirPath != m_previousDirPath ) {
		m_previousDirPath = dirPath;
		KURL servURL = "kdevsvn+http://fakeserver_this_is_normal_behavior/";
		TQByteArray parms;
		TQDataStream s( parms, IO_WriteOnly );
		int cmd = 9;
		TQString rPath = projectDirectory( );
		rPath += TQDir::separator() + dirPath;
		kdDebug(9036) << "DIR : " << rPath << " " << KURL( TQFileInfo( rPath ).absFilePath() ) << endl;

// 		s << cmd << KURL( TQFileInfo( rPath ).absFilePath() ) << true << true; //original line

		// Dukju Ahn: if checkRepos is set, status() accesses remote repository,
		// which causes significant delaym_owner especially when network speed is not fast enough.
		// Of course, the user cannot get information about the out-of-dateness of his local copy.
		s << cmd << KURL( TQFileInfo( rPath ).absFilePath() ) << false/*checkRepos*/ << false /*fullRecurse*/;

		TDEIO::SimpleJob *job2 = TDEIO::special(servURL, parms, false);
		job2->setWindow( m_part->mainWindow()->main() );


        TQMap<TQString,TQString> ma;

		TDEIO::NetAccess::synchronousRun(job2, m_part->mainWindow()->main(), 0, 0, &ma );

		TQValueList<TQString> keys = ma.keys();
		qHeapSort( keys );
		TQValueList<TQString>::Iterator begin = keys.begin(), end = keys.end(), it;

		TQString path;
		int text_status = 0, prop_status = 0, repos_text_status = 0, repos_prop_status = 0;
		long int rev = 0;
		int curIdx, lastIdx;

		TQRegExp rx( "([0-9]*)(.*)" );
		for ( it = begin; it != end; ) {
			kdDebug(9036) << "METADATA : " << *it << ":" << ma[ *it ] << endl;
			if ( rx.search( *it ) == -1 ) return m_cachedDirEntries; // something is wrong ! :)
            /* if some notification comes here, consume these notification metadatas */
            if ( rx.cap( 2 ) == "action" ){
                curIdx = lastIdx = rx.cap( 1 ).toInt();
                while ( curIdx == lastIdx ){
                    ++it;
                    if ( it == end ) break;
                    if ( rx.search( *it ) == -1 ) continue; // something is wrong
                    curIdx = rx.cap( 1 ).toInt();
                }
                continue;
            }
			curIdx = lastIdx = rx.cap( 1 ).toInt();
			while ( curIdx == lastIdx ) {
				if ( rx.cap( 2 ) == "path" )
					path = ma[ *it ];
				else if ( rx.cap( 2	 ) == "text" )
					text_status = ma[ *it ].toInt();
				else if ( rx.cap( 2	 ) == "prop" )
					prop_status = ma[ *it ].toInt();
				else if ( rx.cap( 2	 ) == "reptxt" )
					repos_text_status = ma[ *it ].toInt();
				else if ( rx.cap( 2	 ) == "repprop" )
					repos_prop_status = ma[ *it ].toInt();
				else if ( rx.cap( 2	 ) == "rev" )
					rev = ma[ *it ].toLong();
				++it;
                if ( it == end )
                    break;
				if ( rx.search( *it ) == -1 ) break; // something is wrong ! :)
				curIdx = rx.cap( 1 ).toInt();
			}
			slotStatus(path, text_status, prop_status, repos_text_status, repos_prop_status, rev);
		}
	}
	kdDebug(9036) << " Returning VcsFileInfoMap. provider::status() finished " << endl;
    return m_cachedDirEntries;
}

bool SVNFileInfoProvider::requestStatus( const TQString &dirPath, void *callerData, bool recursive, bool checkRepos ) {
	kdDebug(9036) << "##################################################################################### svn provider : request status" << endl;
    m_savedCallerData = callerData;
    // Flush old cache
    if (m_cachedDirEntries)
    {
        delete m_cachedDirEntries;
        m_cachedDirEntries = 0;
        m_previousDirPath = dirPath;
    }

	TQByteArray parms;
	TQDataStream s( parms, IO_WriteOnly );
	int cmd = 9;
	TQString rPath = projectDirectory( );
	rPath += TQDir::separator() + dirPath;
    
    if( ! m_part->isValidDirectory( rPath ) ){
        return false;
    }
    
	kdDebug(9036) << "DIR : " << rPath << " " << TQFileInfo( rPath ).absFilePath() << endl;
	s << cmd << KURL( TQFileInfo( rPath ).absFilePath() ) << checkRepos << recursive;
	KURL servURL = "kdevsvn+http://fakeserver_this_is_normal_behavior/";
	job = TDEIO::special(servURL, parms, false);
	connect( job, TQT_SIGNAL( result( TDEIO::Job * ) ), this, TQT_SLOT( slotResult( TDEIO::Job * ) ) );
	if( checkRepos )
		m_part->svncore()->initProcessDlg( job, dirPath, i18n("Subversion File/Directory Status") );
    return true;
}

void SVNFileInfoProvider::slotResult( TDEIO::Job *j ) {
	if ( j->error() )
		j->showErrorDialog( m_part->mainWindow()->main() );

	TDEIO::MetaData ma = j->metaData();
	TQValueList<TQString> keys = ma.keys();
	qHeapSort( keys );
	TQValueList<TQString>::Iterator begin = keys.begin(), end = keys.end(), it;

	TQString path;
	int text_status = 0, prop_status = 0, repos_text_status = 0, repos_prop_status = 0;
	long int rev = 0;
	int curIdx, lastIdx;

	TQRegExp rx( "([0-9]*)(.*)" );
	for ( it = begin; it != end; ) {
		kdDebug(9036) << "METADATA : " << *it << ":" << ma[ *it ] << endl;
		if ( rx.search( *it ) == -1 ) return; // something is wrong ! :)
        /* if some notification comes here, consume these notification metadatas */
        if ( rx.cap( 2 ) == "action" ){
            curIdx = lastIdx = rx.cap( 1 ).toInt();
            while ( curIdx == lastIdx ){
                ++it;
                if ( it == end ) break;
                if ( rx.search( *it ) == -1 ) continue; // something is wrong
                curIdx = rx.cap( 1 ).toInt();
            }
            continue;
        }
		curIdx = lastIdx = rx.cap( 1 ).toInt();
		while ( curIdx == lastIdx ) {
			if ( rx.cap( 2 ) == "path" )
				path = ma[ *it ];
			else if ( rx.cap( 2	 ) == "text" )
				text_status = ma[ *it ].toInt();
			else if ( rx.cap( 2	 ) == "prop" )
				prop_status = ma[ *it ].toInt();
			else if ( rx.cap( 2	 ) == "reptxt" )
				repos_text_status = ma[ *it ].toInt();
			else if ( rx.cap( 2	 ) == "repprop" )
				repos_prop_status = ma[ *it ].toInt();
			else if ( rx.cap( 2	 ) == "rev" )
				rev = ma[ *it ].toLong();
			++it;
            if ( it == end )
                break;
			if ( rx.search( *it ) == -1 ) break; // something is wrong ! :)
			curIdx = rx.cap( 1 ).toInt();
		}
		slotStatus(path, text_status, prop_status, repos_text_status, repos_prop_status, rev);
	}

	if ( m_cachedDirEntries )
		emit statusReady(*m_cachedDirEntries, m_savedCallerData);
}

void SVNFileInfoProvider::slotStatus( const TQString& path,int text_status, int prop_status,int repos_text_status, int repos_prop_status, long int rev) {
// 	kdDebug(9036) << "##################################################################################### svn provider : slotstatus"
// 		<< " path " << path << " text_status " << text_status << " prop_status " << prop_status << " repos_text_status " << repos_text_status
// 		<< " repos_prop_status " << repos_prop_status << " rev " << rev
// 		<< endl;

	if ( !m_cachedDirEntries )
		m_cachedDirEntries = new VCSFileInfoMap;

	TQString wRev = TQString::number( rev ); //work rev
	TQString rRev = TQString::number( rev );// repo rev
	VCSFileInfo::FileState state = VCSFileInfo::Unknown;

	switch ( text_status ) {
		case 1:
			break;
		case 2:
			break;
		case 3:
			state = VCSFileInfo::Uptodate;
			break;
		case 4:
			state = VCSFileInfo::Added;
			break;
		case 5:
			break;
		case 6: //deleted
			state = VCSFileInfo::Deleted;
			break;
		case 7: //replaced
            state = VCSFileInfo::Replaced;
			break;
		case 8: //modified
			state = VCSFileInfo::Modified;
			break;
		case 9: //merged
			break;
		case 10: //conflicted
			state = VCSFileInfo::Conflict;
			break;
		case 11: //ignored
			break;
		case 12: //obstructed
			break;
		case 13: //external
			break;
		case 14: //incomplete
			break;
	}
	switch( prop_status ) {
		case 8:
			state = VCSFileInfo::Modified;
			break;
	}
	switch ( repos_text_status ) {
		case 1:
			break;
		case 2:
			break;
		case 3:
			break;
		case 4:
			break;
		case 5:
			break;
		case 6: //deleted
			break;
		case 7: //replaced
			break;
		case 8: //modified
			state = VCSFileInfo::NeedsPatch;
			break;
		case 9: //merged
			break;
		case 10: //conflicted
			break;
		case 11: //ignored
			break;
		case 12: //obstructed
			break;
		case 13: //external
			break;
		case 14: //incomplete
			break;
	}

	VCSFileInfo info(TQFileInfo( path ).fileName(),wRev,rRev,state);
	kdDebug(9036) << "Inserting " << info.toString() << endl;
	m_cachedDirEntries->insert( TQFileInfo( path ).fileName(), info);
}

TQString SVNFileInfoProvider::projectDirectory() const {
	return owner()->project()->projectDirectory();
}

const VCSFileInfoMap *SVNFileInfoProvider::statusExt( const TQString &dirPath,
	bool checkRepos, bool fullRecurse, bool getAll, bool noIgnore )
{
	if ( !m_recursiveDirEntries )
		m_recursiveDirEntries = new VCSFileInfoMap;

// 	if ( dirPath != m_recursivePreviousDirPath ) {
	m_recursiveDirEntries->clear();
	m_recursivePreviousDirPath = dirPath;
	KURL servURL = "kdevsvn+http://fakeserver_this_is_normal_behavior/";
	TQByteArray parms;
	TQDataStream s( parms, IO_WriteOnly );
	int cmd = 109;
	TQString rPath = projectDirectory( );
	rPath += TQDir::separator() + dirPath;
	kdDebug(9036) << "DIR : " << rPath << " " << KURL( TQFileInfo( rPath ).absFilePath() ) << endl;
	s << cmd << checkRepos << fullRecurse << getAll << noIgnore << -1 << "WORKING" << KURL( TQFileInfo( rPath ).absFilePath() );
	TDEIO::SimpleJob *job2 = TDEIO::special(servURL, parms, false);
	job2->setWindow( m_part->mainWindow()->main() );


	TQMap<TQString,TQString> ma;
	TDEIO::NetAccess::synchronousRun(job2, m_part->mainWindow()->main(), 0, 0, &ma );

	TQValueList<TQString> keys = ma.keys();
	qHeapSort( keys );
	TQValueList<TQString>::Iterator begin = keys.begin(), end = keys.end(), it;

	TQString path;
	int text_status = 0, prop_status = 0, repos_text_status = 0, repos_prop_status = 0;
	long int rev = 0;
	int curIdx, lastIdx;

	TQRegExp rx( "([0-9]*)(.*)" );
	for ( it = begin; it != end; ) {
		kdDebug(9036) << "METADATA : " << *it << ":" << ma[ *it ] << endl;
		if ( rx.search( *it ) == -1 ) return m_recursiveDirEntries; // something is wrong ! :)
		/* if some notification comes here, consume these notification metadatas */
		if ( rx.cap( 2 ) == "action" ){
			curIdx = lastIdx = rx.cap( 1 ).toInt();
			while ( curIdx == lastIdx ){
				++it;
				if ( it == end ) break;
				if ( rx.search( *it ) == -1 ) continue; // something is wrong
				curIdx = rx.cap( 1 ).toInt();
			}
			continue;
		}
		/* get properties */
		curIdx = lastIdx = rx.cap( 1 ).toInt();
		while ( curIdx == lastIdx ) {
			if ( rx.cap( 2 ) == "path" )
				path = ma[ *it ];
			else if ( rx.cap( 2	 ) == "text" )
				text_status = ma[ *it ].toInt();
			else if ( rx.cap( 2	 ) == "prop" )
				prop_status = ma[ *it ].toInt();
			else if ( rx.cap( 2	 ) == "reptxt" )
				repos_text_status = ma[ *it ].toInt();
			else if ( rx.cap( 2	 ) == "repprop" )
				repos_prop_status = ma[ *it ].toInt();
			else if ( rx.cap( 2	 ) == "rev" )
				rev = ma[ *it ].toLong();
			++it;
			if ( it == end )
				break;
			if ( rx.search( *it ) == -1 ) break; // something is wrong ! :)
			curIdx = rx.cap( 1 ).toInt();
		}
		slotStatusExt(dirPath, path, text_status, prop_status, repos_text_status, repos_prop_status, rev);
	}
// 	}

	return m_recursiveDirEntries;
}

void SVNFileInfoProvider::slotStatusExt(
	const TQString& reqPath, const TQString& path,int text_status, int prop_status,int repos_text_status, int repos_prop_status, long int rev)
{

	if ( !m_recursiveDirEntries )
		m_recursiveDirEntries = new VCSFileInfoMap;

	TQString wRev = TQString::number( rev ); //work rev
	TQString rRev = TQString::number( rev );// repo rev
	VCSFileInfo::FileState state = VCSFileInfo::Unknown;

	switch ( text_status ) {
		case 1: // does not exist
			break;
		case 2: // unversioned
			break;
		case 3:
			state = VCSFileInfo::Uptodate;
			break;
		case 4:
			state = VCSFileInfo::Added;
			break;
		case 5: // missing
			break;
		case 6: //deleted
			state = VCSFileInfo::Deleted;
			break;
		case 7: //replaced
			state = VCSFileInfo::Replaced;
			break;
		case 8: //modified
			state = VCSFileInfo::Modified;
			break;
		case 9: //merged
			break;
		case 10: //conflicted
			state = VCSFileInfo::Conflict;
			break;
		case 11: //ignored
			break;
		case 12: //obstructed
			break;
		case 13: //external
			break;
		case 14: //incomplete
			break;
	}
	switch( prop_status ) {
		case 8:
			state = VCSFileInfo::Modified;
			break;
	}
	switch ( repos_text_status ) {
		case 1:
			break;
		case 2:
			break;
		case 3:
			break;
		case 4:
			break;
		case 5:
			break;
		case 6: //deleted
			break;
		case 7: //replaced
			break;
		case 8: //modified
			state = VCSFileInfo::NeedsPatch;
			break;
		case 9: //merged
			break;
		case 10: //conflicted
			break;
		case 11: //ignored
			break;
		case 12: //obstructed
			break;
		case 13: //external
			break;
		case 14: //incomplete
			break;
	}

	TQString relativeReqPath;
	if (reqPath == "./"){
		// case of project top directory
		TQString reqAbsPath = projectDirectory();

        if( path == reqAbsPath ){
            //key of VCSInfo is project directory itself. So it is set to .
            relativeReqPath = ".";
        }
        else{
            relativeReqPath = path.right( path.length() - reqAbsPath.length() - 1 );
        }
	}
	else {
		TQString reqAbsPath = projectDirectory() + TQDir::separator() + reqPath;
		relativeReqPath = path.right( path.length() - reqAbsPath.length() - 1 );

		if (relativeReqPath == reqAbsPath){
			// case of requested directory itself.
			relativeReqPath = ".";
		}
	}

	VCSFileInfo info(relativeReqPath, wRev, rRev, state);
	m_recursiveDirEntries->insert( relativeReqPath, info );

// 	VCSFileInfo info(TQFileInfo( path ).fileName(),wRev,rRev,state);
 	kdDebug(9036) << "Inserting " << info.toString() << endl;
// 	m_recursiveDirEntries->insert( TQFileInfo( path ).fileName(), info);
}

#include "subversion_fileinfo.moc"