Skip to content

Commit e19488a

Browse files
pks-tgitster
authored andcommitted
refs: refactor resolve_gitlink_ref() to accept a repository
In `resolve_gitlink_ref()` we implicitly rely on `the_repository` to look up the submodule ref store. Now that we can look up submodule ref stores for arbitrary repositories we can improve this function to instead accept a repository as parameter for which we want to resolve the gitlink. Do so and adjust callers accordingly. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 965f899 commit e19488a

File tree

11 files changed

+29
-18
lines changed

11 files changed

+29
-18
lines changed

attr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,8 @@ static const char *builtin_object_mode_attr(struct index_state *istate, const ch
12881288
if (pos >= 0) {
12891289
if (S_ISGITLINK(istate->cache[pos]->ce_mode))
12901290
mode = istate->cache[pos]->ce_mode;
1291-
} else if (resolve_gitlink_ref(path, "HEAD", &oid) == 0) {
1291+
} else if (repo_resolve_gitlink_ref(the_repository, path,
1292+
"HEAD", &oid) == 0) {
12921293
mode = S_IFGITLINK;
12931294
}
12941295
}

builtin/submodule--helper.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,8 @@ static int update_submodule(struct update_data *update_data)
26002600

26012601
if (update_data->just_cloned)
26022602
oidcpy(&update_data->suboid, null_oid());
2603-
else if (resolve_gitlink_ref(update_data->sm_path, "HEAD", &update_data->suboid))
2603+
else if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path,
2604+
"HEAD", &update_data->suboid))
26042605
return die_message(_("Unable to find current revision in submodule path '%s'"),
26052606
update_data->displaypath);
26062607

@@ -2627,7 +2628,8 @@ static int update_submodule(struct update_data *update_data)
26272628
update_data->sm_path);
26282629
}
26292630

2630-
if (resolve_gitlink_ref(update_data->sm_path, remote_ref, &update_data->oid))
2631+
if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path,
2632+
remote_ref, &update_data->oid))
26312633
return die_message(_("Unable to find %s revision in submodule path '%s'"),
26322634
remote_ref, update_data->sm_path);
26332635

@@ -3357,7 +3359,7 @@ static void die_on_repo_without_commits(const char *path)
33573359
strbuf_addstr(&sb, path);
33583360
if (is_nonbare_repository_dir(&sb)) {
33593361
struct object_id oid;
3360-
if (resolve_gitlink_ref(path, "HEAD", &oid) < 0)
3362+
if (repo_resolve_gitlink_ref(the_repository, path, "HEAD", &oid) < 0)
33613363
die(_("'%s' does not have a commit checked out"), path);
33623364
}
33633365
strbuf_release(&sb);

builtin/update-index.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ static int process_directory(const char *path, int len, struct stat *st)
349349
if (S_ISGITLINK(ce->ce_mode)) {
350350

351351
/* Do nothing to the index if there is no HEAD! */
352-
if (resolve_gitlink_ref(path, "HEAD", &oid) < 0)
352+
if (repo_resolve_gitlink_ref(the_repository, path,
353+
"HEAD", &oid) < 0)
353354
return 0;
354355

355356
return add_one_path(ce, path, len, st);
@@ -375,7 +376,7 @@ static int process_directory(const char *path, int len, struct stat *st)
375376
}
376377

377378
/* No match - should we add it as a gitlink? */
378-
if (!resolve_gitlink_ref(path, "HEAD", &oid))
379+
if (!repo_resolve_gitlink_ref(the_repository, path, "HEAD", &oid))
379380
return add_one_path(NULL, path, len, st);
380381

381382
/* Error out. */

