refs: change signatures of get_packed_refs() and get_loose_refs()
Change get_packed_refs() and get_loose_refs() to take a (struct ref_cache *) instead of the name of the submodule. Change get_ref_dir() to take a submodule name (i.e., "" for the main module) rather than a submodule pointer (i.e., NULL for the main module) so that refs->name can be used as its argument. (In a moment this function will also be changed to take a (struct ref_cache *), too.) Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Dec 12, 2011 at 06:38 UTC
316b097ac138c3c5232ce9bbaede83d68fb686ea
1 file changed
+17
-19
refs.c
+17
-19
@@ -278,16 +278,14 @@ void clear_extra_refs(void)
278
clear_ref_array(&extra_refs);
279
}
280
281
-static struct ref_array *get_packed_refs(const char *submodule)
281
+static struct ref_array *get_packed_refs(struct ref_cache *refs)
282
{
283
- struct ref_cache *refs = get_ref_cache(submodule);
284
-
283
if (!refs->did_packed) {
284
const char *packed_refs_file;
285
FILE *f;
286
289
- if (submodule)
290
- packed_refs_file = git_path_submodule(submodule, "packed-refs");
287
+ if (*refs->name)
288
+ packed_refs_file = git_path_submodule(refs->name, "packed-refs");
289
else
290
packed_refs_file = git_path("packed-refs");
291
f = fopen(packed_refs_file, "r");
@@ -306,7 +304,7 @@ static void get_ref_dir(const char *submodule, const char *base,
304
DIR *dir;
305
const char *path;
306
309
- if (submodule)
307
+ if (*submodule)
308
path = git_path_submodule(submodule, "%s", base);
309
else
310
path = git_path("%s", base);
@@ -399,12 +397,10 @@ void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)
397
for_each_rawref(warn_if_dangling_symref, &data);
398
}
399
402
-static struct ref_array *get_loose_refs(const char *submodule)
400
+static struct ref_array *get_loose_refs(struct ref_cache *refs)
401
{
404
- struct ref_cache *refs = get_ref_cache(submodule);
405
-
402
if (!refs->did_loose) {
407
- get_ref_dir(submodule, "refs", &refs->loose);
403
+ get_ref_dir(refs->name, "refs", &refs->loose);
404
sort_ref_array(&refs->loose);
405
refs->did_loose = 1;
406
}
@@ -431,7 +427,7 @@ static int resolve_gitlink_packed_ref(char *name, int pathlen,
427
if (pathlen < 6 || memcmp(name + pathlen - 6, "/.git/", 6))
428
die("Oops");
429
name[pathlen - 6] = '\0'; /* make it path to the submodule */
434
- array = get_packed_refs(name);
430
+ array = get_packed_refs(get_ref_cache(name));
431
ref = search_ref_array(array, refname);
432
if (ref != NULL) {
433
memcpy(sha1, ref->sha1, 20);
@@ -511,7 +507,7 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sh
507
*/
508
static int get_packed_ref(const char *refname, unsigned char *sha1)
509
{
514
- struct ref_array *packed = get_packed_refs(NULL);
510
+ struct ref_array *packed = get_packed_refs(get_ref_cache(NULL));
511
struct ref_entry *entry = search_ref_array(packed, refname);
512
if (entry) {
513
hashcpy(sha1, entry->sha1);
@@ -695,7 +691,7 @@ int peel_ref(const char *refname, unsigned char *sha1)
691
return -1;
692
693
if ((flag & REF_ISPACKED)) {
698
- struct ref_array *array = get_packed_refs(NULL);
694
+ struct ref_array *array = get_packed_refs(get_ref_cache(NULL));
695
struct ref_entry *r = search_ref_array(array, refname);
696
697
if (r != NULL && r->flag & REF_KNOWS_PEELED) {
@@ -720,8 +716,9 @@ static int do_for_each_ref(const char *submodule, const char *base, each_ref_fn
716
int trim, int flags, void *cb_data)
717
{
718
int retval = 0, i, p = 0, l = 0;
723
- struct ref_array *packed = get_packed_refs(submodule);
724
- struct ref_array *loose = get_loose_refs(submodule);
719
+ struct ref_cache *refs = get_ref_cache(submodule);
720
+ struct ref_array *packed = get_packed_refs(refs);
721
+ struct ref_array *loose = get_loose_refs(refs);
722
723
struct ref_array *extra = &extra_refs;
724
@@ -1238,7 +1235,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
1235
* name is a proper prefix of our refname.
1236
*/
1237
if (missing &&
1241
- !is_refname_available(refname, NULL, get_packed_refs(NULL))) {
1238
+ !is_refname_available(refname, NULL, get_packed_refs(get_ref_cache(NULL)))) {
1239
last_errno = ENOTDIR;
1240
goto error_return;
1241
}
@@ -1298,7 +1295,7 @@ static int repack_without_ref(const char *refname)
1295
struct ref_entry *ref;
1296
int fd, i;
1297
1301
- packed = get_packed_refs(NULL);
1298
+ packed = get_packed_refs(get_ref_cache(NULL));
1299
ref = search_ref_array(packed, refname);
1300
if (ref == NULL)
1301
return 0;
@@ -1381,6 +1378,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
1378
struct stat loginfo;
1379
int log = !lstat(git_path("logs/%s", oldrefname), &loginfo);
1380
const char *symref = NULL;
1381
+ struct ref_cache *refs = get_ref_cache(NULL);
1382
1383
if (log && S_ISLNK(loginfo.st_mode))
1384
return error("reflog for %s is a symlink", oldrefname);
@@ -1392,10 +1390,10 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
1390
if (!symref)
1391
return error("refname %s not found", oldrefname);
1392
1395
- if (!is_refname_available(newrefname, oldrefname, get_packed_refs(NULL)))
1393
+ if (!is_refname_available(newrefname, oldrefname, get_packed_refs(refs)))
1394
return 1;
1395
1398
- if (!is_refname_available(newrefname, oldrefname, get_loose_refs(NULL)))
1396
+ if (!is_refname_available(newrefname, oldrefname, get_loose_refs(refs)))
1397
return 1;
1398
1399
if (log && rename(git_path("logs/%s", oldrefname), git_path(TMP_RENAMED_LOG)))