Re: [PATCH v2] rev-list: support human-readable output for `--disk-usage`
- From
- lilinchao@oschina.cn <lilinchao@oschina.cn>
- Date
- Aug 8, 2022, 09:37 UTC
- Message-ID
- <202208081735108064497@oschina.cn>
- In-Reply-To
- <pull.1313.v2.git.1659947722132.gitgitgadget@gmail.com>
Show 8 quoted lines
> static int show_disk_usage;
> @@ builtin/rev-list.c: static int try_bitmap_disk_usage(struct rev_info *revs,
> int filter_provided_objects)
> {
> struct bitmap_index *bitmap_git;
> -+ struct strbuf bitmap_size_buf = STRBUF_INIT;
> ++ struct strbuf disk_buf = STRBUF_INIT;
> + off_t size_from_bitmap;In next iteration, will move these two lines to more close to their caller place to avoid early return.
Show 20 quoted lines
>
> if (!show_disk_usage)
> @@ builtin/rev-list.c: static int try_bitmap_disk_usage(struct rev_info *revs,
> - printf("%"PRIuMAX"\n",
> - (uintmax_t)get_disk_usage_from_bitmap(bitmap_git, revs));
> + size_from_bitmap = get_disk_usage_from_bitmap(bitmap_git, revs);
> -+ if (human_readable) {
> -+ strbuf_humanise_bytes(&bitmap_size_buf, size_from_bitmap);
> -+ printf("%s\n", bitmap_size_buf.buf);
> -+ } else
> -+ printf("%"PRIuMAX"\n", (uintmax_t)size_from_bitmap);
> -+ strbuf_release(&bitmap_size_buf);
> ++ if (human_readable)
> ++ strbuf_humanise_bytes(&disk_buf, size_from_bitmap);
> ++ else
> ++ strbuf_addf(&disk_buf, "%"PRIuMAX"", (uintmax_t)size_from_bitmap);
> ++ puts(disk_buf.buf);
> ++ strbuf_release(&disk_buf);
> return 0;
> }