|
15 | 15 | #include "diff.h"
|
16 | 16 | #include "revision.h"
|
17 | 17 | #include "list-objects.h"
|
| 18 | +#include "list-objects-filter.h" |
| 19 | +#include "list-objects-filter-options.h" |
18 | 20 | #include "pack-objects.h"
|
19 | 21 | #include "progress.h"
|
20 | 22 | #include "refs.h"
|
@@ -79,6 +81,15 @@ static unsigned long cache_max_small_delta_size = 1000;
|
79 | 81 |
|
80 | 82 | static unsigned long window_memory_limit = 0;
|
81 | 83 |
|
| 84 | +static struct list_objects_filter_options filter_options; |
| 85 | + |
| 86 | +enum missing_action { |
| 87 | + MA_ERROR = 0, /* fail if any missing objects are encountered */ |
| 88 | + MA_ALLOW_ANY, /* silently allow ALL missing objects */ |
| 89 | +}; |
| 90 | +static enum missing_action arg_missing_action; |
| 91 | +static show_object_fn fn_show_object; |
| 92 | + |
82 | 93 | /*
|
83 | 94 | * stats
|
84 | 95 | */
|
@@ -2552,6 +2563,42 @@ static void show_object(struct object *obj, const char *name, void *data)
|
2552 | 2563 | obj->flags |= OBJECT_ADDED;
|
2553 | 2564 | }
|
2554 | 2565 |
|
| 2566 | +static void show_object__ma_allow_any(struct object *obj, const char *name, void *data) |
| 2567 | +{ |
| 2568 | + assert(arg_missing_action == MA_ALLOW_ANY); |
| 2569 | + |
| 2570 | + /* |
| 2571 | + * Quietly ignore ALL missing objects. This avoids problems with |
| 2572 | + * staging them now and getting an odd error later. |
| 2573 | + */ |
| 2574 | + if (!has_object_file(&obj->oid)) |
| 2575 | + return; |
| 2576 | + |
| 2577 | + show_object(obj, name, data); |
| 2578 | +} |
| 2579 | + |
| 2580 | +static int option_parse_missing_action(const struct option *opt, |
| 2581 | + const char *arg, int unset) |
| 2582 | +{ |
| 2583 | + assert(arg); |
| 2584 | + assert(!unset); |
| 2585 | + |
| 2586 | + if (!strcmp(arg, "error")) { |
| 2587 | + arg_missing_action = MA_ERROR; |
| 2588 | + fn_show_object = show_object; |
| 2589 | + return 0; |
| 2590 | + } |
| 2591 | + |
| 2592 | + if (!strcmp(arg, "allow-any")) { |
| 2593 | + arg_missing_action = MA_ALLOW_ANY; |
| 2594 | + fn_show_object = show_object__ma_allow_any; |
| 2595 | + return 0; |
| 2596 | + } |
| 2597 | + |
| 2598 | + die(_("invalid value for --missing")); |
| 2599 | + return 0; |
| 2600 | +} |
| 2601 | + |
2555 | 2602 | static void show_edge(struct commit *commit)
|
2556 | 2603 | {
|
2557 | 2604 | add_preferred_base(commit->object.oid.hash);
|
@@ -2816,7 +2863,12 @@ static void get_object_list(int ac, const char **av)
|
2816 | 2863 | if (prepare_revision_walk(&revs))
|
2817 | 2864 | die("revision walk setup failed");
|
2818 | 2865 | mark_edges_uninteresting(&revs, show_edge);
|
2819 |
| - traverse_commit_list(&revs, show_commit, show_object, NULL); |
| 2866 | + |
| 2867 | + if (!fn_show_object) |
| 2868 | + fn_show_object = show_object; |
| 2869 | + traverse_commit_list_filtered(&filter_options, &revs, |
| 2870 | + show_commit, fn_show_object, NULL, |
| 2871 | + NULL); |
2820 | 2872 |
|
2821 | 2873 | if (unpack_unreachable_expiration) {
|
2822 | 2874 | revs.ignore_missing_links = 1;
|
@@ -2952,6 +3004,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
2952 | 3004 | N_("use a bitmap index if available to speed up counting objects")),
|
2953 | 3005 | OPT_BOOL(0, "write-bitmap-index", &write_bitmap_index,
|
2954 | 3006 | N_("write a bitmap index together with the pack index")),
|
| 3007 | + OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options), |
| 3008 | + { OPTION_CALLBACK, 0, "missing", NULL, N_("action"), |
| 3009 | + N_("handling for missing objects"), PARSE_OPT_NONEG, |
| 3010 | + option_parse_missing_action }, |
2955 | 3011 | OPT_END(),
|
2956 | 3012 | };
|
2957 | 3013 |
|
@@ -3028,6 +3084,12 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
3028 | 3084 | if (!rev_list_all || !rev_list_reflog || !rev_list_index)
|
3029 | 3085 | unpack_unreachable_expiration = 0;
|
3030 | 3086 |
|
| 3087 | + if (filter_options.choice) { |
| 3088 | + if (!pack_to_stdout) |
| 3089 | + die("cannot use --filter without --stdout."); |
| 3090 | + use_bitmap_index = 0; |
| 3091 | + } |
| 3092 | + |
3031 | 3093 | /*
|
3032 | 3094 | * "soft" reasons not to use bitmaps - for on-disk repack by default we want
|
3033 | 3095 | *
|
|
0 commit comments