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

Commit dc95c07

Browse files
Merge branch 'master' into fixes/nested-meta-file
2 parents 5c6685d + eb770ae commit dc95c07

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

+919
-90
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
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using Octokit;
6+
using System.Runtime.Serialization;
67

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

335-
class ApiClientException : Exception
336+
[Serializable]
337+
public class ApiClientException : Exception
336338
{
337339
public ApiClientException()
338340
{ }
@@ -342,8 +344,12 @@ public ApiClientException(string message) : base(message)
342344

343345
public ApiClientException(string message, Exception innerException) : base(message, innerException)
344346
{ }
347+
348+
protected ApiClientException(SerializationInfo info, StreamingContext context) : base(info, context)
349+
{ }
345350
}
346351

352+
[Serializable]
347353
class TokenUsernameMismatchException : ApiClientException
348354
{
349355
public string CachedUsername { get; }
@@ -354,11 +360,22 @@ public TokenUsernameMismatchException(string cachedUsername, string currentUsern
354360
CachedUsername = cachedUsername;
355361
CurrentUsername = currentUsername;
356362
}
363+
protected TokenUsernameMismatchException(SerializationInfo info, StreamingContext context) : base(info, context)
364+
{ }
357365
}
358366

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

src/GitHub.Api/Authentication/Keychain.cs

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

1557
class ConnectionCacheItem

src/GitHub.Api/Events/RepositoryWatcher.cs

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

150150
private int ProcessEvents(Event[] fileEvents)
151151
{
152-
Dictionary<EventType, List<EventData>> events = new Dictionary<EventType, List<EventData>>();
152+
var events = new HashSet<EventType>();
153153
foreach (var fileEvent in fileEvents)
154154
{
155155
if (!running)
@@ -177,90 +177,90 @@ private int ProcessEvents(Event[] fileEvents)
177177
// handling events in .git/*
178178
if (fileA.IsChildOf(paths.DotGitPath))
179179
{
180-
if (!events.ContainsKey(EventType.ConfigChanged) && fileA.Equals(paths.DotGitConfig))
180+
if (!events.Contains(EventType.ConfigChanged) && fileA.Equals(paths.DotGitConfig))
181181
{
182-
events.Add(EventType.ConfigChanged, null);
182+
events.Add(EventType.ConfigChanged);
183183
}
184-
else if (!events.ContainsKey(EventType.HeadChanged) && fileA.Equals(paths.DotGitHead))
184+
else if (!events.Contains(EventType.HeadChanged) && fileA.Equals(paths.DotGitHead))
185185
{
186-
events.Add(EventType.HeadChanged, null);
186+
events.Add(EventType.HeadChanged);
187187
}
188-
else if (!events.ContainsKey(EventType.IndexChanged) && fileA.Equals(paths.DotGitIndex))
188+
else if (!events.Contains(EventType.IndexChanged) && fileA.Equals(paths.DotGitIndex))
189189
{
190-
events.Add(EventType.IndexChanged, null);
190+
events.Add(EventType.IndexChanged);
191191
}
192-
else if (!events.ContainsKey(EventType.RemoteBranchesChanged) && fileA.IsChildOf(paths.RemotesPath))
192+
else if (!events.Contains(EventType.RemoteBranchesChanged) && fileA.IsChildOf(paths.RemotesPath))
193193
{
194-
events.Add(EventType.RemoteBranchesChanged, null);
194+
events.Add(EventType.RemoteBranchesChanged);
195195
}
196-
else if (!events.ContainsKey(EventType.LocalBranchesChanged) && fileA.IsChildOf(paths.BranchesPath))
196+
else if (!events.Contains(EventType.LocalBranchesChanged) && fileA.IsChildOf(paths.BranchesPath))
197197
{
198-
events.Add(EventType.LocalBranchesChanged, null);
198+
events.Add(EventType.LocalBranchesChanged);
199199
}
200-
else if (!events.ContainsKey(EventType.RepositoryCommitted) && fileA.IsChildOf(paths.DotGitCommitEditMsg))
200+
else if (!events.Contains(EventType.RepositoryCommitted) && fileA.IsChildOf(paths.DotGitCommitEditMsg))
201201
{
202-
events.Add(EventType.RepositoryCommitted, null);
202+
events.Add(EventType.RepositoryCommitted);
203203
}
204204
}
205205
else
206206
{
207-
if (events.ContainsKey(EventType.RepositoryChanged) || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath)))
207+
if (events.Contains(EventType.RepositoryChanged) || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath)))
208208
{
209209
continue;
210210
}
211-
events.Add(EventType.RepositoryChanged, null);
211+
events.Add(EventType.RepositoryChanged);
212212
}
213213
}
214214

215215
return FireEvents(events);
216216
}
217217

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

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

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

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

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

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

263-
if (events.ContainsKey(EventType.RepositoryCommitted))
263+
if (events.Contains(EventType.RepositoryCommitted))
264264
{
265265
Logger.Trace("RepositoryCommitted");
266266
RepositoryCommitted?.Invoke();
@@ -306,11 +306,5 @@ private enum EventType
306306
RepositoryChanged,
307307
RepositoryCommitted
308308
}
309-
310-
private class EventData
311-
{
312-
public string Origin;
313-
public string Branch;
314-
}
315309
}
316310
}

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)