| 15 | #include "read-cache-ll.h" |
| 16 | |
| 17 | static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned long size, struct strbuf *err) |
| 18 | { |
| 19 | const char *path; |
| 20 | unsigned int len; |
| 21 | uint16_t mode; |
| 22 | const unsigned hashsz = desc->algo->rawsz; |
| 23 | |
| 24 | if (size < hashsz + 3 || buf[size - (hashsz + 1)]) { |
| 25 | strbuf_addstr(err, _("too-short tree object")); |
| 26 | return -1; |
| 27 | } |
| 28 | |
| 29 | path = parse_mode(buf, &mode); |
| 30 | if (!path) { |
| 31 | strbuf_addstr(err, _("malformed mode in tree entry")); |
| 32 | return -1; |
| 33 | } |
| 34 | if (!*path) { |
| 35 | strbuf_addstr(err, _("empty filename in tree entry")); |
| 36 | return -1; |
| 37 | } |
| 38 | len = strlen(path) + 1; |
| 39 | |
| 40 | /* Initialize the descriptor entry */ |
| 41 | desc->entry.path = path; |
| 42 | desc->entry.mode = (desc->flags & TREE_DESC_RAW_MODES) ? mode : canon_mode(mode); |
| 43 | desc->entry.pathlen = len - 1; |
| 44 | oidread(&desc->entry.oid, (const unsigned char *)path + len, |
| 45 | desc->algo); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static int init_tree_desc_internal(struct tree_desc *desc, |
| 51 | const struct object_id *oid, |
no test coverage detected