Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit e701430

Browse files
Merge branch 'master' into enhancements/using-cache-invalidated-events
2 parents 9c95f34 + 9268a4d commit e701430

File tree

9 files changed

+61
-178
lines changed

9 files changed

+61
-178
lines changed

src/GitHub.Api/Cache/CacheInterfaces.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public interface ILocalConfigBranchDictionary : IDictionary<string, ConfigBranch
6262

6363
}
6464

65-
public interface IRemoteConfigBranchDictionary : IDictionary<string, IDictionary<string, ConfigBranch>>
65+
public interface IRemoteConfigBranchDictionary : IDictionary<string, Dictionary<string, ConfigBranch>>
6666
{
6767

6868
}

src/GitHub.Api/Git/GitClient.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ ITask<string> Unlock(string file, bool force,
8383
ITask<Version> Version(IOutputProcessor<Version> processor = null);
8484

8585
ITask<Version> LfsVersion(IOutputProcessor<Version> processor = null);
86+
87+
ITask<User> SetConfigUserAndEmail(string username, string email);
8688
}
8789

8890
class GitClient : IGitClient
8991
{
92+
private const string UserNameConfigKey = "user.name";
93+
private const string UserEmailConfigKey = "user.email";
9094
private readonly IEnvironment environment;
9195
private readonly IProcessManager processManager;
9296
private readonly ITaskManager taskManager;
@@ -260,23 +264,30 @@ public ITask<User> GetConfigUserAndEmail()
260264
string username = null;
261265
string email = null;
262266

263-
return GetConfig("user.name", GitConfigSource.User)
267+
return GetConfig(UserNameConfigKey, GitConfigSource.User)
264268
.Then((success, value) => {
265269
if (success)
266270
{
267271
username = value;
268272
}
269273
})
270-
.Then(GetConfig("user.email", GitConfigSource.User)
274+
.Then(GetConfig(UserEmailConfigKey, GitConfigSource.User)
271275
.Then((success, value) => {
272276
if (success)
273277
{
274278
email = value;
275279
}
276280
})).Then(success => {
277-
Logger.Trace("{0}:{1} {2}:{3}", "user.name", username, "user.email", email);
278-
return new User { Name= username, Email = email };
279-
});
281+
Logger.Trace("{0}:{1} {2}:{3}", UserNameConfigKey, username, UserEmailConfigKey, email);
282+
return new User { Name = username, Email = email };
283+
});
284+
}
285+
286+
public ITask<User> SetConfigUserAndEmail(string username, string email)
287+
{
288+
return SetConfig(UserNameConfigKey, username, GitConfigSource.User)
289+
.Then(SetConfig(UserEmailConfigKey, email, GitConfigSource.User))
290+
.Then(b => new User { Name = username, Email = email });
280291
}
281292

282293
public ITask<List<GitLock>> ListLocks(bool local, BaseOutputListProcessor<GitLock> processor = null)

src/GitHub.Api/Git/Repository.cs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ private void RepositoryManager_OnCurrentBranchAndRemoteUpdated(ConfigBranch? bra
445445
{
446446
CurrentConfigRemote = remote;
447447
CurrentRemote = GetGitRemote(remote.Value);
448-
UpdateRepositoryInfo();
448+
ClearRepositoryInfo();
449449
}
450450
}) { Affinity = TaskAffinity.UI }.Start();
451451
}
@@ -488,20 +488,10 @@ private void UpdateLocalBranches()
488488
LocalBranches = LocalConfigBranches.Values.Select(GetLocalGitBranch).ToArray();
489489
}
490490

491-
private void UpdateRepositoryInfo()
491+
private void ClearRepositoryInfo()
492492
{
493-
if (CurrentRemote.HasValue)
494-
{
495-
CloneUrl = new UriString(CurrentRemote.Value.Url);
496-
Name = CloneUrl.RepositoryName;
497-
Logger.Trace("CloneUrl: {0}", CloneUrl.ToString());
498-
}
499-
else
500-
{
501-
CloneUrl = null;
502-
Name = LocalPath.FileName;
503-
Logger.Trace("CloneUrl: [NULL]");
504-
}
493+
CloneUrl = null;
494+
Name = null;
505495
}
506496

