]>
Commit | Line | Data |
---|---|---|
16950f83 JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='basic tests of rev-list --disk-usage' | |
4 | . ./test-lib.sh | |
5 | ||
6 | # we want a mix of reachable and unreachable, as well as | |
7 | # objects in the bitmapped pack and some outside of it | |
8 | test_expect_success 'set up repository' ' | |
9 | test_commit --no-tag one && | |
10 | test_commit --no-tag two && | |
11 | git repack -adb && | |
12 | git reset --hard HEAD^ && | |
13 | test_commit --no-tag three && | |
14 | test_commit --no-tag four && | |
15 | git reset --hard HEAD^ | |
16 | ' | |
17 | ||
18 | # We don't want to hardcode sizes, because they depend on the exact details of | |
19 | # packing, zlib, etc. We'll assume that the regular rev-list and cat-file | |
20 | # machinery works and compare the --disk-usage output to that. | |
21 | disk_usage_slow () { | |
22 | git rev-list --no-object-names "$@" | | |
23 | git cat-file --batch-check="%(objectsize:disk)" | | |
24 | perl -lne '$total += $_; END { print $total}' | |
25 | } | |
26 | ||
27 | # check behavior with given rev-list options; note that | |
28 | # whitespace is not preserved in args | |
29 | check_du () { | |
30 | args=$* | |
31 | ||
32 | test_expect_success "generate expected size ($args)" " | |
33 | disk_usage_slow $args >expect | |
34 | " | |
35 | ||
36 | test_expect_success "rev-list --disk-usage without bitmaps ($args)" " | |
37 | git rev-list --disk-usage $args >actual && | |
38 | test_cmp expect actual | |
39 | " | |
40 | ||
41 | test_expect_success "rev-list --disk-usage with bitmaps ($args)" " | |
42 | git rev-list --disk-usage --use-bitmap-index $args >actual && | |
43 | test_cmp expect actual | |
44 | " | |
45 | } | |
46 | ||
47 | check_du HEAD | |
48 | check_du --objects HEAD | |
49 | check_du --objects HEAD^..HEAD | |
50 | ||
9096451a LL |
51 | # As mentioned above, don't use hardcode sizes as actual size, but use the |
52 | # output from git cat-file. | |
53 | test_expect_success 'rev-list --disk-usage=human' ' | |
54 | git rev-list --objects HEAD --disk-usage=human >actual && | |
55 | disk_usage_slow --objects HEAD >actual_size && | |
56 | grep "$(cat actual_size) bytes" actual | |
57 | ' | |
58 | ||
59 | test_expect_success 'rev-list --disk-usage=human with bitmaps' ' | |
60 | git rev-list --objects HEAD --use-bitmap-index --disk-usage=human >actual && | |
61 | disk_usage_slow --objects HEAD >actual_size && | |
62 | grep "$(cat actual_size) bytes" actual | |
63 | ' | |
64 | ||
65 | test_expect_success 'rev-list use --disk-usage unproperly' ' | |
66 | test_must_fail git rev-list --objects HEAD --disk-usage=typo 2>err && | |
67 | cat >expect <<-\EOF && | |
68 | fatal: invalid value for '\''--disk-usage=<format>'\'': '\''typo'\'', the only allowed format is '\''human'\'' | |
69 | EOF | |
70 | test_cmp err expect | |
71 | ' | |
72 | ||
16950f83 | 73 | test_done |