Skip to content

Commit eaf07b7

Browse files
chriscoolgitster
authored andcommitted
oidset: refactor oidset_insert_from_set()
In a following commit, we will need to add all the oids from a set into another set. In "list-objects-filter.c", there is already a static function called add_all() to do that. Let's rename this function oidset_insert_from_set() and move it into oidset.{c,h} to make it generally available. While at it, let's remove a useless `!= NULL`. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3ff56af commit eaf07b7

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

list-objects-filter.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -711,15 +711,6 @@ static void filter_combine__free(void *filter_data)
711711
free(d);
712712
}
713713

714-
static void add_all(struct oidset *dest, struct oidset *src) {
715-
struct oidset_iter iter;
716-
struct object_id *src_oid;
717-
718-
oidset_iter_init(src, &iter);
719-
while ((src_oid = oidset_iter_next(&iter)) != NULL)
720-
oidset_insert(dest, src_oid);
721-
}
722-
723714
static void filter_combine__finalize_omits(
724715
struct oidset *omits,
725716
void *filter_data)
@@ -728,7 +719,7 @@ static void filter_combine__finalize_omits(
728719
size_t sub;
729720

730721
for (sub = 0; sub < d->nr; sub++) {
731-
add_all(omits, &d->sub[sub].omits);
722+
oidset_insert_from_set(omits, &d->sub[sub].omits);
732723
oidset_clear(&d->sub[sub].omits);
733724
}
734725
}

oidset.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ int oidset_insert(struct oidset *set, const struct object_id *oid)
2323
return !added;
2424
}
2525

26+
void oidset_insert_from_set(struct oidset *dest, struct oidset *src)
27+
{
28+
struct oidset_iter iter;
29+
struct object_id *src_oid;
30+
31+
oidset_iter_init(src, &iter);
32+
while ((src_oid = oidset_iter_next(&iter)))
33+
oidset_insert(dest, src_oid);
34+
}
35+
2636
int oidset_remove(struct oidset *set, const struct object_id *oid)
2737
{
2838
khiter_t pos = kh_get_oid_set(&set->set, *oid);

oidset.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ int oidset_contains(const struct oidset *set, const struct object_id *oid);
4747
*/
4848
int oidset_insert(struct oidset *set, const struct object_id *oid);
4949

50+
/**
51+
* Insert all the oids that are in set 'src' into set 'dest'; a copy
52+
* is made of each oid inserted into set 'dest'.
53+
*/
54+
void oidset_insert_from_set(struct oidset *dest, struct oidset *src);
55+
5056
/**
5157
* Remove the oid from the set.
5258
*

0 commit comments

Comments
 (0)