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

Commit 8b2312c

Browse files
committed
* Merge from master
2 parents f0f7d55 + c7cf943 commit 8b2312c

File tree

11 files changed

+170
-153
lines changed

11 files changed

+170
-153
lines changed

common/SolutionInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
namespace System
3232
{
3333
internal static class AssemblyVersionInformation {
34-
internal const string Version = "0.17.0.0";
34+
internal const string Version = "0.18.0.0";
3535
}
3636
}

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ private async Task LogoutInternal(UriString host)
6161
public async Task CreateRepository(NewRepository newRepository, Action<Octokit.Repository, Exception> callback, string organization = null)
6262
{
6363
Guard.ArgumentNotNull(callback, "callback");
64-
await CreateRepositoryInternal(newRepository, callback, organization);
64+
try
65+
{
66+
var repository = await CreateRepositoryInternal(newRepository, organization);
67+
callback(repository, null);
68+
}
69+
catch (Exception e)
70+
{
71+
callback(null, e);
72+
}
6573
}
6674

6775
public async Task GetOrganizations(Action<IList<Organization>> callback)
@@ -71,6 +79,13 @@ public async Task GetOrganizations(Action<IList<Organization>> callback)
7179
callback(organizations);
7280
}
7381

82+
public async Task LoadKeychain(Action<bool> callback)
83+
{
84+
Guard.ArgumentNotNull(callback, "callback");
85+
var hasLoadedKeys = await LoadKeychainInternal();
86+
callback(hasLoadedKeys);
87+
}
88+
7489
public async Task GetCurrentUser(Action<Octokit.User> callback)
7590
{
7691
Guard.ArgumentNotNull(callback, "callback");
@@ -174,16 +189,15 @@ public async Task<bool> ContinueLoginAsync(LoginResult loginResult, Func<LoginRe
174189
return result.Code == LoginResultCodes.Success;
175190
}
176191

177-
private async Task CreateRepositoryInternal(NewRepository newRepository, Action<Octokit.Repository, Exception> callback, string organization)
192+
private async Task<Octokit.Repository> CreateRepositoryInternal(NewRepository newRepository, string organization)
178193
{
179194
try
180195
{
181196
logger.Trace("Creating repository");
182197

183-
if (!await EnsureKeychainLoaded())
198+
if (!await LoadKeychainInternal())
184199
{
185-
callback(null, new Exception("Keychain Not Loaded"));
186-
return;
200+
throw new InvalidOperationException("The keychain did not load");
187201
}
188202

189203
Octokit.Repository repository;
@@ -201,13 +215,12 @@ private async Task CreateRepositoryInternal(NewRepository newRepository, Action<
201215
}
202216

203217
logger.Trace("Created Repository");
204-
205-
callback(repository, null);
218+
return repository;
206219
}
207220
catch (Exception ex)
208221
{
209222
logger.Error(ex, "Error Creating Repository");
210-
callback(null, ex);
223+
throw;
211224
}
212225
}
213226

@@ -217,9 +230,9 @@ private async Task<IList<Organization>> GetOrganizationInternal()
217230
{
218231
logger.Trace("Getting Organizations");
219232

220-
if (!await EnsureKeychainLoaded())
233+
if (!await LoadKeychainInternal())
221234
{
222-
return null;
235+
return new List<Organization>();
223236
}
224237

225238
var organizations = await githubClient.Organization.GetAllForCurrent();
@@ -246,7 +259,7 @@ private async Task<IList<Organization>> GetOrganizationInternal()
246259
{
247260
logger.Trace("Getting Organizations");
248261

249-
if (!await EnsureKeychainLoaded())
262+
if (!await LoadKeychainInternal())
250263
{
251264
return null;
252265
}
@@ -262,27 +275,28 @@ private async Task<IList<Organization>> GetOrganizationInternal()
262275
return userCache;
263276
}
264277

265-
private async Task<bool> EnsureKeychainLoaded()
278+
private async Task<bool> LoadKeychainInternal()
266279
{
267-
logger.Trace("EnsureKeychainLoaded");
280+
logger.Trace("LoadKeychainInternal");
268281

269282
if (keychain.HasKeys)
270283
{
271284
if (!keychain.NeedsLoad)
272285
{
273-
logger.Trace("EnsureKeychainLoaded: Has keys does not need load");
286+
logger.Trace("LoadKeychainInternal: Has keys does not need load");
274287
return true;
275288
}
276289

277-
logger.Trace("EnsureKeychainLoaded: Loading");
290+
logger.Trace("LoadKeychainInternal: Loading");
278291

292+
//TODO: ONE_USER_LOGIN This assumes only ever one user can login
279293
var uriString = keychain.Connections.First().Host;
280294
var keychainAdapter = await keychain.Load(uriString);
281295

282296
return keychainAdapter.OctokitCredentials != Credentials.Anonymous;
283297
}
284298

285-
logger.Trace("EnsureKeychainLoaded: No keys to load");
299+
logger.Trace("LoadKeychainInternal: No keys to load");
286300

287301
return false;
288302
}

src/GitHub.Api/Application/IApiClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ interface IApiClient
1717
Task<bool> ValidateCredentials();
1818
Task Logout(UriString host);
1919
Task GetCurrentUser(Action<Octokit.User> callback);
20+
Task LoadKeychain(Action<bool> callback);
2021
}
2122
}

