| 1402 | } |
| 1403 | |
| 1404 | int index_path(struct index_state *istate, struct object_id *oid, |
| 1405 | const char *path, struct stat *st, unsigned flags) |
| 1406 | { |
| 1407 | int fd; |
| 1408 | struct strbuf sb = STRBUF_INIT; |
| 1409 | int rc = 0; |
| 1410 | |
| 1411 | switch (st->st_mode & S_IFMT) { |
| 1412 | case S_IFREG: |
| 1413 | fd = open(path, O_RDONLY); |
| 1414 | if (fd < 0) |
| 1415 | return error_errno("open(\"%s\")", path); |
| 1416 | if (index_fd(istate, oid, fd, st, OBJ_BLOB, path, flags) < 0) |
| 1417 | return error(_("%s: failed to insert into database"), |
| 1418 | path); |
| 1419 | break; |
| 1420 | case S_IFLNK: |
| 1421 | if (strbuf_readlink(&sb, path, st->st_size)) |
| 1422 | return error_errno("readlink(\"%s\")", path); |
| 1423 | if (!(flags & INDEX_WRITE_OBJECT)) |
| 1424 | hash_object_file(istate->repo->hash_algo, sb.buf, sb.len, |
| 1425 | OBJ_BLOB, oid); |
| 1426 | else if (odb_write_object(istate->repo->objects, sb.buf, sb.len, OBJ_BLOB, oid)) |
| 1427 | rc = error(_("%s: failed to insert into database"), path); |
| 1428 | strbuf_release(&sb); |
| 1429 | break; |
| 1430 | case S_IFDIR: |
| 1431 | if (repo_resolve_gitlink_ref(istate->repo, path, "HEAD", oid)) |
| 1432 | return error(_("'%s' does not have a commit checked out"), path); |
| 1433 | if (&hash_algos[oid->algo] != istate->repo->hash_algo) |
| 1434 | return error(_("cannot add a submodule of a different hash algorithm")); |
| 1435 | break; |
| 1436 | default: |
| 1437 | return error(_("%s: unsupported file type"), path); |
| 1438 | } |
| 1439 | return rc; |
| 1440 | } |
| 1441 | |
| 1442 | int read_pack_header(int fd, struct pack_header *header) |
| 1443 | { |
no test coverage detected