diff --git a/src/Commands/QuerySubmodules.cs b/src/Commands/QuerySubmodules.cs index 622de2fc..24e040d5 100644 --- a/src/Commands/QuerySubmodules.cs +++ b/src/Commands/QuerySubmodules.cs @@ -17,9 +17,10 @@ namespace SourceGit.Commands Args = "submodule status"; } - public List Result() + public List Result() { Exec(); + new UpdateSubmoduleStatus(WorkingDirectory, _submodules).Result(); return _submodules; } @@ -28,17 +29,17 @@ namespace SourceGit.Commands var match = REG_FORMAT1().Match(line); if (match.Success) { - _submodules.Add(match.Groups[1].Value); + _submodules.Add(new Models.Submodule() { Path = match.Groups[1].Value }); return; } match = REG_FORMAT2().Match(line); if (match.Success) { - _submodules.Add(match.Groups[1].Value); + _submodules.Add(new Models.Submodule() { Path = match.Groups[1].Value }); } } - private readonly List _submodules = new List(); + private readonly List _submodules = new List(); } } diff --git a/src/Commands/UpdateSubmoduleStatus.cs b/src/Commands/UpdateSubmoduleStatus.cs new file mode 100644 index 00000000..38b3c33e --- /dev/null +++ b/src/Commands/UpdateSubmoduleStatus.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using System.Text; +using System.Text.RegularExpressions; + +namespace SourceGit.Commands +{ + public partial class UpdateSubmoduleStatus : Command + { + [GeneratedRegex(@"^\s?[\w\?]{1,4}\s+(.+)$")] + private static partial Regex REG_FORMAT(); + + public UpdateSubmoduleStatus(string repo, List submodules) + { + var pathes = new StringBuilder(); + foreach (var submodule in submodules) + pathes.Append($"\"{submodule.Path}\" "); + + _submodules = submodules; + + WorkingDirectory = repo; + Context = repo; + Args = $"status -uno --porcelain -- {pathes}"; + } + + public void Result() + { + Exec(); + + foreach (var submodule in _submodules) + submodule.IsDirty = _changed.Contains(submodule.Path); + } + + protected override void OnReadline(string line) + { + var match = REG_FORMAT().Match(line); + if (match.Success) + _changed.Add(match.Groups[1].Value); + } + + private List _submodules = null; + private HashSet _changed = new HashSet(); + } +} diff --git a/src/Models/IssueTrackerRule.cs b/src/Models/IssueTrackerRule.cs index a4a9a3d1..127cfa98 100644 --- a/src/Models/IssueTrackerRule.cs +++ b/src/Models/IssueTrackerRule.cs @@ -1,8 +1,6 @@ using System.Collections.Generic; using System.Text.RegularExpressions; -using Avalonia.Collections; - using CommunityToolkit.Mvvm.ComponentModel; namespace SourceGit.Models diff --git a/src/Models/Submodule.cs b/src/Models/Submodule.cs new file mode 100644 index 00000000..a038afef --- /dev/null +++ b/src/Models/Submodule.cs @@ -0,0 +1,8 @@ +namespace SourceGit.Models +{ + public class Submodule + { + public string Path { get; set; } = ""; + public bool IsDirty { get; set; } = false; + } +} diff --git a/src/Models/Watcher.cs b/src/Models/Watcher.cs index f8aacecb..971c44f6 100644 --- a/src/Models/Watcher.cs +++ b/src/Models/Watcher.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -70,6 +71,16 @@ namespace SourceGit.Models } } + public void UpdateSubmodules(List submodules) + { + lock (_lockSubmodule) + { + _submodules.Clear(); + foreach (var submodule in submodules) + _submodules.Add(submodule.Path); + } + } + public void MarkBranchDirtyManually() { _updateBranch = DateTime.Now.ToFileTime() - 1; @@ -168,7 +179,7 @@ namespace SourceGit.Models return; var name = e.Name.Replace("\\", "/"); - if (name.StartsWith("modules", StringComparison.Ordinal)) + if (name.StartsWith("modules", StringComparison.Ordinal) && name.EndsWith("HEAD", StringComparison.Ordinal)) { _updateSubmodules = DateTime.Now.AddSeconds(1).ToFileTime(); } @@ -201,6 +212,19 @@ namespace SourceGit.Models var name = e.Name.Replace("\\", "/"); if (name == ".git" || name.StartsWith(".git/", StringComparison.Ordinal)) return; + + lock (_submodules) + { + foreach (var submodule in _submodules) + { + if (name.StartsWith(submodule, StringComparison.Ordinal)) + { + _updateSubmodules = DateTime.Now.AddSeconds(1).ToFileTime(); + return; + } + } + } + _updateWC = DateTime.Now.AddSeconds(1).ToFileTime(); } @@ -214,5 +238,8 @@ namespace SourceGit.Models private long _updateSubmodules = 0; private long _updateStashes = 0; private long _updateTags = 0; + + private object _lockSubmodule = new object(); + private List _submodules = new List(); } } diff --git a/src/Resources/Icons.axaml b/src/Resources/Icons.axaml index 1657ead3..a159d764 100644 --- a/src/Resources/Icons.axaml +++ b/src/Resources/Icons.axaml @@ -68,6 +68,7 @@ M0 4 0 20 16 20 0 4M4 0 20 0 20 16 4 0z M192 192m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0ZM192 512m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0ZM192 832m-64 0a64 64 0 1 0 128 0 64 64 0 1 0-128 0ZM864 160H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32zM864 480H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32zM864 800H352c-17.7 0-32 14.3-32 32s14.3 32 32 32h512c17.7 0 32-14.3 32-32s-14.3-32-32-32z M824 645V307c0-56-46-102-102-102h-102V102l-154 154 154 154V307h102v338c-46 20-82 67-82 123 0 72 61 133 133 133 72 0 133-61 133-133 0-56-36-102-82-123zm-51 195c-41 0-72-31-72-72s31-72 72-72c41 0 72 31 72 72s-31 72-72 72zM384 256c0-72-61-133-133-133-72 0-133 61-133 133 0 56 36 102 82 123v266C154 666 118 712 118 768c0 72 61 133 133 133 72 0 133-61 133-133 0-56-36-102-82-123V379C348 358 384 312 384 256zM323 768c0 41-31 72-72 72-41 0-72-31-72-72s31-72 72-72c41 0 72 31 72 72zM251 328c-41 0-72-31-72-72s31-72 72-72c41 0 72 31 72 72s-31 72-72 72z + M896 64H128C96 64 64 96 64 128v768c0 32 32 64 64 64h768c32 0 64-32 64-64V128c0-32-32-64-64-64z m-64 736c0 16-17 32-32 32H224c-18 0-32-12-32-32V224c0-16 16-32 32-32h576c15 0 32 16 32 32v576zM512 384c-71 0-128 57-128 128s57 128 128 128 128-57 128-128-57-128-128-128z M299 811 299 725 384 725 384 811 299 811M469 811 469 725 555 725 555 811 469 811M640 811 640 725 725 725 725 811 640 811M299 640 299 555 384 555 384 640 299 640M469 640 469 555 555 555 555 640 469 640M640 640 640 555 725 555 725 640 640 640M299 469 299 384 384 384 384 469 299 469M469 469 469 384 555 384 555 469 469 469M640 469 640 384 725 384 725 469 640 469M299 299 299 213 384 213 384 299 299 299M469 299 469 213 555 213 555 299 469 299M640 299 640 213 725 213 725 299 640 299Z M683 409v204L1024 308 683 0v191c-413 0-427 526-427 526c117-229 203-307 427-307zm85 492H102V327h153s38-63 114-122H51c-28 0-51 27-51 61v697c0 34 23 61 51 61h768c28 0 51-27 51-61V614l-102 100v187z M544 85c49 0 90 37 95 85h75a96 96 0 0196 89L811 267a32 32 0 01-28 32L779 299a32 32 0 01-32-28L747 267a32 32 0 00-28-32L715 235h-91a96 96 0 01-80 42H395c-33 0-62-17-80-42L224 235a32 32 0 00-32 28L192 267v576c0 16 12 30 28 32l4 0h128a32 32 0 0132 28l0 4a32 32 0 01-32 32h-128a96 96 0 01-96-89L128 843V267a96 96 0 0189-96L224 171h75a96 96 0 0195-85h150zm256 256a96 96 0 0196 89l0 7v405a96 96 0 01-89 96L800 939h-277a96 96 0 01-96-89L427 843v-405a96 96 0 0189-96L523 341h277zm-256-192H395a32 32 0 000 64h150a32 32 0 100-64z diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 3ee8edd8..17e395ca 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -136,7 +136,7 @@ namespace SourceGit.ViewModels private set => SetProperty(ref _visibleTags, value); } - public List Submodules + public List Submodules { get => _submodules; private set => SetProperty(ref _submodules, value); @@ -778,6 +778,9 @@ namespace SourceGit.ViewModels public void RefreshSubmodules() { var submodules = new Commands.QuerySubmodules(_fullpath).Result(); + if (_watcher != null) + _watcher.UpdateSubmodules(submodules); + Dispatcher.UIThread.Invoke(() => Submodules = submodules); } @@ -1992,7 +1995,7 @@ namespace SourceGit.ViewModels private List _worktrees = new List(); private List _tags = new List(); private List _visibleTags = new List(); - private List _submodules = new List(); + private List _submodules = new List(); private bool _includeUntracked = true; private InProgressContext _inProgressContext = null; diff --git a/src/ViewModels/UpdateSubmodules.cs b/src/ViewModels/UpdateSubmodules.cs index 2e381900..d1c433e2 100644 --- a/src/ViewModels/UpdateSubmodules.cs +++ b/src/ViewModels/UpdateSubmodules.cs @@ -7,8 +7,9 @@ namespace SourceGit.ViewModels { public List Submodules { - get => _repo.Submodules; - } + get; + private set; + } = new List(); public string SelectedSubmodule { @@ -43,7 +44,11 @@ namespace SourceGit.ViewModels public UpdateSubmodules(Repository repo) { _repo = repo; - SelectedSubmodule = repo.Submodules.Count > 0 ? repo.Submodules[0] : string.Empty; + + foreach (var submodule in _repo.Submodules) + Submodules.Add(submodule.Path); + + SelectedSubmodule = Submodules.Count > 0 ? Submodules[0] : string.Empty; View = new Views.UpdateSubmodules() { DataContext = this }; } diff --git a/src/Views/Repository.axaml b/src/Views/Repository.axaml index b06b056b..be29a543 100644 --- a/src/Views/Repository.axaml +++ b/src/Views/Repository.axaml @@ -349,9 +349,14 @@ - - - + + + + diff --git a/src/Views/Repository.axaml.cs b/src/Views/Repository.axaml.cs index cfe9d7ef..0c9a106f 100644 --- a/src/Views/Repository.axaml.cs +++ b/src/Views/Repository.axaml.cs @@ -123,9 +123,9 @@ namespace SourceGit.Views private void OnSubmoduleContextRequested(object sender, ContextRequestedEventArgs e) { - if (sender is DataGrid { SelectedItem: string submodule } grid && DataContext is ViewModels.Repository repo) + if (sender is DataGrid { SelectedItem: Models.Submodule submodule } grid && DataContext is ViewModels.Repository repo) { - var menu = repo.CreateContextMenuForSubmodule(submodule); + var menu = repo.CreateContextMenuForSubmodule(submodule.Path); grid.OpenContextMenu(menu); } @@ -134,9 +134,9 @@ namespace SourceGit.Views private void OnDoubleTappedSubmodule(object sender, TappedEventArgs e) { - if (sender is DataGrid { SelectedItem: string submodule } && DataContext is ViewModels.Repository repo) + if (sender is DataGrid { SelectedItem: Models.Submodule submodule } && DataContext is ViewModels.Repository repo) { - repo.OpenSubmodule(submodule); + repo.OpenSubmodule(submodule.Path); } e.Handled = true;