39
struct object_id peeled;
40
};
41
42
-struct ref_cache;
42
+struct files_ref_store;
43
44
/*
45
* Information used (along with the information in ref_entry) to
78
*/
79
int sorted;
80
81
- /* A pointer to the ref_cache that contains this ref_dir. */
82
- struct ref_cache *ref_cache;
81
+ /* A pointer to the files_ref_store that contains this ref_dir. */
82
+ struct files_ref_store *ref_store;
83
84
struct ref_entry **entries;
85
};
161
162
static void read_loose_refs(const char *dirname, struct ref_dir *dir);
163
static int search_ref_dir(struct ref_dir *dir, const char *refname, size_t len);
164
-static struct ref_entry *create_dir_entry(struct ref_cache *ref_cache,
164
+static struct ref_entry *create_dir_entry(struct files_ref_store *ref_store,
165
const char *dirname, size_t len,
166
int incomplete);
167
static void add_entry_to_dir(struct ref_dir *dir, struct ref_entry *entry);
183
int pos = search_ref_dir(dir, "refs/bisect/", 12);
184
if (pos < 0) {
185
struct ref_entry *child_entry;
186
- child_entry = create_dir_entry(dir->ref_cache,
186
+ child_entry = create_dir_entry(dir->ref_store,
187
"refs/bisect/",
188
12, 1);
189
add_entry_to_dir(dir, child_entry);
261
* dirname is the name of the directory with a trailing slash (e.g.,
262
* "refs/heads/") or "" for the top-level directory.
263
*/
264
-static struct ref_entry *create_dir_entry(struct ref_cache *ref_cache,
264
+static struct ref_entry *create_dir_entry(struct files_ref_store *ref_store,
265
const char *dirname, size_t len,
266
int incomplete)
267
{
268
struct ref_entry *direntry;
269
FLEX_ALLOC_MEM(direntry, name, dirname, len);
270
- direntry->u.subdir.ref_cache = ref_cache;
270
+ direntry->u.subdir.ref_store = ref_store;
271
direntry->flag = REF_DIR | (incomplete ? REF_INCOMPLETE : 0);
272
return direntry;
273
}
343
* therefore, create an empty record for it but mark
344
* the record complete.
345
*/
346
- entry = create_dir_entry(dir->ref_cache, subdirname, len, 0);
346
+ entry = create_dir_entry(dir->ref_store, subdirname, len, 0);
347
add_entry_to_dir(dir, entry);
348
} else {
349
entry = dir->entries[entry_index];
887
888
/*
889
* Count of references to the data structure in this instance,
890
- * including the pointer from ref_cache::packed if any. The
891
- * data will not be freed as long as the reference count is
892
- * nonzero.
890
+ * including the pointer from files_ref_store::packed if any.
891
+ * The data will not be freed as long as the reference count
892
+ * is nonzero.
893
*/
894
unsigned int referrers;
895
910
* Future: need to be in "struct repository"
911
* when doing a full libification.
912
*/
913
-static struct ref_cache {
914
- struct ref_cache *next;
913
+static struct files_ref_store {
914
+ struct files_ref_store *next;
915
struct ref_entry *loose;
916
struct packed_ref_cache *packed;
917
/*
918
- * The submodule name, or "" for the main repo. We allocate
919
- * length 1 rather than FLEX_ARRAY so that the main ref_cache
920
- * is initialized correctly.
918
+ * The submodule name, or "" for the main repo. We allocate
919
+ * length 1 rather than FLEX_ARRAY so that the main
920
+ * files_ref_store is initialized correctly.
921
*/
922
char name[1];
923
-} ref_cache, *submodule_ref_caches;
923
+} ref_store, *submodule_ref_stores;
924
925
/* Lock used for the main packed-refs file: */
926
static struct lock_file packlock;
949
}
950
}
951
952
-static void clear_packed_ref_cache(struct ref_cache *refs)
952
+static void clear_packed_ref_cache(struct files_ref_store *refs)
953
{
954
if (refs->packed) {
955
struct packed_ref_cache *packed_refs = refs->packed;
961
}
962
}
963
964
-static void clear_loose_ref_cache(struct ref_cache *refs)
964
+static void clear_loose_ref_cache(struct files_ref_store *refs)
965
{
966
if (refs->loose) {
967
free_ref_entry(refs->loose);
973
* Create a new submodule ref cache and add it to the internal
974
* set of caches.
975
*/
976
-static struct ref_cache *create_ref_cache(const char *submodule)
976
+static struct files_ref_store *create_ref_store(const char *submodule)
977
{
978
- struct ref_cache *refs;
978
+ struct files_ref_store *refs;
979
if (!submodule)
980
submodule = "";
981
FLEX_ALLOC_STR(refs, name, submodule);
982
- refs->next = submodule_ref_caches;
983
- submodule_ref_caches = refs;
982
+ refs->next = submodule_ref_stores;
983
+ submodule_ref_stores = refs;
984
return refs;
985
}
986
987
-static struct ref_cache *lookup_ref_cache(const char *submodule)
987
+static struct files_ref_store *lookup_ref_store(const char *submodule)
988
{
989
- struct ref_cache *refs;
989
+ struct files_ref_store *refs;
990
991
if (!submodule || !*submodule)
992
- return &ref_cache;
992
+ return &ref_store;
993
994
- for (refs = submodule_ref_caches; refs; refs = refs->next)
994
+ for (refs = submodule_ref_stores; refs; refs = refs->next)
995
if (!strcmp(submodule, refs->name))
996
return refs;
997
return NULL;
998
}
999
1000
/*
1001
- * Return a pointer to a ref_cache for the specified submodule. For
1001
+ * Return a pointer to a files_ref_store for the specified submodule. For
1002
* the main repository, use submodule==NULL; such a call cannot fail.
1003
* For a submodule, the submodule must exist and be a nonbare
1004
* repository, otherwise return NULL.
1006
* The returned structure will be allocated and initialized but not
1007
* necessarily populated; it should not be freed.
1008
*/
1009
-static struct ref_cache *get_ref_cache(const char *submodule)
1009
+static struct files_ref_store *get_ref_store(const char *submodule)
1010
{
1011
- struct ref_cache *refs = lookup_ref_cache(submodule);
1011
+ struct files_ref_store *refs = lookup_ref_store(submodule);
1012
1013
if (!refs) {
1014
struct strbuf submodule_sb = STRBUF_INIT;
1015
1016
strbuf_addstr(&submodule_sb, submodule);
1017
if (is_nonbare_repository_dir(&submodule_sb))
1018
- refs = create_ref_cache(submodule);
1018
+ refs = create_ref_store(submodule);
1019
strbuf_release(&submodule_sb);
1020
}
1021
1151
}
1152
1153
/*
1154
- * Get the packed_ref_cache for the specified ref_cache, creating it
1155
- * if necessary.
1154
+ * Get the packed_ref_cache for the specified files_ref_store,
1155
+ * creating it if necessary.
1156
*/
1157
-static struct packed_ref_cache *get_packed_ref_cache(struct ref_cache *refs)
1157
+static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *refs)
1158
{
1159
char *packed_refs_file;
1160
1189
return get_ref_dir(packed_ref_cache->root);
1190
}
1191
1192
-static struct ref_dir *get_packed_refs(struct ref_cache *refs)
1192
+static struct ref_dir *get_packed_refs(struct files_ref_store *refs)
1193
{
1194
return get_packed_ref_dir(get_packed_ref_cache(refs));
1195
}
1203
static void add_packed_ref(const char *refname, const unsigned char *sha1)
1204
{
1205
struct packed_ref_cache *packed_ref_cache =
1206
- get_packed_ref_cache(&ref_cache);
1206
+ get_packed_ref_cache(&ref_store);
1207
1208
if (!packed_ref_cache->lock)
1209
die("internal error: packed refs not locked");
1218
*/
1219
static void read_loose_refs(const char *dirname, struct ref_dir *dir)
1220
{
1221
- struct ref_cache *refs = dir->ref_cache;
1221
+ struct files_ref_store *refs = dir->ref_store;
1222
DIR *d;
1223
struct dirent *de;
1224
int dirnamelen = strlen(dirname);
1306
closedir(d);
1307
}
1308
1309
-static struct ref_dir *get_loose_refs(struct ref_cache *refs)
1309
+static struct ref_dir *get_loose_refs(struct files_ref_store *refs)
1310
{
1311
if (!refs->loose) {
1312
/*
1328
1329
/*
1330
* Called by resolve_gitlink_ref_recursive() after it failed to read
1331
- * from the loose refs in ref_cache refs. Find <refname> in the
1332
- * packed-refs file for the submodule.
1331
+ * from the loose refs in refs. Find <refname> in the packed-refs file
1332
+ * for the submodule.
1333
*/
1334
-static int resolve_gitlink_packed_ref(struct ref_cache *refs,
1334
+static int resolve_gitlink_packed_ref(struct files_ref_store *refs,
1335
const char *refname, unsigned char *sha1)
1336
{
1337
struct ref_entry *ref;
1345
return 0;
1346
}
1347
1348
-static int resolve_gitlink_ref_recursive(struct ref_cache *refs,
1348
+static int resolve_gitlink_ref_recursive(struct files_ref_store *refs,
1349
const char *refname, unsigned char *sha1,
1350
int recursion)
1351
{
1389
{
1390
int len = strlen(path);
1391
struct strbuf submodule = STRBUF_INIT;
1392
- struct ref_cache *refs;
1392
+ struct files_ref_store *refs;
1393
1394
while (len && path[len-1] == '/')
1395
len--;
1397
return -1;
1398
1399
strbuf_add(&submodule, path, len);
1400
- refs = get_ref_cache(submodule.buf);
1400
+ refs = get_ref_store(submodule.buf);
1401
if (!refs) {
1402
strbuf_release(&submodule);
1403
return -1;
1413
*/
1414
static struct ref_entry *get_packed_ref(const char *refname)
1415
{
1416
- return find_ref(get_packed_refs(&ref_cache), refname);
1416
+ return find_ref(get_packed_refs(&ref_store), refname);
1417
}
1418
1419
/*
1745
REMOVE_DIR_EMPTY_ONLY)) {
1746
if (verify_refname_available_dir(
1747
refname, extras, skip,
1748
- get_loose_refs(&ref_cache),
1748
+ get_loose_refs(&ref_store),
1749
err)) {
1750
/*
1751
* The error message set by
1784
*/
1785
if (verify_refname_available_dir(
1786
refname, extras, skip,
1787
- get_packed_refs(&ref_cache),
1787
+ get_packed_refs(&ref_store),
1788
err)) {
1789
goto error_return;
1790
}
1942
const char *submodule,
1943
const char *prefix, unsigned int flags)
1944
{
1945
- struct ref_cache *refs = get_ref_cache(submodule);
1945
+ struct files_ref_store *refs = get_ref_store(submodule);
1946
struct ref_dir *loose_dir, *packed_dir;
1947
struct ref_iterator *loose_iter, *packed_iter;
1948
struct files_ref_iterator *iter;
2096
if (remove_empty_directories(&ref_file)) {
2097
last_errno = errno;
2098
if (!verify_refname_available_dir(refname, extras, skip,
2099
- get_loose_refs(&ref_cache), err))
2099
+ get_loose_refs(&ref_store), err))
2100
strbuf_addf(err, "there are still refs under '%s'",
2101
refname);
2102
goto error_return;
2108
last_errno = errno;
2109
if (last_errno != ENOTDIR ||
2110
!verify_refname_available_dir(refname, extras, skip,
2111
- get_loose_refs(&ref_cache), err))
2111
+ get_loose_refs(&ref_store), err))
2112
strbuf_addf(err, "unable to resolve reference '%s': %s",
2113
refname, strerror(last_errno));
2114
2123
*/
2124
if (is_null_oid(&lock->old_oid) &&
2125
verify_refname_available_dir(refname, extras, skip,
2126
- get_packed_refs(&ref_cache), err)) {
2126
+ get_packed_refs(&ref_store), err)) {
2127
last_errno = ENOTDIR;
2128
goto error_return;
2129
}
2232
* this will automatically invalidate the cache and re-read
2233
* the packed-refs file.
2234
*/
2235
- packed_ref_cache = get_packed_ref_cache(&ref_cache);
2235
+ packed_ref_cache = get_packed_ref_cache(&ref_store);
2236
packed_ref_cache->lock = &packlock;
2237
/* Increment the reference count to prevent it from being freed: */
2238
acquire_packed_ref_cache(packed_ref_cache);
2248
static int commit_packed_refs(void)
2249
{
2250
struct packed_ref_cache *packed_ref_cache =
2251
- get_packed_ref_cache(&ref_cache);
2251
+ get_packed_ref_cache(&ref_store);
2252
int error = 0;
2253
int save_errno = 0;
2254
FILE *out;
2282
static void rollback_packed_refs(void)
2283
{
2284
struct packed_ref_cache *packed_ref_cache =
2285
- get_packed_ref_cache(&ref_cache);
2285
+ get_packed_ref_cache(&ref_store);
2286
2287
if (!packed_ref_cache->lock)
2288
die("internal error: packed-refs not locked");
2289
rollback_lock_file(packed_ref_cache->lock);
2290
packed_ref_cache->lock = NULL;
2291
release_packed_ref_cache(packed_ref_cache);
2292
- clear_packed_ref_cache(&ref_cache);
2292
+ clear_packed_ref_cache(&ref_store);
2293
}
2294
2295
struct ref_to_prune {
2428
cbdata.flags = flags;
2429
2430
lock_packed_refs(LOCK_DIE_ON_ERROR);
2431
- cbdata.packed_refs = get_packed_refs(&ref_cache);
2431
+ cbdata.packed_refs = get_packed_refs(&ref_store);
2432
2433
- do_for_each_entry_in_dir(get_loose_refs(&ref_cache), 0,
2433
+ do_for_each_entry_in_dir(get_loose_refs(&ref_store), 0,
2434
pack_if_possible_fn, &cbdata);
2435
2436
if (commit_packed_refs())
2471
unable_to_lock_message(git_path("packed-refs"), errno, err);
2472
return -1;
2473
}
2474
- packed = get_packed_refs(&ref_cache);
2474
+ packed = get_packed_refs(&ref_store);
2475
2476
/* Remove refnames from the cache */
2477
for_each_string_list_item(refname, refnames)
2616
const struct string_list *skip,
2617
struct strbuf *err)
2618
{
2619
- struct ref_dir *packed_refs = get_packed_refs(&ref_cache);
2620
- struct ref_dir *loose_refs = get_loose_refs(&ref_cache);
2619
+ struct ref_dir *packed_refs = get_packed_refs(&ref_store);
2620
+ struct ref_dir *loose_refs = get_loose_refs(&ref_store);
2621
2622
if (verify_refname_available_dir(newname, extras, skip,
2623
packed_refs, err) ||
2968
const unsigned char *sha1, const char *logmsg,
2969
struct strbuf *err)
2970
{
2971
- clear_loose_ref_cache(&ref_cache);
2971
+ clear_loose_ref_cache(&ref_store);
2972
if (log_ref_write(lock->ref_name, lock->old_oid.hash, sha1, logmsg, 0, err)) {
2973
char *old_msg = strbuf_detach(err, NULL);
2974
strbuf_addf(err, "cannot update the ref '%s': %s",
3790
}
3791
}
3792
if (update->flags & REF_NEEDS_COMMIT) {
3793
- clear_loose_ref_cache(&ref_cache);
3793
+ clear_loose_ref_cache(&ref_store);
3794
if (commit_ref(lock)) {
3795
strbuf_addf(err, "couldn't set '%s'", lock->ref_name);
3796
unlock_ref(lock);
3823
}
3824
for_each_string_list_item(ref_to_delete, &refs_to_delete)
3825
unlink_or_warn(git_path("logs/%s", ref_to_delete->string));
3826
- clear_loose_ref_cache(&ref_cache);
3826
+ clear_loose_ref_cache(&ref_store);
3827
3828
cleanup:
3829
transaction->state = REF_TRANSACTION_CLOSED;