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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Mar 26, 2017 at 09:42 UTC
f57f37e2e1bf11ab4cdfd221ad47e961ba9353a0
1 file changed
+38
-5
refs/files-backend.c
+38
-5
@@ -923,7 +923,8 @@ struct files_ref_store {
923
* store:
924
*/
925
const char *submodule;
926
-
926
+ char *gitdir;
927
+ char *gitcommondir;
928
char *packed_refs_path;
929
930
struct ref_entry *loose;
@@ -985,6 +986,8 @@ static struct ref_store *files_ref_store_create(const char *submodule)
986
{
987
struct files_ref_store *refs = xcalloc(1, sizeof(*refs));
988
struct ref_store *ref_store = (struct ref_store *)refs;
989
+ struct strbuf sb = STRBUF_INIT;
990
+ const char *gitdir = get_git_dir();
991
992
base_ref_store_init(ref_store, &refs_be_files);
993
@@ -995,7 +998,11 @@ static struct ref_store *files_ref_store_create(const char *submodule)
998
return ref_store;
999
}
1000
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);
1006
1007
return ref_store;
1008
}
@@ -1173,11 +1180,26 @@ static void files_reflog_path(struct files_ref_store *refs,
1180
const char *refname)
1181
{
1182
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);
1188
return;
1189
}
1190
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
+ }
1203
}
1204
1205
static void files_ref_path(struct files_ref_store *refs,
@@ -1189,7 +1211,18 @@ static void files_ref_path(struct files_ref_store *refs,
1211
return;
1212
}
1213
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
+ }
1226
}
1227
1228
/*