Skip to content

Commit 09e6564

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e146cc9 commit 09e6564

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

refs/files-backend.c

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,33 @@ static void files_ref_path(struct files_ref_store *refs,
213213
}
214214
}
215215

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+
216243
/*
217244
* Read the loose references from the namespace dirname into dir
218245
* (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,
296323
strbuf_release(&path);
297324
closedir(d);
298325

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);
321327
}
322328

323329
static struct ref_cache *get_loose_ref_cache(struct files_ref_store *refs)

0 commit comments

Comments
 (0)