11using System ;
22using System . Collections . Generic ;
33using System . IO ;
4- using System . Text ;
54using System . Threading . Tasks ;
65
76using Avalonia . Collections ;
@@ -36,10 +35,10 @@ public object ViewContent
3635 set => SetProperty ( ref _viewContent , value ) ;
3736 }
3837
39- public FileHistoriesSingleRevision ( string repo , string file , Models . Commit revision , bool prevIsDiffMode )
38+ public FileHistoriesSingleRevision ( string repo , Models . FileVersion revision , bool prevIsDiffMode )
4039 {
4140 _repo = repo ;
42- _file = file ;
41+ _file = revision . Path ;
4342 _revision = revision ;
4443 _isDiffMode = prevIsDiffMode ;
4544 _viewContent = null ;
@@ -155,26 +154,25 @@ private async Task<object> GetRevisionFileContentAsync(Models.Object obj)
155154
156155 private void SetViewContentAsDiff ( )
157156 {
158- var option = new Models . DiffOption ( _revision , _file ) ;
159- ViewContent = new DiffContext ( _repo , option , _viewContent as DiffContext ) ;
157+ ViewContent = new DiffContext ( _repo , new Models . DiffOption ( _revision ) , _viewContent as DiffContext ) ;
160158 }
161159
162160 private string _repo = null ;
163161 private string _file = null ;
164- private Models . Commit _revision = null ;
162+ private Models . FileVersion _revision = null ;
165163 private bool _isDiffMode = false ;
166164 private object _viewContent = null ;
167165 }
168166
169167 public class FileHistoriesCompareRevisions : ObservableObject
170168 {
171- public Models . Commit StartPoint
169+ public Models . FileVersion StartPoint
172170 {
173171 get => _startPoint ;
174172 set => SetProperty ( ref _startPoint , value ) ;
175173 }
176174
177- public Models . Commit EndPoint
175+ public Models . FileVersion EndPoint
178176 {
179177 get => _endPoint ;
180178 set => SetProperty ( ref _endPoint , value ) ;
@@ -186,19 +184,18 @@ public DiffContext ViewContent
186184 set => SetProperty ( ref _viewContent , value ) ;
187185 }
188186
189- public FileHistoriesCompareRevisions ( string repo , string file , Models . Commit start , Models . Commit end )
187+ public FileHistoriesCompareRevisions ( string repo , Models . FileVersion start , Models . FileVersion end )
190188 {
191189 _repo = repo ;
192- _file = file ;
193190 _startPoint = start ;
194191 _endPoint = end ;
195- RefreshViewContent ( ) ;
192+ _viewContent = new ( _repo , new ( start , end ) ) ;
196193 }
197194
198195 public void Swap ( )
199196 {
200197 ( StartPoint , EndPoint ) = ( _endPoint , _startPoint ) ;
201- RefreshViewContent ( ) ;
198+ ViewContent = new ( _repo , new ( _startPoint , _endPoint ) , _viewContent ) ;
202199 }
203200
204201 public async Task < bool > SaveAsPatch ( string saveTo )
@@ -208,27 +205,9 @@ public async Task<bool> SaveAsPatch(string saveTo)
208205 . ConfigureAwait ( false ) ;
209206 }
210207
211- private void RefreshViewContent ( )
212- {
213- Task . Run ( async ( ) =>
214- {
215- _changes = await new Commands . CompareRevisions ( _repo , _startPoint . SHA , _endPoint . SHA , _file ) . ReadAsync ( ) . ConfigureAwait ( false ) ;
216- if ( _changes . Count == 0 )
217- {
218- Dispatcher . UIThread . Post ( ( ) => ViewContent = null ) ;
219- }
220- else
221- {
222- var option = new Models . DiffOption ( _startPoint . SHA , _endPoint . SHA , _changes [ 0 ] ) ;
223- Dispatcher . UIThread . Post ( ( ) => ViewContent = new DiffContext ( _repo , option , _viewContent ) ) ;
224- }
225- } ) ;
226- }
227-
228208 private string _repo = null ;
229- private string _file = null ;
230- private Models . Commit _startPoint = null ;
231- private Models . Commit _endPoint = null ;
209+ private Models . FileVersion _startPoint = null ;
210+ private Models . FileVersion _endPoint = null ;
232211 private List < Models . Change > _changes = [ ] ;
233212 private DiffContext _viewContent = null ;
234213 }
@@ -246,13 +225,13 @@ public bool IsLoading
246225 private set => SetProperty ( ref _isLoading , value ) ;
247226 }
248227
249- public List < Models . Commit > Commits
228+ public List < Models . FileVersion > Revisions
250229 {
251- get => _commits ;
252- set => SetProperty ( ref _commits , value ) ;
230+ get => _revisions ;
231+ set => SetProperty ( ref _revisions , value ) ;
253232 }
254233
255- public AvaloniaList < Models . Commit > SelectedCommits
234+ public AvaloniaList < Models . FileVersion > SelectedRevisions
256235 {
257236 get ;
258237 set ;
@@ -275,41 +254,34 @@ public FileHistories(string repo, string file, string commit = null)
275254
276255 Task . Run ( async ( ) =>
277256 {
278- var argsBuilder = new StringBuilder ( ) ;
279- argsBuilder
280- . Append ( "--date-order -n 10000 " )
281- . Append ( commit ?? string . Empty )
282- . Append ( " -- " )
283- . Append ( file . Quoted ( ) ) ;
284-
285- var commits = await new Commands . QueryCommits ( _repo , argsBuilder . ToString ( ) , false )
257+ var revisions = await new Commands . QueryFileHistory ( _repo , file , commit )
286258 . GetResultAsync ( )
287259 . ConfigureAwait ( false ) ;
288260
289261 Dispatcher . UIThread . Post ( ( ) =>
290262 {
291263 IsLoading = false ;
292- Commits = commits ;
293- if ( Commits . Count > 0 )
294- SelectedCommits . Add ( Commits [ 0 ] ) ;
264+ Revisions = revisions ;
265+ if ( revisions . Count > 0 )
266+ SelectedRevisions . Add ( revisions [ 0 ] ) ;
295267 } ) ;
296268 } ) ;
297269
298- SelectedCommits . CollectionChanged += ( _ , _ ) =>
270+ SelectedRevisions . CollectionChanged += ( _ , _ ) =>
299271 {
300272 if ( _viewContent is FileHistoriesSingleRevision singleRevision )
301273 _prevIsDiffMode = singleRevision . IsDiffMode ;
302274
303- ViewContent = SelectedCommits . Count switch
275+ ViewContent = SelectedRevisions . Count switch
304276 {
305- 1 => new FileHistoriesSingleRevision ( _repo , file , SelectedCommits [ 0 ] , _prevIsDiffMode ) ,
306- 2 => new FileHistoriesCompareRevisions ( _repo , file , SelectedCommits [ 0 ] , SelectedCommits [ 1 ] ) ,
307- _ => SelectedCommits . Count ,
277+ 1 => new FileHistoriesSingleRevision ( _repo , SelectedRevisions [ 0 ] , _prevIsDiffMode ) ,
278+ 2 => new FileHistoriesCompareRevisions ( _repo , SelectedRevisions [ 0 ] , SelectedRevisions [ 1 ] ) ,
279+ _ => SelectedRevisions . Count ,
308280 } ;
309281 } ;
310282 }
311283
312- public void NavigateToCommit ( Models . Commit commit )
284+ public void NavigateToCommit ( Models . FileVersion revision )
313285 {
314286 var launcher = App . GetLauncher ( ) ;
315287 if ( launcher != null )
@@ -318,16 +290,16 @@ public void NavigateToCommit(Models.Commit commit)
318290 {
319291 if ( page . Data is Repository repo && repo . FullPath . Equals ( _repo , StringComparison . Ordinal ) )
320292 {
321- repo . NavigateToCommit ( commit . SHA ) ;
293+ repo . NavigateToCommit ( revision . SHA ) ;
322294 break ;
323295 }
324296 }
325297 }
326298 }
327299
328- public string GetCommitFullMessage ( Models . Commit commit )
300+ public string GetCommitFullMessage ( Models . FileVersion revision )
329301 {
330- var sha = commit . SHA ;
302+ var sha = revision . SHA ;
331303 if ( _fullCommitMessages . TryGetValue ( sha , out var msg ) )
332304 return msg ;
333305
@@ -339,7 +311,7 @@ public string GetCommitFullMessage(Models.Commit commit)
339311 private readonly string _repo = null ;
340312 private bool _isLoading = true ;
341313 private bool _prevIsDiffMode = true ;
342- private List < Models . Commit > _commits = null ;
314+ private List < Models . FileVersion > _revisions = null ;
343315 private Dictionary < string , string > _fullCommitMessages = new ( ) ;
344316 private object _viewContent = null ;
345317 }
0 commit comments