@@ -10,9 +10,10 @@ namespace SourceGit.ViewModels
1010{
1111 public class Blame : ObservableObject
1212 {
13- public string FilePath
13+ public string File
1414 {
15- get ;
15+ get => _file ;
16+ private set => SetProperty ( ref _file , value ) ;
1617 }
1718
1819 public Models . Commit Revision
@@ -55,14 +56,9 @@ public bool CanForward
5556 public Blame ( string repo , string file , Models . Commit commit )
5657 {
5758 var sha = commit . SHA . Substring ( 0 , 10 ) ;
58-
59- FilePath = file ;
60- Revision = commit ;
61- PrevRevision = null ;
62-
6359 _repo = repo ;
64- _navigationHistory . Add ( sha ) ;
65- SetBlameData ( sha ) ;
60+ _navigationHistory . Add ( new RevisionInfo ( file , sha ) ) ;
61+ SetBlameData ( _navigationHistory [ 0 ] ) ;
6662 }
6763
6864 public string GetCommitMessage ( string sha )
@@ -83,7 +79,7 @@ public void Back()
8379 _navigationActiveIndex -- ;
8480 OnPropertyChanged ( nameof ( CanBack ) ) ;
8581 OnPropertyChanged ( nameof ( CanForward ) ) ;
86- NavigateToCommit ( _navigationHistory [ _navigationActiveIndex ] , true ) ;
82+ NavigateToCommit ( _navigationHistory [ _navigationActiveIndex ] ) ;
8783 }
8884
8985 public void Forward ( )
@@ -94,65 +90,80 @@ public void Forward()
9490 _navigationActiveIndex ++ ;
9591 OnPropertyChanged ( nameof ( CanBack ) ) ;
9692 OnPropertyChanged ( nameof ( CanForward ) ) ;
97- NavigateToCommit ( _navigationHistory [ _navigationActiveIndex ] , true ) ;
93+ NavigateToCommit ( _navigationHistory [ _navigationActiveIndex ] ) ;
9894 }
9995
10096 public void GotoPrevRevision ( )
10197 {
102- if ( _prevRevision == null )
103- return ;
104-
105- NavigateToCommit ( _prevRevision . SHA , false ) ;
98+ if ( _prevRevision != null )
99+ NavigateToCommit ( _file , _prevRevision . SHA . Substring ( 0 , 10 ) ) ;
106100 }
107101
108- public void NavigateToCommit ( string commitSHA , bool isBackOrForward )
102+ public void NavigateToCommit ( string file , string sha )
109103 {
110104 if ( App . GetLauncher ( ) is { Pages : { } pages } )
111105 {
112106 foreach ( var page in pages )
113107 {
114108 if ( page . Data is Repository repo && repo . FullPath . Equals ( _repo ) )
115109 {
116- repo . NavigateToCommit ( commitSHA ) ;
110+ repo . NavigateToCommit ( sha ) ;
117111 break ;
118112 }
119113 }
120114 }
121115
122- if ( Revision . SHA . StartsWith ( commitSHA , StringComparison . Ordinal ) )
116+ if ( Revision . SHA . StartsWith ( sha , StringComparison . Ordinal ) )
123117 return ;
124118
125- if ( ! isBackOrForward )
119+ var count = _navigationHistory . Count ;
120+ if ( _navigationActiveIndex < count - 1 )
121+ _navigationHistory . RemoveRange ( _navigationActiveIndex + 1 , count - _navigationActiveIndex - 1 ) ;
122+
123+ var rev = new RevisionInfo ( file , sha ) ;
124+ _navigationHistory . Add ( rev ) ;
125+ _navigationActiveIndex ++ ;
126+ OnPropertyChanged ( nameof ( CanBack ) ) ;
127+ OnPropertyChanged ( nameof ( CanForward ) ) ;
128+ SetBlameData ( rev ) ;
129+ }
130+
131+ private void NavigateToCommit ( RevisionInfo rev )
132+ {
133+ if ( App . GetLauncher ( ) is { Pages : { } pages } )
126134 {
127- var count = _navigationHistory . Count ;
128- if ( _navigationActiveIndex < count - 1 )
129- _navigationHistory . RemoveRange ( _navigationActiveIndex + 1 , count - _navigationActiveIndex - 1 ) ;
130-
131- _navigationHistory . Add ( commitSHA ) ;
132- _navigationActiveIndex ++ ;
133- OnPropertyChanged ( nameof ( CanBack ) ) ;
134- OnPropertyChanged ( nameof ( CanForward ) ) ;
135+ foreach ( var page in pages )
136+ {
137+ if ( page . Data is Repository repo && repo . FullPath . Equals ( _repo ) )
138+ {
139+ repo . NavigateToCommit ( rev . SHA ) ;
140+ break ;
141+ }
142+ }
135143 }
136144
137- SetBlameData ( commitSHA ) ;
145+ if ( ! Revision . SHA . StartsWith ( rev . SHA , StringComparison . Ordinal ) )
146+ SetBlameData ( rev ) ;
138147 }
139148
140- private void SetBlameData ( string commitSHA )
149+ private void SetBlameData ( RevisionInfo rev )
141150 {
142151 if ( _cancellationSource is { IsCancellationRequested : false } )
143152 _cancellationSource . Cancel ( ) ;
144153
145154 _cancellationSource = new CancellationTokenSource ( ) ;
146155 var token = _cancellationSource . Token ;
147156
157+ File = rev . File ;
158+
148159 Task . Run ( async ( ) =>
149160 {
150161 var argsBuilder = new StringBuilder ( ) ;
151162 argsBuilder
152163 . Append ( "--date-order -n 2 " )
153- . Append ( commitSHA ?? string . Empty )
164+ . Append ( rev . SHA )
154165 . Append ( " -- " )
155- . Append ( FilePath . Quoted ( ) ) ;
166+ . Append ( rev . File . Quoted ( ) ) ;
156167
157168 var commits = await new Commands . QueryCommits ( _repo , argsBuilder . ToString ( ) , false )
158169 . GetResultAsync ( )
@@ -163,14 +174,14 @@ private void SetBlameData(string commitSHA)
163174 if ( ! token . IsCancellationRequested )
164175 {
165176 Revision = commits . Count > 0 ? commits [ 0 ] : null ;
166- PrevRevision = commits . Count == 2 ? commits [ 1 ] : null ;
177+ PrevRevision = commits . Count > 1 ? commits [ 1 ] : null ;
167178 }
168179 } ) ;
169180 } ) ;
170181
171182 Task . Run ( async ( ) =>
172183 {
173- var result = await new Commands . Blame ( _repo , FilePath , commitSHA )
184+ var result = await new Commands . Blame ( _repo , rev . File , rev . SHA )
174185 . ReadAsync ( )
175186 . ConfigureAwait ( false ) ;
176187
@@ -182,12 +193,25 @@ private void SetBlameData(string commitSHA)
182193 } , token ) ;
183194 }
184195
196+ private class RevisionInfo
197+ {
198+ public string File { get ; set ; } = string . Empty ;
199+ public string SHA { get ; set ; } = string . Empty ;
200+
201+ public RevisionInfo ( string file , string sha )
202+ {
203+ File = file ;
204+ SHA = sha ;
205+ }
206+ }
207+
185208 private string _repo ;
209+ private string _file ;
186210 private Models . Commit _revision ;
187211 private Models . Commit _prevRevision ;
188212 private CancellationTokenSource _cancellationSource = null ;
189213 private int _navigationActiveIndex = 0 ;
190- private List < string > _navigationHistory = [ ] ;
214+ private List < RevisionInfo > _navigationHistory = [ ] ;
191215 private Models . BlameData _data = null ;
192216 private Dictionary < string , string > _commitMessages = new ( ) ;
193217 }
0 commit comments