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

Commit ad90c86

Browse files
Start of a working File History
1 parent 5a2cb01 commit ad90c86

File tree

13 files changed

+192
-57
lines changed

13 files changed

+192
-57
lines changed

src/GitHub.Api/Cache/CacheContainer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public void Dispose()
9090

9191
public IBranchCache BranchCache { get { return (IBranchCache)caches[CacheType.Branches].Value; } }
9292
public IGitLogCache GitLogCache { get { return (IGitLogCache)caches[CacheType.GitLog].Value; } }
93+
public IGitFileLogCache GitFileLogCache { get { return (IGitFileLogCache)caches[CacheType.GitFileLog].Value; } }
9394
public IGitAheadBehindCache GitTrackingStatusCache { get { return (IGitAheadBehindCache)caches[CacheType.GitAheadBehind].Value; } }
9495
public IGitStatusCache GitStatusEntriesCache { get { return (IGitStatusCache)caches[CacheType.GitStatus].Value; } }
9596
public IGitLocksCache GitLocksCache { get { return (IGitLocksCache)caches[CacheType.GitLocks].Value; } }

src/GitHub.Api/Cache/CacheInterfaces.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public enum CacheType
99
RepositoryInfo,
1010
Branches,
1111
GitLog,
12+
GitFileLog,
1213
GitAheadBehind,
1314
GitStatus,
1415
GitLocks,
@@ -22,6 +23,7 @@ public interface ICacheContainer : IDisposable
2223

2324
IBranchCache BranchCache { get; }
2425
IGitLogCache GitLogCache { get; }
26+
IGitFileLogCache GitFileLogCache { get; }
2527
IGitAheadBehindCache GitTrackingStatusCache { get; }
2628
IGitStatusCache GitStatusEntriesCache { get; }
2729
IGitLocksCache GitLocksCache { get; }
@@ -115,6 +117,11 @@ public interface IGitLogCache : IManagedCache
115117
List<GitLogEntry> Log { get; set; }
116118
}
117119

120+
public interface IGitFileLogCache : IManagedCache
121+
{
122+
GitFileLog FileLog { get; set; }
123+
}
124+
118125
public interface ICanUpdate<T>
119126
{
120127
void UpdateData(T data);

src/GitHub.Api/Git/GitClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@ public ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> process
360360
///<inheritdoc/>
361361
public ITask<List<GitLogEntry>> LogFile(NPath file, BaseOutputListProcessor<GitLogEntry> processor = null)
362362
{
363+
if (file == NPath.Default)
364+
{
365+
return new FuncTask<List<GitLogEntry>>(cancellationToken, () => new List<GitLogEntry>(0));
366+
}
367+
363368
return new GitLogTask(file, new GitObjectFactory(environment), cancellationToken, processor)
364369
.Configure(processManager)
365370
.Catch(exception => exception is ProcessException &&

src/GitHub.Api/Git/GitFileLog.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace GitHub.Unity
5+
{
6+
[Serializable]
7+
public struct GitFileLog
8+
{
9+
public static GitFileLog Default = new GitFileLog(NPath.Default, new List<GitLogEntry>(0));
10+
11+
public NPath path;
12+
public List<GitLogEntry> logEntries;
13+
14+
public GitFileLog(NPath path, List<GitLogEntry> logEntries)
15+
{
16+
this.path = path;
17+
this.logEntries = logEntries;
18+
}
19+
20+
public NPath Path
21+
{
22+
get { return path; }
23+
set { path = value; }
24+
}
25+
26+
public List<GitLogEntry> LogEntries
27+
{
28+
get { return logEntries; }
29+
set { logEntries = value; }
30+
}
31+
}
32+
}

src/GitHub.Api/Git/IRepository.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ public interface IRepository : IEquatable<IRepository>, IDisposable, IBackedByCa
6161
List<GitLogEntry> CurrentLog { get; }
6262
bool IsBusy { get; }
6363
string CurrentHead { get; }
64+
GitFileLog CurrentFileLog { get; }
6465

6566
event Action<CacheUpdateEvent> LogChanged;
67+
event Action<CacheUpdateEvent> FileLogChanged;
6668
event Action<CacheUpdateEvent> TrackingStatusChanged;
6769
event Action<CacheUpdateEvent> StatusEntriesChanged;
6870
event Action<CacheUpdateEvent> CurrentBranchChanged;
@@ -80,5 +82,6 @@ public interface IRepository : IEquatable<IRepository>, IDisposable, IBackedByCa
8082
ITask SwitchBranch(string branch);
8183
void Refresh(CacheType cacheType);
8284
event Action<IProgress> OnProgress;
85+
ITask UpdateFileLog(NPath path);
8386
}
84-
}
87+
}

