Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxiaojian committed Mar 7, 2024
1 parent 53dc2d0 commit ee0071d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public void cleanMainBranchFile() {

@Override
public void replaceMainBranch(String branchName) {
branchManager().commitMainBranchFile(branchName);
branchManager().commitMainBranch(branchName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,21 @@ public Path branchDirectory() {
/** Return the path string of a branch. */
public static String getBranchPath(FileIO fileIO, Path tablePath, String branchName) {
if (branchName.equals(DEFAULT_MAIN_BRANCH)) {
branchName = forwardBranchName(fileIO, tablePath, branchName);
}
// No main branch replacement has occurred.
if (branchName.equals(DEFAULT_MAIN_BRANCH)) {
return tablePath.toString();
Path path = new Path(tablePath, MAIN_BRANCH_FILE);
try {
if (fileIO.exists(path)) {
String data = fileIO.readFileUtf8(path);
if (StringUtils.isBlank(data)) {
return tablePath.toString();
} else {
return tablePath.toString() + "/branch/" + BRANCH_PREFIX + data;
}
} else {
return tablePath.toString();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tablePath.toString() + "/branch/" + BRANCH_PREFIX + branchName;
}
Expand All @@ -101,35 +111,13 @@ public String mainBranch() {
}
}

/** Forward branch name. */
public static String forwardBranchName(FileIO fileIO, Path tablePath, String branchName) {
if (branchName.equals(DEFAULT_MAIN_BRANCH)) {
Path path = new Path(tablePath, MAIN_BRANCH_FILE);
try {
if (fileIO.exists(path)) {
String data = fileIO.readFileUtf8(path);
if (StringUtils.isBlank(data)) {
return DEFAULT_MAIN_BRANCH;
} else {
return data;
}
} else {
return DEFAULT_MAIN_BRANCH;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return branchName;
}

/** Return the path of a branch. */
public Path branchPath(String branchName) {
return new Path(getBranchPath(fileIO, tablePath, branchName));
}

/** Replace main by specify branch. */
public void commitMainBranchFile(String branchName) {
public void commitMainBranch(String branchName) {
Path mainBranchFile = new Path(tablePath, MAIN_BRANCH_FILE);
try {
fileIO.delete(mainBranchFile, false);
Expand Down

0 comments on commit ee0071d

Please sign in to comment.