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

Commit d1f99de

Browse files
Merge branch 'master' into fixes/application-cache-initial-times
# Conflicts: # src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs
2 parents 92b65da + 1a30da4 commit d1f99de

20 files changed

+497
-194
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.23.0";
34+
internal const string Version = "0.24.0";
3535
}
3636
}

src/GitHub.Api/Cache/CacheInterfaces.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public interface IGitUserCache : IManagedCache
5555

5656
public interface IGitStatusCache : IManagedCache
5757
{
58-
GitStatus GitStatus { get; set; }
58+
int Ahead { get; set; }
59+
int Behind { get; set; }
60+
List<GitStatusEntry> Entries { get; set; }
5961
}
6062

6163
public interface ILocalConfigBranchDictionary : IDictionary<string, ConfigBranch>

src/GitHub.Api/Extensions/GitStatusExtensions.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
3+
namespace GitHub.Unity
4+
{
5+
[Serializable]
6+
public struct GitAheadBehindStatus
7+
{
8+
public static GitAheadBehindStatus Default = new GitAheadBehindStatus();
9+
10+
public int ahead;
11+
public int behind;
12+
13+
public GitAheadBehindStatus(int ahead, int behind)
14+
{
15+
this.ahead = ahead;
16+
this.behind = behind;
17+
}
18+
19+
public int Ahead => ahead;
20+
21+
public int Behind => behind;
22+
}
23+
}

src/GitHub.Api/Git/GitClient.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public interface IGitClient
1515

1616
ITask LfsInstall(IOutputProcessor<string> processor = null);
1717

18+
ITask<GitAheadBehindStatus> AheadBehindStatus(string gitRef, string otherRef,
19+
IOutputProcessor<GitAheadBehindStatus> processor = null);
20+
1821
ITask<GitStatus> Status(IOutputProcessor<GitStatus> processor = null);
1922

2023
ITask<string> GetConfig(string key, GitConfigSource configSource,
@@ -219,6 +222,14 @@ public ITask<GitStatus> Status(IOutputProcessor<GitStatus> processor = null)
219222
.Configure(processManager);
220223
}
221224

225+
public ITask<GitAheadBehindStatus> AheadBehindStatus(string gitRef, string otherRef, IOutputProcessor<GitAheadBehindStatus> processor = null)
226+
{
227+
Logger.Trace("AheadBehindStatus");
228+
229+
return new GitAheadBehindStatusTask(gitRef, otherRef, cancellationToken, processor)
230+
.Configure(processManager);
231+
}
232+
222233
public ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> processor = null)
223234
{
224235
Logger.Trace("Log");

src/GitHub.Api/Git/GitConfig.cs

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,56 @@ namespace GitHub.Unity
99
[Serializable]
1010
public struct ConfigRemote
1111
{
12-
public string Name;
13-
public string Url;
12+
public static ConfigRemote Default = new ConfigRemote(String.Empty, String.Empty);
13+
14+
public string name;
15+
public string url;
16+
17+
public ConfigRemote(string name, string url)
18+
{
19+
this.name = name;
20+
this.url = url;
21+
}
22+
23+
public string Name => name;
24+
25+
public string Url => url;
1426

1527
public override string ToString()
1628
{
17-
return String.Format("{{Remote {0} {1}}}", Name, Url);
29+
return $"{{Remote {Name} {Url}}}";
1830
}
1931
}
2032

2133
[Serializable]
2234
public struct ConfigBranch
2335
{
24-
public string Name;
25-
public ConfigRemote? Remote;
36+
public static ConfigBranch Default = new ConfigBranch(String.Empty);
37+
38+
public string name;
39+
public ConfigRemote remote;
40+
41+
public ConfigBranch(string name)
42+
{
43+
this.name = name;
44+
remote = ConfigRemote.Default;
45+
}
46+
47+
public ConfigBranch(string name, ConfigRemote? remote)
48+
{
49+
this.name = name;
50+
this.remote = remote ?? ConfigRemote.Default;
51+
}
52+
2653
public bool IsTracking => Remote.HasValue;
2754

55+
public string Name => name;
56+
57+
public ConfigRemote? Remote => Equals(remote, ConfigRemote.Default) ? (ConfigRemote?) null : remote;
58+
2859
public override string ToString()
2960
{
30-
return String.Format("{{Branch {0} {1}}}", Name, Remote?.ToString() ?? "Untracked");
61+
return $"{{Branch {Name} {Remote?.ToString() ?? "Untracked"}}}";
3162
}
3263
}
3364

@@ -74,11 +105,7 @@ public IEnumerable<ConfigBranch> GetBranches()
74105
return groups
75106
.Where(x => x.Key == "branch")
76107
.SelectMany(x => x.Value)
77-
.Select(x => new ConfigBranch
78-
{
79-
Name = x.Key,
80-
Remote = GetRemote(x.Value.TryGetString("remote"))
81-
});
108+
.Select(x => new ConfigBranch(x.Key, GetRemote(x.Value.TryGetString("remote"))));
82109
}
83110

