@@ -49,7 +49,8 @@ public FileHistoriesSingleRevision(Repository repo, string file, Models.Commit r
4949
5050 public void ResetToSelectedRevision ( )
5151 {
52- new Commands . Checkout ( _repo . FullPath ) . FileWithRevision ( _file , $ "{ _revision . SHA } ") ;
52+ var revisionFilePath = new Commands . QueryFilePathInRevision ( _repo . FullPath , _revision . SHA , _file ) . Result ( ) ;
53+ new Commands . Checkout ( _repo . FullPath ) . FileWithRevision ( revisionFilePath , $ "{ _revision . SHA } ") ;
5354 }
5455
5556 private void RefreshViewContent ( )
@@ -62,10 +63,12 @@ private void RefreshViewContent()
6263
6364 private void SetViewContentAsRevisionFile ( )
6465 {
65- var objs = new Commands . QueryRevisionObjects ( _repo . FullPath , _revision . SHA , _file ) . Result ( ) ;
66+ var revisionFilePath = new Commands . QueryFilePathInRevision ( _repo . FullPath , _revision . SHA , _file ) . Result ( ) ;
67+
68+ var objs = new Commands . QueryRevisionObjects ( _repo . FullPath , _revision . SHA , revisionFilePath ) . Result ( ) ;
6669 if ( objs . Count == 0 )
6770 {
68- ViewContent = new FileHistoriesRevisionFile ( _file , null ) ;
71+ ViewContent = new FileHistoriesRevisionFile ( revisionFilePath , null ) ;
6972 return ;
7073 }
7174
@@ -75,50 +78,49 @@ private void SetViewContentAsRevisionFile()
7578 case Models . ObjectType . Blob :
7679 Task . Run ( ( ) =>
7780 {
78- var isBinary = new Commands . IsBinary ( _repo . FullPath , _revision . SHA , _file ) . Result ( ) ;
81+ var isBinary = new Commands . IsBinary ( _repo . FullPath , _revision . SHA , revisionFilePath ) . Result ( ) ;
7982 if ( isBinary )
8083 {
81- var ext = Path . GetExtension ( _file ) ;
84+ var ext = Path . GetExtension ( revisionFilePath ) ;
8285 if ( IMG_EXTS . Contains ( ext ) )
8386 {
84- var stream = Commands . QueryFileContent . Run ( _repo . FullPath , _revision . SHA , _file ) ;
87+ var stream = Commands . QueryFileContent . Run ( _repo . FullPath , _revision . SHA , revisionFilePath ) ;
8588 var fileSize = stream . Length ;
8689 var bitmap = fileSize > 0 ? new Bitmap ( stream ) : null ;
87- var imageType = Path . GetExtension ( _file ) . TrimStart ( '.' ) . ToUpper ( CultureInfo . CurrentCulture ) ;
90+ var imageType = Path . GetExtension ( revisionFilePath ) . TrimStart ( '.' ) . ToUpper ( CultureInfo . CurrentCulture ) ;
8891 var image = new Models . RevisionImageFile ( ) { Image = bitmap , FileSize = fileSize , ImageType = imageType } ;
89- Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , image ) ) ;
92+ Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( revisionFilePath , image ) ) ;
9093 }
9194 else
9295 {
93- var size = new Commands . QueryFileSize ( _repo . FullPath , _file , _revision . SHA ) . Result ( ) ;
96+ var size = new Commands . QueryFileSize ( _repo . FullPath , revisionFilePath , _revision . SHA ) . Result ( ) ;
9497 var binaryFile = new Models . RevisionBinaryFile ( ) { Size = size } ;
95- Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , binaryFile ) ) ;
98+ Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( revisionFilePath , binaryFile ) ) ;
9699 }
97-
98100 return ;
99101 }
100102
101- var contentStream = Commands . QueryFileContent . Run ( _repo . FullPath , _revision . SHA , _file ) ;
103+ var contentStream = Commands . QueryFileContent . Run ( _repo . FullPath , _revision . SHA , revisionFilePath ) ;
102104 var content = new StreamReader ( contentStream ) . ReadToEnd ( ) ;
103105 var matchLFS = REG_LFS_FORMAT ( ) . Match ( content ) ;
104106 if ( matchLFS . Success )
105107 {
106108 var lfs = new Models . RevisionLFSObject ( ) { Object = new Models . LFSObject ( ) } ;
107109 lfs . Object . Oid = matchLFS . Groups [ 1 ] . Value ;
108110 lfs . Object . Size = long . Parse ( matchLFS . Groups [ 2 ] . Value ) ;
109- Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , lfs ) ) ;
111+ Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( revisionFilePath , lfs ) ) ;
110112 }
111113 else
112114 {
113115 var txt = new Models . RevisionTextFile ( ) { FileName = obj . Path , Content = content } ;
114- Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , txt ) ) ;
116+ Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( revisionFilePath , txt ) ) ;
115117 }
116118 } ) ;
117119 break ;
118120 case Models . ObjectType . Commit :
119121 Task . Run ( ( ) =>
120122 {
121- var submoduleRoot = Path . Combine ( _repo . FullPath , _file ) ;
123+ var submoduleRoot = Path . Combine ( _repo . FullPath , revisionFilePath ) ;
122124 var commit = new Commands . QuerySingleCommit ( submoduleRoot , obj . SHA ) . Result ( ) ;
123125 if ( commit != null )
124126 {
@@ -128,7 +130,7 @@ private void SetViewContentAsRevisionFile()
128130 Commit = commit ,
129131 FullMessage = new Models . CommitFullMessage { Message = message }
130132 } ;
131- Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , module ) ) ;
133+ Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( revisionFilePath , module ) ) ;
132134 }
133135 else
134136 {
@@ -137,19 +139,21 @@ private void SetViewContentAsRevisionFile()
137139 Commit = new Models . Commit ( ) { SHA = obj . SHA } ,
138140 FullMessage = null
139141 } ;
140- Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , module ) ) ;
142+ Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( revisionFilePath , module ) ) ;
141143 }
142144 } ) ;
143145 break ;
144146 default :
145- ViewContent = new FileHistoriesRevisionFile ( _file , null ) ;
147+ ViewContent = new FileHistoriesRevisionFile ( revisionFilePath , null ) ;
146148 break ;
147149 }
148150 }
149151
150152 private void SetViewContentAsDiff ( )
151153 {
152- var option = new Models . DiffOption ( _revision , _file ) ;
154+ var revisionFilePath = new Commands . QueryFilePathInRevision ( _repo . FullPath , _revision . SHA , _file ) . Result ( ) ;
155+
156+ var option = new Models . DiffOption ( _revision , revisionFilePath ) ;
153157 ViewContent = new DiffContext ( _repo . FullPath , option , _viewContent as DiffContext ) ;
154158 }
155159
@@ -216,7 +220,50 @@ private void RefreshViewContent()
216220 {
217221 Task . Run ( ( ) =>
218222 {
219- _changes = new Commands . CompareRevisions ( _repo . FullPath , _startPoint . SHA , _endPoint . SHA , _file ) . Result ( ) ;
223+ var startFilePath = new Commands . QueryFilePathInRevision ( _repo . FullPath , _startPoint . SHA , _file ) . Result ( ) ;
224+ var endFilePath = new Commands . QueryFilePathInRevision ( _repo . FullPath , _endPoint . SHA , _file ) . Result ( ) ;
225+
226+ var allChanges = new Commands . CompareRevisions ( _repo . FullPath , _startPoint . SHA , _endPoint . SHA ) . Result ( ) ;
227+
228+ Models . Change renamedChange = null ;
229+ foreach ( var change in allChanges )
230+ {
231+ if ( change . WorkTree != Models . ChangeState . Renamed && change . Index != Models . ChangeState . Renamed )
232+ continue ;
233+ if ( change . Path != endFilePath && change . OriginalPath != startFilePath )
234+ continue ;
235+
236+ renamedChange = change ;
237+ break ;
238+ }
239+
240+ if ( renamedChange != null )
241+ {
242+ _changes = [ renamedChange ] ;
243+ }
244+ else
245+ {
246+ _changes = new Commands . CompareRevisions ( _repo . FullPath , _startPoint . SHA , _endPoint . SHA , startFilePath ) . Result ( ) ;
247+
248+ if ( _changes . Count == 0 && startFilePath != endFilePath )
249+ {
250+ var renamed = new Models . Change ( )
251+ {
252+ OriginalPath = startFilePath ,
253+ Path = endFilePath
254+ } ;
255+ renamed . Set ( Models . ChangeState . Renamed ) ;
256+ _changes = [ renamed ] ;
257+ }
258+ else if ( _changes . Count == 0 )
259+ {
260+ _changes = new Commands . CompareRevisions ( _repo . FullPath , _startPoint . SHA , _endPoint . SHA , endFilePath ) . Result ( ) ;
261+
262+ if ( _changes . Count == 0 )
263+ _changes = new Commands . CompareRevisions ( _repo . FullPath , _startPoint . SHA , _endPoint . SHA , _file ) . Result ( ) ;
264+ }
265+ }
266+
220267 if ( _changes . Count == 0 )
221268 {
222269 Dispatcher . UIThread . Invoke ( ( ) => ViewContent = null ) ;
@@ -270,7 +317,7 @@ public FileHistories(Repository repo, string file, string commit = null)
270317 Task . Run ( ( ) =>
271318 {
272319 var based = commit ?? string . Empty ;
273- var commits = new Commands . QueryCommits ( _repo . FullPath , $ "--date-order -n 10000 { based } -- \" { file } \" ", false ) . Result ( ) ;
320+ var commits = new Commands . QueryCommits ( _repo . FullPath , $ "--date-order --follow - n 10000 { based } -- \" { file } \" ", false ) . Result ( ) ;
274321 Dispatcher . UIThread . Invoke ( ( ) =>
275322 {
276323 IsLoading = false ;
0 commit comments