files-backend.c: factor out per-worktree code in loose_fill_ref_dir()
This is the first step for further cleaning up and extending this function. 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 7, 2019 at 19:29 UTC
09e65645e3b092e4d93bb8513b14474c68df23d8
1 file changed
+28
-22
refs/files-backend.c
+28
-22
@@ -213,6 +213,33 @@ static void files_ref_path(struct files_ref_store *refs,
213
}
214
}
215
216
+/*
217
+ * Manually add refs/bisect and refs/worktree, which, being
218
+ * per-worktree, might not appear in the directory listing for
219
+ * refs/ in the main repo.
220
+ */
221
+static void add_per_worktree_entries_to_dir(struct ref_dir *dir, const char *dirname)
222
+{
223
+ int pos;
224
+
225
+ if (strcmp(dirname, "refs/"))
226
+ return;
227
+
228
+ pos = search_ref_dir(dir, "refs/bisect/", 12);
229
+ if (pos < 0) {
230
+ struct ref_entry *child_entry =
231
+ create_dir_entry(dir->cache, "refs/bisect/", 12, 1);
232
+ add_entry_to_dir(dir, child_entry);
233
+ }
234
+
235
+ pos = search_ref_dir(dir, "refs/worktree/", 11);
236
+ if (pos < 0) {
237
+ struct ref_entry *child_entry =
238
+ create_dir_entry(dir->cache, "refs/worktree/", 11, 1);
239
+ add_entry_to_dir(dir, child_entry);
240
+ }
241
+}
242
+
243
/*
244
* Read the loose references from the namespace dirname into dir
245
* (without recursing). dirname must end with '/'. dir must be the
@@ -296,28 +323,7 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
323
strbuf_release(&path);
324
closedir(d);
325
299
- /*
300
- * Manually add refs/bisect and refs/worktree, which, being
301
- * per-worktree, might not appear in the directory listing for
302
- * refs/ in the main repo.
303
- */
304
- if (!strcmp(dirname, "refs/")) {
305
- int pos = search_ref_dir(dir, "refs/bisect/", 12);
306
-
307
- if (pos < 0) {
308
- struct ref_entry *child_entry = create_dir_entry(
309
- dir->cache, "refs/bisect/", 12, 1);
310
- add_entry_to_dir(dir, child_entry);
311
- }
312
-
313
- pos = search_ref_dir(dir, "refs/worktree/", 11);
314
-
315
- if (pos < 0) {
316
- struct ref_entry *child_entry = create_dir_entry(
317
- dir->cache, "refs/worktree/", 11, 1);
318
- add_entry_to_dir(dir, child_entry);
319
- }
320
- }
326
+ add_per_worktree_entries_to_dir(dir, dirname);
327
}
328
329
static struct ref_cache *get_loose_ref_cache(struct files_ref_store *refs)