Skip to content

Commit d5f1890

Browse files
committed
code_style: move platform-dependent code to SourceGit.Native.OS
Signed-off-by: leo <[email protected]>
1 parent 9d3335d commit d5f1890

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/Converters/PathConverters.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
21
using System.IO;
3-
42
using Avalonia.Data.Converters;
53

64
namespace SourceGit.Converters
@@ -14,17 +12,6 @@ public static class PathConverters
1412
new(v => Path.GetDirectoryName(v) ?? "");
1513

1614
public static readonly FuncValueConverter<string, string> RelativeToHome =
17-
new(v =>
18-
{
19-
if (OperatingSystem.IsWindows())
20-
return v;
21-
22-
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
23-
var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length;
24-
if (v.StartsWith(home, StringComparison.Ordinal))
25-
return $"~{v.AsSpan(prefixLen)}";
26-
27-
return v;
28-
});
15+
new(Native.OS.GetRelativePathToHome);
2916
}
3017
}

src/Native/OS.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,19 @@ public static string GetAbsPath(string root, string sub)
229229
return fullpath;
230230
}
231231

232+
public static string GetRelativePathToHome(string path)
233+
{
234+
if (OperatingSystem.IsWindows())
235+
return path;
236+
237+
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
238+
var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length;
239+
if (path.StartsWith(home, StringComparison.Ordinal))
240+
return $"~{path.AsSpan(prefixLen)}";
241+
242+
return path;
243+
}
244+
232245
private static void UpdateGitVersion()
233246
{
234247
if (string.IsNullOrEmpty(_gitExecutable) || !File.Exists(_gitExecutable))

0 commit comments

Comments
 (0)