| 3552 | } |
| 3553 | |
| 3554 | void refs_compute_filesystem_location(const char *gitdir, const char *payload, |
| 3555 | bool *is_worktree, struct strbuf *refdir, |
| 3556 | struct strbuf *ref_common_dir) |
| 3557 | { |
| 3558 | struct strbuf sb = STRBUF_INIT; |
| 3559 | |
| 3560 | *is_worktree = get_common_dir_noenv(ref_common_dir, gitdir); |
| 3561 | |
| 3562 | if (!payload) { |
| 3563 | /* |
| 3564 | * We can use the 'gitdir' as the 'refdir' without appending the |
| 3565 | * worktree path, as the 'gitdir' here is already the worktree |
| 3566 | * path and is different from 'commondir' denoted by 'ref_common_dir'. |
| 3567 | */ |
| 3568 | strbuf_addstr(refdir, gitdir); |
| 3569 | return; |
| 3570 | } |
| 3571 | |
| 3572 | if (!is_absolute_path(payload)) { |
| 3573 | strbuf_addf(&sb, "%s/%s", ref_common_dir->buf, payload); |
| 3574 | strbuf_realpath(ref_common_dir, sb.buf, 1); |
| 3575 | } else { |
| 3576 | strbuf_realpath(ref_common_dir, payload, 1); |
| 3577 | } |
| 3578 | |
| 3579 | strbuf_addbuf(refdir, ref_common_dir); |
| 3580 | |
| 3581 | if (*is_worktree) { |
| 3582 | const char *wt_id = strrchr(gitdir, '/'); |
| 3583 | if (!wt_id) |
| 3584 | BUG("worktree path does not contain slash"); |
| 3585 | strbuf_addf(refdir, "/worktrees/%s", wt_id + 1); |
| 3586 | } |
| 3587 | |
| 3588 | strbuf_release(&sb); |
| 3589 | } |
no test coverage detected