From 014af08531910d6fdac4bd5ce027e466365740aa Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 29 Mar 2021 17:01:04 +0400 Subject: [PATCH] #16 -- Remove repo after indexing --- .../extractor/service/GitRepositoryService.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/service/GitRepositoryService.java b/src/main/java/ru/ulstu/extractor/service/GitRepositoryService.java index 63082d0..558b179 100644 --- a/src/main/java/ru/ulstu/extractor/service/GitRepositoryService.java +++ b/src/main/java/ru/ulstu/extractor/service/GitRepositoryService.java @@ -1,5 +1,6 @@ package ru.ulstu.extractor.service; +import org.apache.commons.io.FileUtils; import org.eclipse.jgit.api.CreateBranchCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.ListBranchCommand; @@ -42,14 +43,14 @@ public class GitRepositoryService { Repository localRepo = new FileRepository(getProjectGitDirectory(url)); git = new Git(localRepo); git.pull().call(); + localRepo.close(); } else { git = Git.cloneRepository() .setURI(url) .setDirectory(getProjectDirectoryFile(url)) .call(); } - Iterable commits = git.log().call(); - //commits.forEach(c -> System.out.println(c.getFullMessage())); + git.close(); } private String getProjectDirectory(String url) { @@ -101,6 +102,8 @@ public class GitRepositoryService { list.add(commit); prevCommit = revCommit; } + git.close(); + localRepo.close(); return list; } @@ -207,14 +210,17 @@ public class GitRepositoryService { cloneOrUpdateRepo(url); Repository localRepo = new FileRepository(getProjectGitDirectory(url)); Git git = new Git(localRepo); - return git.branchList().setListMode(ListBranchCommand.ListMode.REMOTE) + List branches = git.branchList().setListMode(ListBranchCommand.ListMode.REMOTE) .call() .stream() .map(r -> new Branch(r.getName().replace(BRANCH_PREFIX, ""))) .collect(Collectors.toList()); + git.close(); + localRepo.close(); + return branches; } public void remove(String repositoryUrl) throws IOException { - //FileUtils.deleteDirectory(getProjectDirectoryFile(repositoryUrl)); + FileUtils.deleteDirectory(getProjectDirectoryFile(repositoryUrl)); } }