Skip to content

The Unified and Autonomous Development Platform

sort TreeFormatterEntry when insert entries into TreeFormatter with byte

robin shenefce2c6a757b
diff --git a/core/src/main/java/com/gitplex/server/git/BlobEdits.java b/core/src/main/java/com/gitplex/server/git/BlobEdits.java
index f01c45ca62..5ac7b0bc4e 100644
--- a/core/src/main/java/com/gitplex/server/git/BlobEdits.java
+++ b/core/src/main/java/com/gitplex/server/git/BlobEdits.java
@@ -3,9 +3,10 @@ package com.gitplex.server.git;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -30,6 +31,7 @@ import com.gitplex.server.git.exception.NotTreeException;
import com.gitplex.server.git.exception.ObjectAlreadyExistsException;
import com.gitplex.server.git.exception.ObjectNotFoundException;
import com.gitplex.server.git.exception.ObsoleteCommitException;
+import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
@@ -50,7 +52,7 @@ public class BlobEdits implements Serializable {
else
throw new IllegalArgumentException("Invalid old path: " + oldPath);
}
- this.newBlobs = new LinkedHashMap<>();
+ this.newBlobs = new HashMap<>();
for (Map.Entry<String, BlobContent> entry: newBlobs.entrySet()) {
String normalizedPath = GitUtils.normalizePath(entry.getKey());
if (normalizedPath != null)
@@ -93,7 +95,7 @@ public class BlobEdits implements Serializable {
it.remove();
}
}
- Map<String, BlobContent> childNewBlobs = new LinkedHashMap<>();
+ Map<String, BlobContent> childNewBlobs = new HashMap<>();
for (Iterator<Map.Entry<String, BlobContent>> it = currentNewBlobs.entrySet().iterator();
it.hasNext();) {
Map.Entry<String, BlobContent> entry = it.next();
@@ -154,7 +156,7 @@ public class BlobEdits implements Serializable {
}
}
for (String topLevelPathSegment: topLevelPathSegments) {
- Map<String, BlobContent> childNewBlobs = new LinkedHashMap<>();
+ Map<String, BlobContent> childNewBlobs = new HashMap<>();
for (Map.Entry<String, BlobContent> entry: currentNewBlobs.entrySet()) {
String path = entry.getKey();
if (path.startsWith(topLevelPathSegment + "/"))
@@ -168,6 +170,7 @@ public class BlobEdits implements Serializable {
}
if (!entries.isEmpty()) {
TreeFormatter formatter = new TreeFormatter();
+ Collections.sort(entries);
for (TreeFormatterEntry entry: entries)
formatter.append(entry.name, entry.mode, entry.id);
return inserter.insert(formatter);
@@ -224,7 +227,7 @@ public class BlobEdits implements Serializable {
treeWalk.addTree(revTree);
ObjectId treeId = insertTree(revTree, treeWalk, inserter, null, new HashSet<>(oldPaths),
- new LinkedHashMap<>(newBlobs));
+ new HashMap<>(newBlobs));
if (treeId != null)
commit.setTreeId(treeId);
@@ -245,18 +248,34 @@ public class BlobEdits implements Serializable {
}
}
- public static class TreeFormatterEntry {
+ public static class TreeFormatterEntry implements Comparable<TreeFormatterEntry> {
- String name;
+ final String name;
- FileMode mode;
+ final FileMode mode;
- ObjectId id;
+ final ObjectId id;
+
+ final byte[] nameBytes;
public TreeFormatterEntry(String name, FileMode mode, ObjectId id) {
this.name = name;
this.mode = mode;
this.id = id;
+ if (mode.equals(FileMode.TYPE_TREE))
+ nameBytes = (name + "/").getBytes(Charsets.UTF_8);
+ else
+ nameBytes = name.getBytes(Charsets.UTF_8);
+ }
+
+ @Override
+ public int compareTo(TreeFormatterEntry o) {
+ for (int i = 0; i<nameBytes.length && i<o.nameBytes.length; i++) {
+ final int cmp = (nameBytes[i] & 0xff) - (o.nameBytes[i] & 0xff);
+ if (cmp != 0)
+ return cmp;
+ }
+ return nameBytes.length - o.nameBytes.length;
}
}
diff --git a/core/src/test/java/com/gitplex/server/git/BlobEditsTest.java b/core/src/test/java/com/gitplex/server/git/BlobEditsTest.java
index 410de8f243..992e94e0d3 100644
--- a/core/src/test/java/com/gitplex/server/git/BlobEditsTest.java
+++ b/core/src/test/java/com/gitplex/server/git/BlobEditsTest.java
@@ -1,13 +1,13 @@
package com.gitplex.server.git;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.LinkedHashMap;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -92,7 +92,7 @@ public class BlobEditsTest extends AbstractGitTest {
Set<String> oldPaths = Sets.newHashSet("server/src/com/example/a/a.java",
"server/src/com/example/b/b.java");
- Map<String, BlobContent> newBlobs = new LinkedHashMap<>();
+ Map<String, BlobContent> newBlobs = new HashMap<>();
newBlobs.put("client/c.java", new BlobContent.Immutable("a".getBytes(), FileMode.REGULAR_FILE));
newBlobs.put("client/d.java", new BlobContent.Immutable("a".getBytes(), FileMode.REGULAR_FILE));
BlobEdits edits = new BlobEdits(oldPaths, newBlobs);
@@ -122,7 +122,7 @@ public class BlobEditsTest extends AbstractGitTest {
String refName = "refs/heads/master";
ObjectId oldCommitId = git.getRepository().resolve(refName);
- Map<String, BlobContent> newBlobs = new LinkedHashMap<>();
+ Map<String, BlobContent> newBlobs = new HashMap<>();
newBlobs.put("client/c.java", new BlobContent.Immutable("a".getBytes(), FileMode.REGULAR_FILE));
BlobEdits edits = new BlobEdits(Sets.newHashSet("server/src/com/example/a"), newBlobs);
ObjectId newCommitId = edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user,
@@ -148,7 +148,7 @@ public class BlobEditsTest extends AbstractGitTest {
String refName = "refs/heads/master";
ObjectId oldCommitId = git.getRepository().resolve(refName);
- Map<String, BlobContent> newBlobs = new LinkedHashMap<>();
+ Map<String, BlobContent> newBlobs = new HashMap<>();
newBlobs.put("client/a.java/a.java", new BlobContent.Immutable("a".getBytes(), FileMode.REGULAR_FILE));
BlobEdits edits = new BlobEdits(Sets.newHashSet("server/src/com/example/a/a.java"), newBlobs);
try {
@@ -172,7 +172,7 @@ public class BlobEditsTest extends AbstractGitTest {
String refName = "refs/heads/master";
ObjectId oldCommitId = git.getRepository().resolve(refName);
- Map<String, BlobContent> newBlobs = new LinkedHashMap<>();
+ Map<String, BlobContent> newBlobs = new HashMap<>();
newBlobs.put("/server/src/com/example/c/c.java", new BlobContent.Immutable("c".getBytes(), FileMode.REGULAR_FILE));
newBlobs.put("/server/src/com/example/d/d.java", new BlobContent.Immutable("d".getBytes(), FileMode.REGULAR_FILE));
BlobEdits edits = new BlobEdits(Sets.newHashSet(), newBlobs);
@@ -189,7 +189,7 @@ public class BlobEditsTest extends AbstractGitTest {
}
oldCommitId = newCommitId;
- newBlobs = new LinkedHashMap<>();
+ newBlobs = new HashMap<>();
newBlobs.put("/common/common.java", new BlobContent.Immutable("common".getBytes(), FileMode.REGULAR_FILE));
edits = new BlobEdits(Sets.newHashSet(), newBlobs);
newCommitId = edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test add");
@@ -212,7 +212,7 @@ public class BlobEditsTest extends AbstractGitTest {
String refName = "refs/heads/master";
ObjectId oldCommitId = git.getRepository().resolve(refName);
- Map<String, BlobContent> newBlobs = new LinkedHashMap<>();
+ Map<String, BlobContent> newBlobs = new HashMap<>();
newBlobs.put("/dir/file", new BlobContent.Immutable("c".getBytes(), FileMode.REGULAR_FILE));
newBlobs.put("/dir/file/a.java", new BlobContent.Immutable("d".getBytes(), FileMode.REGULAR_FILE));
BlobEdits edits = new BlobEdits(Sets.newHashSet(), newBlobs);
@@ -232,7 +232,7 @@ public class BlobEditsTest extends AbstractGitTest {
String refName = "refs/heads/master";
ObjectId oldCommitId = git.getRepository().resolve(refName);
- Map<String, BlobContent> newBlobs = new LinkedHashMap<>();
+ Map<String, BlobContent> newBlobs = new HashMap<>();
newBlobs.put("client/dir2/file4", new BlobContent.Immutable("c".getBytes(), FileMode.REGULAR_FILE));
newBlobs.put("client/security/dir1/file2", new BlobContent.Immutable("d".getBytes(), FileMode.REGULAR_FILE));
newBlobs.put("client/security/dir2/file3", new BlobContent.Immutable("d".getBytes(), FileMode.REGULAR_FILE));
@@ -255,16 +255,16 @@ public class BlobEditsTest extends AbstractGitTest {
}
assertEquals(10, paths.size());
- assertEquals("client/security/file", paths.get(0));
- assertEquals("client/security/dir1/file2", paths.get(1));
- assertEquals("client/security/dir1/subdir/file", paths.get(2));
- assertEquals("client/security/dir2/file3", paths.get(3));
- assertEquals("client/dir2/file4", paths.get(4));
- assertEquals("client/dir1/file1", paths.get(5));
- assertEquals("client/dir1/file0", paths.get(6));
+ assertEquals("client/dir1/file0", paths.get(0));
+ assertEquals("client/dir1/file1", paths.get(1));
+ assertEquals("client/dir2/file4", paths.get(2));
+ assertEquals("client/security/dir1/file2", paths.get(3));
+ assertEquals("client/security/dir1/subdir/file", paths.get(4));
+ assertEquals("client/security/dir2/file3", paths.get(5));
+ assertEquals("client/security/file", paths.get(6));
assertEquals("file", paths.get(7));
- assertEquals("server/file2", paths.get(8));
- assertEquals("server/file1", paths.get(9));
+ assertEquals("server/file1", paths.get(8));
+ assertEquals("server/file2", paths.get(9));
}
@Test
@@ -273,7 +273,9 @@ public class BlobEditsTest extends AbstractGitTest {
addFileAndCommit("a/file.java", "", "add a/file.java");
createDir("a.b");
- addFileAndCommit("a.b/file.java", "", "add a.b/file.java");
+ addFileAndCommit("a.b/file2.java", "", "add a.b/file.java");
+ addFileAndCommit("a.b/file1.java", "", "add a.b/file.java");
+ addFileAndCommit("a.b/file1", "", "add a.b/file.java");
String refName = "refs/heads/master";
ObjectId oldCommitId = git.getRepository().resolve(refName);
@@ -286,9 +288,9 @@ public class BlobEditsTest extends AbstractGitTest {
oldPaths.add(treeWalk.getPathString());
}
- Map<String, BlobContent> newBlobs = new LinkedHashMap<>();
- newBlobs.put("a.b/file.java", new BlobContent.Immutable("hello".getBytes(), FileMode.REGULAR_FILE));
- BlobEdits edits = new BlobEdits(Sets.newHashSet("a.b/file.java"), newBlobs);
+ Map<String, BlobContent> newBlobs = new HashMap<>();
+ newBlobs.put("a.b/file2.java", new BlobContent.Immutable("hello".getBytes(), FileMode.REGULAR_FILE));
+ BlobEdits edits = new BlobEdits(Sets.newHashSet("a.b/file2.java"), newBlobs);
ObjectId newCommitId = edits.commit(git.getRepository(), refName, oldCommitId, oldCommitId, user, "test modify");
List<String> newPaths = new ArrayList<>();
@@ -316,7 +318,7 @@ public class BlobEditsTest extends AbstractGitTest {
String refName = "refs/heads/master";
ObjectId oldCommitId = git.getRepository().resolve(refName);
- Map<String, BlobContent> newBlobs = new LinkedHashMap<>();
+ Map<String, BlobContent> newBlobs = new HashMap<>();
newBlobs.put("client/a.java", new BlobContent.Immutable("a".getBytes(), FileMode.REGULAR_FILE));
BlobEdits edits = new BlobEdits(Sets.newHashSet(), newBlobs);
try {
@@ -337,7 +339,7 @@ public class BlobEditsTest extends AbstractGitTest {
ObjectId newCommitId = git.getRepository().resolve(refName);
- Map<String, BlobContent> newBlobs = new LinkedHashMap<>();
+ Map<String, BlobContent> newBlobs = new HashMap<>();
newBlobs.put("/server/src/com/example/c/c.java", new BlobContent.Immutable("c".getBytes(), FileMode.REGULAR_FILE));
BlobEdits edits = new BlobEdits(Sets.newHashSet(), newBlobs);
try {
diff --git a/web/src/main/java/com/gitplex/server/web/component/dropzonefield/dropzone-field.css b/web/src/main/java/com/gitplex/server/web/component/dropzonefield/dropzone-field.css
index 1a7cf0803f..138c9e03d7 100644
--- a/web/src/main/java/com/gitplex/server/web/component/dropzonefield/dropzone-field.css
+++ b/web/src/main/java/com/gitplex/server/web/component/dropzonefield/dropzone-field.css
@@ -5,4 +5,8 @@
.dropzone-field .dz-message {
font-size: 20px;
color: #444;
+}
+
+.dropzone .dz-preview .dz-error-message {
+ top: 150px !important;
}
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/page/project/blob/BlobUploadPanel.java b/web/src/main/java/com/gitplex/server/web/page/project/blob/BlobUploadPanel.java
index 5de6102bb9..99fb1a4e4e 100644
--- a/web/src/main/java/com/gitplex/server/web/page/project/blob/BlobUploadPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/page/project/blob/BlobUploadPanel.java
@@ -2,7 +2,7 @@ package com.gitplex.server.web.page.project.blob;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.LinkedHashMap;
+import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
@@ -88,7 +88,7 @@ abstract class BlobUploadPanel extends Panel {
super.onSubmit(target, form);
ProjectManager projectManager = GitPlex.getInstance(ProjectManager.class);
- Map<String, BlobContent> newBlobs = new LinkedHashMap<>();
+ Map<String, BlobContent> newBlobs = new HashMap<>();
String directory;
if (context.getBlobIdent().path != null) {
diff --git a/web/src/main/java/com/gitplex/server/web/page/project/blob/render/commitoption/CommitOptionPanel.java b/web/src/main/java/com/gitplex/server/web/page/project/blob/render/commitoption/CommitOptionPanel.java
index 39d7415b3b..ebcc9521f9 100644
--- a/web/src/main/java/com/gitplex/server/web/page/project/blob/render/commitoption/CommitOptionPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/page/project/blob/render/commitoption/CommitOptionPanel.java
@@ -2,8 +2,8 @@ package com.gitplex.server.web.page.project.blob.render.commitoption;
import java.io.IOException;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.HashSet;
-import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
@@ -315,7 +315,7 @@ public class CommitOptionPanel extends Panel {
Repository repository = context.getProject().getRepository();
ObjectId newCommitId = null;
- Map<String, BlobContent> newBlobs = new LinkedHashMap<>();
+ Map<String, BlobContent> newBlobs = new HashMap<>();
if (newContentProvider != null) {
if (GitPlex.getInstance(ProjectManager.class).isModificationNeedsQualityCheck(SecurityUtils.getUser(),
diff --git a/web/src/main/java/com/gitplex/server/web/page/test/TestPage.java b/web/src/main/java/com/gitplex/server/web/page/test/TestPage.java
index 54b39e86e3..6fff5c58c8 100644
--- a/web/src/main/java/com/gitplex/server/web/page/test/TestPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/test/TestPage.java
@@ -14,7 +14,8 @@ public class TestPage extends BasePage {
add(new Link<Void>("test") {
@Override
- public void onClick() {
+ public void onClick() {
+
}
});