84111
public IEnumerable<ConfigRemote> GetRemotes()
@@ -87,11 +114,7 @@ public IEnumerable<ConfigRemote> GetRemotes()
87114
.Where(x => x.Key == "remote")
88115
.SelectMany(x => x.Value)
89116
.Where(x => x.Value.TryGetString("url") != null)
90-
.Select(x => new ConfigRemote
91-
{
92-
Name = x.Key,
93-
Url = x.Value.TryGetString("url")
94-
});
117+
.Select(x => new ConfigRemote(x.Key, x.Value.TryGetString("url")));
95118
}
96119

97120
public ConfigRemote? GetRemote(string remote)
@@ -100,11 +123,7 @@ public IEnumerable<ConfigRemote> GetRemotes()
100123
.Where(x => x.Key == "remote")
101124
.SelectMany(x => x.Value)
102125
.Where(x => x.Key == remote && x.Value.TryGetString("url") != null)
103-
.Select(x => new ConfigRemote
104-
{
105-
Name = x.Key,
106-
Url = x.Value.GetString("url")
107-
} as ConfigRemote?)
126+
.Select(x => new ConfigRemote(x.Key,x.Value.GetString("url")) as ConfigRemote?)
108127
.FirstOrDefault();
109128
}
110129

@@ -114,11 +133,7 @@ public IEnumerable<ConfigRemote> GetRemotes()
114133
.Where(x => x.Key == "branch")
115134
.SelectMany(x => x.Value)
116135
.Where(x => x.Key == branch)
117-
.Select(x => new ConfigBranch
118-
{
119-
Name = x.Key,
120-
Remote = GetRemote(x.Value.TryGetString("remote"))
121-
} as ConfigBranch?)
136+
.Select(x => new ConfigBranch(x.Key,GetRemote(x.Value.TryGetString("remote"))) as ConfigBranch?)
122137
.FirstOrDefault();
123138
}
124139

src/GitHub.Api/Git/GitRemote.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public enum GitRemoteFunction
1414
[Serializable]
1515
public struct GitRemote
1616
{
17-
public static GitRemote Default = new GitRemote();
17+
public static GitRemote Default = new GitRemote(String.Empty, String.Empty, String.Empty, GitRemoteFunction.Unknown, string.Empty, string.Empty, string.Empty);
1818

1919
public string name;
2020
public string url;

src/GitHub.Api/Git/IRepository.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public interface IRepository : IEquatable<IRepository>
5757
/// Gets the current branch of the repository.
5858
/// </summary>
5959
GitBranch? CurrentBranch { get; }
60-
GitStatus CurrentStatus { get; }
60+
int CurrentAhead { get; }
61+
int CurrentBehind { get; }
62+
List<GitStatusEntry> CurrentChanges { get; }
6163
GitRemote[] Remotes { get; }
6264
GitBranch[] LocalBranches { get; }
6365
GitBranch[] RemoteBranches { get; }

src/GitHub.Api/Git/Repository.cs

Lines changed: 68 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public void Initialize(IRepositoryManager initRepositoryManager)
4949
repositoryManager = initRepositoryManager;
5050
repositoryManager.CurrentBranchUpdated += RepositoryManagerOnCurrentBranchUpdated;
5151
repositoryManager.GitStatusUpdated += RepositoryManagerOnGitStatusUpdated;
52+
repositoryManager.GitAheadBehindStatusUpdated += RepositoryManagerOnGitAheadBehindStatusUpdated;
5253
repositoryManager.GitLogUpdated += RepositoryManagerOnGitLogUpdated;
54+
repositoryManager.GitLocksUpdated += RepositoryManagerOnGitLocksUpdated;
5355
repositoryManager.LocalBranchesUpdated += RepositoryManagerOnLocalBranchesUpdated;
5456
repositoryManager.RemoteBranchesUpdated += RepositoryManagerOnRemoteBranchesUpdated;
5557
}
@@ -266,7 +268,7 @@ private void CacheContainer_OnCacheInvalidated(CacheType cacheType)
266268
break;
267269

268270
case CacheType.GitLocksCache:
269-
repositoryManager?.UpdateLocks();
271+
UpdateLocks();
270272
break;
271273

272274
case CacheType.GitUserCache:
@@ -352,26 +354,36 @@ private void RepositoryManagerOnCurrentBranchUpdated(ConfigBranch? branch, Confi
352354
new ActionTask(CancellationToken.None, () => {
353355
if (!Nullable.Equals(CurrentConfigBranch, branch))
354356
{
355-
var currentBranch = branch != null ? (GitBranch?)GetLocalGitBranch(branch.Value) : null;
357+
var currentBranch = branch != null ? (GitBranch?)GetLocalGitBranch(branch.Value) : null;
356358

357-
CurrentConfigBranch = branch;
358-
CurrentBranch = currentBranch;
359-
UpdateLocalBranches();
359+
CurrentConfigBranch = branch;
360+
CurrentBranch = currentBranch;
361+
UpdateLocalBranches();
360362
}
361363

362364
if (!Nullable.Equals(CurrentConfigRemote, remote))
363365
{
364-
CurrentConfigRemote = remote;
365-
CurrentRemote = GetGitRemote(remote.Value);
366-
ClearRepositoryInfo();
366+
CurrentConfigRemote = remote;
367+
CurrentRemote = remote.HasValue ? (GitRemote?)GetGitRemote(remote.Value) : null;
368+
ClearRepositoryInfo();
367369
}
368370
}) { Affinity = TaskAffinity.UI }.Start();
369371
}
370372

