1111import java .net .SocketAddress ;
1212import java .net .URI ;
1313import java .nio .charset .StandardCharsets ;
14- import java .util .*;
14+ import java .util .ArrayList ;
15+ import java .util .Collections ;
16+ import java .util .HashSet ;
17+ import java .util .List ;
18+ import java .util .Set ;
1519
1620import org .apache .commons .io .FileUtils ;
1721import org .apache .commons .io .IOUtils ;
2630import org .eclipse .jgit .diff .DiffEntry .ChangeType ;
2731import org .eclipse .jgit .diff .DiffEntry .Side ;
2832import org .eclipse .jgit .diff .DiffFormatter ;
29- import org .eclipse .jgit .errors .IncorrectObjectTypeException ;
30- import org .eclipse .jgit .errors .MissingObjectException ;
31- import org .eclipse .jgit .errors .StopWalkException ;
32- import org .eclipse .jgit .lib .*;
33- import org .eclipse .jgit .revwalk .*;
34- import org .eclipse .jgit .revwalk .filter .RevFilter ;
33+ import org .eclipse .jgit .lib .Constants ;
34+ import org .eclipse .jgit .lib .ObjectId ;
35+ import org .eclipse .jgit .lib .ObjectReader ;
36+ import org .eclipse .jgit .lib .Ref ;
37+ import org .eclipse .jgit .lib .Repository ;
38+ import org .eclipse .jgit .revwalk .RevCommit ;
39+ import org .eclipse .jgit .revwalk .RevSort ;
40+ import org .eclipse .jgit .revwalk .RevWalk ;
3541import org .eclipse .jgit .storage .file .FileRepositoryBuilder ;
3642import org .eclipse .jgit .transport .CredentialsProvider ;
3743import org .eclipse .jgit .transport .RefSpec ;
@@ -286,33 +292,36 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
286292 public String getRepoUrl () {
287293 return repo .getRepoUrl ();
288294 }
289-
290- @ Override
291- public String getFileContent (String branchName , String fileRelativePath , String encoding ) {
292- File file ;
295+
296+ private File getFileFromRepo (String branchName , String fileRelativePath , String encoding ) {
293297 try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ();
294- Git git = getLocalGit (wc );
295- Repository gitRepo = git .getRepository ()) {
298+ Git git = getLocalGit (wc );
299+ Repository gitRepo = git .getRepository ()) {
296300
297- String bn = getRealBranchName (branchName );
298- git
299- .pull ()
300- .setCredentialsProvider (credentials )
301- .call ();
301+ String bn = getRealBranchName (branchName );
302+ git
303+ .pull ()
304+ .setCredentialsProvider (credentials )
305+ .call ();
302306
303- git
304- .checkout ()
305- .setCreateBranch (gitRepo .exactRef ("refs/heads/" + bn ) == null )
306- .addPath (fileRelativePath )
307- .setName (bn )
308- .call ();
307+ git
308+ .checkout ()
309+ .setCreateBranch (gitRepo .exactRef ("refs/heads/" + bn ) == null )
310+ .addPath (fileRelativePath )
311+ .setName (bn )
312+ .call ();
309313
310- file = new File (wc .getFolder (), fileRelativePath );
311- } catch (GitAPIException e ) {
312- throw new EVCSException (e );
313- } catch (Exception e ) {
314- throw new RuntimeException (e );
315- }
314+ return new File (wc .getFolder (), fileRelativePath );
315+ } catch (GitAPIException e ) {
316+ throw new EVCSException (e );
317+ } catch (Exception e ) {
318+ throw new RuntimeException (e );
319+ }
320+ }
321+
322+ @ Override
323+ public String getFileContent (String branchName , String fileRelativePath , String encoding ) {
324+ File file = getFileFromRepo (branchName , fileRelativePath , encoding );
316325 if (!file .exists ()) {
317326 throw new EVCSFileNotFound (String .format ("File %s is not found" , fileRelativePath ));
318327 }
@@ -657,7 +666,7 @@ public List<VCSCommit> getCommitsRange(String branchName, String startFromCommit
657666 }
658667 }
659668
660- private RevCommit getBranchHeadCommit (String branchName ) {
669+ private RevCommit getHeadRevCommit (String branchName ) {
661670 try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ();
662671 Git git = getLocalGit (wc );
663672 Repository gitRepo = git .getRepository ();
@@ -681,7 +690,7 @@ private RevCommit getBranchHeadCommit (String branchName) {
681690
682691 @ Override
683692 public VCSCommit getHeadCommit (String branchName ) {
684- RevCommit branchHeadCommit = getBranchHeadCommit (getRealBranchName (branchName ));
693+ RevCommit branchHeadCommit = getHeadRevCommit (getRealBranchName (branchName ));
685694 return new VCSCommit (branchHeadCommit .getName (), branchHeadCommit .getFullMessage (),
686695 branchHeadCommit .getAuthorIdent ().getName ());
687696 }
@@ -693,7 +702,6 @@ public String toString() {
693702
694703 @ Override
695704 public Boolean fileExists (String branchName , String filePath ) {
696- // TODO Auto-generated method stub
697- return null ;
705+ return getFileFromRepo (branchName , filePath , StandardCharsets .UTF_8 .name ()).exists ();
698706 }
699707}
0 commit comments