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

Commit

Permalink
Merge branch 'master' into fixes/refresh-status-and-log-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
shana authored Nov 10, 2017
2 parents 767b979 + e1f42ce commit 88469f6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 72 deletions.
36 changes: 19 additions & 17 deletions src/GitHub.Api/Git/GitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ITask<string> GetConfig(string key, GitConfigSource configSource,
ITask<string> SetConfig(string key, string value, GitConfigSource configSource,
IOutputProcessor<string> processor = null);

ITask<string[]> GetConfigUserAndEmail();
ITask<User> GetConfigUserAndEmail();

ITask<List<GitLock>> ListLocks(bool local,
BaseOutputListProcessor<GitLock> processor = null);
Expand Down Expand Up @@ -255,26 +255,28 @@ public ITask<string> SetConfig(string key, string value, GitConfigSource configS
.Configure(processManager);
}

public ITask<string[]> GetConfigUserAndEmail()
public ITask<User> GetConfigUserAndEmail()
{
string username = null;
string email = null;

return GetConfig("user.name", GitConfigSource.User).Then((success, value) => {
if (success)
{
username = value;
}

}).Then(GetConfig("user.email", GitConfigSource.User).Then((success, value) => {
if (success)
{
email = value;
}
})).Then(success => {
Logger.Trace("user.name:{1} user.email:{2}", success, username, email);
return new[] { username, email };
});
return GetConfig("user.name", GitConfigSource.User)
.Then((success, value) => {
if (success)
{
username = value;
}
})
.Then(GetConfig("user.email", GitConfigSource.User)
.Then((success, value) => {
if (success)
{
email = value;
}
})).Then(success => {
Logger.Trace("{0}:{1} {2}:{3}", "user.name", username, "user.email", email);
return new User { Name= username, Email = email };
});
}

public ITask<List<GitLock>> ListLocks(bool local, BaseOutputListProcessor<GitLock> processor = null)
Expand Down
11 changes: 1 addition & 10 deletions src/GitHub.Api/Git/RepositoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,9 @@ public ITask UnlockFile(string file, bool force)
private void LoadGitUser()
{
GitClient.GetConfigUserAndEmail()
.Then((success, strings) => {
var username = strings[0];
var email = strings[1];

var user = new User {
Name = username,
Email = email
};

.Then((success, user) => {
Logger.Trace("OnGitUserLoaded: {0}", user);
OnGitUserLoaded?.Invoke(user);

}).Start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,9 @@ private void CheckForUser()
Logger.Trace("Checking for user");
isBusy = true;

GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, strings) => {
var username = strings[0];
var email = strings[1];

GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, user) => {
isBusy = false;
isUserDataPresent = success && !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(email);
isUserDataPresent = success && !String.IsNullOrEmpty(user.Name) && !String.IsNullOrEmpty(user.Email);
hasCompletedInitialCheck = true;

Logger.Trace("User Present: {0}", isUserDataPresent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class UserSettingsView : Subview
[SerializeField] private string gitEmail;
[SerializeField] private string newGitName;
[SerializeField] private string newGitEmail;
[SerializeField] private User cachedUser;

public override void InitializeView(IView parent)
{
Expand Down Expand Up @@ -63,15 +62,11 @@ public override void OnGUI()
{
if (Repository != null)
{
Repository.User.Name = newGitName;
Repository.User.Name = gitName = newGitName;
}
else
{
if (cachedUser == null)
{
cachedUser = new User();
}
cachedUser.Name = newGitName;
gitName = newGitName;
}
}
})
Expand All @@ -83,11 +78,11 @@ public override void OnGUI()
{
if (Repository != null)
{
Repository.User.Email = newGitEmail;
Repository.User.Email = gitEmail = newGitEmail;
}
else
{
cachedUser.Email = newGitEmail;
gitEmail = newGitEmail;
}

userDataHasChanged = true;
Expand All @@ -107,49 +102,53 @@ public override void OnGUI()
EditorGUI.EndDisabledGroup();
}

public override void OnEnable()
{
base.OnEnable();
userDataHasChanged = true;
}

private void MaybeUpdateData()
{
if (Repository == null)
if (userDataHasChanged)
{
if (!String.IsNullOrEmpty(EntryPoint.Environment.GitExecutablePath))
userDataHasChanged = false;

if (Repository == null)
{
if ((cachedUser == null || String.IsNullOrEmpty(cachedUser.Name)) && GitClient != null)
{
GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, strings) => {
var username = strings[0];
var email = strings[1];

if (success && !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(email))
{
cachedUser = new User {
Name = username,
Email = email
};

userDataHasChanged = true;
Redraw();
}
}).Start();
}
UpdateUserDataFromClient();
}

if (userDataHasChanged)
else
{
newGitName = gitName = cachedUser.Name;
newGitEmail = gitEmail = cachedUser.Email;
userDataHasChanged = false;
newGitName = gitName = Repository.User.Name;
newGitEmail = gitEmail = Repository.User.Email;
}
return;
}
}

userDataHasChanged = Repository.User.Name != gitName || Repository.User.Email != gitEmail;
private void UpdateUserDataFromClient()
{
if (String.IsNullOrEmpty(EntryPoint.Environment.GitExecutablePath))
{
return;
}

if (!userDataHasChanged)
if (GitClient == null)
{
return;
}

Logger.Trace("Update user data from GitClient");

userDataHasChanged = false;
newGitName = gitName = Repository.User.Name;
newGitEmail = gitEmail = Repository.User.Email;
GitClient.GetConfigUserAndEmail()
.ThenInUI((success, user) => {
if (success && !String.IsNullOrEmpty(user.Name) && !String.IsNullOrEmpty(user.Email))
{
newGitName = gitName = user.Name;
newGitEmail = gitEmail = user.Email;
Redraw();
}
}).Start();
}

public override bool IsBusy
Expand Down

0 comments on commit 88469f6

Please sign in to comment.