315
add_per_worktree_entries_to_dir(dir, dirname);
316
}
317
318
-static struct ref_cache *get_loose_ref_cache(struct files_ref_store *refs)
318
+/*
319
+ * Add pseudorefs to the ref dir by parsing the directory for any files
320
+ * which follow the pseudoref syntax.
321
+ */
322
+static void add_pseudoref_and_head_entries(struct ref_store *ref_store,
323
+ struct ref_dir *dir,
324
+ const char *dirname)
325
+{
326
+ struct files_ref_store *refs =
327
+ files_downcast(ref_store, REF_STORE_READ, "fill_ref_dir");
328
+ struct strbuf path = STRBUF_INIT, refname = STRBUF_INIT;
329
+ struct dirent *de;
330
+ size_t dirnamelen;
331
+ DIR *d;
332
+
333
+ files_ref_path(refs, &path, dirname);
334
+
335
+ d = opendir(path.buf);
336
+ if (!d) {
337
+ strbuf_release(&path);
338
+ return;
339
+ }
340
+
341
+ strbuf_addstr(&refname, dirname);
342
+ dirnamelen = refname.len;
343
+
344
+ while ((de = readdir(d)) != NULL) {
345
+ unsigned char dtype;
346
+
347
+ if (de->d_name[0] == '.')
348
+ continue;
349
+ if (ends_with(de->d_name, ".lock"))
350
+ continue;
351
+ strbuf_addstr(&refname, de->d_name);
352
+
353
+ dtype = get_dtype(de, &path, 1);
354
+ if (dtype == DT_REG && (is_pseudoref(ref_store, de->d_name) ||
355
+ is_headref(ref_store, de->d_name)))
356
+ loose_fill_ref_dir_regular_file(refs, refname.buf, dir);
357
+
358
+ strbuf_setlen(&refname, dirnamelen);
359
+ }
360
+ strbuf_release(&refname);
361
+ strbuf_release(&path);
362
+ closedir(d);
363
+}
364
+
365
+static struct ref_cache *get_loose_ref_cache(struct files_ref_store *refs,
366
+ unsigned int flags)
367
{
368
if (!refs->loose) {
369
+ struct ref_dir *dir;
370
+
371
/*
372
* Mark the top-level directory complete because we
373
* are about to read the only subdirectory that can
378
/* We're going to fill the top level ourselves: */
379
refs->loose->root->flag &= ~REF_INCOMPLETE;
380
381
+ dir = get_ref_dir(refs->loose->root);
382
+
383
+ if (flags & DO_FOR_EACH_INCLUDE_ROOT_REFS)
384
+ add_pseudoref_and_head_entries(dir->cache->ref_store, dir,
385
+ refs->loose->root->name);
386
+
387
/*
388
* Add an incomplete entry for "refs/" (to be filled
389
* lazily):
390
*/
335
- add_entry_to_dir(get_ref_dir(refs->loose->root),
336
- create_dir_entry(refs->loose, "refs/", 5));
391
+ add_entry_to_dir(dir, create_dir_entry(refs->loose, "refs/", 5));
392
}
393
return refs->loose;
394
}
916
* disk, and re-reads it if not.
917
*/
918
864
- loose_iter = cache_ref_iterator_begin(get_loose_ref_cache(refs),
919
+ loose_iter = cache_ref_iterator_begin(get_loose_ref_cache(refs, flags),
920
prefix, ref_store->repo, 1);
921
922
/*
1277
1278
packed_refs_lock(refs->packed_ref_store, LOCK_DIE_ON_ERROR, &err);
1279
1225
- iter = cache_ref_iterator_begin(get_loose_ref_cache(refs), NULL,
1280
+ iter = cache_ref_iterator_begin(get_loose_ref_cache(refs, 0), NULL,
1281
the_repository, 0);
1282
while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
1283
/*