507497
private void RepositoryManager_OnLocalBranchRemoved(string name)

src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs

Lines changed: 2 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -378,106 +378,6 @@ public void OnAfterDeserialize()
378378
Add(remote, branchesDictionary);
379379
}
380380
}
381-
382-
IEnumerator<KeyValuePair<string, IDictionary<string, ConfigBranch>>> IEnumerable<KeyValuePair<string, IDictionary<string, ConfigBranch>>>.GetEnumerator()
383-
{
384-
throw new NotImplementedException();
385-
//return AsDictionary
386-
// .Select(pair => new KeyValuePair<string, IDictionary<string, ConfigBranch>>(pair.Key, pair.Value.AsDictionary))
387-
// .GetEnumerator();
388-
}
389-
390-
void ICollection<KeyValuePair<string, IDictionary<string, ConfigBranch>>>.Add(KeyValuePair<string, IDictionary<string, ConfigBranch>> item)
391-
{
392-
throw new NotImplementedException();
393-
//Guard.ArgumentNotNull(item, "item");
394-
//Guard.ArgumentNotNull(item.Value, "item.Value");
395-
//
396-
//var serializableDictionary = item.Value as SerializableDictionary<string, ConfigBranch>;
397-
//if (serializableDictionary == null)
398-
//{
399-
// serializableDictionary = new SerializableDictionary<string, ConfigBranch>(item.Value);
400-
//}
401-
//
402-
//Add(item.Key, serializableDictionary);
403-
}
404-
405-
bool ICollection<KeyValuePair<string, IDictionary<string, ConfigBranch>>>.Contains(KeyValuePair<string, IDictionary<string, ConfigBranch>> item)
406-
{
407-
throw new NotImplementedException();
408-
}
409-
410-
void ICollection<KeyValuePair<string, IDictionary<string, ConfigBranch>>>.CopyTo(KeyValuePair<string, IDictionary<string, ConfigBranch>>[] array, int arrayIndex)
411-
{
412-
throw new NotImplementedException();
413-
}
414-
415-
bool ICollection<KeyValuePair<string, IDictionary<string, ConfigBranch>>>.Remove(KeyValuePair<string, IDictionary<string, ConfigBranch>> item)
416-
{
417-
throw new NotImplementedException();
418-
}
419-
420-
bool ICollection<KeyValuePair<string, IDictionary<string, ConfigBranch>>>.IsReadOnly
421-
{
422-
get { throw new NotImplementedException(); }
423-
}
424-
425-
void IDictionary<string, IDictionary<string, ConfigBranch>>.Add(string key, IDictionary<string, ConfigBranch> value)
426-
{
427-
throw new NotImplementedException();
428-
}
429-
430-
bool IDictionary<string, IDictionary<string, ConfigBranch>>.TryGetValue(string key, out IDictionary<string, ConfigBranch> value)
431-
{
432-
value = null;
433-
434-
Dictionary<string, ConfigBranch> branches;
435-
if (TryGetValue(key, out branches))
436-
{
437-
value = branches;
438-
return true;
439-
}
440-
441-
return false;
442-
}
443-
444-
IDictionary<string, ConfigBranch> IDictionary<string, IDictionary<string, ConfigBranch>>.this[string key]
445-
{
446-
get
447-
{
448-
throw new NotImplementedException();
449-
//var dictionary = (IDictionary<string, IDictionary<string, ConfigBranch>>)this;
450-
//IDictionary<string, ConfigBranch> value;
451-
//if (!dictionary.TryGetValue(key, out value))
452-
//{
453-
// throw new KeyNotFoundException();
454-
//}
455-
//
456-
//return value;
457-
}
458-
set
459-
{
460-
throw new NotImplementedException();
461-
//var dictionary = (IDictionary<string, IDictionary<string, ConfigBranch>>)this;
462-
//dictionary.Add(key, value);
463-
}
464-
}
465-
466-
ICollection<string> IDictionary<string, IDictionary<string, ConfigBranch>>.Keys
467-
{
468-
get
469-
{
470-
throw new NotImplementedException();
471-
}
472-
}
473-
474-
ICollection<IDictionary<string, ConfigBranch>> IDictionary<string, IDictionary<string, ConfigBranch>>.Values
475-
{
476-
get
477-
{
478-
return Values.Cast<IDictionary<string,ConfigBranch>>().ToArray();
479-
}
480-
}
481381
}
482382

