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

File History Window #999

Merged
merged 27 commits into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
afec12d
File History
sambonfire Nov 8, 2018
6796651
Merge branch 'master' into master
sambonfire Dec 4, 2018
423f38d
Merge branch 'master' into master
StanleyGoldman Jan 2, 2019
f9f5202
Fixing build error
StanleyGoldman Jan 2, 2019
f5bab7a
Nit pick text
StanleyGoldman Jan 2, 2019
29b5142
Fixing project reference
StanleyGoldman Jan 2, 2019
32aa03d
Merge remote-tracking branch 'remotes/origin/master' into 961-fixes
StanleyGoldman Jan 14, 2019
dd5218d
Adding a context menu
StanleyGoldman Jan 14, 2019
333df3d
Merge pull request #1 from github-for-unity/961-fixes
sambonfire Jan 14, 2019
5f566c4
Prefer IList vs IEnumerable
sambonfire Jan 14, 2019
6e8ed9a
Adding generalized FileHistoryWindow and HistoryBase
StanleyGoldman Jan 15, 2019
5a2cb01
Fixing context menu displays
StanleyGoldman Jan 15, 2019
ad90c86
Start of a working File History
StanleyGoldman Jan 17, 2019
64087c1
Header and reactions to selected context
StanleyGoldman Jan 17, 2019
0940957
Dont default to locked
StanleyGoldman Jan 17, 2019
ae8e308
Using a folder icon when needed
StanleyGoldman Jan 23, 2019
bf5ddc4
Merge branch 'master' into file-history-view
StanleyGoldman Jan 23, 2019
1b3d0de
Layout and functionality to find file in asset explorer
StanleyGoldman Jan 23, 2019
9a5d027
refresh asset database after revert
sambonfire Jan 30, 2019
1b12912
added individual file revert; fixed domain reload bugs
sambonfire Jan 31, 2019
e6bb0b1
Merge pull request #1008 from bonfirestudios/file-history-refresh
StanleyGoldman Feb 12, 2019
24dd8be
Merge pull request #1009 from bonfirestudios/file-history-revert
StanleyGoldman Feb 12, 2019
31127b0
Calling GitClient.CheckoutVersion through Repository
StanleyGoldman Feb 11, 2019
b2bb6ce
Using the cache objects to keep file Status
StanleyGoldman Feb 12, 2019
ae75484
Using string over NPath; NPath is not serializable by Unity
StanleyGoldman Feb 12, 2019
299890b
Merge branch 'master' into file-history-view
StanleyGoldman Feb 12, 2019
a1ec31c
Design changes
StanleyGoldman Feb 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/GitHub.Api/Application/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,20 +469,20 @@ private GitHubUser GetValidatedGitHubUser()
}
}

class GitHubHostMeta
public class GitHubHostMeta
{
public bool VerifiablePasswordAuthentication { get; set; }
public string GithubServicesSha { get; set; }
public string InstalledVersion { get; set; }
}

class GitHubUser
public class GitHubUser
{
public string Name { get; set; }
public string Login { get; set; }
}

