| 979 | } |
| 980 | |
| 981 | static void setup_additional_headers(struct diff_options *o, |
| 982 | struct strmap *all_headers) |
| 983 | { |
| 984 | struct hashmap_iter iter; |
| 985 | struct strmap_entry *entry; |
| 986 | |
| 987 | /* |
| 988 | * Make o->additional_path_headers contain the subset of all_headers |
| 989 | * that match o->pathspec. If there aren't any that match o->pathspec, |
| 990 | * then make o->additional_path_headers be NULL. |
| 991 | */ |
| 992 | |
| 993 | if (!o->pathspec.nr) { |
| 994 | o->additional_path_headers = all_headers; |
| 995 | return; |
| 996 | } |
| 997 | |
| 998 | o->additional_path_headers = xmalloc(sizeof(struct strmap)); |
| 999 | strmap_init_with_options(o->additional_path_headers, NULL, 0); |
| 1000 | strmap_for_each_entry(all_headers, &iter, entry) { |
| 1001 | if (match_pathspec(the_repository->index, &o->pathspec, |
| 1002 | entry->key, strlen(entry->key), |
| 1003 | 0 /* prefix */, NULL /* seen */, |
| 1004 | 0 /* is_dir */)) |
| 1005 | strmap_put(o->additional_path_headers, |
| 1006 | entry->key, entry->value); |
| 1007 | } |
| 1008 | if (!strmap_get_size(o->additional_path_headers)) { |
| 1009 | strmap_clear(o->additional_path_headers, 0); |
| 1010 | FREE_AND_NULL(o->additional_path_headers); |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | static void cleanup_additional_headers(struct diff_options *o) |
| 1015 | { |
no test coverage detected