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

Commit ae75484

Browse files
Using string over NPath; NPath is not serializable by Unity
1 parent b2bb6ce commit ae75484

File tree

7 files changed

+33
-29
lines changed

7 files changed

+33
-29
lines changed

src/GitHub.Api/Git/GitClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,10 @@ public interface IGitClient
262262
/// <summary>
263263
/// Executes `git log -- <file>` to get the history of a specific file.
264264
/// </summary>
265+
/// <param name="file"></param>
265266
/// <param name="processor">A custom output processor instance</param>
266267
/// <returns><see cref="List&lt;T&gt;"/> of <see cref="GitLogEntry"/> output</returns>
267-
ITask<List<GitLogEntry>> LogFile(NPath file, BaseOutputListProcessor<GitLogEntry> processor = null);
268+
ITask<List<GitLogEntry>> LogFile(string file, BaseOutputListProcessor<GitLogEntry> processor = null);
268269

269270
/// <summary>
270271
/// Executes `git --version` to get the git version.
@@ -358,7 +359,7 @@ public ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> process
358359
}
359360

360361
///<inheritdoc/>
361-
public ITask<List<GitLogEntry>> LogFile(NPath file, BaseOutputListProcessor<GitLogEntry> processor = null)
362+
public ITask<List<GitLogEntry>> LogFile(string file, BaseOutputListProcessor<GitLogEntry> processor = null)
362363
{
363364
if (file == NPath.Default)
364365
{

src/GitHub.Api/Git/GitFileLog.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ namespace GitHub.Unity
66
[Serializable]
77
public struct GitFileLog
88
{
9-
public static GitFileLog Default = new GitFileLog(NPath.Default, new List<GitLogEntry>(0));
9+
public static GitFileLog Default = new GitFileLog(null, new List<GitLogEntry>(0));
1010

11-
public NPath path;
11+
public string path;
1212
public List<GitLogEntry> logEntries;
1313

14-
public GitFileLog(NPath path, List<GitLogEntry> logEntries)
14+
public GitFileLog(string path, List<GitLogEntry> logEntries)
1515
{
1616
this.path = path;
1717
this.logEntries = logEntries;
1818
}
1919

20-
public NPath Path
20+
public string Path
2121
{
2222
get { return path; }
2323
set { path = value; }

src/GitHub.Api/Git/IRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public interface IRepository : IEquatable<IRepository>, IDisposable, IBackedByCa
8181
ITask DeleteBranch(string branch, bool force);
8282
ITask CreateBranch(string branch, string baseBranch);
8383
ITask SwitchBranch(string branch);
84+
ITask UpdateFileLog(string path);
8485
void Refresh(CacheType cacheType);
8586
event Action<IProgress> OnProgress;
86-
ITask UpdateFileLog(NPath path);
8787
}
8888
}

src/GitHub.Api/Git/Repository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ 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;
28+
private string lastFileLog;
2929

3030
public event Action<CacheUpdateEvent> LogChanged;
3131
public event Action<CacheUpdateEvent> FileLogChanged;
@@ -148,7 +148,7 @@ public ITask SetupRemote(string remote, string remoteUrl)
148148
public ITask DeleteBranch(string branch, bool force) => repositoryManager.DeleteBranch(branch, force);
149149
public ITask CreateBranch(string branch, string baseBranch) => repositoryManager.CreateBranch(branch, baseBranch);
150150
public ITask SwitchBranch(string branch) => repositoryManager.SwitchBranch(branch);
151-
public ITask UpdateFileLog(NPath path)
151+
public ITask UpdateFileLog(string path)
152152
{
153153
lastFileLog = path;
154154
return repositoryManager.UpdateFileLog(path);

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public interface IRepositoryManager : IDisposable
4545
ITask UpdateLocks();
4646
ITask UpdateRepositoryInfo();
4747
ITask UpdateBranches();
48-
ITask UpdateFileLog(NPath path);
48+
ITask UpdateFileLog(string path);
4949

5050

5151
int WaitForEvents();
@@ -366,7 +366,7 @@ public ITask UpdateGitLog()
366366
return HookupHandlers(task, false);
367367
}
368368

369-
public ITask UpdateFileLog(NPath path)
369+
public ITask UpdateFileLog(string path)
370370
{
371371
var task = GitClient.LogFile(path)
372372
.Then((success, logEntries) =>

src/GitHub.Api/Git/Tasks/GitLogTask.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ public GitLogTask(IGitObjectFactory gitObjectFactory,
1616
arguments = baseArguments;
1717
}
1818

19-
public GitLogTask(NPath file,
19+
public GitLogTask(string file,
2020
IGitObjectFactory gitObjectFactory,
2121
CancellationToken token, BaseOutputListProcessor<GitLogEntry> processor = null)
2222
: base(token, processor ?? new LogEntryOutputProcessor(gitObjectFactory))
2323
{
2424
Name = TaskName;
2525
arguments = baseArguments;
2626
arguments += " -- ";
27-
arguments += " \"" + file.ToString(SlashMode.Forward) + "\"";
27+
arguments += " \"" + file + "\"";
2828
}
2929

3030
public override string ProcessArguments

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,28 @@ private static bool GitFileHistoryValidation()
3838
[SerializeField] private bool locked;
3939
[SerializeField] private FileHistoryView fileHistoryView = new FileHistoryView();
4040
[SerializeField] private UnityEngine.Object selectedObject;
41-
[SerializeField] private NPath selectedObjectAssetPath;
41+
[SerializeField] private string selectedObjectAssetPath;
42+
[SerializeField] private string selectedObjectRepositoryPath;
4243

43-
public void SetSelectedPath(NPath assetPath)
44+
public void SetSelectedPath(string assetPath)
4445
{
45-
NPath repositoryPath = NPath.Default;
46-
47-
selectedObjectAssetPath = assetPath;
4846
selectedObject = null;
47+
selectedObjectAssetPath = null;
48+
selectedObjectRepositoryPath = null;
4949

5050
if (selectedObjectAssetPath != NPath.Default)
5151
{
52-
selectedObject = AssetDatabase.LoadMainAssetAtPath(selectedObjectAssetPath.ToString());
52+
selectedObjectAssetPath = assetPath;
53+
selectedObject = AssetDatabase.LoadMainAssetAtPath(selectedObjectAssetPath);
5354

54-
repositoryPath = Environment.GetRepositoryPath(assetPath);
55+
selectedObjectRepositoryPath =
56+
Environment.GetRepositoryPath(assetPath.ToNPath())
57+
.ToString(SlashMode.Forward);
5558
}
5659

5760
LoadSelectedIcon();
5861

59-
Repository.UpdateFileLog(repositoryPath)
62+
Repository.UpdateFileLog(selectedObjectRepositoryPath)
6063
.Start();
6164
}
6265

@@ -124,14 +127,14 @@ public override void OnSelectionChange()
124127
if (!locked)
125128
{
126129
selectedObject = Selection.activeObject;
127-
selectedObjectAssetPath = NPath.Default;
130+
131+
string assetPath = null;
128132
if (selectedObject != null)
129133
{
130-
selectedObjectAssetPath = AssetDatabase.GetAssetPath(selectedObject)
131-
.ToNPath();
132-
133-
SetSelectedPath(selectedObjectAssetPath);
134+
assetPath = AssetDatabase.GetAssetPath(selectedObject);
134135
}
136+
137+
SetSelectedPath(assetPath);
135138
}
136139
}
137140

@@ -185,15 +188,15 @@ private void LoadSelectedIcon()
185188
{
186189
Texture nodeIcon = null;
187190

188-
if (selectedObjectAssetPath != NPath.Default)
191+
if (!string.IsNullOrEmpty(selectedObjectAssetPath))
189192
{
190-
if (selectedObjectAssetPath.DirectoryExists())
193+
if (selectedObjectAssetPath.ToNPath().DirectoryExists())
191194
{
192195
nodeIcon = Styles.FolderIcon;
193196
}
194197
else
195198
{
196-
nodeIcon = UnityEditorInternal.InternalEditorUtility.GetIconForFile(selectedObjectAssetPath.ToString());
199+
nodeIcon = UnityEditorInternal.InternalEditorUtility.GetIconForFile(selectedObjectAssetPath);
197200
}
198201

199202
nodeIcon.hideFlags = HideFlags.HideAndDontSave;

0 commit comments

Comments
 (0)