class GitHubRepository
public class GitHubRepository
{
public string Name { get; set; }
public string CloneUrl { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.Api/Application/IApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GitHub.Unity
{
interface IApiClient
public interface IApiClient
{
HostAddress HostAddress { get; }
void CreateRepository(string name, string description, bool isPrivate,
Expand Down
4 changes: 2 additions & 2 deletions src/GitHub.Api/Application/Organization.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace GitHub.Unity
{
class Organization
public class Organization
{
public string Name { get; set; }
public string Login { get; set; }
}
}
}
1 change: 1 addition & 0 deletions src/GitHub.Api/Cache/CacheContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void Dispose()

public IBranchCache BranchCache { get { return (IBranchCache)caches[CacheType.Branches].Value; } }
public IGitLogCache GitLogCache { get { return (IGitLogCache)caches[CacheType.GitLog].Value; } }
public IGitFileLogCache GitFileLogCache { get { return (IGitFileLogCache)caches[CacheType.GitFileLog].Value; } }
public IGitAheadBehindCache GitTrackingStatusCache { get { return (IGitAheadBehindCache)caches[CacheType.GitAheadBehind].Value; } }
public IGitStatusCache GitStatusEntriesCache { get { return (IGitStatusCache)caches[CacheType.GitStatus].Value; } }
public IGitLocksCache GitLocksCache { get { return (IGitLocksCache)caches[CacheType.GitLocks].Value; } }
Expand Down
7 changes: 7 additions & 0 deletions src/GitHub.Api/Cache/CacheInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum CacheType
RepositoryInfo,
Branches,
GitLog,
GitFileLog,
GitAheadBehind,
GitStatus,
GitLocks,
Expand All @@ -22,6 +23,7 @@ public interface ICacheContainer : IDisposable

IBranchCache BranchCache { get; }
IGitLogCache GitLogCache { get; }
IGitFileLogCache GitFileLogCache { get; }
IGitAheadBehindCache GitTrackingStatusCache { get; }
IGitStatusCache GitStatusEntriesCache { get; }
IGitLocksCache GitLocksCache { get; }
Expand Down Expand Up @@ -115,6 +117,11 @@ public interface IGitLogCache : IManagedCache
List<GitLogEntry> Log { get; set; }
}

public interface IGitFileLogCache : IManagedCache
{
GitFileLog FileLog { get; set; }
}

public interface ICanUpdate<T>
{
void UpdateData(T data);
Expand Down
40 changes: 40 additions & 0 deletions src/GitHub.Api/Git/GitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ public interface IGitClient
/// <returns>String output of git command</returns>
ITask<string> DiscardAll(IOutputProcessor<string> processor = null);

/// <summary>
/// Executes at least one `git checkout` command to checkout files at the given changeset
/// </summary>
/// <param name="changeset">The md5 of the changeset</param>
/// <param name="files">The files to check out</param>
/// <param name="processor">A custom output processor instance</param>
/// <returns>String output of git command</returns>
ITask<string> CheckoutVersion(string changeset, IList<string> files, IOutputProcessor<string> processor = null);

/// <summary>
/// Executes at least one `git reset HEAD` command to remove files from the git index.
/// </summary>
Expand Down Expand Up @@ -250,6 +259,14 @@ public interface IGitClient
/// <returns><see cref="List&lt;T&gt;"/> of <see cref="GitLogEntry"/> output</returns>
ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> processor = null);

/// <summary>
/// Executes `git log -- <file>` to get the history of a specific file.
/// </summary>
/// <param name="file"></param>
/// <param name="processor">A custom output processor instance</param>
/// <returns><see cref="List&lt;T&gt;"/> of <see cref="GitLogEntry"/> output</returns>
ITask<List<GitLogEntry>> LogFile(string file, BaseOutputListProcessor<GitLogEntry> processor = null);

/// <summary>
/// Executes `git --version` to get the git version.
/// </summary>
Expand Down Expand Up @@ -341,6 +358,22 @@ public ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> process
.Then((success, list) => success ? list : new List<GitLogEntry>());
}

///<inheritdoc/>
public ITask<List<GitLogEntry>> LogFile(string file, BaseOutputListProcessor<GitLogEntry> processor = null)
{
if (file == NPath.Default)
{
return new FuncTask<List<GitLogEntry>>(cancellationToken, () => new List<GitLogEntry>(0));
}

return new GitLogTask(file, new GitObjectFactory(environment), cancellationToken, processor)
.Configure(processManager)
.Catch(exception => exception is ProcessException &&
exception.Message.StartsWith("fatal: your current branch") &&
exception.Message.EndsWith("does not have any commits yet"))
.Then((success, list) => success ? list : new List<GitLogEntry>());
}

///<inheritdoc/>
public ITask<TheVersion> Version(IOutputProcessor<TheVersion> processor = null)
{
Expand Down Expand Up @@ -565,6 +598,13 @@ public ITask<string> DiscardAll(IOutputProcessor<string> processor = null)
.Configure(processManager);
}

///<inheritdoc/>
public ITask<string> CheckoutVersion(string changeset, IList<string> files, IOutputProcessor<string> processor = null)
{
return new GitCheckoutTask(changeset, files, cancellationToken, processor)
.Configure(processManager);
}

///<inheritdoc/>
public ITask<string> Remove(IList<string> files,
IOutputProcessor<string> processor = null)
Expand Down
32 changes: 32 additions & 0 deletions src/GitHub.Api/Git/GitFileLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;

namespace GitHub.Unity
{
[Serializable]
public struct GitFileLog
{
public static GitFileLog Default = new GitFileLog(null, new List<GitLogEntry>(0));

public string path;
public List<GitLogEntry> logEntries;

public GitFileLog(string path, List<GitLogEntry> logEntries)
{
this.path = path;
this.logEntries = logEntries;
}

public string Path
{
get { return path; }
set { path = value; }
}

public List<GitLogEntry> LogEntries
{
get { return logEntries; }
set { logEntries = value; }
}
}
}
6 changes: 5 additions & 1 deletion src/GitHub.Api/Git/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public interface IRepository : IEquatable<IRepository>, IDisposable, IBackedByCa
ITask RequestLock(NPath file);
ITask ReleaseLock(NPath file, bool force);
ITask DiscardChanges(GitStatusEntry[] discardEntries);
ITask CheckoutVersion(string changeset, IList<string> files);

/// <summary>
/// Gets the name of the repository.
Expand Down Expand Up @@ -61,8 +62,10 @@ public interface IRepository : IEquatable<IRepository>, IDisposable, IBackedByCa
List<GitLogEntry> CurrentLog { get; }
bool IsBusy { get; }
string CurrentHead { get; }
GitFileLog CurrentFileLog { get; }

event Action<CacheUpdateEvent> LogChanged;
event Action<CacheUpdateEvent> FileLogChanged;
event Action<CacheUpdateEvent> TrackingStatusChanged;
event Action<CacheUpdateEvent> StatusEntriesChanged;
event Action<CacheUpdateEvent> CurrentBranchChanged;
Expand All @@ -78,7 +81,8 @@ public interface IRepository : IEquatable<IRepository>, IDisposable, IBackedByCa
ITask DeleteBranch(string branch, bool force);
ITask CreateBranch(string branch, string baseBranch);
ITask SwitchBranch(string branch);
ITask UpdateFileLog(string path);
void Refresh(CacheType cacheType);
event Action<IProgress> OnProgress;
}
}
}
20 changes: 20 additions & 0 deletions src/GitHub.Api/Git/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ sealed class Repository : IEquatable<Repository>, IRepository
private HashSet<CacheType> cacheInvalidationRequests = new HashSet<CacheType>();
private Dictionary<CacheType, Action<CacheUpdateEvent>> cacheUpdateEvents;
private ProgressReporter progressReporter = new ProgressReporter();
private string lastFileLog;

