MCPcopy Create free account
hub / github.com/NixOS/nix / parseTree

Function parseTree

src/libutil/git.cc:113–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113void parseTree(
114 FileSystemObjectSink & sink,
115 const CanonPath & sinkPath,
116 Source & source,
117 HashAlgorithm hashAlgo,
118 fun<SinkHook> hook,
119 const ExperimentalFeatureSettings & xpSettings)
120{
121 const unsigned long long size = std::stoi(getStringUntil(source, 0));
122 unsigned long long left = size;
123
124 sink.createDirectory(sinkPath);
125
126 while (left) {
127 std::string perms = getStringUntil(source, ' ');
128 left -= perms.size();
129 left -= 1;
130
131 RawMode rawMode = std::stoi(perms, 0, 8);
132 auto modeOpt = decodeMode(rawMode);
133 if (!modeOpt)
134 throw Error("Unknown Git permission: %o", rawMode);
135 auto mode = std::move(*modeOpt);
136
137 std::string name = getStringUntil(source, '\0');
138 left -= name.size();
139 left -= 1;
140
141 const auto hashSize = regularHashSize(hashAlgo);
142 std::string hashs = getString(source, hashSize);
143 left -= hashSize;
144
145 if (!(hashAlgo == HashAlgorithm::SHA1 || hashAlgo == HashAlgorithm::SHA256)) {
146 throw Error("Unsupported hash algorithm for git trees: %s", printHashAlgo(hashAlgo));
147 }
148
149 Hash hash(hashAlgo);
150 std::copy(hashs.begin(), hashs.end(), hash.hash);
151
152 hook(
153 CanonPath{name},
154 TreeEntry{
155 .mode = mode,
156 .hash = hash,
157 });
158 }
159}
160
161ObjectType parseObjectType(Source & source, const ExperimentalFeatureSettings & xpSettings)
162{

Callers 2

parseFunction · 0.85
mkTreeReadTestFunction · 0.85

Calls 10

getStringUntilFunction · 0.85
decodeModeFunction · 0.85
ErrorEnum · 0.85
regularHashSizeFunction · 0.85
getStringFunction · 0.85
printHashAlgoFunction · 0.85
createDirectoryMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected