Skip to content

Commit

Permalink
wip build time sort
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup committed Oct 31, 2022
1 parent 824d2ce commit 1427d39
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/createrepo_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,22 @@ static int strlensort(gconstpointer a, gconstpointer b)
}
}

// Sorting function for DuplicateLocation pointers, by pkg build time.
// Compatible with g_array_sort()
static int buildtimesort(gconstpointer a, gconstpointer b)
{
// Function is supposed to take a double-pointer so unfortunately you cannot pass a
// string-comparison function directly.
struct DuplicateLocation *a_loc = (struct DuplicateLocation *)a;
struct DuplicateLocation *b_loc = (struct DuplicateLocation *)b;

assert(a_loc->pkg->time_build != 0);
assert(b_loc->pkg->time_build != 0);

int64_t result = a_loc->pkg->time_build - b_loc->pkg->time_build;
return result;
}


int
handle_nevra_duplicates(GArray *locations, CmdDupNevra option)
Expand Down Expand Up @@ -1386,7 +1402,7 @@ main(int argc, char **argv)
if (locations->len > 1) {
g_warning("Package '%s' has duplicate metadata entries, only one should exist", nevra);

g_array_sort(locations, strlensort);
g_array_sort(locations, buildtimesort);
skipped_pkgs += handle_nevra_duplicates(locations, cmd_options->nevra_duplicates);
}

Expand Down

0 comments on commit 1427d39

Please sign in to comment.