|
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 | }
|
@@ -556,7 +539,7 @@ public List<VCSCommit> getCommitsRange(String branchName, String afterCommitId,
|
556 | 539 | .call();
|
557 | 540 |
|
558 | 541 | ObjectId sinceCommit = afterCommitId == null ?
|
559 |
| - getInitialCommit(git, gitRepo, bn).getId() : |
| 542 | + getInitialCommit(gitRepo, bn).getId() : |
560 | 543 | ObjectId.fromString(afterCommitId);
|
561 | 544 |
|
562 | 545 | ObjectId untilCommit = untilCommitId == null ?
|
@@ -585,7 +568,7 @@ public List<VCSCommit> getCommitsRange(String branchName, String afterCommitId,
|
585 | 568 | }
|
586 | 569 | }
|
587 | 570 |
|
588 |
| - private RevCommit getInitialCommit(Git git, Repository gitRepo, String branchName) throws Exception { |
| 571 | + private RevCommit getInitialCommit(Repository gitRepo, String branchName) throws Exception { |
589 | 572 | try (RevWalk rw = new RevWalk(gitRepo)) {
|
590 | 573 | Ref ref = gitRepo.exactRef("refs/heads/" + branchName);
|
591 | 574 | ObjectId headCommitId = ref.getObjectId();
|
@@ -624,15 +607,15 @@ public List<VCSCommit> getCommitsRange(String branchName, String startFromCommit
|
624 | 607 | ObjectId headCommitId = ref.getObjectId();
|
625 | 608 | startCommit = rw.parseCommit( headCommitId );
|
626 | 609 | ObjectId sinceCommit = startFromCommitId == null ?
|
627 |
| - getInitialCommit(git, gitRepo, bn).getId() : |
| 610 | + getInitialCommit(gitRepo, bn).getId() : |
628 | 611 | ObjectId.fromString(startFromCommitId);
|
629 | 612 | endCommit = rw.parseCommit(sinceCommit);
|
630 | 613 | } else {
|
631 | 614 | ObjectId sinceCommit = startFromCommitId == null ?
|
632 | 615 | gitRepo.exactRef("refs/heads/" + bn).getObjectId() :
|
633 | 616 | ObjectId.fromString(startFromCommitId);
|
634 | 617 | startCommit = rw.parseCommit( sinceCommit );
|
635 |
| - endCommit = getInitialCommit(git, gitRepo, bn); |
| 618 | + endCommit = getInitialCommit(gitRepo, bn); |
636 | 619 | }
|
637 | 620 |
|
638 | 621 | rw.markStart(startCommit);
|
@@ -700,6 +683,6 @@ public String toString() {
|
700 | 683 |
|
701 | 684 | @Override
|
702 | 685 | public Boolean fileExists(String branchName, String filePath) {
|
703 |
| - return getFileFromRepo(branchName, filePath, StandardCharsets.UTF_8.name()).exists(); |
| 686 | + return getFileFromRepo(branchName, filePath).exists(); |
704 | 687 | }
|
705 | 688 | }
|
0 commit comments