git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
897acaa3652d560db0ed84b0c7df7e10a82e25b5 blob 14528 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
 
#!/bin/sh
#
# Copyright (c) 2018 Jiang Xin
#

test_description='Test git pack-redundant

In order to test git-pack-redundant, we will create a number of objects and
packs in the repository `master.git`. The relationship between packs (P1-P8)
and objects (T, A-R) is showed in the following chart. Objects of a pack will
be marked with letter x, while objects of redundant packs will be marked with
exclamation point, and redundant pack itself will be marked with asterisk.

        | T A B C D E F G H I J K L M N O P Q R
    ----+--------------------------------------
    P1  | x x x x x x x                       x
    P2* |     ! ! ! !   ! ! !
    P3  |             x     x x x x x
    P4* |                     ! ! ! !     !
    P5  |               x x           x x
    P6* |                             ! !   !
    P7  |                                 x x
    P8* |   !
    ----+--------------------------------------
    ALL | x x x x x x x x x x x x x x x x x x x

Another repository `shared.git` has unique objects (X-Z), while other objects
(marked with letter s) are shared through alt-odb (of `master.git`). The
relationship between packs and objects is as follows:

        | T A B C D E F G H I J K L M N O P Q R   X Y Z
    ----+----------------------------------------------
    Px1 |   s s s                                 x x x
    Px2 |         s s s                           x x x
'

. ./test-lib.sh

master_repo=master.git
shared_repo=shared.git

# Note: DO NOT run it in a subshell, otherwise the variables will not be set
# Usage: create_commits_in <repo> A B C ...
create_commits_in () {
	repo="$1" &&
	parent=$(git -C "$repo" rev-parse HEAD^{} 2>/dev/null) || parent=
	T=$(git -C "$repo" write-tree) &&
	shift &&
	while test $# -gt 0
	do
		name=$1 &&
		test_tick &&
		if test -z "$parent"
		then
			oid=$(echo $name | git -C "$repo" commit-tree $T)
		else
			oid=$(echo $name | git -C "$repo" commit-tree -p $parent $T)
		fi &&
		eval $name=$oid &&
		parent=$oid &&
		shift ||
		return 1
	done
	git -C "$repo" update-ref refs/heads/master $oid
}

# Note: DO NOT run it in a subshell, otherwise the variables will not be set
create_pack_1 () {
	P1=$(git -C "$master_repo/objects/pack" pack-objects -q pack <<-EOF
		$T
		$A
		$B
		$C
		$D
		$E
		$F
		$R
		EOF
	) &&
	eval P$P1=P1:$P1
}

create_pack_2 () {
	P2=$(git -C "$master_repo/objects/pack" pack-objects -q pack <<-EOF
		$B
		$C
		$D
		$E
		$G
		$H
		$I
		EOF
	) &&
	eval P$P2=P2:$P2
}

create_pack_3 () {
	P3=$(git -C "$master_repo/objects/pack" pack-objects -q pack <<-EOF
		$F
		$I
		$J
		$K
		$L
		$M
		EOF
	) &&
	eval P$P3=P3:$P3
}

create_pack_4 () {
	P4=$(git -C "$master_repo/objects/pack" pack-objects -q pack <<-EOF
		$J
		$K
		$L
		$M
		$P
		EOF
	) &&
	eval P$P4=P4:$P4
}

create_pack_5 () {
	P5=$(git -C "$master_repo/objects/pack" pack-objects -q pack <<-EOF
		$G
		$H
		$N
		$O
		EOF
	) &&
	eval P$P5=P5:$P5
}

create_pack_6 () {
	P6=$(git -C "$master_repo/objects/pack" pack-objects -q pack <<-EOF
		$N
		$O
		$Q
		EOF
	) &&
	eval P$P6=P6:$P6
}

create_pack_7 () {
	P7=$(git -C "$master_repo/objects/pack" pack-objects -q pack <<-EOF
		$P
		$Q
		EOF
	) &&
	eval P$P7=P7:$P7
}

