Skip to content

Commit 19c76e8

Browse files
pks-tgitster
authored andcommitted
refs: move object peeling into "object.c"
Peeling an object has nothing to do with refs, but we still have the code in "refs.c". Move it over into "object.c", which is a more natural place to put it. Ideally, we'd also move `peel_iterated_oid()` over into "object.c". But this function is tied to the refs interfaces because it uses a global ref iterator variable to optimize peeling when the iterator already has the peeled object ID readily available. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 330a2ae commit 19c76e8

File tree

4 files changed

+55
-56
lines changed

4 files changed

+55
-56
lines changed

object.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,27 @@ struct object *lookup_object_by_type(struct repository *r,
207207
}
208208
}
209209

210+
enum peel_status peel_object(const struct object_id *name, struct object_id *oid)
211+
{
212+
struct object *o = lookup_unknown_object(the_repository, name);
213+
214+
if (o->type == OBJ_NONE) {
215+
int type = oid_object_info(the_repository, name, NULL);
216+
if (type < 0 || !object_as_type(o, type, 0))
217+
return PEEL_INVALID;
218+
}
219+
220+
if (o->type != OBJ_TAG)
221+
return PEEL_NON_TAG;
222+
223+
o = deref_tag_noverify(o);
224+
if (!o)
225+
return PEEL_INVALID;
226+
227+
oidcpy(oid, &o->oid);
228+
return PEEL_PEELED;
229+
}
230+
210231
struct object *parse_object_buffer(struct repository *r, const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
211232
{
212233
struct object *obj;

object.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,40 @@ struct object *lookup_unknown_object(struct repository *r, const struct object_i
256256
struct object *lookup_object_by_type(struct repository *r, const struct object_id *oid,
257257
enum object_type type);
258258

259+
enum peel_status {
260+
/* object was peeled successfully: */
261+
PEEL_PEELED = 0,
262+
263+
/*
264+
* object cannot be peeled because the named object (or an
265+
* object referred to by a tag in the peel chain), does not
266+
* exist.
267+
*/
268+
PEEL_INVALID = -1,
269+
270+
/* object cannot be peeled because it is not a tag: */
271+
PEEL_NON_TAG = -2,
272+
273+
/* ref_entry contains no peeled value because it is a symref: */
274+
PEEL_IS_SYMREF = -3,
275+
276+
/*
277+
* ref_entry cannot be peeled because it is broken (i.e., the
278+
* symbolic reference cannot even be resolved to an object
279+
* name):
280+
*/
281+
PEEL_BROKEN = -4
282+
};
283+
284+
/*
285+
* Peel the named object; i.e., if the object is a tag, resolve the
286+
* tag recursively until a non-tag is found. If successful, store the
287+
* result to oid and return PEEL_PEELED. If the object is not a tag
288+
* or is not valid, return PEEL_NON_TAG or PEEL_INVALID, respectively,
289+
* and leave oid unchanged.
290+
*/
291+
enum peel_status peel_object(const struct object_id *name, struct object_id *oid);
292+
259293
struct object_list *object_list_insert(struct object *item,
260294
struct object_list **list_p);
261295

refs.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "object-store-ll.h"
2020
#include "object.h"
2121
#include "path.h"
22-
#include "tag.h"
2322
#include "submodule.h"
2423
#include "worktree.h"
2524
#include "strvec.h"
@@ -425,27 +424,6 @@ static int for_each_filter_refs(const char *refname,
425424
return filter->fn(refname, oid, flags, filter->cb_data);
426425
}
427426

428-
enum peel_status peel_object(const struct object_id *name, struct object_id *oid)
429-
{
430-
struct object *o = lookup_unknown_object(the_repository, name);
431-
432-
if (o->type == OBJ_NONE) {
433-
int type = oid_object_info(the_repository, name, NULL);
434-
if (type < 0 || !object_as_type(o, type, 0))
435-
return PEEL_INVALID;
436-
}
437-
438-
if (o->type != OBJ_TAG)
439-
return PEEL_NON_TAG;
440-
441-
o = deref_tag_noverify(o);
442-
if (!o)
443-
return PEEL_INVALID;
444-
445-
oidcpy(oid, &o->oid);
446-
return PEEL_PEELED;
447-
}
448-
449427
struct warn_if_dangling_data {
450428
struct ref_store *refs;
451429
FILE *fp;

refs/refs-internal.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,40 +69,6 @@ int ref_resolves_to_object(const char *refname,
6969
const struct object_id *oid,
7070
unsigned int flags);
7171

72-
enum peel_status {
73-
/* object was peeled successfully: */
74-
PEEL_PEELED = 0,
75-
76-
/*
77-
* object cannot be peeled because the named object (or an
78-
* object referred to by a tag in the peel chain), does not
79-
* exist.
80-
*/
81-
PEEL_INVALID = -1,
82-
83-
/* object cannot be peeled because it is not a tag: */
84-
PEEL_NON_TAG = -2,
85-
86-
/* ref_entry contains no peeled value because it is a symref: */
87-
PEEL_IS_SYMREF = -3,
88-
89-
/*
90-
* ref_entry cannot be peeled because it is broken (i.e., the
91-
* symbolic reference cannot even be resolved to an object
92-
* name):
93-
*/
94-
PEEL_BROKEN = -4
95-
};
96-
97-
/*
98-
* Peel the named object; i.e., if the object is a tag, resolve the
99-
* tag recursively until a non-tag is found. If successful, store the
100-
* result to oid and return PEEL_PEELED. If the object is not a tag
101-
* or is not valid, return PEEL_NON_TAG or PEEL_INVALID, respectively,
102-
* and leave oid unchanged.
103-
*/
104-
enum peel_status peel_object(const struct object_id *name, struct object_id *oid);
105-
10672
/**
10773
* Information needed for a single ref update. Set new_oid to the new
10874
* value or to null_oid to delete the ref. To check the old value

0 commit comments

Comments
 (0)