Skip to content

Commit

Permalink
Let RevWalk close
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnNiang committed Jan 23, 2021
1 parent a10af60 commit 4b6dc74
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/main/java/run/halo/app/theme/GitThemeFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public ThemeProperty fetch(Object source) {
.orElseThrow(() -> new ThemePropertyMissingException("主题配置文件缺失,请确认后重试!"));

// fetch property
return ThemePropertyScanner.INSTANCE.fetchThemeProperty(themePropertyPath.getParent()).orElseThrow();
return ThemePropertyScanner.INSTANCE.fetchThemeProperty(themePropertyPath.getParent())
.orElseThrow();
} catch (IOException | GitAPIException e) {
throw new RuntimeException("主题拉取失败!(" + e.getMessage() + ")", e);
}
Expand Down
38 changes: 22 additions & 16 deletions src/test/java/run/halo/app/utils/GitTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package run.halo.app.utils;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
Expand Down Expand Up @@ -31,8 +35,6 @@
import org.junit.jupiter.api.Test;
import org.springframework.test.context.ActiveProfiles;

import static org.junit.jupiter.api.Assertions.*;

/**
* Git test.
*
Expand Down Expand Up @@ -62,7 +64,8 @@ void destroy() throws IOException {

@Test
void openFailureTest() {
Assertions.assertThrows(RepositoryNotFoundException.class, () -> Git.open(tempPath.toFile()));
Assertions
.assertThrows(RepositoryNotFoundException.class, () -> Git.open(tempPath.toFile()));
}

@Test
Expand Down Expand Up @@ -245,23 +248,26 @@ void findTags() throws GitAPIException, IOException {
git.branchList()
.setListMode(ListBranchCommand.ListMode.ALL)
.call()
.forEach(ref -> log.debug("ref: {}, object id: {}", ref.getName(), ref.getObjectId()));
.forEach(ref -> log
.debug("ref: {}, object id: {}", ref.getName(), ref.getObjectId()));

ObjectId objectId = ObjectId.fromString("51bf554e58f38cff22bb93f8e6cd8f8b72aa2d64");
RevWalk revWalk = new RevWalk(git.getRepository());
revWalk.reset();
revWalk.setTreeFilter(TreeFilter.ANY_DIFF);
revWalk.sort(RevSort.TOPO, true);
revWalk.sort(RevSort.COMMIT_TIME_DESC, true);
RevCommit revCommit = revWalk.parseCommit(objectId);
log.debug("Found commit: {} for object: {}", revCommit, objectId);
log.debug("Commit details: {} {} {}",
revCommit.getName(),
revCommit.getFullMessage(),
new Timestamp(revCommit.getCommitTime() * 1000L));
try (final var revWalk = new RevWalk(git.getRepository())) {
revWalk.reset();
revWalk.setTreeFilter(TreeFilter.ANY_DIFF);
revWalk.sort(RevSort.TOPO, true);
revWalk.sort(RevSort.COMMIT_TIME_DESC, true);
RevCommit revCommit = revWalk.parseCommit(objectId);
log.debug("Found commit: {} for object: {}", revCommit, objectId);
log.debug("Commit details: {} {} {}",
revCommit.getName(),
revCommit.getFullMessage(),
new Timestamp(revCommit.getCommitTime() * 1000L));
}
git.tagList()
.call()
.forEach(ref -> log.debug("ref: {}, object id: {}", ref.getName(), ref.getObjectId()));
.forEach(ref -> log
.debug("ref: {}, object id: {}", ref.getName(), ref.getObjectId()));
}
}

Expand Down

0 comments on commit 4b6dc74

Please sign in to comment.