3030import java .io .InputStream ;
3131import java .io .InputStreamReader ;
3232import java .io .Reader ;
33+ import java .nio .charset .StandardCharsets ;
3334import java .nio .file .Paths ;
3435import java .text .ParseException ;
3536import java .util .ArrayList ;
3839import java .util .LinkedList ;
3940import java .util .List ;
4041import java .util .TreeSet ;
41- import java .util .function .Supplier ;
4242import java .util .logging .Level ;
4343import java .util .logging .Logger ;
4444import java .util .regex .Matcher ;
@@ -166,10 +166,11 @@ Executor getRenamedFilesExecutor(final File file, String sinceRevision) throws I
166166 cmd .add (sinceRevision + ".." );
167167 }
168168
169- if (file .getCanonicalPath ().length () > getDirectoryName ().length () + 1 ) {
169+ String canonicalPath = file .getCanonicalPath ();
170+ if (canonicalPath .length () > getCanonicalDirectoryName ().length () + 1 ) {
170171 // this is a file in the repository
171172 cmd .add ("--" );
172- cmd .add (file . getCanonicalPath (). substring ( getDirectoryName (). length () + 1 ));
173+ cmd .add (getPathRelativeToCanonicalRepositoryRoot ( canonicalPath ));
173174 }
174175
175176 return new Executor (cmd , new File (getDirectoryName ()), sinceRevision != null );
@@ -250,12 +251,9 @@ boolean getHistoryGet(
250251 try {
251252 origpath = findOriginalName (fullpath , rev );
252253 } 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 ));
259257 return false ;
260258 }
261259
@@ -283,19 +281,22 @@ public String get() {
283281 *
284282 * @param input a stream with the output from a log or blame command
285283 * @return a reader that reads the input
286- * @throws IOException if the reader cannot be created
287284 */
288- static Reader newLogReader (InputStream input ) throws IOException {
285+ static Reader newLogReader (InputStream input ) {
289286 // Bug #17731: Git always encodes the log output using UTF-8 (unless
290287 // overridden by i18n.logoutputencoding, but let's assume that hasn't
291288 // been done for now). Create a reader that uses UTF-8 instead of the
292289 // platform's default encoding.
293- return new InputStreamReader (input , "UTF-8" );
290+ return new InputStreamReader (input , StandardCharsets . UTF_8 );
294291 }
295292
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 ;
299300 }
300301
301302 /**
@@ -306,11 +307,11 @@ private String getPathRelativeToRepositoryRoot(String fullpath) {
306307 * @param changeset changeset
307308 * @return original filename relative to the repository root
308309 * @throws java.io.IOException if I/O exception occurred
309- * @see #getPathRelativeToRepositoryRoot (String)
310+ * @see #getPathRelativeToCanonicalRepositoryRoot (String)
310311 */
311- protected String findOriginalName (String fullpath , String changeset )
312+ String findOriginalName (String fullpath , String changeset )
312313 throws IOException {
313- if (fullpath == null || fullpath .isEmpty () || fullpath . length () < getDirectoryName (). length () ) {
314+ if (fullpath == null || fullpath .isEmpty ()) {
314315 throw new IOException (String .format ("Invalid file path string: %s" , fullpath ));
315316 }
316317
@@ -319,7 +320,7 @@ protected String findOriginalName(String fullpath, String changeset)
319320 fullpath , changeset ));
320321 }
321322
322- String fileInRepo = getPathRelativeToRepositoryRoot (fullpath );
323+ String fileInRepo = getPathRelativeToCanonicalRepositoryRoot (fullpath );
323324
324325 /*
325326 * 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 {
447448 }
448449 }
449450 cmd .add ("--" );
450- cmd .add (getPathRelativeToRepositoryRoot (file .getCanonicalPath ()));
451+ cmd .add (getPathRelativeToCanonicalRepositoryRoot (file .getCanonicalPath ()));
451452
452453 Executor exec = new Executor (cmd , new File (getDirectoryName ()),
453454 RuntimeEnvironment .getInstance ().getInteractiveCommandTimeout ());
0 commit comments