Skip to content

Commit f57f37e

Browse files
pcloudsgitster
authored andcommitted
files-backend: remove the use of git_path()
Given $GIT_DIR and $GIT_COMMON_DIR, files-backend is now in charge of deciding what goes where (*). The end goal is to pass $GIT_DIR only. A refs "view" of a linked worktree is a logical ref store that combines two files backends together. (*) Not entirely true since strbuf_git_path_submodule() still does path translation underneath. But that's for another patch. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 19e02f4 commit f57f37e

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

refs/files-backend.c

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,8 @@ struct files_ref_store {
923923
* store:
924924
*/
925925
const char *submodule;
926-
926+
char *gitdir;
927+
char *gitcommondir;
927928
char *packed_refs_path;
928929

929930
struct ref_entry *loose;
@@ -985,6 +986,8 @@ static struct ref_store *files_ref_store_create(const char *submodule)
985986
{
986987
struct files_ref_store *refs = xcalloc(1, sizeof(*refs));
987988
struct ref_store *ref_store = (struct ref_store *)refs;
989+
struct strbuf sb = STRBUF_INIT;
990+
const char *gitdir = get_git_dir();
988991

989992
base_ref_store_init(ref_store, &refs_be_files);
990993

@@ -995,7 +998,11 @@ static struct ref_store *files_ref_store_create(const char *submodule)
995998
return ref_store;
996999
}
9971000

998-
refs->packed_refs_path = git_pathdup("packed-refs");
1001+
refs->gitdir = xstrdup(gitdir);
1002+
get_common_dir_noenv(&sb, gitdir);
1003+
refs->gitcommondir = strbuf_detach(&sb, NULL);
1004+
strbuf_addf(&sb, "%s/packed-refs", refs->gitcommondir);
1005+
refs->packed_refs_path = strbuf_detach(&sb, NULL);
9991006

10001007
return ref_store;
10011008
}
@@ -1173,11 +1180,26 @@ static void files_reflog_path(struct files_ref_store *refs,
11731180
const char *refname)
11741181
{
11751182
if (!refname) {
1176-
strbuf_git_path(sb, "logs");
1183+
/*
1184+
* FIXME: of course this is wrong in multi worktree
1185+
* setting. To be fixed real soon.
1186+
*/
1187+
strbuf_addf(sb, "%s/logs", refs->gitcommondir);
11771188
return;
11781189
}
11791190

1180-
strbuf_git_path(sb, "logs/%s", refname);
1191+
switch (ref_type(refname)) {
1192+
case REF_TYPE_PER_WORKTREE:
1193+
case REF_TYPE_PSEUDOREF:
1194+
strbuf_addf(sb, "%s/logs/%s", refs->gitdir, refname);
1195+
break;
1196+
case REF_TYPE_NORMAL:
1197+
strbuf_addf(sb, "%s/logs/%s", refs->gitcommondir, refname);
1198+
break;
1199+
default:
1200+
die("BUG: unknown ref type %d of ref %s",
1201+
ref_type(refname), refname);
1202+
}
11811203
}
11821204

11831205
static void files_ref_path(struct files_ref_store *refs,
@@ -1189,7 +1211,18 @@ static void files_ref_path(struct files_ref_store *refs,
11891211
return;
11901212
}
11911213

1192-
strbuf_git_path(sb, "%s", refname);
1214+
switch (ref_type(refname)) {
1215+
case REF_TYPE_PER_WORKTREE:
1216+
case REF_TYPE_PSEUDOREF:
1217+
strbuf_addf(sb, "%s/%s", refs->gitdir, refname);
1218+
break;
1219+
case REF_TYPE_NORMAL:
1220+
strbuf_addf(sb, "%s/%s", refs->gitcommondir, refname);
1221+
break;
1222+
default:
1223+
die("BUG: unknown ref type %d of ref %s",
1224+
ref_type(refname), refname);
1225+
}
11931226
}
11941227

11951228
/*

0 commit comments

Comments
 (0)