public event Action<CacheUpdateEvent> LogChanged;
public event Action<CacheUpdateEvent> FileLogChanged;
public event Action<CacheUpdateEvent> TrackingStatusChanged;
public event Action<CacheUpdateEvent> StatusEntriesChanged;
public event Action<CacheUpdateEvent> CurrentBranchChanged;
Expand Down Expand Up @@ -63,6 +65,7 @@ public Repository(NPath localPath, ICacheContainer container)
{ CacheType.GitAheadBehind, c => TrackingStatusChanged?.Invoke(c) },
{ CacheType.GitLocks, c => LocksChanged?.Invoke(c) },
{ CacheType.GitLog, c => LogChanged?.Invoke(c) },
{ CacheType.GitFileLog, c => FileLogChanged?.Invoke(c) },
{ CacheType.GitStatus, c => StatusEntriesChanged?.Invoke(c) },
{ CacheType.GitUser, cacheUpdateEvent => { } },
{ CacheType.RepositoryInfo, cacheUpdateEvent => {
Expand Down Expand Up @@ -91,6 +94,7 @@ public void Initialize(IRepositoryManager theRepositoryManager, ITaskManager the
this.repositoryManager.GitStatusUpdated += RepositoryManagerOnGitStatusUpdated;
this.repositoryManager.GitAheadBehindStatusUpdated += RepositoryManagerOnGitAheadBehindStatusUpdated;
this.repositoryManager.GitLogUpdated += RepositoryManagerOnGitLogUpdated;
this.repositoryManager.GitFileLogUpdated += RepositoryManagerOnGitFileLogUpdated;
this.repositoryManager.GitLocksUpdated += RepositoryManagerOnGitLocksUpdated;
this.repositoryManager.LocalBranchesUpdated += RepositoryManagerOnLocalBranchesUpdated;
this.repositoryManager.RemoteBranchesUpdated += RepositoryManagerOnRemoteBranchesUpdated;
Expand Down Expand Up @@ -138,11 +142,17 @@ public ITask SetupRemote(string remote, string remoteUrl)
public ITask RequestLock(NPath file) => repositoryManager.LockFile(file);
public ITask ReleaseLock(NPath file, bool force) => repositoryManager.UnlockFile(file, force);
public ITask DiscardChanges(GitStatusEntry[] gitStatusEntry) => repositoryManager.DiscardChanges(gitStatusEntry);
public ITask CheckoutVersion(string changeset, IList<string> files) => repositoryManager.CheckoutVersion(changeset, files);
public ITask RemoteAdd(string remote, string url) => repositoryManager.RemoteAdd(remote, url);
public ITask RemoteRemove(string remote) => repositoryManager.RemoteRemove(remote);
public ITask DeleteBranch(string branch, bool force) => repositoryManager.DeleteBranch(branch, force);
public ITask CreateBranch(string branch, string baseBranch) => repositoryManager.CreateBranch(branch, baseBranch);
public ITask SwitchBranch(string branch) => repositoryManager.SwitchBranch(branch);
public ITask UpdateFileLog(string path)
{
lastFileLog = path;
return repositoryManager.UpdateFileLog(path);
}

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

Expand Down Expand Up @@ -215,6 +225,10 @@ private void CacheHasBeenInvalidated(CacheType cacheType)
repositoryManager?.UpdateGitLog().Catch(ex => InvalidationFailed(ex, cacheType)).Start();
break;

case CacheType.GitFileLog:
repositoryManager?.UpdateFileLog(lastFileLog).Catch(ex => InvalidationFailed(ex, cacheType)).Start();
break;

case CacheType.GitAheadBehind:
repositoryManager?.UpdateGitAheadBehindStatus().Catch(ex => InvalidationFailed(ex, cacheType)).Start();
break;
Expand Down Expand Up @@ -295,6 +309,11 @@ private void RepositoryManagerOnGitLogUpdated(List<GitLogEntry> gitLogEntries)
taskManager.RunInUI(() => cacheContainer.GitLogCache.Log = gitLogEntries);
}

private void RepositoryManagerOnGitFileLogUpdated(GitFileLog gitFileLog)
{
taskManager.RunInUI(() => cacheContainer.GitFileLogCache.FileLog = gitFileLog);
}

private void RepositoryManagerOnGitLocksUpdated(List<GitLock> gitLocks)
{
taskManager.RunInUI(() => cacheContainer.GitLocksCache.GitLocks = gitLocks);
Expand Down Expand Up @@ -360,6 +379,7 @@ public void Dispose()
public string CurrentBranchName => CurrentConfigBranch?.Name;
public GitRemote? CurrentRemote => cacheContainer.RepositoryInfoCache.CurrentGitRemote;
public List<GitLogEntry> CurrentLog => cacheContainer.GitLogCache.Log;
public GitFileLog CurrentFileLog => cacheContainer.GitFileLogCache.FileLog;
public List<GitLock> CurrentLocks => cacheContainer.GitLocksCache.GitLocks;
public string CurrentHead => cacheContainer.RepositoryInfoCache.CurrentHead;

Expand Down
27 changes: 27 additions & 0 deletions src/GitHub.Api/Git/RepositoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface IRepositoryManager : IDisposable
event Action<GitStatus> GitStatusUpdated;
event Action<List<GitLock>> GitLocksUpdated;
event Action<List<GitLogEntry>> GitLogUpdated;
event Action<GitFileLog> GitFileLogUpdated;
event Action<Dictionary<string, ConfigBranch>> LocalBranchesUpdated;
event Action<Dictionary<string, ConfigRemote>, Dictionary<string, Dictionary<string, ConfigBranch>>> RemoteBranchesUpdated;
event Action<GitAheadBehindStatus> GitAheadBehindStatusUpdated;
Expand All @@ -37,12 +38,15 @@ public interface IRepositoryManager : IDisposable
ITask LockFile(NPath file);
ITask UnlockFile(NPath file, bool force);
ITask DiscardChanges(GitStatusEntry[] gitStatusEntries);
ITask CheckoutVersion(string changeset, IList<string> files);
ITask UpdateGitLog();
ITask UpdateGitStatus();
ITask UpdateGitAheadBehindStatus();
ITask UpdateLocks();
ITask UpdateRepositoryInfo();
ITask UpdateBranches();
ITask UpdateFileLog(string path);


int WaitForEvents();

Expand Down Expand Up @@ -136,6 +140,7 @@ class RepositoryManager : IRepositoryManager
public event Action<GitAheadBehindStatus> GitAheadBehindStatusUpdated;
public event Action<List<GitLock>> GitLocksUpdated;
public event Action<List<GitLogEntry>> GitLogUpdated;
public event Action<GitFileLog> GitFileLogUpdated;
public event Action<Dictionary<string, ConfigBranch>> LocalBranchesUpdated;
public event Action<Dictionary<string, ConfigRemote>, Dictionary<string, Dictionary<string, ConfigBranch>>> RemoteBranchesUpdated;

Expand Down Expand Up @@ -341,6 +346,13 @@ public ITask DiscardChanges(GitStatusEntry[] gitStatusEntries)
return HookupHandlers(task, true);
}

public ITask CheckoutVersion(string changeset, IList<string> files)
{
var task = GitClient.CheckoutVersion(changeset, files)
.Then(() => DataNeedsRefreshing?.Invoke(CacheType.GitStatus));
return HookupHandlers(task, false);
}

public ITask UpdateGitLog()
{
var task = GitClient.Log()
Expand All @@ -354,6 +366,20 @@ public ITask UpdateGitLog()
return HookupHandlers(task, false);
}

public ITask UpdateFileLog(string path)
{
var task = GitClient.LogFile(path)
.Then((success, logEntries) =>
{
if (success)
{
var gitFileLog = new GitFileLog(path, logEntries);
GitFileLogUpdated?.Invoke(gitFileLog);
}
});
return HookupHandlers(task, false);
}

public ITask UpdateGitStatus()
{
var task = GitClient.Status()
Expand Down Expand Up @@ -644,6 +670,7 @@ private void Dispose(bool disposing)
GitStatusUpdated = null;
GitAheadBehindStatusUpdated = null;
GitLogUpdated = null;
GitFileLogUpdated = null;
GitLocksUpdated = null;
LocalBranchesUpdated = null;
RemoteBranchesUpdated = null;
Expand Down
25 changes: 23 additions & 2 deletions src/GitHub.Api/Git/Tasks/GitCheckoutTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,29 @@ public GitCheckoutTask(CancellationToken token,
arguments = "checkout -- .";
}

public GitCheckoutTask(
string changeset,
IEnumerable<string> files,
CancellationToken token,
IOutputProcessor<string> processor = null) : base(token, processor ?? new SimpleOutputProcessor())
{
Guard.ArgumentNotNull(files, "files");
Name = TaskName;

arguments = "checkout ";
arguments += changeset;
arguments += " -- ";

foreach (var file in files)
{
arguments += " \"" + file.ToNPath().ToString(SlashMode.Forward) + "\"";
}

Message = "Checking out files at rev " + changeset.Substring(0, 7);
}

public override string ProcessArguments { get { return arguments; } }
public override TaskAffinity Affinity { get { return TaskAffinity.Exclusive; } }
public override string Message { get; set; } = "Checking out branch...";
public override string Message { get; set; } = "Checking out files...";
}
}
}
Loading