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

Commit b89e924

Browse files
authored
Merge pull request #725 from github-for-unity/features/lock-files-view
Dedicated view to Locked files
2 parents 1c6b0da + 565b080 commit b89e924

25 files changed

+1015
-204
lines changed

src/GitHub.Api/Extensions/StringExtensions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@
77

88
namespace GitHub.Unity
99
{
10+
static class DateTimeOffsetExtensions
11+
{
12+
private const string Today = "Today";
13+
private const string Yesterday = "Yesterday";
14+
15+
public static string CreateRelativeTime(this DateTimeOffset @from, DateTimeOffset to)
16+
{
17+
return String.Format("{0}, {1:HH}:{1:mm}",
18+
@from.DayOfYear == to.DayOfYear
19+
? Today
20+
: @from.DayOfYear == to.DayOfYear - 1
21+
? Yesterday
22+
: @from.ToString("d MMM yyyy"), @from);
23+
}
24+
}
25+
1026
static class StringExtensions
1127
{
1228
public static bool Contains(this string s, string expectedSubstring, StringComparison comparison)

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/GitLogEntry.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ namespace GitHub.Unity
88
[Serializable]
99
public struct GitLogEntry
1010
{
11-
private const string Today = "Today";
12-
private const string Yesterday = "Yesterday";
13-
1411
public static GitLogEntry Default = new GitLogEntry(String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, DateTimeOffset.MinValue, DateTimeOffset.MinValue, new List<GitStatusEntry>(), String.Empty, String.Empty);
1512

1613
public string commitID;
@@ -61,18 +58,7 @@ public GitLogEntry(string commitID,
6158
this.mergeB = mergeB ?? string.Empty;
6259
}
6360

64-
public string PrettyTimeString
65-
{
66-
get
67-
{
68-
DateTimeOffset now = DateTimeOffset.Now, relative = Time.ToLocalTime();
69-
70-
return String.Format("{0}, {1:HH}:{1:mm}",
71-
relative.DayOfYear == now.DayOfYear
72-
? Today
73-
: relative.DayOfYear == now.DayOfYear - 1 ? Yesterday : relative.ToString("d MMM yyyy"), relative);
74-
}
75-
}
61+
public string PrettyTimeString => Time.ToLocalTime().CreateRelativeTime(DateTimeOffset.Now);
7662

7763
[NonSerialized] private DateTimeOffset? timeValue;
7864
public DateTimeOffset Time

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>

0 commit comments

Comments
 (0)