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

Commit 3bf5020

Browse files
committed
Merge master into enhancements/async-git-setup-rollup
2 parents 7b734a8 + 155aa37 commit 3bf5020

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+982
-180
lines changed

common/build.targets

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
<Compile Include="$(SolutionDir)common\SolutionInfo.cs">
66
<Link>Properties\SolutionInfo.cs</Link>
77
</Compile>
8-
<None Include="$(SolutionDir)common\GitHub.ruleset">
9-
<Link>Properties\GitHub.ruleset</Link>
8+
<None Include="$(SolutionDir)common\codeanalysis-release.ruleset">
9+
<Link>Properties\codeanalysis-release.ruleset</Link>
10+
</None>
11+
<None Include="$(SolutionDir)common\codeanalysis-debug.ruleset">
12+
<Link>Properties\codeanalysis-debug.ruleset</Link>
1013
</None>
1114
</ItemGroup>
1215

common/codeanalysis-small.ruleset renamed to common/codeanalysis-debug.ruleset

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@
9494

9595
<!-- link demand -->
9696
<Rule Id="CA2123" Action="None" />
97+
98+
<!-- disposable -->
99+
<Rule Id="CA1001" Action="None" />
100+
101+
<!-- no we like our event handler signatures thankyouverymuch -->
102+
<Rule Id="CA1009" Action="None" />
103+
104+
<!-- calling TryParse without using its return value is not a crime, Microsoft -->
105+
<Rule Id="CA1806" Action="None" />
106+
107+
<!-- we're returning arrays from properties -->
108+
<Rule Id="CA1819" Action="None" />
109+
110+
<!-- Unity does its own serialization and doesn't need special serializable type constructors -->
111+
<Rule Id="CA2229" Action="None" />
112+
<Rule Id="CA2240" Action="None" />
113+
114+
<!-- the compiler already warns about this -->
115+
<Rule Id="CA1823" Action="None" />
116+
97117
</Rules>
98118
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Features" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Features">
99119
<Rule Id="IDE0001" Action="None" />

common/codeanalysis-full.ruleset renamed to common/codeanalysis-release.ruleset

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,28 @@
8080
<Rule Id="CA2227" Action="None" />
8181
<Rule Id="CA2235" Action="None" />
8282
<Rule Id="IDE001" Action="None" />
83+
84+
<!-- link demand -->
85+
<Rule Id="CA2123" Action="None" />
86+
87+
<!-- disposable -->
88+
<Rule Id="CA1001" Action="None" />
89+
90+
<!-- no we like our event handler signatures thankyouverymuch -->
91+
<Rule Id="CA1009" Action="None" />
92+
93+
<!-- calling TryParse without using its return value is not a crime, Microsoft -->
94+
<Rule Id="CA1806" Action="None" />
95+
96+
<!-- we're returning arrays from properties -->
97+
<Rule Id="CA1819" Action="None" />
98+
99+
<!-- Unity does its own serialization and doesn't need special serializable type constructors -->
100+
<Rule Id="CA2229" Action="None" />
101+
<Rule Id="CA2240" Action="None" />
102+
103+
<!-- the compiler already warns about this -->
104+
<Rule Id="CA1823" Action="None" />
83105
</Rules>
84106
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Features" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Features">
85107
<Rule Id="IDE0001" Action="None" />

common/properties.props

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,15 @@
1212
<UnityDir Condition="$(UnityDir) == '' and Exists('\Applications\Unity\Unity.app\Contents\Managed\UnityEditor.dll')">\Applications\Unity\Unity.app\Contents\Managed\</UnityDir>
1313
<BuildConfig Condition=" '$(BuildConfig)' == '' ">Debug</BuildConfig>
1414
</PropertyGroup>
15+
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<CodeAnalysisRuleSet>$(SolutionDir)\common\codeanalysis-debug.ruleset</CodeAnalysisRuleSet>
18+
</PropertyGroup>
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
20+
<CodeAnalysisRuleSet>$(SolutionDir)\common\codeanalysis-release.ruleset</CodeAnalysisRuleSet>
21+
</PropertyGroup>
22+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'dev|AnyCPU'">
23+
<CodeAnalysisRuleSet>$(SolutionDir)\common\codeanalysis-debug.ruleset</CodeAnalysisRuleSet>
24+
</PropertyGroup>
25+
1526
</Project>

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading.Tasks;
55
using Octokit;
66
using GitHub.Logging;
7+
using System.Runtime.Serialization;
78

89
namespace GitHub.Unity
910
{
@@ -333,7 +334,8 @@ class GitHubRepository
333334
public string CloneUrl { get; set; }
334335
}
335336

336-
class ApiClientException : Exception
337+
[Serializable]
338+
public class ApiClientException : Exception
337339
{
338340
public ApiClientException()
339341
{ }
@@ -343,8 +345,12 @@ public ApiClientException(string message) : base(message)
343345

344346
public ApiClientException(string message, Exception innerException) : base(message, innerException)
345347
{ }
348+
349+
protected ApiClientException(SerializationInfo info, StreamingContext context) : base(info, context)
350+
{ }
346351
}
347352

