Skip to content

Commit 316b097

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 202a56a commit 316b097

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

refs.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -278,16 +278,14 @@ void clear_extra_refs(void)
278278
clear_ref_array(&extra_refs);
279279
}
280280

281-
static struct ref_array *get_packed_refs(const char *submodule)
281+
static struct ref_array *get_packed_refs(struct ref_cache *refs)
282282
{
283-
struct ref_cache *refs = get_ref_cache(submodule);
284-
285283
if (!refs->did_packed) {
286284
const char *packed_refs_file;
287285
FILE *f;
288286

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");
291289
else
292290
packed_refs_file = git_path("packed-refs");
293291
f = fopen(packed_refs_file, "r");
@@ -306,7 +304,7 @@ static void get_ref_dir(const char *submodule, const char *base,
306304
DIR *dir;
307305
const char *path;
308306

309-
if (submodule)
307+
if (*submodule)
310308
path = git_path_submodule(submodule, "%s", base);
311309
else
312310
path = git_path("%s", base);
@@ -399,12 +397,10 @@ void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)
399397
for_each_rawref(warn_if_dangling_symref, &data);
400398
}
401399

402-
static struct ref_array *get_loose_refs(const char *submodule)
400+
static struct ref_array *get_loose_refs(struct ref_cache *refs)
403401
{
404-
struct ref_cache *refs = get_ref_cache(submodule);
405-
406402
if (!refs->did_loose) {
407-
get_ref_dir(submodule, "refs", &refs->loose);
403+
get_ref_dir(refs->name, "refs", &refs->loose);
408404
sort_ref_array(&refs->loose);
409405
refs->did_loose = 1;
410406
}
@@ -431,7 +427,7 @@ static int resolve_gitlink_packed_ref(char *name, int pathlen,
431427
if (pathlen < 6 || memcmp(name + pathlen - 6, "/.git/", 6))
432428
die("Oops");
433429
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));
435431
ref = search_ref_array(array, refname);
436432
if (ref != NULL) {
437433
memcpy(sha1, ref->sha1, 20);
@@ -511,7 +507,7 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sh
511507
*/
512508
static int get_packed_ref(const char *refname, unsigned char *sha1)
513509
{
514-
struct ref_array *packed = get_packed_refs(NULL);
510+
struct ref_array *packed = get_packed_refs(get_ref_cache(NULL));
515511
struct ref_entry *entry = search_ref_array(packed, refname);
516512
if (entry) {
517513
hashcpy(sha1, entry->sha1);
@@ -695,7 +691,7 @@ int peel_ref(const char *refname, unsigned char *sha1)
695691
return -1;
696692

697693
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));
699695
struct ref_entry *r = search_ref_array(array, refname);
700696

701697
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
720716
int trim, int flags, void *cb_data)
721717
{
722718
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);
725722

726723
struct ref_array *extra = &extra_refs;
727724

@@ -1238,7 +1235,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
12381235
* name is a proper prefix of our refname.
12391236
*/
12401237
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)))) {
12421239
last_errno = ENOTDIR;
12431240
goto error_return;
12441241
}
@@ -1298,7 +1295,7 @@ static int repack_without_ref(const char *refname)
12981295
struct ref_entry *ref;
12991296
int fd, i;
13001297

1301-
packed = get_packed_refs(NULL);
1298+
packed = get_packed_refs(get_ref_cache(NULL));
13021299
ref = search_ref_array(packed, refname);
13031300
if (ref == NULL)
13041301
return 0;
@@ -1381,6 +1378,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms
13811378
struct stat loginfo;
13821379
int log = !lstat(git_path("logs/%s", oldrefname), &loginfo);
13831380
const char *symref = NULL;
1381+
struct ref_cache *refs = get_ref_cache(NULL);
13841382

13851383
if (log && S_ISLNK(loginfo.st_mode))
13861384
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
13921390
if (!symref)
13931391
return error("refname %s not found", oldrefname);
13941392

1395-
if (!is_refname_available(newrefname, oldrefname, get_packed_refs(NULL)))
1393+
if (!is_refname_available(newrefname, oldrefname, get_packed_refs(refs)))
13961394
return 1;
13971395

1398-
if (!is_refname_available(newrefname, oldrefname, get_loose_refs(NULL)))
1396+
if (!is_refname_available(newrefname, oldrefname, get_loose_refs(refs)))
13991397
return 1;
14001398

14011399
if (log && rename(git_path("logs/%s", oldrefname), git_path(TMP_RENAMED_LOG)))

0 commit comments

Comments
 (0)