@@ -18,6 +18,7 @@ class Repository : IEquatable<Repository>, IRepository
18
18
public event Action < CacheUpdateEvent > GitLogCacheUpdated ;
19
19
public event Action < CacheUpdateEvent > GitLockCacheUpdated ;
20
20
public event Action < CacheUpdateEvent > BranchCacheUpdated ;
21
+ public event Action < CacheUpdateEvent > RepositoryInfoCacheUpdated ;
21
22
22
23
/// <summary>
23
24
/// Initializes a new instance of the <see cref="Repository"/> class.
@@ -88,6 +89,10 @@ private void CacheContainer_OnCacheUpdated(CacheType cacheType, DateTimeOffset o
88
89
case CacheType . GitUserCache :
89
90
break ;
90
91
92
+ case CacheType . RepositoryInfoCache :
93
+ FireRepositoryInfoCacheUpdated ( offset ) ;
94
+ break ;
95
+
91
96
default :
92
97
throw new ArgumentOutOfRangeException ( nameof ( cacheType ) , cacheType , null ) ;
93
98
}
@@ -117,6 +122,12 @@ private void FireGitLocksCacheUpdated(DateTimeOffset dateTimeOffset)
117
122
GitLockCacheUpdated ? . Invoke ( new CacheUpdateEvent { UpdatedTimeString = dateTimeOffset . ToString ( ) } ) ;
118
123
}
119
124
125
+ private void FireRepositoryInfoCacheUpdated ( DateTimeOffset dateTimeOffset )
126
+ {
127
+ Logger . Trace ( "RepositoryInfoCacheUpdated {0}" , dateTimeOffset ) ;
128
+ RepositoryInfoCacheUpdated ? . Invoke ( new CacheUpdateEvent { UpdatedTimeString = dateTimeOffset . ToString ( ) } ) ;
129
+ }
130
+
120
131
public void Initialize ( IRepositoryManager initRepositoryManager )
121
132
{
122
133
Logger . Trace ( "Initialize" ) ;
@@ -138,8 +149,7 @@ public void Initialize(IRepositoryManager initRepositoryManager)
138
149
UpdateGitStatus ( ) ;
139
150
UpdateGitLog ( ) ;
140
151
141
- new ActionTask ( CancellationToken . None , UpdateLocks )
142
- { Affinity = TaskAffinity . UI } . Start ( ) ;
152
+ new ActionTask ( CancellationToken . None , UpdateLocks ) { Affinity = TaskAffinity . UI } . Start ( ) ;
143
153
}
144
154
145
155
public ITask SetupRemote ( string remote , string remoteUrl )
@@ -196,15 +206,27 @@ public ITask ReleaseLock(string file, bool force)
196
206
return repositoryManager . UnlockFile ( file , force ) . Then ( UpdateLocks ) ;
197
207
}
198
208
209
+ public void CheckRepositoryInfoCacheEvent ( CacheUpdateEvent cacheUpdateEvent )
210
+ {
211
+ var managedCache = cacheContainer . RepositoryInfoCache ;
212
+ var raiseEvent = ShouldRaiseCacheEvent ( cacheUpdateEvent , managedCache ) ;
213
+
214
+ Logger . Trace ( "CheckRepositoryInfoCacheEvent Current:{0} Check:{1} Result:{2}" , managedCache . LastUpdatedAt ,
215
+ cacheUpdateEvent . UpdatedTimeString ?? "[NULL]" , raiseEvent ) ;
216
+
217
+ if ( raiseEvent )
218
+ {
219
+ FireBranchCacheUpdated ( managedCache . LastUpdatedAt ) ;
220
+ }
221
+ }
222
+
199
223
public void CheckBranchCacheEvent ( CacheUpdateEvent cacheUpdateEvent )
200
224
{
201
225
var managedCache = cacheContainer . BranchCache ;
202
226
var raiseEvent = ShouldRaiseCacheEvent ( cacheUpdateEvent , managedCache ) ;
203
227
204
- Logger . Trace ( "CheckBranchCacheEvent Current:{0} Check:{1} Result:{2}" ,
205
- managedCache . LastUpdatedAt ,
206
- cacheUpdateEvent . UpdatedTimeString ?? "[NULL]" ,
207
- raiseEvent ) ;
228
+ Logger . Trace ( "CheckBranchCacheEvent Current:{0} Check:{1} Result:{2}" , managedCache . LastUpdatedAt ,
229
+ cacheUpdateEvent . UpdatedTimeString ?? "[NULL]" , raiseEvent ) ;
208
230
209
231
if ( raiseEvent )
210
232
{
@@ -217,10 +239,8 @@ public void CheckGitStatusCacheEvent(CacheUpdateEvent cacheUpdateEvent)
217
239
var managedCache = cacheContainer . GitStatusCache ;
218
240
var raiseEvent = ShouldRaiseCacheEvent ( cacheUpdateEvent , managedCache ) ;
219
241
220
- Logger . Trace ( "CheckGitStatusCacheEvent Current:{0} Check:{1} Result:{2}" ,
221
- managedCache . LastUpdatedAt ,
222
- cacheUpdateEvent . UpdatedTimeString ?? "[NULL]" ,
223
- raiseEvent ) ;
242
+ Logger . Trace ( "CheckGitStatusCacheEvent Current:{0} Check:{1} Result:{2}" , managedCache . LastUpdatedAt ,
243
+ cacheUpdateEvent . UpdatedTimeString ?? "[NULL]" , raiseEvent ) ;
224
244
225
245
if ( raiseEvent )
226
246
{
@@ -233,10 +253,8 @@ public void CheckGitLogCacheEvent(CacheUpdateEvent cacheUpdateEvent)
233
253
var managedCache = cacheContainer . GitLogCache ;
234
254
var raiseEvent = ShouldRaiseCacheEvent ( cacheUpdateEvent , managedCache ) ;
235
255
236
- Logger . Trace ( "CheckGitLogCacheEvent Current:{0} Check:{1} Result:{2}" ,
237
- managedCache . LastUpdatedAt ,
238
- cacheUpdateEvent . UpdatedTimeString ?? "[NULL]" ,
239
- raiseEvent ) ;
256
+ Logger . Trace ( "CheckGitLogCacheEvent Current:{0} Check:{1} Result:{2}" , managedCache . LastUpdatedAt ,
257
+ cacheUpdateEvent . UpdatedTimeString ?? "[NULL]" , raiseEvent ) ;
240
258
241
259
if ( raiseEvent )
242
260
{
@@ -249,10 +267,8 @@ public void CheckGitLocksCacheEvent(CacheUpdateEvent cacheUpdateEvent)
249
267
var managedCache = cacheContainer . GitLocksCache ;
250
268
var raiseEvent = ShouldRaiseCacheEvent ( cacheUpdateEvent , managedCache ) ;
251
269
252
- Logger . Trace ( "CheckGitLocksCacheEvent Current:{0} Check:{1} Result:{2}" ,
253
- managedCache . LastUpdatedAt ,
254
- cacheUpdateEvent . UpdatedTimeString ?? "[NULL]" ,
255
- raiseEvent ) ;
270
+ Logger . Trace ( "CheckGitLocksCacheEvent Current:{0} Check:{1} Result:{2}" , managedCache . LastUpdatedAt ,
271
+ cacheUpdateEvent . UpdatedTimeString ?? "[NULL]" , raiseEvent ) ;
256
272
257
273
if ( raiseEvent )
258
274
{
@@ -288,6 +304,7 @@ public override bool Equals(object obj)
288
304
{
289
305
if ( ReferenceEquals ( this , obj ) )
290
306
return true ;
307
+
291
308
var other = obj as Repository ;
292
309
return Equals ( other ) ;
293
310
}
@@ -301,8 +318,8 @@ public bool Equals(IRepository other)
301
318
{
302
319
if ( ReferenceEquals ( this , other ) )
303
320
return true ;
304
- return other != null &&
305
- object . Equals ( LocalPath , other . LocalPath ) ;
321
+
322
+ return other != null && object . Equals ( LocalPath , other . LocalPath ) ;
306
323
}
307
324
308
325
private void RepositoryManager_OnCurrentRemoteUpdated ( ConfigRemote ? remote )
@@ -313,7 +330,7 @@ private void RepositoryManager_OnCurrentRemoteUpdated(ConfigRemote? remote)
313
330
CurrentConfigRemote = remote ;
314
331
CurrentRemote = GetGitRemote ( remote . Value ) ;
315
332
UpdateRepositoryInfo ( ) ;
316
- } ) { Affinity = TaskAffinity . UI } . Start ( ) ;
333
+ } ) { Affinity = TaskAffinity . UI } . Start ( ) ;
317
334
}
318
335
}
319
336
@@ -346,17 +363,13 @@ private void RepositoryManager_OnCurrentBranchUpdated(ConfigBranch? branch)
346
363
{
347
364
if ( ! Nullable . Equals ( CurrentConfigBranch , branch ) )
348
365
{
349
- new ActionTask ( CancellationToken . None , ( ) =>
350
- {
351
- var currentBranch = branch != null
352
- ? ( GitBranch ? ) GetLocalGitBranch ( branch . Value )
353
- : null ;
366
+ new ActionTask ( CancellationToken . None , ( ) => {
367
+ var currentBranch = branch != null ? ( GitBranch ? ) GetLocalGitBranch ( branch . Value ) : null ;
354
368
355
369
CurrentConfigBranch = branch ;
356
370
CurrentBranch = currentBranch ;
357
371
UpdateLocalBranches ( ) ;
358
- } )
359
- { Affinity = TaskAffinity . UI } . Start ( ) ;
372
+ } ) { Affinity = TaskAffinity . UI } . Start ( ) ;
360
373
}
361
374
}
362
375
@@ -369,41 +382,36 @@ private void RepositoryManager_OnLocalBranchUpdated(string name)
369
382
}
370
383
}
371
384
372
- private void RepositoryManager_OnRemoteBranchListUpdated ( IDictionary < string , ConfigRemote > remotes , IDictionary < string , IDictionary < string , ConfigBranch > > branches )
385
+ private void RepositoryManager_OnRemoteBranchListUpdated ( IDictionary < string , ConfigRemote > remotes ,
386
+ IDictionary < string , IDictionary < string , ConfigBranch > > branches )
373
387
{
374
- new ActionTask ( CancellationToken . None , ( ) =>
375
- {
388
+ new ActionTask ( CancellationToken . None , ( ) => {
376
389
cacheContainer . BranchCache . SetRemotes ( remotes , branches ) ;
377
390
UpdateRemoteAndRemoteBranches ( ) ;
378
- } )
379
- { Affinity = TaskAffinity . UI } . Start ( ) ;
391
+ } ) { Affinity = TaskAffinity . UI } . Start ( ) ;
380
392
}
381
393
382
394
private void UpdateRemoteAndRemoteBranches ( )
383
395
{
384
396
cacheContainer . BranchCache . Remotes =
385
- cacheContainer . BranchCache . ConfigRemotes . Values
386
- . Select ( GetGitRemote )
387
- . ToArray ( ) ;
388
-
389
- cacheContainer . BranchCache . RemoteBranches =
390
- cacheContainer . BranchCache . RemoteConfigBranches . Values
391
- . SelectMany ( x => x . Values ) . Select ( GetRemoteGitBranch )
392
- . ToArray ( ) ;
397
+ cacheContainer . BranchCache . ConfigRemotes . Values . Select ( GetGitRemote ) . ToArray ( ) ;
398
+
399
+ cacheContainer . BranchCache . RemoteBranches = cacheContainer
400
+ . BranchCache . RemoteConfigBranches . Values . SelectMany ( x => x . Values ) . Select ( GetRemoteGitBranch ) . ToArray ( ) ;
393
401
}
394
402
395
403
private void RepositoryManager_OnLocalBranchListUpdated ( IDictionary < string , ConfigBranch > branches )
396
404
{
397
405
new ActionTask ( CancellationToken . None , ( ) => {
398
- cacheContainer . BranchCache . SetLocals ( branches ) ;
399
- UpdateLocalBranches ( ) ;
400
- } )
401
- { Affinity = TaskAffinity . UI } . Start ( ) ;
406
+ cacheContainer . BranchCache . SetLocals ( branches ) ;
407
+ UpdateLocalBranches ( ) ;
408
+ } ) { Affinity = TaskAffinity . UI } . Start ( ) ;
402
409
}
403
410
404
411
private void UpdateLocalBranches ( )
405
412
{
406
- cacheContainer . BranchCache . LocalBranches = cacheContainer . BranchCache . LocalConfigBranches . Values . Select ( GetLocalGitBranch ) . ToArray ( ) ;
413
+ cacheContainer . BranchCache . LocalBranches = cacheContainer
414
+ . BranchCache . LocalConfigBranches . Values . Select ( GetLocalGitBranch ) . ToArray ( ) ;
407
415
}
408
416
409
417
private void UpdateRepositoryInfo ( )
@@ -424,42 +432,34 @@ private void UpdateRepositoryInfo()
424
432
425
433
private void RepositoryManager_OnLocalBranchRemoved ( string name )
426
434
{
427
- new ActionTask ( CancellationToken . None , ( ) =>
428
- {
435
+ new ActionTask ( CancellationToken . None , ( ) => {
429
436
cacheContainer . BranchCache . RemoveLocalBranch ( name ) ;
430
437
UpdateLocalBranches ( ) ;
431
- } )
432
- { Affinity = TaskAffinity . UI } . Start ( ) ;
438
+ } ) { Affinity = TaskAffinity . UI } . Start ( ) ;
433
439
}
434
440
435
441
private void RepositoryManager_OnLocalBranchAdded ( string name )
436
442
{
437
- new ActionTask ( CancellationToken . None , ( ) =>
438
- {
443
+ new ActionTask ( CancellationToken . None , ( ) => {
439
444
cacheContainer . BranchCache . AddLocalBranch ( name ) ;
440
445
UpdateLocalBranches ( ) ;
441
- } )
442
- { Affinity = TaskAffinity . UI } . Start ( ) ;
446
+ } ) { Affinity = TaskAffinity . UI } . Start ( ) ;
443
447
}
444
448
445
449
private void RepositoryManager_OnRemoteBranchAdded ( string remote , string name )
446
450
{
447
- new ActionTask ( CancellationToken . None , ( ) =>
448
- {
451
+ new ActionTask ( CancellationToken . None , ( ) => {
449
452
cacheContainer . BranchCache . AddRemoteBranch ( remote , name ) ;
450
453
UpdateRemoteAndRemoteBranches ( ) ;
451
- } )
452
- { Affinity = TaskAffinity . UI } . Start ( ) ;
454
+ } ) { Affinity = TaskAffinity . UI } . Start ( ) ;
453
455
}
454
456
455
457
private void RepositoryManager_OnRemoteBranchRemoved ( string remote , string name )
456
458
{
457
- new ActionTask ( CancellationToken . None , ( ) =>
458
- {
459
+ new ActionTask ( CancellationToken . None , ( ) => {
459
460
cacheContainer . BranchCache . RemoveRemoteBranch ( remote , name ) ;
460
461
UpdateRemoteAndRemoteBranches ( ) ;
461
- } )
462
- { Affinity = TaskAffinity . UI } . Start ( ) ;
462
+ } ) { Affinity = TaskAffinity . UI } . Start ( ) ;
463
463
}
464
464
465
465
private GitBranch GetLocalGitBranch ( ConfigBranch x )
@@ -468,14 +468,14 @@ private GitBranch GetLocalGitBranch(ConfigBranch x)
468
468
var trackingName = x . IsTracking ? x . Remote . Value . Name + "/" + name : "[None]" ;
469
469
var isActive = name == CurrentBranchName ;
470
470
471
- return new GitBranch { Name = name , Tracking = trackingName , IsActive = isActive } ;
471
+ return new GitBranch { Name = name , Tracking = trackingName , IsActive = isActive } ;
472
472
}
473
473
474
474
private static GitBranch GetRemoteGitBranch ( ConfigBranch x )
475
475
{
476
476
var name = x . Remote . Value . Name + "/" + x . Name ;
477
477
478
- return new GitBranch { Name = name } ;
478
+ return new GitBranch { Name = name } ;
479
479
}
480
480
481
481
private static GitRemote GetGitRemote ( ConfigRemote configRemote )
@@ -509,16 +509,16 @@ public GitStatus CurrentStatus
509
509
510
510
public GitBranch ? CurrentBranch
511
511
{
512
- get { return cacheContainer . BranchCache . CurentGitBranch ; }
513
- set { cacheContainer . BranchCache . CurentGitBranch = value ; }
512
+ get { return cacheContainer . RepositoryInfoCache . CurentGitBranch ; }
513
+ set { cacheContainer . RepositoryInfoCache . CurentGitBranch = value ; }
514
514
}
515
515
516
516
public string CurrentBranchName => CurrentConfigBranch ? . Name ;
517
517
518
518
public GitRemote ? CurrentRemote
519
519
{
520
- get { return cacheContainer . BranchCache . CurrentGitRemote ; }
521
- set { cacheContainer . BranchCache . CurrentGitRemote = value ; }
520
+ get { return cacheContainer . RepositoryInfoCache . CurrentGitRemote ; }
521
+ set { cacheContainer . RepositoryInfoCache . CurrentGitRemote = value ; }
522
522
}
523
523
524
524
public List < GitLogEntry > CurrentLog
@@ -541,18 +541,14 @@ public List<GitLock> CurrentLocks
541
541
542
542
public string Owner => CloneUrl ? . Owner ?? null ;
543
543
544
- public bool IsGitHub { get { return HostAddress . IsGitHubDotCom ( CloneUrl ) ; } }
544
+ public bool IsGitHub
545
+ {
546
+ get { return HostAddress . IsGitHubDotCom ( CloneUrl ) ; }
547
+ }
545
548
546
- internal string DebuggerDisplay => String . Format (
547
- CultureInfo . InvariantCulture ,
548
- "{0} Owner: {1} Name: {2} CloneUrl: {3} LocalPath: {4} Branch: {5} Remote: {6}" ,
549
- GetHashCode ( ) ,
550
- Owner ,
551
- Name ,
552
- CloneUrl ,
553
- LocalPath ,
554
- CurrentBranch ,
555
- CurrentRemote ) ;
549
+ internal string DebuggerDisplay => String . Format ( CultureInfo . InvariantCulture ,
550
+ "{0} Owner: {1} Name: {2} CloneUrl: {3} LocalPath: {4} Branch: {5} Remote: {6}" , GetHashCode ( ) , Owner , Name ,
551
+ CloneUrl , LocalPath , CurrentBranch , CurrentRemote ) ;
556
552
557
553
public IUser User { get ; set ; }
558
554
@@ -582,4 +578,4 @@ public struct CacheUpdateEvent
582
578
{
583
579
public string UpdatedTimeString ;
584
580
}
585
- }
581
+ }
0 commit comments