Skip to content

Commit a89760c

Browse files
committed
refactor: change the way to refresh repository's data.
* mark dirty instead of calling refresh method directly * force mark branches data dirty after remotes changed
1 parent 3eb8a82 commit a89760c

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

src/Models/Watcher.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ public void SetEnabled(bool enabled) {
5353
}
5454
}
5555

56-
public void MarkWorkingCopyRefreshed() {
57-
_updateWC = 0;
56+
public void MarkBranchDirtyManually() {
57+
_updateBranch = DateTime.Now.ToFileTime() - 1;
58+
}
59+
60+
public void MarkWorkingCopyDirtyManually() {
61+
_updateWC = DateTime.Now.ToFileTime() - 1;
5862
}
5963

6064
public void Dispose() {

src/ViewModels/AddRemote.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ public override Task<bool> Sure() {
7070
new Commands.Config(_repo.FullPath).Set($"remote.{_name}.sshkey", SSHKey);
7171
}
7272
}
73-
CallUIThread(() => _repo.SetWatcherEnabled(true));
73+
CallUIThread(() => {
74+
_repo.MarkBranchesDirtyManually();
75+
_repo.SetWatcherEnabled(true);
76+
});
7477
return succ;
7578
});
7679
}

src/ViewModels/DeleteRemote.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ public override Task<bool> Sure() {
1919

2020
return Task.Run(() => {
2121
var succ = new Commands.Remote(_repo.FullPath).Delete(Remote.Name);
22-
CallUIThread(() => _repo.SetWatcherEnabled(true));
22+
CallUIThread(() => {
23+
_repo.MarkBranchesDirtyManually();
24+
_repo.SetWatcherEnabled(true);
25+
});
2326
return succ;
2427
});
2528
}

src/ViewModels/Repository.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,14 @@ public void SetWatcherEnabled(bool enabled) {
306306
if (_watcher != null) _watcher.SetEnabled(enabled);
307307
}
308308

309+
public void MarkBranchesDirtyManually() {
310+
if (_watcher != null) _watcher.MarkBranchDirtyManually();
311+
}
312+
313+
public void MarkWorkingCopyDirtyManually() {
314+
if (_watcher != null) _watcher.MarkWorkingCopyDirtyManually();
315+
}
316+
309317
public void NavigateToCommit(string sha) {
310318
if (_histories != null) {
311319
SelectedViewIndex = 0;
@@ -357,7 +365,7 @@ public async void ContinueMerge() {
357365
} else if (File.Exists(otherMerge)) {
358366
mode = "merge";
359367
} else {
360-
await Task.Run(RefreshWorkingCopyChanges);
368+
MarkWorkingCopyDirtyManually();
361369
return;
362370
}
363371

@@ -394,7 +402,7 @@ public async void AbortMerge() {
394402
} else if (File.Exists(Path.Combine(_gitDir, "MERGE_HEAD"))) {
395403
cmd.Args = "merge --abort";
396404
} else {
397-
await Task.Run(RefreshWorkingCopyChanges);
405+
MarkWorkingCopyDirtyManually();
398406
return;
399407
}
400408

@@ -491,8 +499,6 @@ public void RefreshWorkingCopyChanges() {
491499
HasUnsolvedConflict = hasUnsolvedConflict;
492500
OnPropertyChanged(nameof(WorkingCopyChangesCount));
493501
});
494-
495-
_watcher.MarkWorkingCopyRefreshed();
496502
}
497503

498504
public void RefreshStashes() {

src/ViewModels/WorkingCopy.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public async void StageChanges(List<Models.Change> changes) {
246246
await Task.Run(() => new Commands.Add(_repo.FullPath, step).Exec());
247247
}
248248
}
249-
_repo.RefreshWorkingCopyChanges();
249+
_repo.MarkWorkingCopyDirtyManually();
250250
_repo.SetWatcherEnabled(true);
251251
IsStaging = false;
252252
}
@@ -266,7 +266,7 @@ public async void UnstageChanges(List<Models.Change> changes) {
266266
await Task.Run(() => new Commands.Reset(_repo.FullPath, step).Exec());
267267
}
268268
}
269-
_repo.RefreshWorkingCopyChanges();
269+
_repo.MarkWorkingCopyDirtyManually();
270270
_repo.SetWatcherEnabled(true);
271271
IsUnstaging = false;
272272
}
@@ -296,7 +296,7 @@ public async void UseTheirs() {
296296
if (succ) {
297297
await Task.Run(() => new Commands.Add(_repo.FullPath, [ctx.Change]).Exec());
298298
}
299-
_repo.RefreshWorkingCopyChanges();
299+
_repo.MarkWorkingCopyDirtyManually();
300300
_repo.SetWatcherEnabled(true);
301301
}
302302
}
@@ -308,7 +308,7 @@ public async void UseMine() {
308308
if (succ) {
309309
await Task.Run(() => new Commands.Add(_repo.FullPath, [ctx.Change]).Exec());
310310
}
311-
_repo.RefreshWorkingCopyChanges();
311+
_repo.MarkWorkingCopyDirtyManually();
312312
_repo.SetWatcherEnabled(true);
313313
}
314314
}
@@ -362,7 +362,7 @@ public async void DoCommit(bool autoPush) {
362362
PopupHost.ShowAndStartPopup(new Push(_repo, null));
363363
}
364364
}
365-
_repo.RefreshWorkingCopyChanges();
365+
_repo.MarkWorkingCopyDirtyManually();
366366
_repo.SetWatcherEnabled(true);
367367
IsCommitting = false;
368368
}

src/Views/TextDiffView.axaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ public void FillContextMenuForWorkingCopyChange(ContextMenu menu, int startLine,
734734
new Commands.Apply(ctx.RepositoryPath, tmpFile, true, "nowarn", "--cache --index").Exec();
735735
File.Delete(tmpFile);
736736

737-
repo.RefreshWorkingCopyChanges();
737+
repo.MarkWorkingCopyDirtyManually();
738738
repo.SetWatcherEnabled(true);
739739
e.Handled = true;
740740
};
@@ -760,7 +760,7 @@ public void FillContextMenuForWorkingCopyChange(ContextMenu menu, int startLine,
760760
new Commands.Apply(ctx.RepositoryPath, tmpFile, true, "nowarn", "--reverse").Exec();
761761
File.Delete(tmpFile);
762762

763-
repo.RefreshWorkingCopyChanges();
763+
repo.MarkWorkingCopyDirtyManually();
764764
repo.SetWatcherEnabled(true);
765765
e.Handled = true;
766766
};
@@ -788,7 +788,7 @@ public void FillContextMenuForWorkingCopyChange(ContextMenu menu, int startLine,
788788
new Commands.Apply(ctx.RepositoryPath, tmpFile, true, "nowarn", "--cache --index --reverse").Exec();
789789
File.Delete(tmpFile);
790790

791-
repo.RefreshWorkingCopyChanges();
791+
repo.MarkWorkingCopyDirtyManually();
792792
repo.SetWatcherEnabled(true);
793793
e.Handled = true;
794794
};
@@ -814,7 +814,7 @@ public void FillContextMenuForWorkingCopyChange(ContextMenu menu, int startLine,
814814
new Commands.Apply(ctx.RepositoryPath, tmpFile, true, "nowarn", "--index --reverse").Exec();
815815
File.Delete(tmpFile);
816816

817-
repo.RefreshWorkingCopyChanges();
817+
repo.MarkWorkingCopyDirtyManually();
818818
repo.SetWatcherEnabled(true);
819819
e.Handled = true;
820820
};

0 commit comments

Comments
 (0)