@@ -49,7 +49,8 @@ public FileHistoriesSingleRevision(Repository repo, string file, Models.Commit r
49
49
50
50
public void ResetToSelectedRevision ( )
51
51
{
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 } ") ;
53
54
}
54
55
55
56
private void RefreshViewContent ( )
@@ -62,10 +63,12 @@ private void RefreshViewContent()
62
63
63
64
private void SetViewContentAsRevisionFile ( )
64
65
{
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 ( ) ;
66
69
if ( objs . Count == 0 )
67
70
{
68
- ViewContent = new FileHistoriesRevisionFile ( _file , null ) ;
71
+ ViewContent = new FileHistoriesRevisionFile ( revisionFilePath , null ) ;
69
72
return ;
70
73
}
71
74
@@ -75,50 +78,49 @@ private void SetViewContentAsRevisionFile()
75
78
case Models . ObjectType . Blob :
76
79
Task . Run ( ( ) =>
77
80
{
78
- var isBinary = new Commands . IsBinary ( _repo . FullPath , _revision . SHA , _file ) . Result ( ) ;
81
+ var isBinary = new Commands . IsBinary ( _repo . FullPath , _revision . SHA , revisionFilePath ) . Result ( ) ;
79
82
if ( isBinary )
80
83
{
81
- var ext = Path . GetExtension ( _file ) ;
84
+ var ext = Path . GetExtension ( revisionFilePath ) ;
82
85
if ( IMG_EXTS . Contains ( ext ) )
83
86
{
84
- var stream = Commands . QueryFileContent . Run ( _repo . FullPath , _revision . SHA , _file ) ;
87
+ var stream = Commands . QueryFileContent . Run ( _repo . FullPath , _revision . SHA , revisionFilePath ) ;
85
88
var fileSize = stream . Length ;
86
89
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 ) ;
88
91
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 ) ) ;
90
93
}
91
94
else
92
95
{
93
- var size = new Commands . QueryFileSize ( _repo . FullPath , _file , _revision . SHA ) . Result ( ) ;
96
+ var size = new Commands . QueryFileSize ( _repo . FullPath , revisionFilePath , _revision . SHA ) . Result ( ) ;
94
97
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 ) ) ;
96
99
}
97
-
98
100
return ;
99
101
}
100
102
101
- var contentStream = Commands . QueryFileContent . Run ( _repo . FullPath , _revision . SHA , _file ) ;
103
+ var contentStream = Commands . QueryFileContent . Run ( _repo . FullPath , _revision . SHA , revisionFilePath ) ;
102
104
var content = new StreamReader ( contentStream ) . ReadToEnd ( ) ;
103
105
var matchLFS = REG_LFS_FORMAT ( ) . Match ( content ) ;
104
106
if ( matchLFS . Success )
105
107
{
106
108
var lfs = new Models . RevisionLFSObject ( ) { Object = new Models . LFSObject ( ) } ;
107
109
lfs . Object . Oid = matchLFS . Groups [ 1 ] . Value ;
108
110
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 ) ) ;
110
112
}
111
113
else
112
114
{
113
115
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 ) ) ;
115
117
}
116
118
} ) ;
117
119
break ;
118
120
case Models . ObjectType . Commit :
119
121
Task . Run ( ( ) =>
120
122
{
121
- var submoduleRoot = Path . Combine ( _repo . FullPath , _file ) ;
123
+ var submoduleRoot = Path . Combine ( _repo . FullPath , revisionFilePath ) ;
122
124
var commit = new Commands . QuerySingleCommit ( submoduleRoot , obj . SHA ) . Result ( ) ;
123
125
if ( commit != null )
124
126
{
@@ -128,7 +130,7 @@ private void SetViewContentAsRevisionFile()
128
130
Commit = commit ,
129
131
FullMessage = new Models . CommitFullMessage { Message = message }
130
132
} ;
131
- Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , module ) ) ;
133
+ Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( revisionFilePath , module ) ) ;
132
134
}
133
135
else
134
136
{
@@ -137,19 +139,21 @@ private void SetViewContentAsRevisionFile()
137
139
Commit = new Models . Commit ( ) { SHA = obj . SHA } ,
138
140
FullMessage = null
139
141
} ;
140
- Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( _file , module ) ) ;
142
+ Dispatcher . UIThread . Invoke ( ( ) => ViewContent = new FileHistoriesRevisionFile ( revisionFilePath , module ) ) ;
141
143
}
142
144
} ) ;
143
145
break ;
144
146
default :
145
- ViewContent = new FileHistoriesRevisionFile ( _file , null ) ;
147
+ ViewContent = new FileHistoriesRevisionFile ( revisionFilePath , null ) ;
146
148
break ;
147
149
}
148
150
}
149
151
150
152
private void SetViewContentAsDiff ( )
151
153
{
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 ) ;
153
157
ViewContent = new DiffContext ( _repo . FullPath , option , _viewContent as DiffContext ) ;
154
158
}
155
159
@@ -216,7 +220,50 @@ private void RefreshViewContent()
216
220
{
217
221
Task . Run ( ( ) =>
218
222
{
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
+
220
267
if ( _changes . Count == 0 )
221
268
{
222
269
Dispatcher . UIThread . Invoke ( ( ) => ViewContent = null ) ;
@@ -270,7 +317,7 @@ public FileHistories(Repository repo, string file, string commit = null)
270
317
Task . Run ( ( ) =>
271
318
{
272
319
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 ( ) ;
274
321
Dispatcher . UIThread . Invoke ( ( ) =>
275
322
{
276
323
IsLoading = false ;
0 commit comments