Skip to content

Commit b3d6c48

Browse files
committed
Merge branch 'jk/ref-array-push'
API clean-up aournd ref-filter code. * jk/ref-array-push: ref-filter: factor ref_array pushing into its own function ref-filter: make ref_array_item allocation more consistent ref-filter: use "struct object_id" consistently
2 parents cb6462f + 427cbc9 commit b3d6c48

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static int verify_tag(const char *name, const char *ref,
118118
return -1;
119119

120120
if (format->format)
121-
pretty_print_ref(name, oid->hash, format);
121+
pretty_print_ref(name, oid, format);
122122

123123
return 0;
124124
}

builtin/verify-tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
7272
}
7373

7474
if (format.format)
75-
pretty_print_ref(name, oid.hash, &format);
75+
pretty_print_ref(name, &oid, &format);
7676
}
7777
return had_error;
7878
}

ref-filter.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,15 +1828,30 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
18281828
return NULL;
18291829
}
18301830

1831-
/* Allocate space for a new ref_array_item and copy the objectname and flag to it */
1831+
/*
1832+
* Allocate space for a new ref_array_item and copy the name and oid to it.
1833+
*
1834+
* Callers can then fill in other struct members at their leisure.
1835+
*/
18321836
static struct ref_array_item *new_ref_array_item(const char *refname,
1833-
const unsigned char *objectname,
1834-
int flag)
1837+
const struct object_id *oid)
18351838
{
18361839
struct ref_array_item *ref;
1840+
18371841
FLEX_ALLOC_STR(ref, refname, refname);
1838-
hashcpy(ref->objectname.hash, objectname);
1839-
ref->flag = flag;
1842+
oidcpy(&ref->objectname, oid);
1843+
1844+
return ref;
1845+
}
1846+
1847+
struct ref_array_item *ref_array_push(struct ref_array *array,
1848+
const char *refname,
1849+
const struct object_id *oid)
1850+
{
1851+
struct ref_array_item *ref = new_ref_array_item(refname, oid);
1852+
1853+
ALLOC_GROW(array->items, array->nr + 1, array->alloc);
1854+
array->items[array->nr++] = ref;
18401855

18411856
return ref;
18421857
}
@@ -1931,12 +1946,11 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid,
19311946
* to do its job and the resulting list may yet to be pruned
19321947
* by maxcount logic.
19331948
*/
1934-
ref = new_ref_array_item(refname, oid->hash, flag);
1949+
ref = ref_array_push(ref_cbdata->array, refname, oid);
19351950
ref->commit = commit;
1936-
1937-
REALLOC_ARRAY(ref_cbdata->array->items, ref_cbdata->array->nr + 1);
1938-
ref_cbdata->array->items[ref_cbdata->array->nr++] = ref;
1951+
ref->flag = flag;
19391952
ref->kind = kind;
1953+
19401954
return 0;
19411955
}
19421956

@@ -2169,11 +2183,11 @@ void show_ref_array_item(struct ref_array_item *info,
21692183
putchar('\n');
21702184
}
21712185

2172-
void pretty_print_ref(const char *name, const unsigned char *sha1,
2186+
void pretty_print_ref(const char *name, const struct object_id *oid,
21732187
const struct ref_format *format)
21742188
{
21752189
struct ref_array_item *ref_item;
2176-
ref_item = new_ref_array_item(name, sha1, 0);
2190+
ref_item = new_ref_array_item(name, oid);
21772191
ref_item->kind = ref_kind_from_refname(name);
21782192
show_ref_array_item(ref_item, format);
21792193
free_array_item(ref_item);

ref-filter.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,15 @@ void setup_ref_filter_porcelain_msg(void);
132132
* Print a single ref, outside of any ref-filter. Note that the
133133
* name must be a fully qualified refname.
134134
*/
135-
void pretty_print_ref(const char *name, const unsigned char *sha1,
135+
void pretty_print_ref(const char *name, const struct object_id *oid,
136136
const struct ref_format *format);
137137

138+
/*
139+
* Push a single ref onto the array; this can be used to construct your own
140+
* ref_array without using filter_refs().
141+
*/
142+
struct ref_array_item *ref_array_push(struct ref_array *array,
143+
const char *refname,
144+
const struct object_id *oid);
145+
138146
#endif /* REF_FILTER_H */

0 commit comments

Comments
 (0)