create_pack_8 () {
	P8=$(git -C "$master_repo/objects/pack" pack-objects -q pack <<-EOF
		$A
		EOF
	) &&
	eval P$P8=P8:$P8
}

format_packfiles () {
	sed \
		-e "s#.*/pack-\(.*\)\.idx#\1#" \
		-e "s#.*/pack-\(.*\)\.pack#\1#" |
	sort -u |
	while read p
	do
		if test -z "$(eval echo \${P$p})"
		then
			echo $p
		else
			eval echo "\${P$p}"
		fi
	done |
	sort
}

test_expect_success 'setup master repo' '
	git init --bare "$master_repo" &&
	create_commits_in "$master_repo" A B C D E F G H I J K L M N O P Q R
'

#############################################################################
# Chart of packs and objects for this test case
#
#         | T A B C D E F G H I J K L M N O P Q R
#     ----+--------------------------------------
#     P1  | x x x x x x x                       x
#     P2  |     x x x x   x x x
#     P3  |             x     x x x x x
#     ----+--------------------------------------
#     ALL | x x x x x x x x x x x x x x         x
#
#############################################################################
test_expect_success 'no redundant for pack 1, 2, 3' '
	create_pack_1 && create_pack_2 && create_pack_3 &&
	(
		cd "$master_repo" &&
		git pack-redundant --all >out &&
		test_must_be_empty out
	)
'

test_expect_success 'create pack 4, 5' '
	create_pack_4 && create_pack_5
'

