|
1 | 1 | package org.scm4j.vcs;
|
2 | 2 |
|
3 |
| -import java.io.ByteArrayOutputStream; |
4 |
| -import java.io.File; |
5 |
| -import java.io.FileWriter; |
6 |
| -import java.io.IOException; |
7 |
| -import java.net.InetSocketAddress; |
8 |
| -import java.net.Proxy; |
9 |
| -import java.net.Proxy.Type; |
10 |
| -import java.net.ProxySelector; |
11 |
| -import java.net.SocketAddress; |
12 |
| -import java.net.URI; |
13 |
| -import java.nio.charset.StandardCharsets; |
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; |
19 |
| - |
20 | 3 | import org.apache.commons.io.FileUtils;
|
21 | 4 | import org.apache.commons.io.IOUtils;
|
22 | 5 | import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
|
|
30 | 13 | import org.eclipse.jgit.diff.DiffEntry.ChangeType;
|
31 | 14 | import org.eclipse.jgit.diff.DiffEntry.Side;
|
32 | 15 | import org.eclipse.jgit.diff.DiffFormatter;
|
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; |
| 16 | +import org.eclipse.jgit.lib.*; |
38 | 17 | import org.eclipse.jgit.revwalk.RevCommit;
|
39 | 18 | import org.eclipse.jgit.revwalk.RevSort;
|
40 | 19 | import org.eclipse.jgit.revwalk.RevWalk;
|
|
43 | 22 | import org.eclipse.jgit.transport.RefSpec;
|
44 | 23 | import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
|
45 | 24 | import org.eclipse.jgit.treewalk.CanonicalTreeParser;
|
46 |
| -import org.scm4j.vcs.api.IVCS; |
47 |
| -import org.scm4j.vcs.api.VCSChangeType; |
48 |
| -import org.scm4j.vcs.api.VCSCommit; |
49 |
| -import org.scm4j.vcs.api.VCSDiffEntry; |
50 |
| -import org.scm4j.vcs.api.VCSMergeResult; |
51 |
| -import org.scm4j.vcs.api.WalkDirection; |
| 25 | +import org.scm4j.vcs.api.*; |
52 | 26 | import org.scm4j.vcs.api.exceptions.EVCSBranchExists;
|
53 | 27 | import org.scm4j.vcs.api.exceptions.EVCSException;
|
54 | 28 | import org.scm4j.vcs.api.exceptions.EVCSFileNotFound;
|
55 | 29 | import org.scm4j.vcs.api.workingcopy.IVCSLockedWorkingCopy;
|
56 | 30 | import org.scm4j.vcs.api.workingcopy.IVCSRepositoryWorkspace;
|
57 | 31 | import org.scm4j.vcs.api.workingcopy.IVCSWorkspace;
|
58 | 32 |
|
| 33 | +import java.io.ByteArrayOutputStream; |
| 34 | +import java.io.File; |
| 35 | +import java.io.FileWriter; |
| 36 | +import java.io.IOException; |
| 37 | +import java.net.*; |
| 38 | +import java.net.Proxy.Type; |
| 39 | +import java.nio.charset.StandardCharsets; |
| 40 | +import java.util.*; |
| 41 | + |
59 | 42 | public class GitVCS implements IVCS {
|
60 | 43 |
|
61 | 44 | private static final String MASTER_BRANCH_NAME = "master";
|
@@ -293,7 +276,7 @@ public String getRepoUrl() {
|
293 | 276 | return repo.getRepoUrl();
|
294 | 277 | }
|
295 | 278 |
|
296 |
| - private File getFileFromRepo(String branchName, String fileRelativePath, String encoding) { |
| 279 | + private File getFileFromRepo(String branchName, String fileRelativePath) { |
297 | 280 | try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy();
|
298 | 281 | Git git = getLocalGit(wc);
|
299 | 282 | Repository gitRepo = git.getRepository()) {
|
@@ -321,7 +304,7 @@ private File getFileFromRepo(String branchName, String fileRelativePath, String
|
321 | 304 |
|
322 | 305 | @Override
|
323 | 306 | public String getFileContent(String branchName, String fileRelativePath, String encoding) {
|
324 |
| - File file = getFileFromRepo(branchName, fileRelativePath, encoding); |
| 307 | + File file = getFileFromRepo(branchName, fileRelativePath); |
325 | 308 | if (!file.exists()) {
|
326 | 309 | throw new EVCSFileNotFound(String.format("File %s is not found", fileRelativePath));
|
327 | 310 | }
|
@@ -558,7 +541,7 @@ public List<VCSCommit> getCommitsRange(String branchName, String afterCommitId,
|
558 | 541 | .call();
|
559 | 542 |
|
560 | 543 | ObjectId sinceCommit = afterCommitId == null ?
|
561 |
| - getInitialCommit(git, gitRepo, bn).getId() : |
| 544 | + getInitialCommit(gitRepo, bn).getId() : |
562 | 545 | ObjectId.fromString(afterCommitId);
|
563 | 546 |
|
564 | 547 | ObjectId untilCommit = untilCommitId == null ?
|
@@ -587,7 +570,7 @@ public List<VCSCommit> getCommitsRange(String branchName, String afterCommitId,
|
587 | 570 | }
|
588 | 571 | }
|
589 | 572 |
|
590 |
| - private RevCommit getInitialCommit(Git git, Repository gitRepo, String branchName) throws Exception { |
| 573 | + private RevCommit getInitialCommit(Repository gitRepo, String branchName) throws Exception { |
591 | 574 | try (RevWalk rw = new RevWalk(gitRepo)) {
|
592 | 575 | Ref ref = gitRepo.exactRef("refs/heads/" + branchName);
|
593 | 576 | ObjectId headCommitId = ref.getObjectId();
|
@@ -626,15 +609,15 @@ public List<VCSCommit> getCommitsRange(String branchName, String startFromCommit
|
626 | 609 | ObjectId headCommitId = ref.getObjectId();
|
627 | 610 | startCommit = rw.parseCommit( headCommitId );
|
628 | 611 | ObjectId sinceCommit = startFromCommitId == null ?
|
629 |
| - getInitialCommit(git, gitRepo, bn).getId() : |
| 612 | + getInitialCommit(gitRepo, bn).getId() : |
630 | 613 | ObjectId.fromString(startFromCommitId);
|
631 | 614 | endCommit = rw.parseCommit(sinceCommit);
|
632 | 615 | } else {
|
633 | 616 | ObjectId sinceCommit = startFromCommitId == null ?
|
634 | 617 | gitRepo.exactRef("refs/heads/" + bn).getObjectId() :
|
635 | 618 | ObjectId.fromString(startFromCommitId);
|
636 | 619 | startCommit = rw.parseCommit( sinceCommit );
|
637 |
| - endCommit = getInitialCommit(git, gitRepo, bn); |
| 620 | + endCommit = getInitialCommit(gitRepo, bn); |
638 | 621 | }
|
639 | 622 |
|
640 | 623 | rw.markStart(startCommit);
|
@@ -702,6 +685,6 @@ public String toString() {
|
702 | 685 |
|
703 | 686 | @Override
|
704 | 687 | public Boolean fileExists(String branchName, String filePath) {
|
705 |
| - return getFileFromRepo(branchName, filePath, StandardCharsets.UTF_8.name()).exists(); |
| 688 | + return getFileFromRepo(branchName, filePath).exists(); |
706 | 689 | }
|
707 | 690 | }
|
0 commit comments