| 95 | }; |
| 96 | |
| 97 | int cmd_count_objects(int argc, |
| 98 | const char **argv, |
| 99 | const char *prefix, |
| 100 | struct repository *repo UNUSED) |
| 101 | { |
| 102 | int human_readable = 0; |
| 103 | struct option opts[] = { |
| 104 | OPT__VERBOSE(&verbose, N_("be verbose")), |
| 105 | OPT_BOOL('H', "human-readable", &human_readable, |
| 106 | N_("print sizes in human readable format")), |
| 107 | OPT_END(), |
| 108 | }; |
| 109 | |
| 110 | repo_config(the_repository, git_default_config, NULL); |
| 111 | |
| 112 | argc = parse_options(argc, argv, prefix, opts, count_objects_usage, 0); |
| 113 | /* we do not take arguments other than flags for now */ |
| 114 | if (argc) |
| 115 | usage_with_options(count_objects_usage, opts); |
| 116 | if (verbose) { |
| 117 | report_garbage = real_report_garbage; |
| 118 | report_linked_checkout_garbage(the_repository); |
| 119 | } |
| 120 | |
| 121 | for_each_loose_file_in_source(the_repository->objects->sources, |
| 122 | count_loose, count_cruft, NULL, NULL); |
| 123 | |
| 124 | if (verbose) { |
| 125 | struct packed_git *p; |
| 126 | unsigned long num_pack = 0; |
| 127 | off_t size_pack = 0; |
| 128 | struct strbuf loose_buf = STRBUF_INIT; |
| 129 | struct strbuf pack_buf = STRBUF_INIT; |
| 130 | struct strbuf garbage_buf = STRBUF_INIT; |
| 131 | |
| 132 | repo_for_each_pack(the_repository, p) { |
| 133 | if (!p->pack_local) |
| 134 | continue; |
| 135 | if (open_pack_index(p)) |
| 136 | continue; |
| 137 | packed += p->num_objects; |
| 138 | size_pack += p->pack_size + p->index_size; |
| 139 | num_pack++; |
| 140 | } |
| 141 | |
| 142 | if (human_readable) { |
| 143 | strbuf_humanise_bytes(&loose_buf, loose_size); |
| 144 | strbuf_humanise_bytes(&pack_buf, size_pack); |
| 145 | strbuf_humanise_bytes(&garbage_buf, size_garbage); |
| 146 | } else { |
| 147 | strbuf_addf(&loose_buf, "%lu", |
| 148 | (unsigned long)(loose_size / 1024)); |
| 149 | strbuf_addf(&pack_buf, "%lu", |
| 150 | (unsigned long)(size_pack / 1024)); |
| 151 | strbuf_addf(&garbage_buf, "%lu", |
| 152 | (unsigned long)(size_garbage / 1024)); |
| 153 | } |
| 154 |
nothing calls this directly
no test coverage detected