summaryrefslogtreecommitdiff
path: root/builtin/pack-redundant.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/pack-redundant.c')
-rw-r--r--builtin/pack-redundant.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
index 649c3aaa93..0a86132af9 100644
--- a/builtin/pack-redundant.c
+++ b/builtin/pack-redundant.c
@@ -567,29 +567,42 @@ static struct pack_list * add_pack(struct packed_git *p)
return pack_list_insert(&altodb_packs, &l);
}
+struct add_pack_data {
+ const char *filename;
+ int found;
+ struct pack_list *added_pack;
+};
+
+static int add_pack_fn(struct packed_git *p, void *data)
+{
+ struct add_pack_data *apd = (struct add_pack_data *) data;
+ if (apd->filename && strstr(p->pack_name, apd->filename)) {
+ apd->found = 1;
+ apd->added_pack = add_pack(p);
+ return 1;
+ } else if (!apd->filename) {
+ add_pack(p);
+ }
+ return 0;
+}
+
static struct pack_list * add_pack_file(const char *filename)
{
- struct packed_git *p = packed_git;
+ struct add_pack_data apd = {filename, 0, NULL};
if (strlen(filename) < 40)
die("Bad pack filename: %s", filename);
- while (p) {
- if (strstr(p->pack_name, filename))
- return add_pack(p);
- p = p->next;
- }
+ foreach_packed_git(add_pack_fn, NULL, &apd);
+ if (apd.found)
+ return apd.added_pack;
die("Filename %s not found in packed_git", filename);
}
static void load_all(void)
{
- struct packed_git *p = packed_git;
-
- while (p) {
- add_pack(p);
- p = p->next;
- }
+ struct add_pack_data apd = {NULL, 0, NULL};
+ foreach_packed_git(add_pack_fn, NULL, &apd);
}
int cmd_pack_redundant(int argc, const char **argv, const char *prefix)