combine-diff.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
10661066
elem->mode = canon_mode(st.st_mode);
10671067
} else if (S_ISDIR(st.st_mode)) {
10681068
struct object_id oid;
1069-
if (resolve_gitlink_ref(elem->path, "HEAD", &oid) < 0)
1069+
if (repo_resolve_gitlink_ref(the_repository, elem->path,
1070+
"HEAD", &oid) < 0)
10701071
result = grab_blob(opt->repo, &elem->oid,
10711072
elem->mode, &result_size,
10721073
NULL, NULL);

diff-lib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ static int check_removed(const struct cache_entry *ce, struct stat *st)
6666
* a directory --- the blob was removed!
6767
*/
6868
if (!S_ISGITLINK(ce->ce_mode) &&
69-
resolve_gitlink_ref(ce->name, "HEAD", &sub))
69+
repo_resolve_gitlink_ref(the_repository, ce->name,
70+
"HEAD", &sub))
7071
return 1;
7172
}
7273
return 0;

dir.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3318,7 +3318,8 @@ static int remove_dir_recurse(struct strbuf *path, int flag, int *kept_up)
33183318
struct object_id submodule_head;
33193319

33203320
if ((flag & REMOVE_DIR_KEEP_NESTED_GIT) &&
3321-
!resolve_gitlink_ref(path->buf, "HEAD", &submodule_head)) {
3321+
!repo_resolve_gitlink_ref(the_repository, path->buf,
3322+
"HEAD", &submodule_head)) {
33223323
/* Do not descend and nuke a nested git work tree. */
33233324
if (kept_up)
33243325
*kept_up = 1;

object-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2669,7 +2669,7 @@ int index_path(struct index_state *istate, struct object_id *oid,
26692669
strbuf_release(&sb);
26702670
break;
26712671
case S_IFDIR:
2672-
return resolve_gitlink_ref(path, "HEAD", oid);
2672+
return repo_resolve_gitlink_ref(the_repository, path, "HEAD", oid);
26732673
default:
26742674
return error(_("%s: unsupported file type"), path);
26752675
}

read-cache.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ static int ce_compare_gitlink(const struct cache_entry *ce)
271271
*
272272
* If so, we consider it always to match.
273273
*/
274-
if (resolve_gitlink_ref(ce->name, "HEAD", &oid) < 0)
274+
if (repo_resolve_gitlink_ref(the_repository, ce->name,
275+
"HEAD", &oid) < 0)
275276
return 0;
276277
return !oideq(&oid, &ce->oid);
277278
}
@@ -711,7 +712,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
711712

712713
namelen = strlen(path);
713714
if (S_ISDIR(st_mode)) {
714-
if (resolve_gitlink_ref(path, "HEAD", &oid) < 0)
715+
if (repo_resolve_gitlink_ref(the_repository, path, "HEAD", &oid) < 0)
715716
return error(_("'%s' does not have a commit checked out"), path);
716717
while (namelen && path[namelen-1] == '/')
717718
namelen--;

refs.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,13 +1943,14 @@ int ref_store_create_on_disk(struct ref_store *refs, int flags, struct strbuf *e
19431943
return refs->be->create_on_disk(refs, flags, err);
19441944
}
19451945

1946-
int resolve_gitlink_ref(const char *submodule, const char *refname,
1947-
struct object_id *oid)
1946+
int repo_resolve_gitlink_ref(struct repository *r,
1947+
const char *submodule, const char *refname,
1948+
struct object_id *oid)
19481949
{
19491950
struct ref_store *refs;
19501951
int flags;
19511952

1952-
refs = repo_get_submodule_ref_store(the_repository, submodule);
1953+
refs = repo_get_submodule_ref_store(r, submodule);
19531954
if (!refs)
19541955
return -1;
19551956

refs.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ int peel_iterated_oid(const struct object_id *base, struct object_id *peeled);
141141
* successful, return 0 and set oid to the name of the object;
142142
* otherwise, return a non-zero value.
143143
*/
144-
int resolve_gitlink_ref(const char *submodule, const char *refname,
145-
struct object_id *oid);
144+
int repo_resolve_gitlink_ref(struct repository *r,
145+
const char *submodule, const char *refname,
146+
struct object_id *oid);
146147

147148
/*
148149
* Return true iff abbrev_name is a possible abbreviation for

0 commit comments

Comments
 (0)