-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyRepository.m
2309 lines (1820 loc) · 64.8 KB
/
MyRepository.m
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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// MyRepository.m - Manages the repository inspector interface
//
#import "MyRepository.h"
#import "MySvn.h"
#import "Tasks.h"
#import "DrawerLogView.h"
#import "MyFileMergeController.h"
#import "MySvnOperationController.h"
#import "MySvnRepositoryBrowserView.h"
#import "MySvnLogView.h"
#import "NSString+MyAdditions.h"
#import "RepoItem.h"
#import "SvnLogReport.h"
#import "CommonUtils.h"
#import "MySvnLogParser.h"
#import "SvnInterface.h"
#import "ViewUtils.h"
static ConstString keyWidowFrame = @"winFrame",
keyViewMode = @"viewMode",
keyShowToolbar = @"showToolbar",
keyShowSidebar = @"showSidebar",
keySplitViews = @"splitViews";
//----------------------------------------------------------------------------------------
static NSString*
TrimSlashes (RepoItem* obj)
{
return [[[obj url] absoluteString] trimSlashes];
}
//----------------------------------------------------------------------------------------
static inline NSString*
PrefKey (NSString* nameKey)
{
return [@"Repo:" stringByAppendingString: nameKey];
}
//----------------------------------------------------------------------------------------
// Return true if the command sent from sender wants its option enabled.
static bool
wantsOption (id sender)
{
enum { kAltOrShift = 0, kOptionOff = 1, kOptionOn = 2 };
const int tag = [sender tag];
Assert(tag >= kAltOrShift && tag <= kOptionOn);
return (tag == kAltOrShift && AltOrShiftPressed()) || tag == kOptionOn;
}
//----------------------------------------------------------------------------------------
// Path items in log items
static NSString*
getPath (NSDictionary* obj)
{
return [obj objectForKey: @"path"];
}
//----------------------------------------------------------------------------------------
static int
getAction (NSDictionary* obj)
{
ConstString action = [obj objectForKey: @"action"];
if (action && [action length])
return [action characterAtIndex: 0];
return 0;
}
//----------------------------------------------------------------------------------------
static NSString*
getRevision (NSDictionary* obj)
{
return [obj objectForKey: @"revision"];
}
//----------------------------------------------------------------------------------------
static int
compareRevisions (id obj1, id obj2, void* context)
{
#pragma unused(context)
return [(NSNumber*) [obj2 objectForKey: @"revision_n"] compare: [obj1 objectForKey: @"revision_n"]];
}
//----------------------------------------------------------------------------------------
#pragma mark -
//----------------------------------------------------------------------------------------
@interface MyRepository (Private)
- (void) savePrefs;
- (void) changeRepositoryUrl: (NSURL*) anUrl;
- (BOOL) svnErrorIf: (id) taskObj;
- (void) svnInfoCompletedCallback: (id) taskObj;
- (void) fetchSvnInfo: (SEL) selector;
- (void) fetchSvnInfo;
- (void) fetchSvnInfoReceiveDataFinished: (NSString*) result;
- (NSArray*) userValidatedFiles: (NSArray*) files
forDestination: (NSURL*) destinationURL;
- (NSArray*) exportFiles: (NSArray*) fileObjs
toFolder: (NSURL*) folderURL
includeRev: (BOOL) includeRev
openAfter: (BOOL) openAfter;
- (void) importFiles: (NSArray*) files
intoFolder: (RepoItem*) destRepoDir;
- (void) requestReport;
- (void) setRevision: (NSString*) aRevision;
- (void) setUrl: (NSURL*) anUrl;
- (void) checkRepositoryURL;
- (void) setDisplayedTaskObj: (NSMutableDictionary*) aDisplayedTaskObj;
- (NSInvocation*) makeSvnOptionInvocation;
- (NSInvocation*) makeCommandCallback;
- (NSInvocation*) makeExtractedCallback;
@end
//----------------------------------------------------------------------------------------
@implementation MyRepository
#if 0
- init
{
if (self = [super init])
{
[self setRevision: nil];
// logViewKind = GetPreferenceBool(@"defaultLogViewKindIsAdvanced") ? kAdvanced : kSimple;
// useAdvancedLogView = GetPreferenceBool(@"defaultLogViewKindIsAdvanced");
}
return self;
}
#endif
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
[svnLogView unload];
[svnBrowserView unload];
[fRootURL release];
[fURL release];
[fRevision release];
[windowTitle release];
[user release];
[pass release];
[fLog release];
[displayedTaskObj release];
// NSLog(@"Repository dealloc'ed");
SvnEndClient(fSvnEnv);
[super dealloc];
}
//----------------------------------------------------------------------------------------
- (NSWindow*) window
{
return [svnLogView window];
}
//----------------------------------------------------------------------------------------
- (void) showWindows
{
[super showWindows];
const BOOL showURL = GetPreferenceBool(@"repURLInWindowTitle");
[[self window] setTitle: [NSString stringWithFormat: (showURL ? @"Repository: %@ - %@"
: @"Repository: %@"),
windowTitle, fRootURL]];
}
//----------------------------------------------------------------------------------------
- (NSString*) windowNibName
{
return @"MyRepository";
}
//----------------------------------------------------------------------------------------
- (void) windowControllerDidLoadNib: (NSWindowController*) aController
{
[aController setShouldCascadeWindows: NO];
}
//----------------------------------------------------------------------------------------
- (void) windowWillClose: (NSNotification*) notification
{
#pragma unused(notification)
fPrefsChanged = TRUE;
[self savePrefs];
[svnLogView removeObserver: self forKeyPath: @"currentRevision"];
}
//----------------------------------------------------------------------------------------
// Mark prefs as changed but defer saving for 5 secs.
- (void) prefsChanged
{
if (!fPrefsChanged)
{
fPrefsChanged = TRUE;
[self performSelector: @selector(savePrefs) withObject: nil afterDelay: 5];
}
}
//----------------------------------------------------------------------------------------
- (void) savePrefs
{
NSWindow* const window = [self window];
if (!fPrefsChanged || ![window isVisible])
return;
fPrefsChanged = FALSE;
SetPreference(PrefKey(windowTitle),
[NSDictionary dictionaryWithObjectsAndKeys:
[window stringWithSavedFrame], keyWidowFrame,
NSBool([svnLogView advanced]), keyViewMode,
NSBool([[window toolbar] isVisible]), keyShowToolbar,
NSBool(IsOpen(sidebar)), keyShowSidebar,
getValuesForSplitViews(window), keySplitViews,
nil]);
}
//----------------------------------------------------------------------------------------
- (void) quitting: (NSNotification*) notification
{
#pragma unused(notification)
fPrefsChanged = TRUE;
[self savePrefs];
}
//----------------------------------------------------------------------------------------
- (void) awakeFromNib
{
[svnLogView addObserver: self forKeyPath: @"currentRevision" options: NSKeyValueChangeSetting context: nil];
[svnBrowserView setSvnOptionsInvocation: [self makeSvnOptionInvocation]];
[svnBrowserView setUrl: fURL];
[svnLogView setIsFetching: TRUE];
[svnLogView setSvnOptionsInvocation: [self makeSvnOptionInvocation]];
[svnLogView setUrl: fURL];
// [svnLogView setSvnOptions: [self makeSvnOptionInvocation] url: fURL currentRevision: [self revision]];
// [svnLogView setupUrl: fURL options: [self makeSvnOptionInvocation] currentRevision: [self revision]];
// display the known url as raw text while svn info is fetching data
[urlTextView setBackgroundColor: [NSColor windowBackgroundColor]];
[urlTextView setString: [fURL absoluteString]];
NSWindow* const window = [self window];
[window setDelegate: self]; // for windowWillClose messages
[drawerLogView setup: self forWindow: window];
Assert(windowTitle);
ConstString prefKey = PrefKey(windowTitle);
NSDictionary* const settings = GetPreference(prefKey);
if (settings)
{
if (![[settings objectForKey: keyShowToolbar] boolValue])
[[window toolbar] setVisible: NO];
[window setFrameFromString: [settings objectForKey: keyWidowFrame]];
if ([[settings objectForKey: keyShowSidebar] boolValue])
[sidebar performSelector: @selector(open) withObject: nil afterDelay: 0.125];
[svnLogView setAdvanced: [[settings objectForKey: keyViewMode] boolValue]];
setupSplitViews(window, [settings objectForKey: keySplitViews], nil);
}
else
{
ConstString widowFrameKey = [@"repoWinFrame:" stringByAppendingString: windowTitle];
[window setFrameUsingName: widowFrameKey];
}
[svnLogView setAutosaveName: prefKey];
// fetch svn info in order to know the repository's root URL & HEAD revision
[self performSelector: @selector(updateLog) withObject: nil afterDelay: 0];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(quitting:)
name: NSApplicationWillTerminateNotification object: nil];
}
//----------------------------------------------------------------------------------------
- (void) observeValueForKeyPath: (NSString*) keyPath
ofObject: (id) object
change: (NSDictionary*) change
context: (void*) context
{
#pragma unused(object, context)
if ([keyPath isEqualToString: @"currentRevision"]) // A new current revision was selected in the svnLogView
{
const id value = [change objectForKey: NSKeyValueChangeNewKey];
[self setRevision: value];
[svnBrowserView setRevision: value];
[svnBrowserView fetchSvn];
}
}
//----------------------------------------------------------------------------------------
- (void) setupTitle: (NSString*) title
username: (NSString*) username
password: (NSString*) password
url: (NSURL*) repoURL
{
windowTitle = [title retain];
user = [username retain];
pass = [password retain];
Assert(fRootURL == nil);
fRootURL = [repoURL retain];
[self setUrl: repoURL];
}
//----------------------------------------------------------------------------------------
// Private:
- (NSString*) pathToURL: (NSString*) path
{
Assert(path);
return [[fRootURL absoluteString] stringByAppendingString: [path escapeURL]];
}
//----------------------------------------------------------------------------------------
- (IBAction) toggleSidebar: (id) sender
{
[sidebar toggle: sender];
}
- (IBAction) pickedAFolderInBrowserView: (NSMenuItem*) sender
{
// "Browse as sub-repository" context menu item. (see "browserContextMenu" Menu in IB)
// representedObject of the sender menu item is the same as the row's in the browser.
// Was set in MySvnRepositoryBrowserView.
[self changeRepositoryUrl: [[sender representedObject] url]];
}
//----------------------------------------------------------------------------------------
#pragma mark -
#pragma mark clickable url
//----------------------------------------------------------------------------------------
- (void) displayUrlTextView
{
if (![[self window] isVisible])
return;
[self checkRepositoryURL];
NSString* tmpString = UnEscapeURL(fURL);
int rootLength = [UnEscapeURL(fRootURL) length];
if (rootLength == 0)
rootLength = [tmpString length];
const id layout = [urlTextView layoutManager];
[urlTextView setString: @""]; // workaround to clean-up the style for sure
[urlTextView setString: tmpString];
[urlTextView setFont: [NSFont systemFontOfSize: 11]];
[urlTextView setFont: [NSFont boldSystemFontOfSize: 11] range: NSMakeRange(0, rootLength)];
[layout addTemporaryAttributes:
[NSDictionary dictionaryWithObject: [NSNumber numberWithInt: NSUnderlineStyleNone]
forKey: NSUnderlineStyleAttributeName]
forCharacterRange: NSMakeRange(0, [tmpString length])];
NSMutableDictionary* linkAttributes =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: -0.5], NSKernAttributeName,
[NSColor blackColor], NSForegroundColorAttributeName,
[NSNumber numberWithInt: NSUnderlineStyleThick], NSUnderlineStyleAttributeName,
[NSCursor pointingHandCursor], NSCursorAttributeName,
[NSColor blueColor], NSUnderlineColorAttributeName,
nil];
// Make a link on each part of the url. Stop at the root of the repository.
while (TRUE)
{
NSString* tmp = [[tmpString stringByDeletingLastComponent] stringByAppendingString: @"/"];
const int tmpLength = [tmp length];
int oldLength = [tmpString length] - 1;
if ([tmpString characterAtIndex: oldLength] != '/')
++oldLength;
if (oldLength <= tmpLength) break;
NSRange range = { tmpLength, oldLength - tmpLength };
if (tmpLength < rootLength)
{
int l = range.location;
range.location = 0;
range.length += l;
}
NSString* urlString = EscapeURL(tmpString);
[linkAttributes setObject: urlString forKey: NSToolTipAttributeName];
[linkAttributes setObject: urlString forKey: NSLinkAttributeName];
[[urlTextView textStorage] addAttributes: linkAttributes range: range]; // required to set the link
[layout addTemporaryAttributes: linkAttributes forCharacterRange: range]; // required to turn it to black
if (tmpLength < rootLength) break;
tmpString = tmp;
}
}
//----------------------------------------------------------------------------------------
// Handle a click on the repository url (MyRepository is urlTextView's delegate).
- (BOOL) textView: (NSTextView*) textView
clickedOnLink: (id) link
atIndex: (unsigned) charIndex
{
#pragma unused(textView, charIndex)
if ([link isKindOfClass: [NSString class]])
{
// [svnLogView setRevision: fRevision]; // FIX_ME: call latestRevision:pegRev:
[self changeRepositoryUrl: [NSURL URLWithString: link]];
return YES;
}
return NO;
}
//----------------------------------------------------------------------------------------
- (NSDictionary*) documentNameDict
{
return [NSDictionary dictionaryWithObject: windowTitle forKey: @"documentName"];
}
//----------------------------------------------------------------------------------------
- (NSString*) pathAtCurrentRevision: (RepoItem*) repoItem
{
// <path>@<revision>
return [NSString stringWithFormat: @"%@@%@", TrimSlashes(repoItem), fRevision];
}
//----------------------------------------------------------------------------------------
#pragma mark -
#pragma mark Log Management
//----------------------------------------------------------------------------------------
// Sort, remove duplicates & return newest revision.
+ (unsigned int) cleanUpLog: (NSMutableArray*) aLog
{
unsigned int revision = 0,
count = [aLog count];
if (count)
{
[aLog sortUsingFunction: compareRevisions context: NULL];
--count;
for (unsigned int i = 0; i < count; ) // remove duplicates
{
const id rev = getRevision([aLog objectAtIndex: i]);
++i;
if ([rev isEqualToString: getRevision([aLog objectAtIndex: i])])
{
[aLog removeObjectAtIndex: i];
--i;
--count;
}
}
revision = [getRevision([aLog objectAtIndex: 0]) intValue];
}
return revision;
}
//----------------------------------------------------------------------------------------
- (void) setLog: (NSMutableArray*) newLog
{
id oldLog = fLog;
fLog = [newLog retain];
[oldLog release];
fLogRevision = [MyRepository cleanUpLog: newLog];
}
//----------------------------------------------------------------------------------------
- (NSString*) getCachePath
{
Assert(fRootURL);
return [MySvn cachePathForKey: [[fRootURL absoluteString] stringByAppendingString: @" repo_log"]];
}
//----------------------------------------------------------------------------------------
// Initiate fetching of repository log entries HEAD thru fLogRevision.
- (void) fetchSvnLog: (SEL) completedMsg
{
[svnLogView fetchSvn: MakeCallbackInvocation(self, completedMsg)];
}
//----------------------------------------------------------------------------------------
// Initiate fetching of repository log entries HEAD thru fLogRevision.
- (void) fetchSvnLog
{
[self fetchSvnLog: @selector(svnLogCompleted:)];
}
//----------------------------------------------------------------------------------------
- (void) svnLogCompleted: (id) taskObj
{
[svnLogView fetchSvnReceiveDataFinished: taskObj];
[self setLog: [svnLogView logArray]];
}
//----------------------------------------------------------------------------------------
// Initiate fetching of repository info then any new log entries.
- (void) updateLog
{
[self fetchSvnInfo: @selector(updateLog_InfoCompleted:)];
}
//----------------------------------------------------------------------------------------
- (void) updateLog_InfoCompleted: (id) taskObj
{
if (!SvnWantAndHave())
[self svnInfoCompletedCallback: taskObj];
[self fetchSvnLog];
}
//----------------------------------------------------------------------------------------
#pragma mark -
#pragma mark Repository URL
//----------------------------------------------------------------------------------------
- (NSString*) latestRevision: (NSURL*) aURL
pegRev: (NSString*) pegRev
{
#pragma unused(aURL)
return pegRev;
}
//----------------------------------------------------------------------------------------
// Private:
- (void) browseURL: (NSURL*) aURL
revision: (NSString*) revision
{
// dprintf("aURL=<%@> rev. %@=>%@", [aURL absoluteString], fRevision, revision);
id oldRev = [fRevision retain];
if (revision != oldRev)
[svnLogView setRevision: revision];
[self changeRepositoryUrl: aURL];
if (revision != oldRev)
[svnLogView setRevision: oldRev];
// [svnBrowserView setRevision: revision];
[oldRev release];
}
//----------------------------------------------------------------------------------------
// Set browse URL from repository browser
- (void) openItem: (RepoItem*) repoItem
revision: (NSString*) pegRevision
{
if ([repoItem isRoot])
return;
NSString* path = [repoItem path];
if ([repoItem isDir])
path = [path stringByAppendingString: @"/"];
if (!pegRevision)
pegRevision = [repoItem revision];
// pegRevision = [repoItem modRev];
// dprintf("path='%@' revision=%@\n fURL=<%@>", [path escapeURL], pegRevision, fURL);
NSURL* aURL = [path isEqualToString: @"/"]
? [NSURL URLWithString: [[fRootURL absoluteString] stringByAppendingString: @"/"]]
: [NSURL URLWithString: [path escapeURL] relativeToURL: fURL];
NSString* rev = [self latestRevision: aURL pegRev: pegRevision];
[self browseURL: aURL revision: rev];
}
//----------------------------------------------------------------------------------------
// Set browse URL from a path in a log entry
- (void) openLogPath: (NSDictionary*) pathInfo
revision: (NSString*) pegRevision
{
NSString* relativePath = getPath(pathInfo);
NSURL* aURL = [NSURL URLWithString: [[fRootURL absoluteString]
stringByAppendingString: [relativePath escapeURL]]];
// dprintf("path='%@' revision=%@\n aURL=<%@>", [relativePath escapeURL], pegRevision, aURL);
NSString* rev = [self latestRevision: aURL pegRev: pegRevision];
[self browseURL: aURL revision: rev];
}
//----------------------------------------------------------------------------------------
- (void) openLogPath: (NSDictionary*) pathInfo
forLogEntry: (NSDictionary*) logEntry
{
[self openLogPath: pathInfo revision: getRevision(logEntry)];
}
//----------------------------------------------------------------------------------------
- (void) changeRepositoryUrl: (NSURL*) anUrl
{
[self setUrl: anUrl];
[svnBrowserView setUrl: fURL];
[self displayUrlTextView];
[svnLogView resetUrl: fURL];
[self updateLog];
[svnBrowserView fetchSvn];
}
//----------------------------------------------------------------------------------------
#pragma mark -
#pragma mark svn info
//----------------------------------------------------------------------------------------
struct SvnInfoEnv
{
SvnRevNum fRevision;
SvnNodeKind fKind;
char fURL[2048];
};
typedef struct SvnInfoEnv SvnInfoEnv;
//----------------------------------------------------------------------------------------
// Repo 'svn info' callback. Sets <revision> and <url>.
static SvnError
svnInfoReceiver (void* baton,
const char* path,
SvnInfo info,
SvnPool pool)
{
#pragma unused(path, pool)
// dprintf("revision=%d URL=<%s>", info->rev, info->repos_root_URL);
SvnInfoEnv* env = (SvnInfoEnv*) baton;
env->fRevision = info->rev;
env->fKind = info->kind;
strncpy(env->fURL, info->repos_root_URL, sizeof(env->fURL));
// strncpy(env->fUUID, info->repos_UUID, sizeof(env->fUUID));
// svn_revnum_t last_changed_rev;
// apr_time_t last_changed_date;
// const char *last_changed_author;
return SVN_NO_ERROR;
}
//----------------------------------------------------------------------------------------
// svn info of <fRootURL> via SvnInterface (called by separate thread)
- (void) svnDoInfo: (Message*) completedMsg
{
// NSLog(@"svn info - begin");
NSAutoreleasePool* autoPool = [NSAutoreleasePool new];
SvnPool pool = SvnNewPool(); // Create top-level memory pool.
@try
{
SvnClient ctx = SvnSetupClient(&fSvnEnv, self);
char path[PATH_MAX * 2];
if (ToUTF8([fRootURL absoluteString], path, sizeof(path)))
{
int len = strlen(path);
if (len > 5 && path[len - 1] == '/' && path[len - 2] != '/')
path[len - 1] = 0;
const SvnOptRevision peg_rev = { svn_opt_revision_head, 0 },
rev_opt = { svn_opt_revision_unspecified, 0 };
SvnInfoEnv env;
env.fRevision = 0;
env.fKind = svn_node_unknown;
env.fURL[0] = 0;
// dprintf("svn_client_info URL=<%s>", path);
// Retrive HEAD revision info from repository root.
SvnThrowIf(svn_client_info(path, &peg_rev, &rev_opt,
svnInfoReceiver, &env, !kSvnRecurse,
ctx, pool));
// fIsFile = (env.fKind == svn_node_file);
[fRootURL release];
fRootURL = (NSURL*) CFURLCreateWithBytes(kCFAllocatorDefault,
(const UInt8*) env.fURL, strlen(env.fURL),
kCFStringEncodingUTF8, NULL);
fHeadRevision = env.fRevision;
[self checkRepositoryURL];
/* dprintf("'%s' => env.fRevision=%d fLogRevision=%d fIsFile=%d",
path, env.fRevision, fLogRevision, fIsFile);*/
[completedMsg sendToOnMainThread: self];
[self performSelectorOnMainThread: @selector(displayUrlTextView) withObject: nil waitUntilDone: NO];
}
}
@catch (SvnException* ex)
{
SvnReportCatch(ex);
if (fRevision == nil) // First time?
{
if (fLog != nil)
[self performSelectorOnMainThread: @selector(setRevision:)
withObject: getRevision([fLog objectAtIndex: 0]) waitUntilDone: NO];
[completedMsg sendToOnMainThread: self];
[self performSelectorOnMainThread: @selector(displayUrlTextView) withObject: nil waitUntilDone: NO];
}
[self performSelectorOnMainThread: @selector(svnError:) withObject: [ex message] waitUntilDone: NO];
}
@finally
{
SvnDeletePool(pool);
[autoPool release];
[completedMsg release];
// NSLog(@"svn info - end");
}
}
//----------------------------------------------------------------------------------------
// Get current repository info & send <completedMsg> to self on completion.
- (void) fetchSvnInfo: (SEL) completedMsg
{
if (!SvnWantAndHave())
{
if (completedMsg == NULL)
completedMsg = @selector(svnInfoCompletedCallback:);
[MySvn genericCommand: @"info"
arguments: [NSArray arrayWithObject: [fURL absoluteString]]
generalOptions: [self svnOptionsInvocation]
options: nil
callback: MakeCallbackInvocation(self, completedMsg)
callbackInfo: nil
taskInfo: [self documentNameDict]];
}
else
{
id message = [[Message alloc] initWithMessage: completedMsg];
[NSThread detachNewThreadSelector: @selector(svnDoInfo:) toTarget: self withObject: message];
}
}
//----------------------------------------------------------------------------------------
- (void) fetchSvnInfo
{
[self fetchSvnInfo: NULL];
}
//----------------------------------------------------------------------------------------
- (void) svnInfoCompletedCallback: (id) taskObj
{
if (isCompleted(taskObj))
{
[self fetchSvnInfoReceiveDataFinished: stdOut(taskObj)];
}
[self svnErrorIf: taskObj];
}
//----------------------------------------------------------------------------------------
- (void) fetchSvnInfoReceiveDataFinished: (NSString*) result
{
NSArray* lines = [result componentsSeparatedByString: @"\n"];
const int count = [lines count];
if (count < 5)
{
[self svnError: result];
}
else
{
BOOL isFile = NO;
NSString* url = nil;
for (int i = 0; i < count; ++i)
{
NSString* line = [lines objectAtIndex: i];
const int len = [line length];
if (len > 16 &&
[[line substringWithRange: NSMakeRange(0, 17)] isEqualToString: @"Repository Root: "])
{
url = [line substringFromIndex: 17];
}
else if (len > 14 &&
[[line substringWithRange: NSMakeRange(0, 15)] isEqualToString: @"Node Kind: file"])
{
isFile = TRUE;
}
else if (len > 10 &&
[[line substringWithRange: NSMakeRange(0, 10)] isEqualToString: @"Revision: "])
{
fHeadRevision = [[line substringFromIndex: 10] intValue];
}
}
// dprintf("isFile=%d fHeadRevision=%d url=<%@>", isFile, fHeadRevision, url);
if (url != nil)
{
// fIsFile = isFile;
[fRootURL release];
fRootURL = [[NSURL URLWithString: url] retain];
[self displayUrlTextView];
}
}
}
//----------------------------------------------------------------------------------------
// If there is a single selected repository-browser item then return it else return nil.
// Private:
- (RepoItem*) selectedItemOrNil
{
return [svnBrowserView selectedItemOrNil];
}
//----------------------------------------------------------------------------------------
// Get the deepest selected directory from the repository-browser.
// Private:
- (RepoItem*) selectedDirectory
{
RepoItem* dir = nil;
NSArray* const selectedObjects = [svnBrowserView selectedItems];
if ([selectedObjects count] > 0)
dir = [selectedObjects objectAtIndex: 0];
if (dir == nil || ![dir isDir])
{
NSBrowser* browser = [svnBrowserView valueForKey: @"browser"];
int col = [browser selectedColumn] - 1;
col = MAX(col, 0);
int row = [browser selectedRowInColumn: col];
row = MAX(row, 0);
dir = [[[browser matrixInColumn: col] cellAtRow: row column: 0] representedObject];
}
return dir;
}
//----------------------------------------------------------------------------------------
#pragma mark -
#pragma mark svn operations
- (IBAction) svnCopy: (id) sender
{
#pragma unused(sender)
RepoItem* selection = [self selectedItemOrNil];
if (!selection)
{
[self svnError: @"Please select exactly one item to copy."];
}
else if ([selection isRoot])
{
[self svnError: @"Can't copy root folder."];
}
else
{
[MySvnOperationController runSheet: kSvnCopy repository: self url: fURL sourceItem: selection];
}
}
//----------------------------------------------------------------------------------------
- (IBAction) svnMove: (id) sender
{
#pragma unused(sender)
RepoItem* selection = [self selectedItemOrNil];
if (!selection)
{
[self svnError: @"Please select exactly one item to move."];
}
else if ([selection isRoot])
{
[self svnError: @"Can't move root folder."];
}
else
{
[MySvnOperationController runSheet: kSvnMove repository: self url: fURL sourceItem: selection];
}
}
//----------------------------------------------------------------------------------------
- (IBAction) svnMkdir: (id) sender
{
#pragma unused(sender)
[MySvnOperationController runSheet: kSvnMkdir repository: self url: fURL sourceItem: nil];
}
//----------------------------------------------------------------------------------------
- (IBAction) svnDelete: (id) sender
{
#pragma unused(sender)
[MySvnOperationController runSheet: kSvnDelete repository: self url: fURL sourceItem: nil];
}
//----------------------------------------------------------------------------------------
- (IBAction) svnFileMerge: (id) sender
{
[self svnDiff: sender];
}
//----------------------------------------------------------------------------------------
// Return TRUE if there is no sheet blocking this window, otherwise beep & return FALSE.
- (BOOL) noSheet
{
if ([[self window] attachedSheet])
{
NSBeep();
return FALSE;
}
return TRUE;
}