MCPcopy Create free account
hub / github.com/ReZeroS/git / writeTreeRecursive

Method writeTreeRecursive

src/main/java/club/qqtim/command/WriteTree.java:83–103  ·  view source on GitHub ↗

this is an easy dfs for writing objects and trees

(Map<String, Object> treeDict)

Source from the content-addressed store, hash-verified

81 * this is an easy dfs for writing objects and trees
82 */
83 private String writeTreeRecursive(Map<String, Object> treeDict) {
84 List<ZitObject> zitObjects = new ArrayList<>();
85 for (Map.Entry<String, Object> keyVal : treeDict.entrySet()) {
86 String type, objectId;
87 String name = keyVal.getKey();
88 Object value = keyVal.getValue();
89 if (value instanceof Map) {
90 type = ConstantVal.TREE;
91 // get tree id
92 objectId = writeTreeRecursive((Map<String, Object>) value);
93 } else {
94 type = ConstantVal.BLOB;
95 objectId = (String) value;
96 }
97 zitObjects.add(new ZitObject(type, objectId, name));
98 }
99 String fileContent = zitObjects.stream().sorted()
100 .map(e -> String.format("%s %s %s\n", e.getType(), e.getObjectId(), e.getName()))
101 .collect(Collectors.joining());
102 return HashObject.hashObject(fileContent.getBytes(Charsets.UTF_8), ConstantVal.TREE);
103 }
104
105
106}

Callers 1

writeTreeMethod · 0.95

Calls 1

hashObjectMethod · 0.95

Tested by

no test coverage detected