#############################################################################
# Chart of packs and objects for this test case
#
#         | T A B C D E F G H I J K L M N O P Q R
#     ----+--------------------------------------
#     P1  | x x x x x x x                       x
#     P2* |     ! ! ! !   ! ! !
#     P3  |             x     x x x x x
#     P4  |                     x x x x     x
#     P5  |               x x           x x
#     ----+--------------------------------------
#     ALL | x x x x x x x x x x x x x x x x x   x
#
#############################################################################
test_expect_failure 'one of pack-2/pack-3 is redundant (failed on Mac)' '
	(
		cd "$master_repo" &&
		cat >expect <<-EOF &&
			P2:$P2
			EOF
		git pack-redundant --all >out &&
		format_packfiles <out >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'create pack 6, 7' '
	create_pack_6 && create_pack_7
'

#############################################################################
# Chart of packs and objects for this test case
#
#         | T A B C D E F G H I J K L M N O P Q R
#     ----+--------------------------------------
#     P1  | x x x x x x x                       x
#     P2* |     ! ! ! !   ! ! !
#     P3  |             x     x x x x x
#     P4* |                     ! ! ! !     !
#     P5  |               x x           x x
#     P6* |                             ! !   !
#     P7  |                                 x x
#     ----+--------------------------------------
#     ALL | x x x x x x x x x x x x x x x x x x x
#
#############################################################################
test_expect_failure 'pack 2, 4, and 6 are redundant (failed on Mac)' '
	(
		cd "$master_repo" &&
		cat >expect <<-EOF &&
			P2:$P2
			P4:$P4
			P6:$P6
			EOF
		git pack-redundant --all >out &&
		format_packfiles <out >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'create pack 8' '
	create_pack_8
'

#############################################################################
# Chart of packs and objects for this test case
#
#         | T A B C D E F G H I J K L M N O P Q R
#     ----+--------------------------------------
#     P1  | x x x x x x x                       x
#     P2* |     ! ! ! !   ! ! !
#     P3  |             x     x x x x x
#     P4* |                     ! ! ! !     !
#     P5  |               x x           x x
#     P6* |                             ! !   !
#     P7  |                                 x x
#     P8* |   !
#     ----+--------------------------------------
#     ALL | x x x x x x x x x x x x x x x x x x x
#
#############################################################################
test_expect_failure 'pack-8 (subset of pack-1) is also redundant (failed on Mac)' '
	(
		cd "$master_repo" &&
		cat >expect <<-EOF &&
			P2:$P2
			P4:$P4
			P6:$P6
			P8:$P8
			EOF
		git pack-redundant --all >out &&
		format_packfiles <out >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'clean loose objects' '
	(
		cd "$master_repo" &&
		git prune-packed &&
		find objects -type f | sed -e "/objects\/pack\//d" >out &&
		test_must_be_empty out
	)
'

test_expect_failure 'remove redundant packs and pass fsck (failed on Mac)' '
	(
		cd "$master_repo" &&
		git pack-redundant --all | xargs rm &&
		git fsck &&
		git pack-redundant --all >out &&
		test_must_be_empty out
	)
'

# The following test cases will execute inside `shared.git`, instead of
# inside `master.git`.
test_expect_success 'setup shared.git' '
	git clone --mirror "$master_repo" "$shared_repo" &&
	(
		cd "$shared_repo" &&
		printf "../../$master_repo/objects\n" >objects/info/alternates
	)
'

test_expect_failure 'no redundant packs without --alt-odb (failed on Mac)' '
	(
		cd "$shared_repo" &&
		git pack-redundant --all >out &&
		test_must_be_empty out
	)
'

#############################################################################
# Chart of packs and objects for this test case
#
#     ================ master.git ===============
#         | T A B C D E F G H I J K L M N O P Q R  <----------+
#     ----+--------------------------------------             |
#     P1  | x x x x x x x                       x             |
#     P3  |             x     x x x x x                       |
#     P5  |               x x           x x                   |
#     P7  |                                 x x               |
#     ----+--------------------------------------             |
#     ALL | x x x x x x x x x x x x x x x x x x x             |
#                                                             |
#                                                             |
#     ================ shared.git ===============             |
#         | T A B C D E F G H I J K L M N O P Q R  <objects/info/alternates>
#     ----+--------------------------------------
#     P1* | s s s s s s s                       s
#     P3* |             s     s s s s s
#     P5* |               s s           s s
#     P7* |                                 s s
#     ----+--------------------------------------
#     ALL | x x x x x x x x x x x x x x x x x x x
#
#############################################################################
test_expect_failure 'pack-redundant --verbose: show duplicate packs in stderr (failed on Mac)' '
	(
		cd "$shared_repo" &&
		cat >expect <<-EOF &&
			P1:$P1
			P3:$P3
			P5:$P5
			P7:$P7
			EOF
		git pack-redundant --all --verbose >out 2>out.err &&
		test_must_be_empty out &&
		grep "pack$" out.err | format_packfiles >actual &&
		test_cmp expect actual
	)
'

test_expect_success 'remove redundant packs by alt-odb, no packs left' '
	(
		cd "$shared_repo" &&
		cat >expect <<-EOF &&
			fatal: Zero packs found!
			EOF
		git pack-redundant --all --alt-odb | xargs rm &&
		git fsck &&
		test_must_fail git pack-redundant --all --alt-odb >actual 2>&1 &&
		test_cmp expect actual
	)
'

# Note: DO NOT run function `create_pack_*` in sub shell, or variables are not set
create_pack_x1_in () {
	repo="$1" &&
	Px1=$(git -C "$repo/objects/pack" pack-objects -q pack <<-EOF
		$X
		$Y
		$Z
		$A
		$B
		$C
		EOF
	) &&
	eval P${Px1}=Px1:${Px1}
}

create_pack_x2_in () {
	repo="$1" &&
	Px2=$(git -C "$repo/objects/pack" pack-objects -q pack <<-EOF
		$X
		$Y
		$Z
		$D
		$E
		$F
		EOF
	) &&
	eval P${Px2}=Px2:${Px2}
}

test_expect_success 'create new objects and packs in shared.git' '
	create_commits_in "$shared_repo" X Y Z &&
	create_pack_x1_in "$shared_repo" &&
	create_pack_x2_in "$shared_repo"
'

test_expect_success 'no redundant without --alt-odb' '
	(
		cd "$shared_repo" &&
		git pack-redundant --all >out &&
		test_must_be_empty out
	)
'

#############################################################################
# Chart of packs and objects for this test case
#
#     ================ master.git ===============
#         | T A B C D E F G H I J K L M N O P Q R  <----------------+
#     ----+--------------------------------------                   |
#     P1  | x x x x x x x                       x                   |
#     P3  |             x     x x x x x                             |
#     P5  |               x x           x x                         |
#     P7  |                                 x x                     |
#     ----+--------------------------------------                   |
#     ALL | x x x x x x x x x x x x x x x x x x x                   |
#                                                                   |
#                                                                   |
#     ================ shared.git =======================           |
#         | T A B C D E F G H I J K L M N O P Q R   X Y Z <objects/info/alternates>
#     ----+----------------------------------------------
#     Px1 |   s s s                                 x x x
#     Px2*|         s s s                           ! ! !
#     ----+----------------------------------------------
#     ALL | s s s s s s s s s s s s s s s s s s s   x x x
#
#############################################################################
test_expect_success 'one pack is redundant' '
	(
		cd "$shared_repo" &&
		git pack-redundant --all --alt-odb >out &&
		format_packfiles <out >actual &&
		test_line_count = 1 actual
	)
'

#############################################################################
# Chart of packs and objects for this test case
#
#     ================ master.git ===============
#         | T A B C D E F G H I J K L M N O P Q R  <----------------+
#     ----+--------------------------------------                   |
#     P1  | x x x x x x x                       x                   |
#     P3  |             x     x x x x x                             |
#     P5  |               x x           x x                         |
#     P7  |                                 x x                     |
#     ----+--------------------------------------                   |
#     ALL | x x x x x x x x x x x x x x x x x x x                   |
#                                                                   |
#                                                                   |
#     ================ shared.git =======================           |
#         | T A B C D E F G H I J K L M N O P Q R   X Y Z <objects/info/alternates>
#     ----+----------------------------------------------
#     Px1*|   s s s                                 i i i
#     Px2*|         s s s                           i i i
#     ----+----------------------------------------------
#     ALL | s s s s s s s s s s s s s s s s s s s   i i i
#                                                  (ignored objects, marked with i)
#
#############################################################################
test_expect_success 'set ignore objects and all two packs are redundant' '
	(
		cd "$shared_repo" &&
		cat >expect <<-EOF &&
			Px1:$Px1
			Px2:$Px2
			EOF
		git pack-redundant --all --alt-odb >out <<-EOF &&
			$X
			$Y
			$Z
			EOF
		format_packfiles <out >actual &&
		test_cmp expect actual
	)
'

test_done
debug log:

solving 897acaa365 ...
found 897acaa365 in https://public-inbox.org/git/20190201162152.31136-5-worldhello.net@gmail.com/
found d224ff3c50 in https://public-inbox.org/git/20190201162152.31136-2-worldhello.net@gmail.com/

applying [1/2] https://public-inbox.org/git/20190201162152.31136-2-worldhello.net@gmail.com/
diff --git a/t/t5323-pack-redundant.sh b/t/t5323-pack-redundant.sh
new file mode 100755
index 0000000000..d224ff3c50


applying [2/2] https://public-inbox.org/git/20190201162152.31136-5-worldhello.net@gmail.com/
diff --git a/t/t5323-pack-redundant.sh b/t/t5323-pack-redundant.sh
index d224ff3c50..897acaa365 100755

Checking patch t/t5323-pack-redundant.sh...
Applied patch t/t5323-pack-redundant.sh cleanly.
Checking patch t/t5323-pack-redundant.sh...
Applied patch t/t5323-pack-redundant.sh cleanly.

index at:
100755 897acaa3652d560db0ed84b0c7df7e10a82e25b5	t/t5323-pack-redundant.sh

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox