| 130 | } |
| 131 | |
| 132 | static 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. |
no test coverage detected