353+
[Serializable]
348354
class TokenUsernameMismatchException : ApiClientException
349355
{
350356
public string CachedUsername { get; }
@@ -355,11 +361,22 @@ public TokenUsernameMismatchException(string cachedUsername, string currentUsern
355361
CachedUsername = cachedUsername;
356362
CurrentUsername = currentUsername;
357363
}
364+
protected TokenUsernameMismatchException(SerializationInfo info, StreamingContext context) : base(info, context)
365+
{ }
358366
}
359367

368+
[Serializable]
360369
class KeychainEmptyException : ApiClientException
361370
{
362371
public KeychainEmptyException()
363372
{ }
373+
public KeychainEmptyException(string message) : base(message)
374+
{ }
375+
376+
public KeychainEmptyException(string message, Exception innerException) : base(message, innerException)
377+
{ }
378+
379+
protected KeychainEmptyException(SerializationInfo info, StreamingContext context) : base(info, context)
380+
{ }
364381
}
365382
}

src/GitHub.Api/Authentication/Keychain.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,48 @@ public struct Connection
1111
{
1212
public UriString Host;
1313
public string Username;
14+
15+
public override int GetHashCode()
16+
{
17+
int hash = 17;
18+
hash = hash * 23 + (Host?.GetHashCode() ?? 0);
19+
hash = hash * 23 + (Username?.GetHashCode() ?? 0);
20+
return hash;
21+
}
22+
23+
public override bool Equals(object other)
24+
{
25+
if (other is Connection)
26+
return Equals((Connection)other);
27+
return false;
28+
}
29+
30+
public bool Equals(Connection other)
31+
{
32+
return
33+
object.Equals(Host, other.Host) &&
34+
String.Equals(Username, other.Username)
35+
;
36+
}
37+
38+
public static bool operator ==(Connection lhs, Connection rhs)
39+
{
40+
// If both are null, or both are same instance, return true.
41+
if (ReferenceEquals(lhs, rhs))
42+
return true;
43+
44+
// If one is null, but not both, return false.
45+
if (((object)lhs == null) || ((object)rhs == null))
46+
return false;
47+
48+
// Return true if the fields match:
49+
return lhs.Equals(rhs);
50+
}
51+
52+
public static bool operator !=(Connection lhs, Connection rhs)
53+
{
54+
return !(lhs == rhs);
55+
}
1456
}
1557

1658
class ConnectionCacheItem

src/GitHub.Api/Events/RepositoryWatcher.cs

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public int CheckAndProcessEvents()
150150

151151
private int ProcessEvents(Event[] fileEvents)
152152
{
153-
Dictionary<EventType, List<EventData>> events = new Dictionary<EventType, List<EventData>>();
153+
var events = new HashSet<EventType>();
154154
foreach (var fileEvent in fileEvents)
155155
{
156156
if (!running)
@@ -178,90 +178,90 @@ private int ProcessEvents(Event[] fileEvents)
178178
// handling events in .git/*
179179
if (fileA.IsChildOf(paths.DotGitPath))
180180
{
181-
if (!events.ContainsKey(EventType.ConfigChanged) && fileA.Equals(paths.DotGitConfig))
181+
if (!events.Contains(EventType.ConfigChanged) && fileA.Equals(paths.DotGitConfig))
182182
{
183-
events.Add(EventType.ConfigChanged, null);
183+
events.Add(EventType.ConfigChanged);
184184
}
185-
else if (!events.ContainsKey(EventType.HeadChanged) && fileA.Equals(paths.DotGitHead))
185+
else if (!events.Contains(EventType.HeadChanged) && fileA.Equals(paths.DotGitHead))
186186
{
187-
events.Add(EventType.HeadChanged, null);
187+
events.Add(EventType.HeadChanged);
188188
}
189-
else if (!events.ContainsKey(EventType.IndexChanged) && fileA.Equals(paths.DotGitIndex))
189+
else if (!events.Contains(EventType.IndexChanged) && fileA.Equals(paths.DotGitIndex))
190190
{
191-
events.Add(EventType.IndexChanged, null);
191+
events.Add(EventType.IndexChanged);
192192
}
193-
else if (!events.ContainsKey(EventType.RemoteBranchesChanged) && fileA.IsChildOf(paths.RemotesPath))
193+
else if (!events.Contains(EventType.RemoteBranchesChanged) && fileA.IsChildOf(paths.RemotesPath))
194194
{
195-
events.Add(EventType.RemoteBranchesChanged, null);
195+
events.Add(EventType.RemoteBranchesChanged);
196196
}
197-
else if (!events.ContainsKey(EventType.LocalBranchesChanged) && fileA.IsChildOf(paths.BranchesPath))
197+
else if (!events.Contains(EventType.LocalBranchesChanged) && fileA.IsChildOf(paths.BranchesPath))
198198
{
199-
events.Add(EventType.LocalBranchesChanged, null);
199+
events.Add(EventType.LocalBranchesChanged);
200200
}
201-
else if (!events.ContainsKey(EventType.RepositoryCommitted) && fileA.IsChildOf(paths.DotGitCommitEditMsg))
201+
else if (!events.Contains(EventType.RepositoryCommitted) && fileA.IsChildOf(paths.DotGitCommitEditMsg))
202202
{
203-
events.Add(EventType.RepositoryCommitted, null);
203+
events.Add(EventType.RepositoryCommitted);
204204
}
205205
}
206206
else
207207
{
208-
if (events.ContainsKey(EventType.RepositoryChanged) || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath)))
208+
if (events.Contains(EventType.RepositoryChanged) || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath)))
209209
{
210210
continue;
211211
}
212-
events.Add(EventType.RepositoryChanged, null);
212+
events.Add(EventType.RepositoryChanged);
213213
}
214214
}
215215

