30
30
import java .io .InputStream ;
31
31
import java .io .InputStreamReader ;
32
32
import java .io .Reader ;
33
+ import java .nio .charset .StandardCharsets ;
33
34
import java .nio .file .Paths ;
34
35
import java .text .ParseException ;
35
36
import java .util .ArrayList ;
38
39
import java .util .LinkedList ;
39
40
import java .util .List ;
40
41
import java .util .TreeSet ;
41
- import java .util .function .Supplier ;
42
42
import java .util .logging .Level ;
43
43
import java .util .logging .Logger ;
44
44
import java .util .regex .Matcher ;
@@ -166,10 +166,11 @@ Executor getRenamedFilesExecutor(final File file, String sinceRevision) throws I
166
166
cmd .add (sinceRevision + ".." );
167
167
}
168
168
169
- if (file .getCanonicalPath ().length () > getDirectoryName ().length () + 1 ) {
169
+ String canonicalPath = file .getCanonicalPath ();
170
+ if (canonicalPath .length () > getCanonicalDirectoryName ().length () + 1 ) {
170
171
// this is a file in the repository
171
172
cmd .add ("--" );
172
- cmd .add (file . getCanonicalPath (). substring ( getDirectoryName (). length () + 1 ));
173
+ cmd .add (getPathRelativeToCanonicalRepositoryRoot ( canonicalPath ));
173
174
}
174
175
175
176
return new Executor (cmd , new File (getDirectoryName ()), sinceRevision != null );
@@ -250,12 +251,9 @@ boolean getHistoryGet(
250
251
try {
251
252
origpath = findOriginalName (fullpath , rev );
252
253
} catch (IOException exp ) {
253
- LOGGER .log (Level .SEVERE , exp , new Supplier <String >() {
254
- @ Override
255
- public String get () {
256
- return String .format ("Failed to get original revision: %s/%s (revision %s)" , parent , basename , rev );
257
- }
258
- });
254
+ LOGGER .log (Level .SEVERE , exp , () -> String .format (
255
+ "Failed to get original revision: %s/%s (revision %s)" ,
256
+ parent , basename , rev ));
259
257
return false ;
260
258
}
261
259
@@ -283,19 +281,22 @@ public String get() {
283
281
*
284
282
* @param input a stream with the output from a log or blame command
285
283
* @return a reader that reads the input
286
- * @throws IOException if the reader cannot be created
287
284
*/
288
- static Reader newLogReader (InputStream input ) throws IOException {
285
+ static Reader newLogReader (InputStream input ) {
289
286
// Bug #17731: Git always encodes the log output using UTF-8 (unless
290
287
// overridden by i18n.logoutputencoding, but let's assume that hasn't
291
288
// been done for now). Create a reader that uses UTF-8 instead of the
292
289
// platform's default encoding.
293
- return new InputStreamReader (input , "UTF-8" );
290
+ return new InputStreamReader (input , StandardCharsets . UTF_8 );
294
291
}
295
292
296
- private String getPathRelativeToRepositoryRoot (String fullpath ) {
297
- String repoPath = getDirectoryName () + File .separator ;
298
- return fullpath .replace (repoPath , "" );
293
+ private String getPathRelativeToCanonicalRepositoryRoot (String fullpath )
294
+ throws IOException {
295
+ String repoPath = getCanonicalDirectoryName () + File .separator ;
296
+ if (fullpath .startsWith (repoPath )) {
297
+ return fullpath .substring (repoPath .length ());
298
+ }
299
+ return fullpath ;
299
300
}
300
301
301
302
/**
@@ -306,11 +307,11 @@ private String getPathRelativeToRepositoryRoot(String fullpath) {
306
307
* @param changeset changeset
307
308
* @return original filename relative to the repository root
308
309
* @throws java.io.IOException if I/O exception occurred
309
- * @see #getPathRelativeToRepositoryRoot (String)
310
+ * @see #getPathRelativeToCanonicalRepositoryRoot (String)
310
311
*/
311
- protected String findOriginalName (String fullpath , String changeset )
312
+ String findOriginalName (String fullpath , String changeset )
312
313
throws IOException {
313
- if (fullpath == null || fullpath .isEmpty () || fullpath . length () < getDirectoryName (). length () ) {
314
+ if (fullpath == null || fullpath .isEmpty ()) {
314
315
throw new IOException (String .format ("Invalid file path string: %s" , fullpath ));
315
316
}
316
317
@@ -319,7 +320,7 @@ protected String findOriginalName(String fullpath, String changeset)
319
320
fullpath , changeset ));
320
321
}
321
322
322
- String fileInRepo = getPathRelativeToRepositoryRoot (fullpath );
323
+ String fileInRepo = getPathRelativeToCanonicalRepositoryRoot (fullpath );
323
324
324
325
/*
325
326
* Get the list of file renames for given file to the specified
@@ -447,7 +448,7 @@ public Annotation annotate(File file, String revision) throws IOException {
447
448
}
448
449
}
449
450
cmd .add ("--" );
450
- cmd .add (getPathRelativeToRepositoryRoot (file .getCanonicalPath ()));
451
+ cmd .add (getPathRelativeToCanonicalRepositoryRoot (file .getCanonicalPath ()));
451
452
452
453
Executor exec = new Executor (cmd , new File (getDirectoryName ()),
453
454
RuntimeEnvironment .getInstance ().getInteractiveCommandTimeout ());
0 commit comments