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

Commit 6718467

Browse files
committed
Fix locks serialization and consolidate resource strings
1 parent f7f5dc2 commit 6718467

File tree

16 files changed

+271
-55
lines changed

16 files changed

+271
-55
lines changed

src/GitHub.Api/Git/GitClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ public ITask<string> Unlock(NPath file, bool force,
306306
protected static ILogging Logger { get; } = LogHelper.GetLogger<GitClient>();
307307
}
308308

309+
[Serializable]
309310
public struct GitUser
310311
{
311312
public static GitUser Default = new GitUser();

src/GitHub.Api/Git/GitLock.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Globalization;
3+
using GitHub.Logging;
24

35
namespace GitHub.Unity
46
{
@@ -10,8 +12,24 @@ public struct GitLock
1012
public int id;
1113
public string path;
1214
public GitUser owner;
13-
public DateTimeOffset locked_at;
14-
15+
[NotSerialized] public string lockedAtString;
16+
public DateTimeOffset locked_at
17+
{
18+
get
19+
{
20+
DateTimeOffset dt;
21+
if (!DateTimeOffset.TryParseExact(lockedAtString, Constants.Iso8601Formats,
22+
CultureInfo.InvariantCulture, Constants.DateTimeStyle, out dt))
23+
{
24+
return DateTimeOffset.MinValue;
25+
}
26+
return dt;
27+
}
28+
set
29+
{
30+
lockedAtString = value.ToUniversalTime().ToString(Constants.Iso8601FormatZ, CultureInfo.InvariantCulture);
31+
}
32+
}
1533
[NotSerialized] public int ID => id;
1634
[NotSerialized] public NPath Path => path.ToNPath();
1735
[NotSerialized] public GitUser Owner => owner;
@@ -22,7 +40,7 @@ public GitLock(int id, NPath path, GitUser owner, DateTimeOffset locked_at)
2240
this.id = id;
2341
this.path = path;
2442
this.owner = owner;
25-
this.locked_at = locked_at;
43+
this.lockedAtString = locked_at.ToUniversalTime().ToString(Constants.Iso8601FormatZ, CultureInfo.InvariantCulture);
2644
}
2745

2846
public override bool Equals(object other)

src/GitHub.Api/Git/IRepository.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace GitHub.Unity
66
/// <summary>
77
/// Represents a repository, either local or retrieved via the GitHub API.
88
/// </summary>
9-
public interface IRepository : IEquatable<IRepository>, IDisposable
9+
public interface IRepository : IEquatable<IRepository>, IDisposable, IBackedByCache
1010
{
1111
void Initialize(IRepositoryManager theRepositoryManager, ITaskManager theTaskManager);
1212
void Start();
@@ -21,7 +21,6 @@ public interface IRepository : IEquatable<IRepository>, IDisposable
2121
ITask RequestLock(NPath file);
2222
ITask ReleaseLock(NPath file, bool force);
2323
ITask DiscardChanges(GitStatusEntry[] discardEntries);
24-
void CheckAndRaiseEventsIfCacheNewer(CacheType cacheType, CacheUpdateEvent cacheUpdateEvent);
2524

2625
/// <summary>
2726
/// Gets the name of the repository.

src/GitHub.Api/Git/Repository.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
using System.Diagnostics;
55
using System.Globalization;
66
using System.Linq;
7-
using System.Threading;
87

98
namespace GitHub.Unity
109
{
10+
public interface IBackedByCache
11+
{
12+
void CheckAndRaiseEventsIfCacheNewer(CacheType cacheType, CacheUpdateEvent cacheUpdateEvent);
13+
}
14+
1115
[DebuggerDisplay("{DebuggerDisplay,nq}")]
1216
sealed class Repository : IEquatable<Repository>, IRepository
1317
{
@@ -380,12 +384,11 @@ public string Name
380384
CloneUrl, LocalPath, CurrentBranch, CurrentRemote);
381385
}
382386

383-
public interface IUser
387+
public interface IUser : IBackedByCache
384388
{
385389
string Name { get; }
386390
string Email { get; }
387391
event Action<CacheUpdateEvent> Changed;
388-
void CheckUserChangedEvent(CacheUpdateEvent cacheUpdateEvent);
389392
void Initialize(IGitClient client);
390393
void SetNameAndEmail(string name, string email);
391394
}
@@ -406,7 +409,7 @@ public User(ICacheContainer cacheContainer)
406409
cacheContainer.CacheUpdated += (type, dt) => { if (type == CacheType.GitUser) CacheHasBeenUpdated(dt); };
407410
}
408411

409-
public void CheckUserChangedEvent(CacheUpdateEvent cacheUpdateEvent) => cacheContainer.CheckAndRaiseEventsIfCacheNewer(CacheType.GitUser, cacheUpdateEvent);
412+
public void CheckAndRaiseEventsIfCacheNewer(CacheType cacheType, CacheUpdateEvent cacheUpdateEvent) => cacheContainer.CheckAndRaiseEventsIfCacheNewer(CacheType.GitUser, cacheUpdateEvent);
410413

411414
public void Initialize(IGitClient client)
412415
{

src/GitHub.Api/Helpers/Constants.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Globalization;
2+
13
namespace GitHub.Unity
24
{
35
static class Constants
@@ -11,11 +13,12 @@ static class Constants
1113
public const string Iso8601Format = @"yyyy-MM-dd\THH\:mm\:ss.fffzzz";
1214
public const string Iso8601FormatZ = @"yyyy-MM-dd\THH\:mm\:ss\Z";
1315
public static readonly string[] Iso8601Formats = {
14-
@"yyyy-MM-dd\THH\:mm\:ss\Z",
16+
Iso8601FormatZ,
1517
@"yyyy-MM-dd\THH\:mm\:ss.fffffffzzz",
16-
@"yyyy-MM-dd\THH\:mm\:ss.fffzzz",
18+
Iso8601Format,
1719
@"yyyy-MM-dd\THH\:mm\:sszzz",
1820
};
21+
public const DateTimeStyles DateTimeStyle = DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal;
1922
public const string SkipVersionKey = "SkipVersion";
2023
public const string GitInstallationState = "GitInstallationState";
2124

src/GitHub.Api/Helpers/SimpleJson.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ class PocoJsonSerializerStrategy : IJsonSerializerStrategy
12551255
@"yyyy-MM-dd\THH\:mm\:sszzz",
12561256
@"yyyy-MM-dd\THH\:mm\:ss.fffffffzzz",
12571257
@"yyyy-MM-dd\THH\:mm\:ss.fffzzz",
1258-
@"yyyy-MM-dd\THH\:mm\:ssZ",
1258+
@"yyyy-MM-dd\THH\:mm\:ss\Z",
12591259
@"yyyy-MM-dd\THH:mm:ss.fffffffzzz",
12601260
@"yyyy-MM-dd\THH:mm:ss.fffzzz",
12611261
@"yyyy-MM-dd\THH:mm:sszzz",

src/GitHub.Api/Localization.Designer.cs

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GitHub.Api/Localization.resx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,25 @@
351351
<data name="RequestLockActionTitle" xml:space="preserve">
352352
<value>Request Lock</value>
353353
</data>
354+
<data name="ForceUnlockFileAssetsMenuItem" xml:space="preserve">
355+
<value>Assets/Release Lock (forced)</value>
356+
</data>
357+
<data name="ForceUnlockFileMenuItem" xml:space="preserve">
358+
<value>Release Lock (forced)</value>
359+
</data>
360+
<data name="LockFileAssetsMenuItem" xml:space="preserve">
361+
<value>Assets/Request Lock</value>
362+
</data>
363+
<data name="LockFileMenuItem" xml:space="preserve">
364+
<value>Request Lock</value>
365+
</data>
366+
<data name="LocksTitle" xml:space="preserve">
367+
<value>Locks</value>
368+
</data>
369+
<data name="UnlockFileAssetsMenuItem" xml:space="preserve">
370+
<value>Assets/Release Lock</value>
371+
</data>
372+
<data name="UnlockFileMenuItem" xml:space="preserve">
373+
<value>Release Lock</value>
374+
</data>
354375
</root>

src/GitHub.Api/Primitives/TheVersion.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace GitHub.Unity
66
{
7+
[Serializable]
78
public struct TheVersion : IComparable<TheVersion>
89
{
910
private const string versionRegex = @"^(?<major>\d+)(\.?(?<minor>[^.]+))?(\.?(?<patch>[^.]+))?(\.?(?<build>.+))?";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override void OnEnable()
3030
base.OnEnable();
3131
AttachHandlers();
3232

33-
User.CheckUserChangedEvent(lastCheckUserChangedEvent);
33+
User.CheckAndRaiseEventsIfCacheNewer(CacheType.GitUser, lastCheckUserChangedEvent);
3434
}
3535

3636
public override void OnDisable()

0 commit comments

Comments
 (0)