From 336c4ed778751ebcadcfa01b550463ef3fe79026 Mon Sep 17 00:00:00 2001 From: shizhendong Date: Thu, 7 Nov 2024 15:05:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20application=20=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=9F=A5=E8=AF=A2=20app=20lastCommit=20?= =?UTF-8?q?=E6=95=88=E7=8E=87=E4=BC=98=E5=8C=96=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/service/impl/GitServiceImpl.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) 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); }