src/GitHub.Api/Git/Repository.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ sealed class Repository : IEquatable<Repository>, IRepository
2525
private HashSet<CacheType> cacheInvalidationRequests = new HashSet<CacheType>();
2626
private Dictionary<CacheType, Action<CacheUpdateEvent>> cacheUpdateEvents;
2727
private ProgressReporter progressReporter = new ProgressReporter();
28+
private NPath lastFileLog = NPath.Default;
2829

2930
public event Action<CacheUpdateEvent> LogChanged;
31+
public event Action<CacheUpdateEvent> FileLogChanged;
3032
public event Action<CacheUpdateEvent> TrackingStatusChanged;
3133
public event Action<CacheUpdateEvent> StatusEntriesChanged;
3234
public event Action<CacheUpdateEvent> CurrentBranchChanged;
@@ -63,6 +65,7 @@ public Repository(NPath localPath, ICacheContainer container)
6365
{ CacheType.GitAheadBehind, c => TrackingStatusChanged?.Invoke(c) },
6466
{ CacheType.GitLocks, c => LocksChanged?.Invoke(c) },
6567
{ CacheType.GitLog, c => LogChanged?.Invoke(c) },
68+
{ CacheType.GitFileLog, c => FileLogChanged?.Invoke(c) },
6669
{ CacheType.GitStatus, c => StatusEntriesChanged?.Invoke(c) },
6770
{ CacheType.GitUser, cacheUpdateEvent => { } },
6871
{ CacheType.RepositoryInfo, cacheUpdateEvent => {
@@ -91,6 +94,7 @@ public void Initialize(IRepositoryManager theRepositoryManager, ITaskManager the
9194
this.repositoryManager.GitStatusUpdated += RepositoryManagerOnGitStatusUpdated;
9295
this.repositoryManager.GitAheadBehindStatusUpdated += RepositoryManagerOnGitAheadBehindStatusUpdated;
9396
this.repositoryManager.GitLogUpdated += RepositoryManagerOnGitLogUpdated;
97+
this.repositoryManager.GitFileLogUpdated += RepositoryManagerOnGitFileLogUpdated;
9498
this.repositoryManager.GitLocksUpdated += RepositoryManagerOnGitLocksUpdated;
9599
this.repositoryManager.LocalBranchesUpdated += RepositoryManagerOnLocalBranchesUpdated;
96100
this.repositoryManager.RemoteBranchesUpdated += RepositoryManagerOnRemoteBranchesUpdated;
@@ -143,6 +147,11 @@ public ITask SetupRemote(string remote, string remoteUrl)
143147
public ITask DeleteBranch(string branch, bool force) => repositoryManager.DeleteBranch(branch, force);
144148
public ITask CreateBranch(string branch, string baseBranch) => repositoryManager.CreateBranch(branch, baseBranch);
145149
public ITask SwitchBranch(string branch) => repositoryManager.SwitchBranch(branch);
150+
public ITask UpdateFileLog(NPath path)
151+
{
152+
lastFileLog = path;
153+
return repositoryManager.UpdateFileLog(path);
154+
}
146155

147156
public void CheckAndRaiseEventsIfCacheNewer(CacheType cacheType, CacheUpdateEvent cacheUpdateEvent) => cacheContainer.CheckAndRaiseEventsIfCacheNewer(cacheType, cacheUpdateEvent);
148157

@@ -215,6 +224,10 @@ private void CacheHasBeenInvalidated(CacheType cacheType)
215224
repositoryManager?.UpdateGitLog().Catch(ex => InvalidationFailed(ex, cacheType)).Start();
216225
break;
217226

227+
case CacheType.GitFileLog:
228+
repositoryManager?.UpdateFileLog(lastFileLog).Catch(ex => InvalidationFailed(ex, cacheType)).Start();
229+
break;
230+
218231
case CacheType.GitAheadBehind:
219232
repositoryManager?.UpdateGitAheadBehindStatus().Catch(ex => InvalidationFailed(ex, cacheType)).Start();
220233
break;
@@ -295,6 +308,11 @@ private void RepositoryManagerOnGitLogUpdated(List<GitLogEntry> gitLogEntries)
295308
taskManager.RunInUI(() => cacheContainer.GitLogCache.Log = gitLogEntries);
296309
}
297310

311+
private void RepositoryManagerOnGitFileLogUpdated(GitFileLog gitFileLog)
312+
{
313+
taskManager.RunInUI(() => cacheContainer.GitFileLogCache.FileLog = gitFileLog);
314+
}
315+
298316
private void RepositoryManagerOnGitLocksUpdated(List<GitLock> gitLocks)
299317
{
300318
taskManager.RunInUI(() => cacheContainer.GitLocksCache.GitLocks = gitLocks);
@@ -360,6 +378,7 @@ public void Dispose()
360378
public string CurrentBranchName => CurrentConfigBranch?.Name;
361379
public GitRemote? CurrentRemote => cacheContainer.RepositoryInfoCache.CurrentGitRemote;
362380
public List<GitLogEntry> CurrentLog => cacheContainer.GitLogCache.Log;
381+
public GitFileLog CurrentFileLog => cacheContainer.GitFileLogCache.FileLog;
363382
public List<GitLock> CurrentLocks => cacheContainer.GitLocksCache.GitLocks;
364383
public string CurrentHead => cacheContainer.RepositoryInfoCache.CurrentHead;
365384

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public interface IRepositoryManager : IDisposable
1313
event Action<GitStatus> GitStatusUpdated;
1414
event Action<List<GitLock>> GitLocksUpdated;
1515
event Action<List<GitLogEntry>> GitLogUpdated;
16+
event Action<GitFileLog> GitFileLogUpdated;
1617
event Action<Dictionary<string, ConfigBranch>> LocalBranchesUpdated;
1718
event Action<Dictionary<string, ConfigRemote>, Dictionary<string, Dictionary<string, ConfigBranch>>> RemoteBranchesUpdated;
1819
event Action<GitAheadBehindStatus> GitAheadBehindStatusUpdated;
@@ -43,6 +44,8 @@ public interface IRepositoryManager : IDisposable
4344
ITask UpdateLocks();
4445
ITask UpdateRepositoryInfo();
4546
ITask UpdateBranches();
47+
ITask UpdateFileLog(NPath path);
48+
4649

4750
int WaitForEvents();
4851

@@ -136,6 +139,7 @@ class RepositoryManager : IRepositoryManager
136139
public event Action<GitAheadBehindStatus> GitAheadBehindStatusUpdated;
137140
public event Action<List<GitLock>> GitLocksUpdated;
138141
public event Action<List<GitLogEntry>> GitLogUpdated;
142+
public event Action<GitFileLog> GitFileLogUpdated;
139143
public event Action<Dictionary<string, ConfigBranch>> LocalBranchesUpdated;
140144
public event Action<Dictionary<string, ConfigRemote>, Dictionary<string, Dictionary<string, ConfigBranch>>> RemoteBranchesUpdated;
141145

@@ -354,6 +358,20 @@ public ITask UpdateGitLog()
354358
return HookupHandlers(task, false);
355359
}
356360

361+
public ITask UpdateFileLog(NPath path)
362+
{
363+
var task = GitClient.LogFile(path)
364+
.Then((success, logEntries) =>
365+
{
366+
if (success)
367+
{
368+
var gitFileLog = new GitFileLog(path, logEntries);
369+
GitFileLogUpdated?.Invoke(gitFileLog);
370+
}
371+
});
372+
return HookupHandlers(task, false);
373+
}
374+
357375
public ITask UpdateGitStatus()
358376
{
359377
var task = GitClient.Status()
@@ -644,6 +662,7 @@ private void Dispose(bool disposing)
644662
GitStatusUpdated = null;
645663
GitAheadBehindStatusUpdated = null;
646664
GitLogUpdated = null;
665+
GitFileLogUpdated = null;
647666
GitLocksUpdated = null;
648667
LocalBranchesUpdated = null;
649668
RemoteBranchesUpdated = null;

src/GitHub.Api/GitHub.Api.45.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<Compile Include="Cache\CachingClasses.cs" />
8080
<Compile Include="Extensions\ActionExtensions.cs" />
8181
<Compile Include="Extensions\ListExtensions.cs" />
82+
<Compile Include="Git\GitFileLog.cs" />
8283
<Compile Include="Git\Tasks\GitCheckoutTask.cs" />
8384
<Compile Include="Git\GitAheadBehindStatus.cs" />
8485
<Compile Include="Git\Tasks\GitAheadBehindStatusTask.cs" />

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<Compile Include="Cache\CachingClasses.cs" />
9191
<Compile Include="Extensions\ActionExtensions.cs" />
9292
<Compile Include="Extensions\ListExtensions.cs" />
93+
<Compile Include="Git\GitFileLog.cs" />
9394
<Compile Include="Git\Tasks\GitCheckoutTask.cs" />
9495
<Compile Include="Git\GitAheadBehindStatus.cs" />
9596
<Compile Include="Git\Tasks\GitAheadBehindStatusTask.cs" />

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public IEnvironment Environment
147147
cacheContainer.SetCacheInitializer(CacheType.GitAheadBehind, () => GitAheadBehindCache.Instance);
148148
cacheContainer.SetCacheInitializer(CacheType.GitLocks, () => GitLocksCache.Instance);
149149
cacheContainer.SetCacheInitializer(CacheType.GitLog, () => GitLogCache.Instance);
150+
cacheContainer.SetCacheInitializer(CacheType.GitFileLog, () => GitFileLogCache.Instance);
150151
cacheContainer.SetCacheInitializer(CacheType.GitStatus, () => GitStatusCache.Instance);
151152
cacheContainer.SetCacheInitializer(CacheType.GitUser, () => GitUserCache.Instance);
152153
cacheContainer.SetCacheInitializer(CacheType.RepositoryInfo, () => RepositoryInfoCache.Instance);
@@ -622,6 +623,46 @@ public List<GitLogEntry> Log
622623
public override TimeSpan DataTimeout { get { return TimeSpan.FromMinutes(1); } }
623624
}
624625

626+
[Location("cache/gitfilelog.yaml", LocationAttribute.Location.LibraryFolder)]
627+
sealed class GitFileLogCache : ManagedCacheBase<GitFileLogCache>, IGitFileLogCache
628+
{
629+
[SerializeField] private GitFileLog fileLog = GitFileLog.Default;
630+
631+
public GitFileLogCache() : base(CacheType.GitFileLog)
632+
{ }
633+
634+
public GitFileLog FileLog
635+
{
636+
get
637+
{
638+
ValidateData();
639+
return fileLog;
640+
}
641+
set
642+
{
643+
var now = DateTimeOffset.Now;
644+
var isUpdated = false;
645+
646+
var shouldUpdate = forcedInvalidation;
647+
648+
if (!shouldUpdate)
649+
{
650+
shouldUpdate = true;
651+
}
652+
653+
if (shouldUpdate)
654+
{
655+
fileLog = value;
656+
isUpdated = true;
657+
}
658+
659+
SaveData(now, isUpdated);
660+
}
661+
}
662+
663+
public override TimeSpan DataTimeout { get { return TimeSpan.FromMinutes(1); } }
664+
}
665+
625666
[Location("cache/gittrackingstatus.yaml", LocationAttribute.Location.LibraryFolder)]
626667
sealed class GitAheadBehindCache : ManagedCacheBase<GitAheadBehindCache>, IGitAheadBehindCache
627668
{

0 commit comments

Comments
 (0)