diff --git a/src/main/java/net/geedge/asw/module/app/service/impl/GitServiceImpl.java b/src/main/java/net/geedge/asw/module/app/service/impl/GitServiceImpl.java index bf0e5b7..c3bd2fe 100644 --- a/src/main/java/net/geedge/asw/module/app/service/impl/GitServiceImpl.java +++ b/src/main/java/net/geedge/asw/module/app/service/impl/GitServiceImpl.java @@ -594,7 +594,7 @@ public class GitServiceImpl implements IGitService { ObjectId branchRef = repository.resolve(branch); result.put("commitId", branchRef.getName()); - List files = T.ListUtil.list(true); + List> files = T.ListUtil.list(true); try (TreeWalk treeWalk = new TreeWalk(repository); RevWalk revWalk = new RevWalk(repository)) { @@ -602,26 +602,29 @@ public class GitServiceImpl implements IGitService { treeWalk.setFilter(PathFilter.create("applications/" + applicationName + "/")); treeWalk.setRecursive(true); + Map appFilePathMapping = T.MapUtil.newHashMap(true); while (treeWalk.next()) { + String pathString = treeWalk.getPathString(); Map m = T.MapUtil.builder() - .put("path", treeWalk.getPathString()) + .put("path", pathString) .build(); - Map fileContent = this.getFileContent(repository, treeWalk.getPathString(), treeWalk.getObjectId(0)); + Map fileContent = this.getFileContent(repository, pathString, treeWalk.getObjectId(0)); m.putAll(fileContent); - - // lastCommitId - Iterable iterable = git.log() - .add(branchRef) - .addPath(treeWalk.getPathString()) - .call(); - Iterator iterator = iterable.iterator(); - m.put("lastCommitId", iterator.hasNext() ? iterator.next().getName() : null); files.add(m); + + appFilePathMapping.put(pathString, pathString); + } + + Map lastCommitMapping = this.getLastCommitIdDataByPath(repository, branch, appFilePathMapping); + for (Map m : files) { + String path = T.MapUtil.getStr(m, "path"); + RevCommit revCommit = lastCommitMapping.get(path); + m.put("lastCommitId", revCommit != null ? revCommit.getName() : null); } } result.put("files", files); - } catch (IOException | GitAPIException e) { + } catch (IOException e) { log.error(e, "[infoApplication] [error] [workspaceId: {}] [branch: {}] [application: {}]", workspaceId, branch, applicationName); throw new ASWException(RCode.ERROR); }