Skip to content

Commit 973e20b

Browse files
committed
Merge branch 'jk/peel-iterated-oid'
The peel_ref() API has been replaced with peel_iterated_oid(). * jk/peel-iterated-oid: refs: switch peel_ref() to peel_iterated_oid()
2 parents 6cd7f9d + 36a3179 commit 973e20b

File tree

12 files changed

+27
-69
lines changed

12 files changed

+27
-69
lines changed

builtin/describe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
194194
}
195195

196196
/* Is it annotated? */
197-
if (!peel_ref(path, &peeled)) {
197+
if (!peel_iterated_oid(oid, &peeled)) {
198198
is_annotated = !oideq(oid, &peeled);
199199
} else {
200200
oidcpy(&peeled, oid);

builtin/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ static int dfs_on_ref(const char *refname,
769769
struct commit_list *stack = NULL;
770770
struct commit *commit;
771771

772-
if (!peel_ref(refname, &peeled))
772+
if (!peel_iterated_oid(oid, &peeled))
773773
oid = &peeled;
774774
if (oid_object_info(the_repository, oid, NULL) != OBJ_COMMIT)
775775
return 0;

builtin/pack-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ static int mark_tagged(const char *path, const struct object_id *oid, int flag,
634634

635635
if (entry)
636636
entry->tagged = 1;
637-
if (!peel_ref(path, &peeled)) {
637+
if (!peel_iterated_oid(oid, &peeled)) {
638638
entry = packlist_find(&to_pack, &peeled);
639639
if (entry)
640640
entry->tagged = 1;
@@ -2819,7 +2819,7 @@ static int add_ref_tag(const char *path, const struct object_id *oid, int flag,
28192819
struct object_id peeled;
28202820

28212821
if (starts_with(path, "refs/tags/") && /* is a tag? */
2822-
!peel_ref(path, &peeled) && /* peelable? */
2822+
!peel_iterated_oid(oid, &peeled) && /* peelable? */
28232823
obj_is_packed(&peeled)) /* object packed? */
28242824
add_tag_chain(oid);
28252825
return 0;

builtin/show-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void show_one(const char *refname, const struct object_id *oid)
4040
if (!deref_tags)
4141
return;
4242

43-
if (!peel_ref(refname, &peeled)) {
43+
if (!peel_iterated_oid(oid, &peeled)) {
4444
hex = find_unique_abbrev(&peeled, abbrev);
4545
printf("%s %s^{}\n", hex, refname);
4646
}

commit-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ static int add_ref_to_set(const char *refname,
14581458
struct object_id peeled;
14591459
struct refs_cb_data *data = (struct refs_cb_data *)cb_data;
14601460

1461-
if (!peel_ref(refname, &peeled))
1461+
if (!peel_iterated_oid(oid, &peeled))
14621462
oid = &peeled;
14631463
if (oid_object_info(the_repository, oid, NULL) == OBJ_COMMIT)
14641464
oidset_insert(data->commits, oid);

ls-refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
6363

6464
if (data->peel) {
6565
struct object_id peeled;
66-
if (!peel_ref(refname, &peeled))
66+
if (!peel_iterated_oid(oid, &peeled))
6767
strbuf_addf(&refline, " peeled:%s", oid_to_hex(&peeled));
6868
}
6969

refs.c

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,31 +1916,14 @@ int refs_pack_refs(struct ref_store *refs, unsigned int flags)
19161916
return refs->be->pack_refs(refs, flags);
19171917
}
19181918

1919-
int refs_peel_ref(struct ref_store *refs, const char *refname,
1920-
struct object_id *oid)
1919+
int peel_iterated_oid(const struct object_id *base, struct object_id *peeled)
19211920
{
1922-
int flag;
1923-
struct object_id base;
1924-
1925-
if (current_ref_iter && current_ref_iter->refname == refname) {
1926-
struct object_id peeled;
1927-
1928-
if (ref_iterator_peel(current_ref_iter, &peeled))
1929-
return -1;
1930-
oidcpy(oid, &peeled);
1931-
return 0;
1932-
}
1921+
if (current_ref_iter &&
1922+
(current_ref_iter->oid == base ||
1923+
oideq(current_ref_iter->oid, base)))
1924+
return ref_iterator_peel(current_ref_iter, peeled);
19331925

1934-
if (refs_read_ref_full(refs, refname,
1935-
RESOLVE_REF_READING, &base, &flag))
1936-
return -1;
1937-
1938-
return peel_object(&base, oid);
1939-
}
1940-
1941-
int peel_ref(const char *refname, struct object_id *oid)
1942-
{
1943-
return refs_peel_ref(get_main_ref_store(the_repository), refname, oid);
1926+
return peel_object(base, peeled);
19441927
}
19451928

19461929
int refs_create_symref(struct ref_store *refs,

refs.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,16 @@ int is_branch(const char *refname);
118118
int refs_init_db(struct strbuf *err);
119119

120120
/*
121-
* If refname is a non-symbolic reference that refers to a tag object,
122-
* and the tag can be (recursively) dereferenced to a non-tag object,
123-
* store the object ID of the referred-to object to oid and return 0.
124-
* If any of these conditions are not met, return a non-zero value.
125-
* Symbolic references are considered unpeelable, even if they
126-
* ultimately resolve to a peelable tag.
127-
*/
128-
int refs_peel_ref(struct ref_store *refs, const char *refname,
129-
struct object_id *oid);
130-
int peel_ref(const char *refname, struct object_id *oid);
121+
* Return the peeled value of the oid currently being iterated via
122+
* for_each_ref(), etc. This is equivalent to calling:
123+
*
124+
* peel_object(oid, &peeled);
125+
*
126+
* with the "oid" value given to the each_ref_fn callback, except
127+
* that some ref storage may be able to answer the query without
128+
* actually loading the object in memory.
129+
*/
130+
int peel_iterated_oid(const struct object_id *base, struct object_id *peeled);
131131

132132
/**
133133
* Resolve refname in the nested "gitlink" repository in the specified

t/helper/test-ref-store.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,6 @@ static int cmd_pack_refs(struct ref_store *refs, const char **argv)
7272
return refs_pack_refs(refs, flags);
7373
}
7474

75-
static int cmd_peel_ref(struct ref_store *refs, const char **argv)
76-
{
77-
const char *refname = notnull(*argv++, "refname");
78-
struct object_id oid;
79-
int ret;
80-
81-
ret = refs_peel_ref(refs, refname, &oid);
82-
if (!ret)
83-
puts(oid_to_hex(&oid));
84-
return ret;
85-
}
86-
8775
static int cmd_create_symref(struct ref_store *refs, const char **argv)
8876
{
8977
const char *refname = notnull(*argv++, "refname");
@@ -255,7 +243,6 @@ struct command {
255243

256244
static struct command commands[] = {
257245
{ "pack-refs", cmd_pack_refs },
258-
{ "peel-ref", cmd_peel_ref },
259246
{ "create-symref", cmd_create_symref },
260247
{ "delete-refs", cmd_delete_refs },
261248
{ "rename-ref", cmd_rename_ref },

t/t1405-main-ref-store.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ test_expect_success 'pack_refs(PACK_REFS_ALL | PACK_REFS_PRUNE)' '
1717
N=`find .git/refs -type f | wc -l`
1818
'
1919

20-
test_expect_success 'peel_ref(new-tag)' '
21-
git rev-parse HEAD >expected &&
22-
git tag -a -m new-tag new-tag HEAD &&
23-
$RUN peel-ref refs/tags/new-tag >actual &&
24-
test_cmp expected actual
25-
'
26-
2720
test_expect_success 'create_symref(FOO, refs/heads/main)' '
2821
$RUN create-symref FOO refs/heads/main nothing &&
2922
echo refs/heads/main >expected &&
@@ -32,6 +25,7 @@ test_expect_success 'create_symref(FOO, refs/heads/main)' '
3225
'
3326

3427
test_expect_success 'delete_refs(FOO, refs/tags/new-tag)' '
28+
git tag -a -m new-tag new-tag HEAD &&
3529
git rev-parse FOO -- &&
3630
git rev-parse refs/tags/new-tag -- &&
3731
m=$(git rev-parse main) &&

0 commit comments

Comments
 (0)