Skip to content

Commit df7702e

Browse files
committed
dss-server: fix rollback
1 parent 493d068 commit df7702e

File tree

1 file changed

+30
-16
lines changed
  • dss-git/dss-git-server/src/main/java/com/webank/wedatasphere/dss/git/utils

1 file changed

+30
-16
lines changed

dss-git/dss-git-server/src/main/java/com/webank/wedatasphere/dss/git/utils/DSSGitUtils.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.google.gson.JsonParser;
66
import com.google.gson.JsonElement;
77
import com.webank.wedatasphere.dss.common.exception.DSSErrorException;
8+
import com.webank.wedatasphere.dss.git.common.protocol.constant.GitConstant;
89
import org.apache.http.client.methods.HttpDelete;
910
import com.webank.wedatasphere.dss.git.common.protocol.GitTree;
1011
import com.webank.wedatasphere.dss.git.common.protocol.GitUserEntity;
@@ -699,8 +700,9 @@ public static List<GitCommitResponse> getLatestCommit(Repository repository, Str
699700

700701
public static GitHistoryResponse listCommitsBetween(Repository repository, String oldCommitId, String newCommitId, String path) throws Exception {
701702
List<GitCommitResponse> gitCommitResponseList = new ArrayList<>();
703+
Set<String> commitIdSet = new HashSet<>();
704+
702705

703-
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
704706
try (RevWalk walk = new RevWalk(repository)) {
705707
Git git = new Git(repository);
706708
ObjectId commitIdNow = null;
@@ -710,17 +712,32 @@ public static GitHistoryResponse listCommitsBetween(Repository repository, Strin
710712
} else {
711713
commitIdNow = repository.resolve(newCommitId);
712714
}
715+
// 代码改动
716+
gitLogHistory(git, repository, oldCommitId, commitIdNow, path, gitCommitResponseList, commitIdSet);
717+
// 元数据改动
718+
gitLogHistory(git, repository, oldCommitId, commitIdNow, GitConstant.GIT_SERVER_META_PATH + File.separator + path, gitCommitResponseList, commitIdSet);
719+
} catch (Exception e) {
720+
throw new GitErrorException(80121, "get log between " + oldCommitId + " and " + newCommitId + "failed, the reason is : ", e);
721+
}
722+
GitHistoryResponse historyResponse = new GitHistoryResponse();
723+
historyResponse.setResponses(gitCommitResponseList);
724+
return historyResponse;
725+
}
713726

714-
715-
Iterable<RevCommit> commits = git.log()
716-
.addRange(repository.resolve(oldCommitId), commitIdNow)
717-
.addPath(path)
718-
.call();
719-
720-
for (RevCommit commit : commits) {
721-
PersonIdent authorIdent = commit.getAuthorIdent(); // 获取提交人信息
722-
GitCommitResponse commitResponse = new GitCommitResponse();
723-
commitResponse.setCommitId(commit.getId().getName());
727+
private static void gitLogHistory(Git git, Repository repository, String oldCommitId, ObjectId commitIdNow, String path, List<GitCommitResponse> gitCommitResponseList, Set<String> commitIdSet) throws IOException, GitAPIException {
728+
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
729+
Iterable<RevCommit> commits = git.log()
730+
.addRange(repository.resolve(oldCommitId), commitIdNow)
731+
.addPath(path)
732+
.call();
733+
734+
for (RevCommit commit : commits) {
735+
PersonIdent authorIdent = commit.getAuthorIdent(); // 获取提交人信息
736+
GitCommitResponse commitResponse = new GitCommitResponse();
737+
String commitId = commit.getId().getName();
738+
if (!commitIdSet.contains(commitId)) {
739+
commitIdSet.add(commitId);
740+
commitResponse.setCommitId(commitId);
724741
commitResponse.setCommitTime(sdf.format(commit.getAuthorIdent().getWhen()));
725742
String shortMessage = commit.getShortMessage();
726743
getUserName(shortMessage, commitResponse, commit);
@@ -730,14 +747,11 @@ public static GitHistoryResponse listCommitsBetween(Repository repository, Strin
730747
logger.info("Commit Message: " + commit.getFullMessage()); // 提交信息
731748
logger.info("Author: " + authorIdent.getName() + " <" + authorIdent.getEmailAddress() + ">"); // 提交人
732749
}
733-
} catch (Exception e) {
734-
throw new GitErrorException(80121, "get log between " + oldCommitId + " and " + newCommitId + "failed, the reason is : ", e);
735750
}
736-
GitHistoryResponse historyResponse = new GitHistoryResponse();
737-
historyResponse.setResponses(gitCommitResponseList);
738-
return historyResponse;
739751
}
740752

753+
754+
741755
public static String generateGitPath(String projectName, Long workspaceId) {
742756
// eg : /data/GitInstall/224/testGit/.git
743757
return DSSGitConstant.GIT_PATH_PRE + workspaceId + File.separator + projectName + File.separator + DSSGitConstant.GIT_PATH_SUFFIX;

0 commit comments

Comments
 (0)