src/GitHub.Api/Git/Tasks/GitCommitTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public GitCommitTask(string message, string body,
1515
Guard.ArgumentNotNullOrWhiteSpace(message, "message");
1616

1717
Name = TaskName;
18-
arguments = "commit ";
18+
arguments = "-c i18n.commitencoding=utf8 commit ";
1919
arguments += String.Format(" -m \"{0}\"", message);
2020
if (!String.IsNullOrEmpty(body))
2121
arguments += String.Format(" -m \"{0}\"", body);

src/GitHub.Api/Git/Tasks/GitLogTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public GitLogTask(IGitObjectFactory gitObjectFactory,
1515

1616
public override string ProcessArguments
1717
{
18-
get { return @"log --pretty=format:""%H%n%P%n%aN%n%aE%n%aI%n%cN%n%cE%n%cI%n%B---GHUBODYEND---"" --name-status"; }
18+
get { return @"-c i18n.logoutputencoding=utf8 -c core.quotepath=false log --pretty=format:""%H%n%P%n%aN%n%aE%n%aI%n%cN%n%cE%n%cI%n%B---GHUBODYEND---"" --name-status"; }
1919
}
2020
}
2121
}

src/GitHub.Api/Git/Tasks/GitStatusTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public GitStatusTask(IGitObjectFactory gitObjectFactory,
1515

1616
public override string ProcessArguments
1717
{
18-
get { return "status -b -u --ignored --porcelain"; }
18+
get { return "-c i18n.logoutputencoding=utf8 -c core.quotepath=false status -b -u --ignored --porcelain"; }
1919
}
2020
public override TaskAffinity Affinity { get { return TaskAffinity.Exclusive; } }
2121
}

src/GitHub.Api/NewTaskSystem/ProcessTask.cs

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ class ProcessWrapper
5656
private readonly Action onEnd;
5757
private readonly Action<Exception, string> onError;
5858
private readonly CancellationToken token;
59-
private readonly List<string> errors = new List<string>();
6059

6160
public Process Process { get; }
6261
public StreamWriter Input { get; private set; }
@@ -78,39 +77,6 @@ public ProcessWrapper(Process process, IOutputProcessor outputProcessor,
7877

7978
public void Run()
8079
{
81-
if (Process.StartInfo.RedirectStandardOutput)
82-
{
83-
Process.OutputDataReceived += (s, e) =>
84-
{
85-
//Logger.Trace("OutputData \"" + (e.Data == null ? "'null'" : e.Data) + "\"");
86-
87-
string encodedData = null;
88-
if (e.Data != null)
89-
{
90-
encodedData = Encoding.UTF8.GetString(Encoding.Default.GetBytes(e.Data));
91-
}
92-
outputProcessor.LineReceived(encodedData);
93-
};
94-
}
95-
96-
if (Process.StartInfo.RedirectStandardError)
97-
{
98-
Process.ErrorDataReceived += (s, e) =>
99-
{
100-
//if (e.Data != null)
101-
//{
102-
// Logger.Trace("ErrorData \"" + (e.Data == null ? "'null'" : e.Data) + "\"");
103-
//}
104-
105-
string encodedData = null;
106-
if (e.Data != null)
107-
{
108-
encodedData = Encoding.UTF8.GetString(Encoding.Default.GetBytes(e.Data));
109-
errors.Add(encodedData);
110-
}
111-
};
112-
}
113-
11480
try
11581
{
11682
Process.Start();
@@ -133,34 +99,65 @@ public void Run()
13399
return;
134100
}
135101

136-
if (Process.StartInfo.RedirectStandardOutput)
137-
Process.BeginOutputReadLine();
138-
if (Process.StartInfo.RedirectStandardError)
139-
Process.BeginErrorReadLine();
140102
if (Process.StartInfo.RedirectStandardInput)
141103
Input = new StreamWriter(Process.StandardInput.BaseStream, new UTF8Encoding(false));
142104

143-
onStart?.Invoke();
105+
var errors = new List<string>();
144106

107+
onStart?.Invoke();
145108
if (Process.StartInfo.CreateNoWindow)
146109
{
147-
while (!WaitForExit(500))
110+
if (Process.StartInfo.RedirectStandardOutput)
148111
{
149-
if (token.IsCancellationRequested)
112+
var outputStream = Process.StandardOutput;
113+
var line = outputStream.ReadLine();
114+
while (line != null)
150115
{
151-
if (!Process.HasExited)
152-
Process.Kill();
153-
Process.Close();
154-
onEnd?.Invoke();
155-
token.ThrowIfCancellationRequested();
116+
outputProcessor.LineReceived(line);
117+
118+
if (token.IsCancellationRequested)
119+
{
120+
if (!Process.HasExited)
121+
Process.Kill();
122+
123+
Process.Close();
124+
onEnd?.Invoke();
125+
token.ThrowIfCancellationRequested();
126+
}
127+
128+
line = outputStream.ReadLine();
156129
}
130+
outputProcessor.LineReceived(null);
157131
}
158132

159-
if (Process.ExitCode != 0 && errors.Count > 0)
133+
if (Process.StartInfo.RedirectStandardError)
160134
{
161-
onError?.Invoke(null, String.Join(Environment.NewLine, errors.ToArray()));
135+
var errorStream = Process.StandardError;
136+
var errorLine = errorStream.ReadLine();
137+
while (errorLine != null)
138+
{
139+
errors.Add(errorLine);
140+
141+
if (token.IsCancellationRequested)
142+
{
143+
if (!Process.HasExited)
144+
Process.Kill();
145+
146+
Process.Close();
147+
onEnd?.Invoke();
148+
token.ThrowIfCancellationRequested();
149+
}
150+
151+
errorLine = errorStream.ReadLine();
152+
}
153+
154+
if (Process.ExitCode != 0 && errors.Count > 0)
155+
{
156+
onError?.Invoke(null, string.Join(Environment.NewLine, errors.ToArray()));
157+
}
162158
}
163159
}
160+
164161
onEnd?.Invoke();
165162
}
166163

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class HistoryView : Subview
3737
private const int HistoryExtraItemCount = 10;
3838
private const float MaxChangelistHeightRatio = .2f;
3939

40-
[NonSerialized] private string currentRemote = "placeholder";
4140
[NonSerialized] private int historyStartIndex;
4241
[NonSerialized] private int historyStopIndex;
4342
[NonSerialized] private float lastWidth;
@@ -62,6 +61,8 @@ class HistoryView : Subview
6261
[SerializeField] private ChangesetTreeView changesetTree = new ChangesetTreeView();
6362
[SerializeField] private List<GitLogEntry> history = new List<GitLogEntry>();
6463
[SerializeField] private bool isBusy;
64+
[SerializeField] private string currentRemote;
65+
[SerializeField] private bool isPublished;
6566

6667
public override void InitializeView(IView parent)
6768
{
@@ -196,7 +197,6 @@ private void UpdateStatusOnMainThread(GitStatus status)
196197

197198
private void UpdateStatus(GitStatus status)
198199
{
199-
currentRemote = Repository.CurrentRemote.HasValue ? Repository.CurrentRemote.Value.Name : null;
200200
statusAhead = status.Ahead;
201201
statusBehind = status.Behind;
202202
}
@@ -225,6 +225,9 @@ private void OnLogUpdate(List<GitLogEntry> entries)
225225

226226
private void MaybeUpdateData()
227227
{
228+
isPublished = Repository.CurrentRemote.HasValue;
229+
currentRemote = isPublished ? Repository.CurrentRemote.Value.Name : "placeholder";
230+
228231
if (!updated)
229232
return;
230233
updated = false;
@@ -351,8 +354,6 @@ public void OnEmbeddedGUI()
351354

352355
GUILayout.FlexibleSpace();
353356

354-
355-
var isPublished = Repository.CurrentRemote.HasValue;
356357
if (isPublished)
357358
{
358359
// Fetch button

0 commit comments

Comments
 (0)