@@ -8,8 +8,6 @@ namespace GitHub.Unity
8
8
{
9
9
public interface IGitClient
10
10
{
11
- event Action < CacheUpdateEvent > CurrentUserChanged ;
12
-
13
11
Task < NPath > FindGitInstallation ( ) ;
14
12
ITask < ValidateGitInstallResult > ValidateGitInstall ( NPath path ) ;
15
13
@@ -25,6 +23,8 @@ ITask<string> GetConfig(string key, GitConfigSource configSource,
25
23
ITask < string > SetConfig ( string key , string value , GitConfigSource configSource ,
26
24
IOutputProcessor < string > processor = null ) ;
27
25
26
+ ITask < GitUser > GetConfigUserAndEmail ( ) ;
27
+
28
28
ITask < List < GitLock > > ListLocks ( bool local ,
29
29
BaseOutputListProcessor < GitLock > processor = null ) ;
30
30
@@ -84,11 +84,7 @@ ITask<string> Unlock(string file, bool force,
84
84
85
85
ITask < Version > LfsVersion ( IOutputProcessor < Version > processor = null ) ;
86
86
87
- void SetConfigUserAndEmail ( string username , string email ) ;
88
-
89
- void CheckUserChangedEvent ( CacheUpdateEvent gitLogCacheUpdateEvent ) ;
90
-
91
- User CurrentUser { get ; }
87
+ ITask < GitUser > SetConfigNameAndEmail ( string username , string email ) ;
92
88
}
93
89
94
90
class GitClient : IGitClient
@@ -100,51 +96,14 @@ class GitClient : IGitClient
100
96
private readonly ITaskManager taskManager ;
101
97
private readonly CancellationToken cancellationToken ;
102
98
103
- public event Action < CacheUpdateEvent > CurrentUserChanged ;
104
- private bool cacheInitialized ;
105
-
106
99
public GitClient ( IEnvironment environment , IProcessManager processManager , ITaskManager taskManager )
107
100
{
108
- Logger . Trace ( "Constructed" ) ;
109
-
110
101
this . environment = environment ;
111
102
this . processManager = processManager ;
112
103
this . taskManager = taskManager ;
113
104
this . cancellationToken = taskManager . Token ;
114
105
}
115
106
116
- public void CheckUserChangedEvent ( CacheUpdateEvent cacheUpdateEvent )
117
- {
118
- var managedCache = environment . CacheContainer . GitUserCache ;
119
- var raiseEvent = managedCache . ShouldRaiseCacheEvent ( cacheUpdateEvent ) ;
120
-
121
- Logger . Trace ( "Check GitUserCache CacheUpdateEvent Current:{0} Check:{1} Result:{2}" , managedCache . LastUpdatedAt ,
122
- cacheUpdateEvent . UpdatedTimeString ?? "[NULL]" , raiseEvent ) ;
123
-
124
- if ( raiseEvent )
125
- {
126
- var dateTimeOffset = managedCache . LastUpdatedAt ;
127
- var updateEvent = new CacheUpdateEvent { UpdatedTimeString = dateTimeOffset . ToString ( ) } ;
128
- HandleGitLogCacheUpdatedEvent ( updateEvent ) ;
129
- }
130
- }
131
-
132
- public User CurrentUser
133
- {
134
- get
135
- {
136
- if ( ! cacheInitialized )
137
- {
138
- cacheInitialized = true ;
139
- environment . CacheContainer . GitUserCache . CacheInvalidated += GitUserCacheOnCacheInvalidated ;
140
- environment . CacheContainer . GitUserCache . CacheUpdated += GitUserCacheOnCacheUpdated ;
141
- }
142
-
143
- return environment . CacheContainer . GitUserCache . User ;
144
- }
145
- private set { environment . CacheContainer . GitUserCache . User = value ; }
146
- }
147
-
148
107
public async Task < NPath > FindGitInstallation ( )
149
108
{
150
109
if ( ! String . IsNullOrEmpty ( environment . GitExecutablePath ) )
@@ -300,12 +259,35 @@ public ITask<string> SetConfig(string key, string value, GitConfigSource configS
300
259
. Configure ( processManager ) ;
301
260
}
302
261
303
- public void SetConfigUserAndEmail ( string username , string email )
262
+ public ITask < GitUser > GetConfigUserAndEmail ( )
263
+ {
264
+ string username = null ;
265
+ string email = null ;
266
+
267
+ return GetConfig ( UserNameConfigKey , GitConfigSource . User )
268
+ . Then ( ( success , value ) => {
269
+ if ( success )
270
+ {
271
+ username = value ;
272
+ }
273
+ } )
274
+ . Then ( GetConfig ( UserEmailConfigKey , GitConfigSource . User )
275
+ . Then ( ( success , value ) => {
276
+ if ( success )
277
+ {
278
+ email = value ;
279
+ }
280
+ } ) ) . Then ( success => {
281
+ Logger . Trace ( "{0}:{1} {2}:{3}" , UserNameConfigKey , username , UserEmailConfigKey , email ) ;
282
+ return new GitUser ( username , email ) ;
283
+ } ) ;
284
+ }
285
+
286
+ public ITask < GitUser > SetConfigNameAndEmail ( string username , string email )
304
287
{
305
- SetConfig ( UserNameConfigKey , username , GitConfigSource . User )
288
+ return SetConfig ( UserNameConfigKey , username , GitConfigSource . User )
306
289
. Then ( SetConfig ( UserEmailConfigKey , email , GitConfigSource . User ) )
307
- . Then ( UpdateUserAndEmail )
308
- . Start ( ) ;
290
+ . Then ( b => new GitUser ( username , email ) ) ;
309
291
}
310
292
311
293
public ITask < List < GitLock > > ListLocks ( bool local , BaseOutputListProcessor < GitLock > processor = null )
@@ -480,54 +462,28 @@ public ITask<string> Unlock(string file, bool force,
480
462
. Configure ( processManager ) ;
481
463
}
482
464
483
- private void GitUserCacheOnCacheUpdated ( DateTimeOffset timeOffset )
484
- {
485
- HandleGitLogCacheUpdatedEvent ( new CacheUpdateEvent
486
- {
487
- UpdatedTimeString = timeOffset . ToString ( )
488
- } ) ;
489
- }
465
+ protected static ILogging Logger { get ; } = Logging . GetLogger < GitClient > ( ) ;
466
+ }
490
467
491
- private void GitUserCacheOnCacheInvalidated ( )
492
- {
493
- Logger . Trace ( "GitUserCache Invalidated" ) ;
494
- UpdateUserAndEmail ( ) ;
495
- }
496
-
497
- private void HandleGitLogCacheUpdatedEvent ( CacheUpdateEvent cacheUpdateEvent )
498
- {
499
- Logger . Trace ( "GitUserCache Updated {0}" , cacheUpdateEvent . UpdatedTimeString ) ;
500
- CurrentUserChanged ? . Invoke ( cacheUpdateEvent ) ;
501
- }
468
+ public struct GitUser
469
+ {
470
+ public static GitUser Default = new GitUser ( ) ;
502
471
503
- private void UpdateUserAndEmail ( )
504
- {
505
- Logger . Trace ( "UpdateUserAndEmail" ) ;
472
+ public string name ;
473
+ public string email ;
506
474
507
- string username = null ;
508
- string email = null ;
475
+ public string Name { get { return name ; } }
476
+ public string Email { get { return email ; } }
509
477
510
- GetConfig ( UserNameConfigKey , GitConfigSource . User )
511
- . Then ( ( success , value ) => {
512
- if ( success )
513
- {
514
- username = value ;
515
- }
516
- } )
517
- . Then ( GetConfig ( UserEmailConfigKey , GitConfigSource . User )
518
- . Then ( ( success , value ) => {
519
- if ( success )
520
- {
521
- email = value ;
522
- }
523
- } ) ) . ThenInUI ( success => {
524
- CurrentUser = new User {
525
- Name = username ,
526
- Email = email
527
- } ;
528
- } ) . Start ( ) ;
478
+ public GitUser ( string name , string email )
479
+ {
480
+ this . name = name ;
481
+ this . email = email ;
529
482
}
530
483
531
- protected static ILogging Logger { get ; } = Logging . GetLogger < GitClient > ( ) ;
484
+ public override string ToString ( )
485
+ {
486
+ return $ "Name:\" { Name } \" Email:\" { Email } \" ";
487
+ }
532
488
}
533
489
}
0 commit comments