Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions src/Models/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public Watcher(IRepository repo, string fullpath, string gitDir)
combined.Renamed += OnRepositoryChanged;
combined.Changed += OnRepositoryChanged;
combined.Deleted += OnRepositoryChanged;
combined.Error += OnWatcherError;
combined.EnableRaisingEvents = false;

_watchers.Add(combined);
Expand All @@ -58,6 +59,7 @@ public Watcher(IRepository repo, string fullpath, string gitDir)
wc.Renamed += OnWorkingCopyChanged;
wc.Changed += OnWorkingCopyChanged;
wc.Deleted += OnWorkingCopyChanged;
wc.Error += OnWatcherError;
wc.EnableRaisingEvents = false;

var git = new FileSystemWatcher();
Expand All @@ -69,6 +71,7 @@ public Watcher(IRepository repo, string fullpath, string gitDir)
git.Renamed += OnGitDirChanged;
git.Changed += OnGitDirChanged;
git.Deleted += OnGitDirChanged;
git.Error += OnWatcherError;
git.EnableRaisingEvents = false;

_watchers.Add(wc);
Expand Down Expand Up @@ -240,6 +243,21 @@ private void OnRepositoryChanged(object o, FileSystemEventArgs e)
HandleWorkingCopyFileChanged(name, e.FullPath);
}

/// <summary>
/// The internal buffer overflowed (a large fetch or checkout writes thousands of files), so
/// some events were dropped and we cannot know which. Reload everything once things settle.
/// </summary>
private void OnWatcherError(object o, ErrorEventArgs e)
{
var desired = DateTime.Now.AddSeconds(1).ToFileTime();
Interlocked.Exchange(ref _updateBranch, desired);
Interlocked.Exchange(ref _updateTags, desired);
Interlocked.Exchange(ref _updateStashes, desired);
Interlocked.Exchange(ref _updateWC, desired);
if (_repo.MayHaveSubmodules())
Interlocked.Exchange(ref _updateSubmodules, desired);
}

private void OnGitDirChanged(object o, FileSystemEventArgs e)
{
if (string.IsNullOrEmpty(e.Name))
Expand Down Expand Up @@ -302,6 +320,12 @@ private void HandleGitDirFileChanged(string name)
{
Interlocked.Exchange(ref _updateBranch, DateTime.Now.AddSeconds(.5).ToFileTime());
}
else if (name.Equals("packed-refs", StringComparison.Ordinal))
{
var desired = DateTime.Now.AddSeconds(.5).ToFileTime();
Interlocked.Exchange(ref _updateBranch, desired);
Interlocked.Exchange(ref _updateTags, desired);
}
else if (name.StartsWith("reftable/", StringComparison.Ordinal))
{
var desired = DateTime.Now.AddSeconds(.5).ToFileTime();
Expand Down
4 changes: 4 additions & 0 deletions src/ViewModels/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public override async Task<bool> Sure()

log.Complete();

_repo.MarkBranchesDirtyManually();
if (!notags)
_repo.MarkTagsDirtyManually();

if (navigateToUpstreamHEAD && !token.IsCancellationRequested)
{
var upstream = _repo.CurrentBranch?.Upstream;
Expand Down
1 change: 1 addition & 0 deletions src/ViewModels/FetchInto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public override async Task<bool> Sure()
.ExecAsync();

log.Complete();
_repo.MarkBranchesDirtyManually();

if (_repo.SelectedViewIndex == 0 && !token.IsCancellationRequested)
{
Expand Down
2 changes: 2 additions & 0 deletions src/ViewModels/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,8 @@ private async Task AutoFetchOnUIThread()
await new Commands.Fetch(FullPath, remote).Use(log).ExecAsync();

_lastFetchTime = DateTime.Now;
MarkBranchesDirtyManually();
MarkTagsDirtyManually();
}
catch
{
Expand Down