Raw
1 #!/bin/sh
2
3 test_description='test git repo structure'
4
5 . ./test-lib.sh
6
7 object_type_disk_usage() {
8 disk_usage_opt="--disk-usage"
9
10 if test "$2" = "true"
11 then
12 disk_usage_opt="--disk-usage=human"
13 fi
14
15 if test "$1" = "all"
16 then
17 git rev-list --all --objects $disk_usage_opt
18 else
19 git rev-list --all --objects $disk_usage_opt \
20 --filter=object:type=$1 --filter-provided-objects
21 fi
22 }
23
24 test_expect_success 'empty repository' '
25 test_when_finished "rm -rf repo" &&
26 git init repo &&
27 (
28 cd repo &&
29 cat >expect <<-\EOF &&
30 | Repository structure | Value |
31 | ------------------------- | ------ |
32 | * References | |
33 | * Count | 0 |
34 | * Branches | 0 |
35 | * Tags | 0 |
36 | * Remotes | 0 |
37 | * Others | 0 |
38 | | |
39 | * Reachable objects | |
40 | * Count | 0 |
41 | * Commits | 0 |
42 | * Trees | 0 |
43 | * Blobs | 0 |
44 | * Tags | 0 |
45 | * Inflated size | 0 B |
46 | * Commits | 0 B |
47 | * Trees | 0 B |
48 | * Blobs | 0 B |
49 | * Tags | 0 B |
50 | * Disk size | 0 B |
51 | * Commits | 0 B |
52 | * Trees | 0 B |
53 | * Blobs | 0 B |
54 | * Tags | 0 B |
55 | | |
56 | * Largest objects | |
57 | * Commits | |
58 | * Maximum size | 0 B |
59 | * Maximum parents | 0 |
60 | * Trees | |
61 | * Maximum size | 0 B |
62 | * Maximum entries | 0 |
63 | * Blobs | |
64 | * Maximum size | 0 B |
65 | * Tags | |
66 | * Maximum size | 0 B |
67 EOF
68
69 git repo structure >out 2>err &&
70
71 test_cmp expect out &&
72 test_line_count = 0 err
73 )
74 '
75
76 test_expect_success SHA1 'repository with references and objects' '
77 test_when_finished "rm -rf repo" &&
78 git init repo &&
79 (
80 cd repo &&
81 test_commit_bulk 1005 &&
82 git tag -a foo -m bar &&
83
84 oid="$(git rev-parse HEAD)" &&
85 git update-ref refs/remotes/origin/foo "$oid" &&
86
87 # Also creates a commit, tree, and blob.
88 git notes add -m foo &&
89
90 # The tags disk size is handled specially due to the
91 # git-rev-list(1) --disk-usage=human option printing the full
92 # "byte/bytes" unit string instead of just "B".
93 cat >expect <<-EOF &&
94 | Repository structure | Value |
95 | ------------------------- | ---------- |
96 | * References | |
97 | * Count | 4 |
98 | * Branches | 1 |
99 | * Tags | 1 |
100 | * Remotes | 1 |
101 | * Others | 1 |
102 | | |
103 | * Reachable objects | |
104 | * Count | 3.02 k |
105 | * Commits | 1.01 k |
106 | * Trees | 1.01 k |
107 | * Blobs | 1.01 k |
108 | * Tags | 1 |
109 | * Inflated size | 16.03 MiB |
110 | * Commits | 217.92 KiB |
111 | * Trees | 15.81 MiB |
112 | * Blobs | 11.68 KiB |
113 | * Tags | 132 B |
114 | * Disk size | $(object_type_disk_usage all true) |
115 | * Commits | $(object_type_disk_usage commit true) |
116 | * Trees | $(object_type_disk_usage tree true) |
117 | * Blobs | $(object_type_disk_usage blob true) |
118 | * Tags | $(object_type_disk_usage tag) B |
119 | | |
120 | * Largest objects | |
121 | * Commits | |
122 | * Maximum size [1] | 223 B |
123 | * Maximum parents [2] | 1 |
124 | * Trees | |
125 | * Maximum size [3] | 32.29 KiB |
126 | * Maximum entries [4] | 1.01 k |
127 | * Blobs | |
128 | * Maximum size [5] | 13 B |
129 | * Tags | |
130 | * Maximum size [6] | 132 B |
131
132 [1] 0dc91eb18580102a3a216c8bfecedeba2b9f9b9a
133 [2] 0dc91eb18580102a3a216c8bfecedeba2b9f9b9a
134 [3] 60665251ab71dbd8c18d9bf2174f4ee0d58aa06c
135 [4] 60665251ab71dbd8c18d9bf2174f4ee0d58aa06c
136 [5] 97d808e45116bf02103490294d3d46dad7a2ac62
137 [6] 4dae4f5954f5e6feb3577cfb1b181daa3fd3afd2
138 EOF
139
140 git repo structure >out 2>err &&
141
142 test_cmp expect out &&
143 test_line_count = 0 err
144 )
145 '
146
147 test_expect_success SHA1 'lines and nul format' '
148 test_when_finished "rm -rf repo" &&
149 git init repo &&
150 (
151 cd repo &&
152 test_commit_bulk 42 &&
153 git tag -a foo -m bar &&
154
155 cat >expect <<-EOF &&
156 references.branches.count=1
157 references.tags.count=1
158 references.remotes.count=0
159 references.others.count=0
160 objects.commits.count=42
161 objects.trees.count=42
162 objects.blobs.count=42
163 objects.tags.count=1
164 objects.commits.inflated_size=9225
165 objects.trees.inflated_size=28554
166 objects.blobs.inflated_size=453
167 objects.tags.inflated_size=132
168 objects.commits.disk_size=$(object_type_disk_usage commit)
169 objects.trees.disk_size=$(object_type_disk_usage tree)
170 objects.blobs.disk_size=$(object_type_disk_usage blob)
171 objects.tags.disk_size=$(object_type_disk_usage tag)
172 objects.commits.max_size=221
173 objects.commits.max_size_oid=de3508174b5c2ace6993da67cae9be9069e2df39
174 objects.trees.max_size=1335
175 objects.trees.max_size_oid=09931deea9d81ec21300d3e13c74412f32eacec5
176 objects.blobs.max_size=11
177 objects.blobs.max_size_oid=eaeeedced46482bd4281fda5a5f05ce24854151f
178 objects.tags.max_size=132
179 objects.tags.max_size_oid=1ee0f2b16ea37d895dbe9dbd76cd2ac70446176c
180 objects.commits.max_parents=1
181 objects.commits.max_parents_oid=de3508174b5c2ace6993da67cae9be9069e2df39
182 objects.trees.max_entries=42
183 objects.trees.max_entries_oid=09931deea9d81ec21300d3e13c74412f32eacec5
184 EOF
185
186 git repo structure --format=lines >out 2>err &&
187
188 test_cmp expect out &&
189 test_line_count = 0 err &&
190
191 git repo structure --format=nul >out 2>err &&
192 tr "\012\000" "=\012" <out >actual &&
193
194 test_cmp expect actual &&
195 test_line_count = 0 err &&
196
197 # "-z", as a synonym to "--format=nul", participates in the
198 # usual "last one wins" rule.
199 git repo structure --format=table -z >out 2>err &&
200 tr "\012\000" "=\012" <out >actual &&
201
202 test_cmp expect actual &&
203 test_line_count = 0 err
204 )
205 '
206
207 test_expect_success 'progress meter option' '
208 test_when_finished "rm -rf repo" &&
209 git init repo &&
210 (
211 cd repo &&
212 test_commit foo &&
213
214 GIT_PROGRESS_DELAY=0 git repo structure --progress >out 2>err &&
215
216 test_file_not_empty out &&
217 test_grep "Counting references: 2, done." err &&
218 test_grep "Counting objects: 3, done." err &&
219
220 GIT_PROGRESS_DELAY=0 git repo structure --no-progress >out 2>err &&
221
222 test_file_not_empty out &&
223 test_line_count = 0 err
224 )
225 '
226
227 test_expect_success 'git repo structure -h shows only repo structure usage' '
228 git repo structure -h >actual &&
229 test_grep "git repo structure" actual &&
230 test_grep ! "git repo info" actual
231 '
232
233 test_done