483383
[Serializable]
@@ -770,7 +670,7 @@ public void AddLocalBranch(string branch)
770670

771671
public void AddRemoteBranch(string remote, string branch)
772672
{
773-
IDictionary<string, ConfigBranch> branchList;
673+
Dictionary<string, ConfigBranch> branchList;
774674
if (RemoteConfigBranches.TryGetValue(remote, out branchList))
775675
{
776676
if (!branchList.ContainsKey(branch))
@@ -793,7 +693,7 @@ public void AddRemoteBranch(string remote, string branch)
793693

794694
public void RemoveRemoteBranch(string remote, string branch)
795695
{
796-
IDictionary<string, ConfigBranch> branchList;
696+
Dictionary<string, ConfigBranch> branchList;
797697
if (RemoteConfigBranches.TryGetValue(remote, out branchList))
798698
{
799699
if (branchList.ContainsKey(branch))

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,9 @@ private void RepositoryOnLocalAndRemoteBranchListChanged(CacheUpdateEvent cacheU
8888
{
8989
if (!lastLocalAndRemoteBranchListChangedEvent.Equals(cacheUpdateEvent))
9090
{
91-
new ActionTask(TaskManager.Token, () =>
92-
{
93-
lastLocalAndRemoteBranchListChangedEvent = cacheUpdateEvent;
94-
localAndRemoteBranchListHasUpdate = true;
95-
Redraw();
96-
})
97-
{ Affinity = TaskAffinity.UI }.Start();
91+
lastLocalAndRemoteBranchListChangedEvent = cacheUpdateEvent;
92+
localAndRemoteBranchListHasUpdate = true;
93+
Redraw();
9894
}
9995
}
10096

@@ -114,16 +110,11 @@ private void MaybeUpdateData()
114110

115111
private void AttachHandlers(IRepository repository)
116112
{
117-
if (repository == null)
118-
return;
119-
120113
repository.LocalAndRemoteBranchListChanged += RepositoryOnLocalAndRemoteBranchListChanged;
121114
}
122115

123116
private void DetachHandlers(IRepository repository)
124117
{
125-
if (repository == null)
126-
return;
127118

128119
repository.LocalAndRemoteBranchListChanged -= RepositoryOnLocalAndRemoteBranchListChanged;
129120
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/PopupWindow.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public override void OnDisable()
7070
public override void OnDataUpdate()
7171
{
7272
base.OnDataUpdate();
73+
if (titleContent.image == null)
74+
titleContent = new GUIContent(ActiveView.Title, Styles.SmallLogo);
7375
ActiveView.OnDataUpdate();
7476
}
7577

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ public override void OnEnable()
5151
userSettingsView.OnEnable();
5252
AttachHandlers(Repository);
5353

54-
if (Repository != null)
55-
{
56-
Repository.CheckCurrentRemoteChangedEvent(lastCurrentRemoteChangedEvent);
57-
Repository.CheckLocksChangedEvent(lastLocksChangedEvent);
58-
}
59-
54+
Repository.CheckCurrentRemoteChangedEvent(lastCurrentRemoteChangedEvent);
55+
Repository.CheckLocksChangedEvent(lastLocksChangedEvent);
6056
metricsHasChanged = true;
6157
}
6258

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/UserSettingsView.cs

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class UserSettingsView : Subview
2222
[SerializeField] private string gitEmail;
2323
[SerializeField] private string newGitName;
2424
[SerializeField] private string newGitEmail;
25+
[SerializeField] private bool needsSaving;
2526

2627
public override void InitializeView(IView parent)
2728
{
@@ -42,11 +43,17 @@ public override void OnGUI()
4243

4344
EditorGUI.BeginDisabledGroup(IsBusy || Parent.IsBusy);
4445
{
45-
newGitName = EditorGUILayout.TextField(GitConfigNameLabel, newGitName);
46-
newGitEmail = EditorGUILayout.TextField(GitConfigEmailLabel, newGitEmail);
46+
EditorGUI.BeginChangeCheck();
47+
{
48+
newGitName = EditorGUILayout.TextField(GitConfigNameLabel, newGitName);
49+
newGitEmail = EditorGUILayout.TextField(GitConfigEmailLabel, newGitEmail);
50+
}
4751

48-
var needsSaving = (newGitName != gitName || newGitEmail != gitEmail)
49-
&& !(string.IsNullOrEmpty(newGitName) || string.IsNullOrEmpty(newGitEmail));
52+
if (EditorGUI.EndChangeCheck())
53+
{
54+
needsSaving = !(string.IsNullOrEmpty(newGitName) || string.IsNullOrEmpty(newGitEmail))
55+
&& (newGitName != gitName || newGitEmail != gitEmail);
56+
}
5057

5158
EditorGUI.BeginDisabledGroup(!needsSaving);
5259
{
@@ -55,45 +62,28 @@ public override void OnGUI()
5562
GUI.FocusControl(null);
5663
isBusy = true;
5764

58-
GitClient.SetConfig("user.name", newGitName, GitConfigSource.User)
59-
.Then((success, value) =>
60-
{
65+
GitClient.SetConfigUserAndEmail(newGitName, newGitEmail)
66+
.FinallyInUI((success, exception, user) => {
67+
isBusy = false;
6168
if (success)
6269
{
6370
if (Repository != null)
6471
{
6572
Repository.User.Name = gitName = newGitName;
73+
Repository.User.Email = gitEmail = newGitEmail;
6674
}
6775
else
6876
{
6977
gitName = newGitName;
78+
gitEmail = newGitEmail;
7079
}
80+
81+
needsSaving = false;
82+
83+
Redraw();
84+
Finish(true);
7185
}
7286
})
73-
.Then(
74-
GitClient.SetConfig("user.email", newGitEmail, GitConfigSource.User)
75-
.Then((success, value) =>
76-
{
77-
if (success)
78-
{
79-
if (Repository != null)
80-
{
81-
Repository.User.Email = gitEmail = newGitEmail;
82-
}
83-
else
84-
{
85-
gitEmail = newGitEmail;
86-
}
87-
88-
userDataHasChanged = true;
89-
}
90-
}))
91-
.FinallyInUI((_, __) =>
92-
{
93-
isBusy = false;
94-
Redraw();
95-
Finish(true);
96-
})
9787
.Start();
9888
}
9989
}
@@ -122,6 +112,7 @@ private void MaybeUpdateData()
122112
{
123113
newGitName = gitName = Repository.User.Name;
124114
newGitEmail = gitEmail = Repository.User.Email;
115+
needsSaving = false;
125116
}
126117
}
127118
}
@@ -146,6 +137,7 @@ private void UpdateUserDataFromClient()
146137
{
147138
newGitName = gitName = user.Name;
148139
newGitEmail = gitEmail = user.Email;
140+
needsSaving = false;
149141
Redraw();
150142
}
151143
}).Start();

0 commit comments

Comments
 (0)