371373
private void RepositoryManagerOnGitStatusUpdated(GitStatus gitStatus)
372374
{
373375
new ActionTask(CancellationToken.None, () => {
374-
CurrentStatus = gitStatus;
376+
CurrentChanges = gitStatus.Entries;
377+
CurrentAhead = gitStatus.Ahead;
378+
CurrentBehind = gitStatus.Behind;
379+
}) { Affinity = TaskAffinity.UI }.Start();
380+
}
381+
382+
private void RepositoryManagerOnGitAheadBehindStatusUpdated(GitAheadBehindStatus aheadBehindStatus)
383+
{
384+
new ActionTask(CancellationToken.None, () => {
385+
CurrentAhead = aheadBehindStatus.Ahead;
386+
CurrentBehind = aheadBehindStatus.Behind;
375387
}) { Affinity = TaskAffinity.UI }.Start();
376388
}
377389

@@ -382,6 +394,14 @@ private void RepositoryManagerOnGitLogUpdated(List<GitLogEntry> gitLogEntries)
382394
}) { Affinity = TaskAffinity.UI }.Start();
383395
}
384396

397+
private void RepositoryManagerOnGitLocksUpdated(List<GitLock> gitLocks)
398+
{
399+
new ActionTask(CancellationToken.None, () => {
400+
CurrentLocks = gitLocks;
401+
})
402+
{ Affinity = TaskAffinity.UI }.Start();
403+
}
404+
385405
private void RepositoryManagerOnRemoteBranchesUpdated(Dictionary<string, ConfigRemote> remotes,
386406
Dictionary<string, Dictionary<string, ConfigBranch>> branches)
387407
{
@@ -400,6 +420,14 @@ private void RepositoryManagerOnLocalBranchesUpdated(Dictionary<string, ConfigBr
400420
}) { Affinity = TaskAffinity.UI }.Start();
401421
}
402422

423+
private void UpdateLocks()
424+
{
425+
if (CurrentRemote.HasValue)
426+
{
427+
repositoryManager?.UpdateLocks();
428+
}
429+
}
430+
403431
private void UpdateLocalBranches()
404432
{
405433
LocalBranches = LocalConfigBranches.Values.Select(GetLocalGitBranch).ToArray();
@@ -468,10 +496,22 @@ private ConfigRemote? CurrentConfigRemote
468496
set { cacheContainer.BranchCache.CurrentConfigRemote = value; }
469497
}
470498

471-
public GitStatus CurrentStatus
499+
public int CurrentAhead
500+
{
501+
get { return cacheContainer.GitStatusCache.Ahead; }
502+
private set { cacheContainer.GitStatusCache.Ahead = value; }
503+
}
504+
505+
public int CurrentBehind
506+
{
507+
get { return cacheContainer.GitStatusCache.Behind; }
508+
private set { cacheContainer.GitStatusCache.Behind = value; }
509+
}
510+
511+
public List<GitStatusEntry> CurrentChanges
472512
{
473-
get { return cacheContainer.GitStatusCache.GitStatus; }
474-
private set { cacheContainer.GitStatusCache.GitStatus = value; }
513+
get { return cacheContainer.GitStatusCache.Entries; }
514+
private set { cacheContainer.GitStatusCache.Entries = value; }
475515
}
476516

477517
public GitBranch? CurrentBranch
@@ -606,6 +646,7 @@ public void Initialize(IGitClient client)
606646
Logger.Trace("Initialize");
607647

608648
gitClient = client;
649+
cacheContainer.GitUserCache.ValidateData();
609650
}
610651

611652
public void SetNameAndEmail(string name, string email)
@@ -659,20 +700,23 @@ private void HandleUserCacheUpdatedEvent(CacheUpdateEvent cacheUpdateEvent)
659700

660701
private void UpdateUserAndEmail()
661702
{
662-
if (gitClient != null)
663-
{
664-
Logger.Trace("UpdateUserAndEmail");
703+
Logger.Trace("UpdateUserAndEmail");
665704

666-
gitClient.GetConfigUserAndEmail()
667-
.ThenInUI((success, value) =>
668-
{
669-
if (success)
670-
{
671-
Name = value.Name;
672-
Email = value.Email;
673-
}
674-
}).Start();
705+
if (gitClient == null)
706+
{
707+
Logger.Trace("GitClient is null");
708+
return;
675709
}
710+
711+
gitClient.GetConfigUserAndEmail()
712+
.ThenInUI((success, value) =>
713+
{
714+
if (success)
715+
{
716+
Name = value.Name;
717+
Email = value.Email;
718+
}
719+
}).Start();
676720
}
677721

678722
protected static ILogging Logger { get; } = Logging.GetLogger<User>();

0 commit comments

Comments
 (0)