MCPcopy Create free account
hub / github.com/git/git / add_tree_entries

Function add_tree_entries

path-walk.c:132–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130}
131
132static int add_tree_entries(struct path_walk_context *ctx,
133 const char *base_path,
134 struct object_id *oid)
135{
136 struct tree_desc desc;
137 struct name_entry entry;
138 struct strbuf path = STRBUF_INIT;
139 size_t base_len;
140 struct tree *tree = lookup_tree(ctx->repo, oid);
141
142 if (!tree) {
143 error(_("failed to walk children of tree %s: not found"),
144 oid_to_hex(oid));
145 return -1;
146 } else if (repo_parse_tree_gently(ctx->repo, tree, 1)) {
147 error("bad tree object %s", oid_to_hex(oid));
148 return -1;
149 }
150
151 strbuf_addstr(&path, base_path);
152 base_len = path.len;
153
154 init_tree_desc(&desc, &tree->object.oid, tree->buffer, tree->size);
155 while (tree_entry(&desc, &entry)) {
156 struct object *o;
157 /* Not actually true, but we will ignore submodules later. */
158 enum object_type type = S_ISDIR(entry.mode) ? OBJ_TREE : OBJ_BLOB;
159
160 /* Skip submodules. */
161 if (S_ISGITLINK(entry.mode))
162 continue;
163
164 /* If the caller doesn't want blobs, then don't bother. */
165 if (!ctx->info->blobs && type == OBJ_BLOB)
166 continue;
167
168 if (type == OBJ_TREE) {
169 struct tree *child = lookup_tree(ctx->repo, &entry.oid);
170 o = child ? &child->object : NULL;
171 } else if (type == OBJ_BLOB) {
172 struct blob *child = lookup_blob(ctx->repo, &entry.oid);
173 o = child ? &child->object : NULL;
174 } else {
175 BUG("invalid type for tree entry: %d", type);
176 }
177
178 if (!o) {
179 error(_("failed to find object %s"),
180 oid_to_hex(&entry.oid));
181 return -1;
182 }
183
184 strbuf_setlen(&path, base_len);
185 strbuf_add(&path, entry.path, entry.pathlen);
186
187 /*
188 * Trees will end with "/" for concatenation and distinction
189 * from blobs at the same path.

Callers 1

walk_pathFunction · 0.85

Calls 15

lookup_treeFunction · 0.85
errorFunction · 0.85
oid_to_hexFunction · 0.85
repo_parse_tree_gentlyFunction · 0.85
strbuf_addstrFunction · 0.85
init_tree_descFunction · 0.85
lookup_blobFunction · 0.85
strbuf_setlenFunction · 0.85
strbuf_addFunction · 0.85
strbuf_addchFunction · 0.85
strmap_containsFunction · 0.85

Tested by

no test coverage detected