216216
return FireEvents(events);
217217
}
218218

219-
private int FireEvents(Dictionary<EventType, List<EventData>> events)
219+
private int FireEvents(HashSet<EventType> events)
220220
{
221221
int eventsProcessed = 0;
222-
if (events.ContainsKey(EventType.ConfigChanged))
222+
if (events.Contains(EventType.ConfigChanged))
223223
{
224224
Logger.Trace("ConfigChanged");
225225
ConfigChanged?.Invoke();
226226
eventsProcessed++;
227227
}
228228

229-
if (events.ContainsKey(EventType.HeadChanged))
229+
if (events.Contains(EventType.HeadChanged))
230230
{
231231
Logger.Trace("HeadChanged");
232232
HeadChanged?.Invoke();
233233
eventsProcessed++;
234234
}
235235

236-
if (events.ContainsKey(EventType.LocalBranchesChanged))
236+
if (events.Contains(EventType.LocalBranchesChanged))
237237
{
238238
Logger.Trace("LocalBranchesChanged");
239239
LocalBranchesChanged?.Invoke();
240240
eventsProcessed++;
241241
}
242242

243-
if (events.ContainsKey(EventType.RemoteBranchesChanged))
243+
if (events.Contains(EventType.RemoteBranchesChanged))
244244
{
245245
Logger.Trace("RemoteBranchesChanged");
246246
RemoteBranchesChanged?.Invoke();
247247
eventsProcessed++;
248248
}
249249

250-
if (events.ContainsKey(EventType.IndexChanged))
250+
if (events.Contains(EventType.IndexChanged))
251251
{
252252
Logger.Trace("IndexChanged");
253253
IndexChanged?.Invoke();
254254
eventsProcessed++;
255255
}
256256

257-
if (events.ContainsKey(EventType.RepositoryChanged))
257+
if (events.Contains(EventType.RepositoryChanged))
258258
{
259259
Logger.Trace("RepositoryChanged");
260260
RepositoryChanged?.Invoke();
261261
eventsProcessed++;
262262
}
263263

264-
if (events.ContainsKey(EventType.RepositoryCommitted))
264+
if (events.Contains(EventType.RepositoryCommitted))
265265
{
266266
Logger.Trace("RepositoryCommitted");
267267
RepositoryCommitted?.Invoke();
@@ -307,11 +307,5 @@ private enum EventType
307307
RepositoryChanged,
308308
RepositoryCommitted
309309
}
310-
311-
private class EventData
312-
{
313-
public string Origin;
314-
public string Branch;
315-
}
316310
}
317311
}

src/GitHub.Api/Extensions/StringExtensions.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,45 @@ public struct StringResult
156156
public string Chunk;
157157
public int Start;
158158
public int End;
159+
160+
public override int GetHashCode()
161+
{
162+
int hash = 17;
163+
hash = hash * 23 + (Chunk?.GetHashCode() ?? 0);
164+
hash = hash * 23 + Start.GetHashCode();
165+
hash = hash * 23 + End.GetHashCode();
166+
return hash;
167+
}
168+
169+
public override bool Equals(object other)
170+
{
171+
if (other is StringResult)
172+
return Equals((StringResult)other);
173+
return false;
174+
}
175+
176+
public bool Equals(StringResult other)
177+
{
178+
return String.Equals(Chunk, other.Chunk) && Start == other.Start && End == other.End;
179+
}
180+
181+
public static bool operator ==(StringResult lhs, StringResult rhs)
182+
{
183+
// If both are null, or both are same instance, return true.
184+
if (ReferenceEquals(lhs, rhs))
185+
return true;
186+
187+
// If one is null, but not both, return false.
188+
if (((object)lhs == null) || ((object)rhs == null))
189+
return false;
190+
191+
// Return true if the fields match:
192+
return lhs.Equals(rhs);
193+
}
194+
195+
public static bool operator !=(StringResult lhs, StringResult rhs)
196+
{
197+
return !(lhs == rhs);
198+
}
159199
}
160200
}

0 commit comments

Comments
 (0)