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

Commit e0a9c9c

Browse files
Splitting values stored by GitStatusCache
Splitting these values in order to update them independently
1 parent d7a3000 commit e0a9c9c

File tree

9 files changed

+55
-53
lines changed

9 files changed

+55
-53
lines changed

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.

src/GitHub.Api/Git/IRepository.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,16 @@ public interface IRepository : IEquatable<IRepository>
5757
/// Gets the current branch of the repository.
5858
/// </summary>
5959
GitBranch? CurrentBranch { get; }
60-
GitStatus CurrentStatus { get; }
60+
// GitStatus CurrentStatus { get; }
6161
GitRemote[] Remotes { get; }
6262
GitBranch[] LocalBranches { get; }
6363
GitBranch[] RemoteBranches { get; }
6464
List<GitLock> CurrentLocks { get; }
6565
string CurrentBranchName { get; }
6666
List<GitLogEntry> CurrentLog { get; }
67+
int CurrentAhead { get; }
68+
int CurrentBehind { get; }
69+
List<GitStatusEntry> CurrentChanges { get; }
6770

6871
event Action<CacheUpdateEvent> LogChanged;
6972
event Action<CacheUpdateEvent> StatusChanged;

src/GitHub.Api/Git/Repository.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,9 @@ private void RepositoryManagerOnCurrentBranchUpdated(ConfigBranch? branch, Confi
372372
private void RepositoryManagerOnGitStatusUpdated(GitStatus gitStatus)
373373
{
374374
new ActionTask(CancellationToken.None, () => {
375-
CurrentStatus = gitStatus;
375+
CurrentChanges = gitStatus.Entries;
376+
CurrentAhead = gitStatus.Ahead;
377+
CurrentBehind = gitStatus.Behind;
376378
}) { Affinity = TaskAffinity.UI }.Start();
377379
}
378380

@@ -469,10 +471,22 @@ private ConfigRemote? CurrentConfigRemote
469471
set { cacheContainer.BranchCache.CurrentConfigRemote = value; }
470472
}
471473

472-
public GitStatus CurrentStatus
474+
public int CurrentAhead
473475
{
474-
get { return cacheContainer.GitStatusCache.GitStatus; }
475-
private set { cacheContainer.GitStatusCache.GitStatus = value; }
476+
get { return cacheContainer.GitStatusCache.Ahead; }
477+
private set { cacheContainer.GitStatusCache.Ahead = value; }
478+
}
479+
480+
public int CurrentBehind
481+
{
482+
get { return cacheContainer.GitStatusCache.Behind; }
483+
private set { cacheContainer.GitStatusCache.Behind = value; }
484+
}
485+
486+
public List<GitStatusEntry> CurrentChanges
487+
{
488+
get { return cacheContainer.GitStatusCache.Entries; }
489+
private set { cacheContainer.GitStatusCache.Entries = value; }
476490
}
477491

478492
public GitBranch? CurrentBranch

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@
149149
<Compile Include="Metrics\UsageModel.cs" />
150150
<Compile Include="Metrics\UsageTracker.cs" />
151151
<Compile Include="Git\Tasks\GitLfsInstallTask.cs" />
152-
<Compile Include="Extensions\GitStatusExtensions.cs" />
153152
<Compile Include="Git\Tasks\GitRemoteChangeTask.cs" />
154153
<Compile Include="Git\Tasks\GitRemoveFromIndexTask.cs" />
155154
<Compile Include="Threading\IMainThreadSynchronizationContext.cs" />

src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -836,35 +836,13 @@ sealed class GitStatusCache : ManagedCacheBase<GitStatusCache>, IGitStatusCache
836836
[SerializeField] private string lastUpdatedAtString = DateTimeOffset.MinValue.ToString();
837837
[SerializeField] private string lastVerifiedAtString = DateTimeOffset.MinValue.ToString();
838838
[SerializeField] private string initializedAtString = DateTimeOffset.MinValue.ToString();
839-
[SerializeField] private GitStatus status;
839+
[SerializeField] private int ahead;
840+
[SerializeField] private int behind;
841+
[SerializeField] private List<GitStatusEntry> entries;
840842

841843
public GitStatusCache() : base(true)
842844
{ }
843845

844-
public GitStatus GitStatus
845-
{
846-
get
847-
{
848-
ValidateData();
849-
return status;
850-
}
851-
set
852-
{
853-
var now = DateTimeOffset.Now;
854-
var isUpdated = false;
855-
856-
Logger.Trace("Updating: {0} gitStatus:{1}", now, value);
857-
858-
if (!status.Equals(value))
859-
{
860-
status = value;
861-
isUpdated = true;
862-
}
863-
864-
SaveData(now, isUpdated);
865-
}
866-
}
867-
868846
public override string LastUpdatedAtString
869847
{
870848
get { return lastUpdatedAtString; }
@@ -887,6 +865,24 @@ public override TimeSpan DataTimeout
887865
{
888866
get { return TimeSpan.FromMinutes(1); }
889867
}
868+
869+
public int Ahead
870+
{
871+
get { return ahead; }
872+
set { ahead = value; }
873+
}
874+
875+
public int Behind
876+
{
877+
get { return behind; }
878+
set { behind = value; }
879+
}
880+
881+
public List<GitStatusEntry> Entries
882+
{
883+
get { return entries; }
884+
set { entries = value; }
885+
}
890886
}
891887

892888
[Location("cache/gitlocks.yaml", LocationAttribute.Location.LibraryFolder)]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ private void MaybeUpdateData()
156156
if (currentStatusHasUpdate)
157157
{
158158
currentStatusHasUpdate = false;
159-
var gitStatus = Repository.CurrentStatus;
160-
tree.UpdateEntries(gitStatus.Entries.Where(x => x.Status != GitFileStatus.Ignored).ToList());
159+
var entries = Repository.CurrentChanges;
160+
tree.UpdateEntries(entries.Where(x => x.Status != GitFileStatus.Ignored).ToList());
161161
}
162162
}
163163

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,12 @@ private void MaybeUpdateData()
373373
{
374374
currentStatusHasUpdate = false;
375375

376-
var currentStatus = Repository.CurrentStatus;
377-
statusAhead = currentStatus.Ahead;
378-
statusBehind = currentStatus.Behind;
379-
hasItemsToCommit = currentStatus.Entries != null &&
380-
currentStatus.GetEntriesExcludingIgnoredAndUntracked().Any();
376+
statusAhead = Repository.CurrentAhead;
377+
statusBehind = Repository.CurrentBehind;
378+
var currentChanges = Repository.CurrentChanges;
379+
380+
hasItemsToCommit = currentChanges != null
381+
&& currentChanges.Any(entry => entry.Status != GitFileStatus.Ignored && !entry.Staged);
381382
}
382383

383384
if (currentLogHasUpdate)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private static void RepositoryOnStatusChanged(CacheUpdateEvent cacheUpdateEvent)
4747
{
4848
lastRepositoryStatusChangedEvent = cacheUpdateEvent;
4949
entries.Clear();
50-
entries.AddRange(repository.CurrentStatus.Entries);
50+
entries.AddRange(repository.CurrentChanges);
5151
OnStatusUpdate();
5252
}
5353
}

0 commit comments

Comments
 (0)