|
1 | | -using System; |
2 | | -using System.Collections.Generic; |
| 1 | +using System.Collections.Generic; |
3 | 2 | using System.Text; |
4 | | -using System.Text.RegularExpressions; |
| 3 | +using System.Text.Json; |
5 | 4 | using System.Threading.Tasks; |
6 | 5 |
|
7 | 6 | namespace SourceGit.Commands |
8 | 7 | { |
9 | | - public partial class LFS : Command |
| 8 | + public class LFS : Command |
10 | 9 | { |
11 | | - [GeneratedRegex(@"^(.+)\s+([\w.]+)\s+\w+:(\d+)$")] |
12 | | - private static partial Regex REG_LOCK(); |
13 | | - |
14 | 10 | public LFS(string repo) |
15 | 11 | { |
16 | 12 | WorkingDirectory = repo; |
@@ -60,30 +56,23 @@ public async Task PruneAsync() |
60 | 56 |
|
61 | 57 | public async Task<List<Models.LFSLock>> GetLocksAsync(string remote) |
62 | 58 | { |
63 | | - Args = $"lfs locks --remote={remote}"; |
| 59 | + Args = $"lfs locks --json --remote={remote}"; |
64 | 60 |
|
65 | 61 | var rs = await ReadToEndAsync().ConfigureAwait(false); |
66 | | - var locks = new List<Models.LFSLock>(); |
67 | | - |
68 | 62 | if (rs.IsSuccess) |
69 | 63 | { |
70 | | - var lines = rs.StdOut.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries); |
71 | | - foreach (var line in lines) |
| 64 | + try |
| 65 | + { |
| 66 | + var locks = JsonSerializer.Deserialize(rs.StdOut, JsonCodeGen.Default.ListLFSLock); |
| 67 | + return locks; |
| 68 | + } |
| 69 | + catch |
72 | 70 | { |
73 | | - var match = REG_LOCK().Match(line); |
74 | | - if (match.Success) |
75 | | - { |
76 | | - locks.Add(new Models.LFSLock() |
77 | | - { |
78 | | - File = match.Groups[1].Value, |
79 | | - User = match.Groups[2].Value, |
80 | | - ID = long.Parse(match.Groups[3].Value), |
81 | | - }); |
82 | | - } |
| 71 | + // Ignore exceptions. |
83 | 72 | } |
84 | 73 | } |
85 | 74 |
|
86 | | - return locks; |
| 75 | + return []; |
87 | 76 | } |
88 | 77 |
|
89 | 78 | public async Task<bool> LockAsync(string remote, string file) |
|
0 commit comments