|
5 | 5 | #define USE_THE_REPOSITORY_VARIABLE |
6 | 6 |
|
7 | 7 | #include "git-compat-util.h" |
| 8 | +#include "abspath.h" |
8 | 9 | #include "advice.h" |
9 | 10 | #include "config.h" |
10 | 11 | #include "environment.h" |
@@ -2225,7 +2226,11 @@ static struct ref_store *ref_store_init(struct repository *repo, |
2225 | 2226 | if (!be) |
2226 | 2227 | BUG("reference backend is unknown"); |
2227 | 2228 |
|
2228 | | - refs = be->init(repo, gitdir, flags); |
| 2229 | + /* |
| 2230 | + * TODO Send in a 'struct worktree' instead of a 'gitdir', and |
| 2231 | + * allow the backend to handle how it wants to deal with worktrees. |
| 2232 | + */ |
| 2233 | + refs = be->init(repo, repo->ref_storage_payload, gitdir, flags); |
2229 | 2234 | return refs; |
2230 | 2235 | } |
2231 | 2236 |
|
@@ -3412,3 +3417,57 @@ const char *ref_transaction_error_msg(enum ref_transaction_error err) |
3412 | 3417 | return "unknown failure"; |
3413 | 3418 | } |
3414 | 3419 | } |
| 3420 | + |
| 3421 | +void refs_create_refdir_stubs(struct repository *repo, const char *refdir, |
| 3422 | + const char *refs_heads_msg) |
| 3423 | +{ |
| 3424 | + struct strbuf path = STRBUF_INIT; |
| 3425 | + |
| 3426 | + |
| 3427 | + strbuf_addf(&path, "%s/HEAD", refdir); |
| 3428 | + write_file(path.buf, "ref: refs/heads/.invalid"); |
| 3429 | + adjust_shared_perm(repo, path.buf); |
| 3430 | + |
| 3431 | + strbuf_reset(&path); |
| 3432 | + strbuf_addf(&path, "%s/refs", refdir); |
| 3433 | + safe_create_dir(repo, path.buf, 1); |
| 3434 | + |
| 3435 | + if (refs_heads_msg) { |
| 3436 | + strbuf_reset(&path); |
| 3437 | + strbuf_addf(&path, "%s/refs/heads", refdir); |
| 3438 | + write_file(path.buf, "%s", refs_heads_msg); |
| 3439 | + adjust_shared_perm(repo, path.buf); |
| 3440 | + } |
| 3441 | + |
| 3442 | + strbuf_release(&path); |
| 3443 | +} |
| 3444 | + |
| 3445 | +void refs_compute_filesystem_location(const char *gitdir, const char *payload, |
| 3446 | + bool *is_worktree, struct strbuf *refdir, |
| 3447 | + struct strbuf *ref_common_dir) |
| 3448 | +{ |
| 3449 | + struct strbuf sb = STRBUF_INIT; |
| 3450 | + |
| 3451 | + strbuf_addstr(refdir, gitdir); |
| 3452 | + *is_worktree = get_common_dir_noenv(ref_common_dir, gitdir); |
| 3453 | + |
| 3454 | + if (!payload) |
| 3455 | + return; |
| 3456 | + |
| 3457 | + if (!is_absolute_path(payload)) { |
| 3458 | + strbuf_addf(&sb, "%s/%s", ref_common_dir->buf, payload); |
| 3459 | + strbuf_realpath(ref_common_dir, sb.buf, 1); |
| 3460 | + } else { |
| 3461 | + strbuf_realpath(ref_common_dir, payload, 1); |
| 3462 | + } |
| 3463 | + |
| 3464 | + strbuf_reset(refdir); |
| 3465 | + strbuf_addbuf(refdir, ref_common_dir); |
| 3466 | + |
| 3467 | + if (*is_worktree) { |
| 3468 | + char *wt_id = strrchr(gitdir, '/') + 1; |
| 3469 | + strbuf_addf(refdir, "/worktrees/%s", wt_id); |
| 3470 | + } |
| 3471 | + |
| 3472 | + strbuf_release(&sb); |
| 3473 | +} |
0 commit comments