-
Notifications
You must be signed in to change notification settings - Fork 5
/
test-push-perforce
executable file
·682 lines (512 loc) · 11.5 KB
/
test-push-perforce
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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
#!/bin/sh
set -e
HELP=0
DEBUG=0
DOSHELL=0
P4PWD=`pwd`
P4ROOT=$P4PWD/depot
P4D=p4d
KEEP=true
ENCODING=
UNICODE=0
while getopts "de:k:p:r:sux" OPT ; do
case "$OPT" in
d)
DEBUG=1
;;
e)
ENCODING=$OPTARG
;;
k)
KEEP=$OPTARG
;;
p)
P4D=$OPTARG
;;
r)
P4ROOT=$OPTARG
;;
s)
DOSHELL=1
;;
u)
UNICODE=1
;;
x)
set -x
;;
\?)
HELP=1
break
;;
esac
done
shift $(($OPTIND-1))
if [ $HELP -ne 0 ] ; then
echo "Usage: $0 [-dekprsu]"
exit 1
fi
# ..........................................................................
P4CHARSET=
P4CONFIG=
P4DIFF=
P4EDITOR=
P4PASSWD=
P4PORT=
P4USER=
# test we have p4 available
if [ -n "$TESTDIR" ] ; then
"$TESTDIR/hghave" p4 || exit 80
fi
# set up p4 environment
export P4ROOT
P4AUDIT=$P4ROOT/audit; export P4AUDIT
P4JOURNAL=$P4ROOT/journal; export P4JOURNAL
P4LOG=$P4ROOT/log; export P4LOG
if [ -z "$HGPORT" ] ; then
HGPORT=16661
fi
P4PORT=localhost:$HGPORT; export P4PORT
P4DEBUG=$DEBUG; export P4DEBUG
P4CLIENT=hg-p4-import; export P4CLIENT
DEPOTPATH=//depot/test-mercurial-push
unset P4CONFIG
unset P4DIFF
unset P4EDITOR
unset P4PASSWD
unset P4USER
# set up Mercurial environment
if [ -n "$ENCODING" ] ; then
export HGENCODING=utf-8
fi
if [ -z "$HGRCPATH" ] ; then
HGRCPATH=$P4PWD/.hgrc ; export HGRCPATH
fi
cat <<EOF >$HGRCPATH
[ui]
username=perfarce
[paths]
default = p4://$P4PORT/$P4CLIENT
[extensions]
convert=
graphlog=
perfarce=$P4PWD/perfarce.py
[perfarce]
keep = $KEEP
EOF
echo % create p4 depot
if [ $DEBUG -ne 0 ] ; then
HG="hg --debug --traceback"
filter() {
cat
}
else
HG="hg"
filter() {
sed -r -e 's,[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9][0-9] [0-9]{2}:[0-9]{2}:[0-9]{2} [0-9]{4} \+[0-9]{4},DATE,' \
-e 's,[0-9]{4}/[0-9]{2}/[0-9]{2},DATE,' \
-e 's,[0-9]{2}:[0-9]{2}:[0-9]{2},TIME,' \
-e 's/[a-z]+@/USER@/' \
-e 's/[0-9a-f]{40}/HGID40/g' \
-e 's/[0-9a-f]{12}/HGID12/g' \
-e 's!'$P4PWD'!P4PWD!g'
}
fi
DATA=0
data() {
echo $DATA
DATA=$((DATA+1))
}
rm -fr $P4ROOT $P4PWD/src $P4PWD/dst $P4PWD/dst2 $P4PWD/dst3 $P4PWD/new || true
echo % start the p4 server
[ ! -d $P4ROOT ] && mkdir $P4ROOT
# start server
$P4D -f -J off >$P4ROOT/stdout 2>$P4ROOT/stderr &
# wait for the server to initialize
while ! p4 ; do
sleep 1
done >/dev/null 2>/dev/null
if [ $UNICODE -ne 0 ] ; then
# stop it
p4 admin stop
sleep 1
# convert database
$P4D -xi
sleep 1
# restart server
$P4D -f -J off >$P4ROOT/stdout 2>$P4ROOT/stderr &
P4CHARSET=$ENCODING
export P4CHARSET
# wait for the server to initialize
while ! p4 ; do
sleep 1
done >/dev/null 2>/dev/null
fi
export DOSHELL
cleanup() {
if [ $DOSHELL -ne 0 ] ; then
echo % run bash
env | sed -r -e '/^P4/! d' -e 's/P4/export\ P4/'
if [ -n "$SRC" ] ; then
env | sed -r -e '/^P4/! d' >$SRC/.p4config
export P4CONFIG=.p4config
fi
bash
if [ -n "$SRC" ] ; then
rm $SRC/.p4config
fi
fi
echo % stop the p4 server
p4 admin stop
}
trap cleanup EXIT
echo % create a client spec
mkdir src
cd src
SRC=$PWD
p4 client -o | sed '/^View:/,$ d' >p4client-$$
echo View: >>p4client-$$
echo " $DEPOTPATH/... //$P4CLIENT/..." >>p4client-$$
p4 client -i <p4client-$$
rm p4client-$$
echo % populate the depot
data > a
mkdir b
data > b/c
p4 add a b/c
p4 submit -d initial
p4 tag -l change-one ...
echo % change some files
p4 edit a
data >> a
p4 submit -d "p4 change a"
data >> '$dollar.txt'
p4 add '$dollar.txt'
p4 submit -d "p4 add dollar"
/bin/echo -e -n 'u\x00t\x00f\x001\x006\x00\n\x00' >utf16
p4 add -t utf16 'utf16'
p4 submit -d "p4 add utf16"
p4 edit b/c
data >> b/c
p4 submit -d "p4 change b/c"
data >>b/d
p4 add b/d
p4 submit -d "p4 add b/d"
p4 tag -l change-four ...
p4 delete b/c
p4 submit -d "p4 delete b/c"
cd ..
hg version
# ..........................................................................
echo % convert
if ! $HG convert -s p4 $DEPOTPATH/... dst; then
# hg convert is broken for Mercurial 4.6 to 5.6.1
rm -rf dst
$HG clone p4://$P4PORT/$P4CLIENT dst
fi
echo % now work in hg
cd dst
$HG up
check_contents() {
hg glog --template '{rev} {p4} "{desc|firstline}" files: {files}\n' | filter
hg manifest | grep -v '.hgtags' | xargs md5sum
}
check_contents
echo % nothing incoming
if $HG incoming ; then
false
fi
echo % nothing outgoing
if $HG outgoing ; then
false
fi
echo % change some files in hg
data >> a
$HG commit -m "hg change a"
data >> b/e
$HG add b/e
$HG ci -m "hg add b/e"
data >>b/d
$HG commit -m "hg change b/d"
echo % id
$HG p4identify | filter
echo % outgoing
$HG outgoing | filter
echo % skip a changelist
p4 change -o | sed -r 's/<.+>/test/' >change.$$
p4 change -d $(p4 change -i <change.$$ | awk '/created/ { print $2 }')
rm change.$$
echo % push
$HG push
echo % p4pending
$HG p4pending | filter
echo % pending
$HG p4pending | filter
echo % submit
$HG p4submit -a
echo % echo % p4pending
$HG p4pending | filter
echo % pending
$HG p4pending | filter
echo % outgoing
$HG outgoing | filter
echo % p4 results
cd ../src
p4 changes | filter
p4 describe -s 7 | filter
p4 tag -l change-seven ...
cd ../dst
echo % incoming
$HG incoming | filter
echo % pull
$HG pull --update
check_contents
echo % push submit
data >a
data >c
$HG add c
$HG ci -m "ac" a c
$HG push --submit
echo % echo % p4pending
$HG p4pending | filter
echo % hg tag
$HG pull --update
$HG tag -r 5 tag-created-in-hg
$HG push --submit
echo % copy files
$HG cp a aa
$HG commit -m "hg copy a"
$HG push -r tip --submit
echo % move files
$HG mv c cc
$HG commit -m "hg move c"
$HG push -r tip --submit
echo % move dir
$HG mv b bb
$HG commit -m "hg move b"
$HG push -r tip --submit
$HG pull --update
echo % push repeatedly
data >a
$HG commit -m "hg a once"
$HG push -r tip --submit
data >a
$HG commit -m "hg a twice"
$HG push -r tip --submit
data >cc
$HG commit -m "hg cc once"
$HG push -r tip --submit
data >a
$HG commit -m "hg a again"
$HG push -r tip --submit
echo % show tags
hg tags | filter
# ..........................................................................
SERVER=$(p4 info|sed -r -e '/Server version/!d' -e 's,[^/]+/[^.]+/([^/]+)/.+$,\1,' -e 's/\..+$//' )
echo % server version $SERVER
if [ $SERVER -ge 2009 ] ; then
echo % p4 move, new in p4 2009.1
cd ../src
p4 sync | filter
echo % new style move
data >f
p4 add f
p4 submit -d new-f
p4 tag -l change-sixteen ...
p4 edit f
p4 move f g
p4 submit -d move-f-to-g
cd ../dst
$HG pull --update
check_contents
fi
# ..........................................................................
if [ $SERVER -ge 2011 ] ; then
echo % p4 copy, new in p4 2010.2
cd ../dst
$HG pull -u
$HG copy a ac
$HG ci -m "copy with p4 copy"
$HG push --submit --config perfarce.copy=true --config perfarce.move=true
# ..........................................................................
echo % copy with edit
$HG copy a ace1
data >>ace1
$HG ci -m "copy+edit with p4 copy"
$HG push --submit --config perfarce.copy=true --config perfarce.move=true
echo % copy/integrate with edit
$HG copy a ace2
data >>ace2
$HG ci -m "copy+edit with p4 integ"
$HG push --submit --config perfarce.copy=false --config perfarce.move=false
echo % move with edit
$HG mv ace1 acm1
data >>acm1
$HG ci -m "move+edit with p4 copy"
$HG push --submit --config perfarce.copy=true --config perfarce.move=true
echo % move/integrate with edit
$HG mv ace2 acm2
data >>acm2
$HG ci -m "move+edit e with p4 integ"
$HG push --submit --config perfarce.copy=false --config perfarce.move=false
fi
# ..........................................................................
if [ $SERVER -ge 2005 ] ; then
echo % overlay mappings, new in p4 2004.2
cd ../src
p4 sync | filter
mkdir h
data > h/j
p4 add h/j
p4 submit -d "p4 add h/j"
p4 client -o >p4client-$$
echo " -$DEPOTPATH/h/... //$P4CLIENT/h/..." >>p4client-$$
echo " +$DEPOTPATH/h/... //$P4CLIENT/..." >>p4client-$$
p4 client -i <p4client-$$
p4 sync -f | filter
cd ../dst
$HG pull --update
check_contents
fi
# ..........................................................................
if [ -n "$ENCODING" ] ; then
echo % encoding
cd ../src
p4 sync | filter
data >k
p4 add k
p4 submit -d "add k special $(/bin/echo -e "\300\301\302\303\304\305\306\307") chars"
cd ../dst
if [ $UNICODE -eq 0 ] ; then
echo "[perfarce]" >>.hg/hgrc
echo "encoding=$ENCODING" >>.hg/hgrc
fi
$HG pull --update
data >k
$HG commit -m "hg change k special $(/bin/echo -e "\303\260\303\261\303\262\303\263\303\264\303\265\303\266\303\267") chars"
$HG push --submit
check_contents
fi
# ..........................................................................
echo % escaped characters initiated on p4 side
cd ../src
p4 sync | filter
data > '@'
data > '#'
data > '%'
data > '*'
p4 add -f '@' '#' '%' '*'
p4 submit -d 'p4 add @ # % *'
data > '%#@#%*@'
p4 add -f '%#@#%*@'
p4 submit -d 'p4 add %#@#%*@'
p4 edit '%40' ; data > '@' ; p4 submit -d 'p4 change @'
p4 edit '%23' ; data > '#' ; p4 submit -d 'p4 change #'
p4 edit '%25' ; data > '%' ; p4 submit -d 'p4 change %'
p4 edit '%2A' ; data > '*' ; p4 submit -d 'p4 change *'
p4 edit '%25%23%40%23%25%2A%40'
data > '%#@#%*@'
p4 submit -d 'p4 change %#@#%*@'
cd ../dst
$HG pull --update
check_contents
# ..........................................................................
echo % escaped characters initiated on hg side
data > '#@'
data > '*%'
$HG add '#@' '*%'
$HG ci -m 'hg add #@ *%'
$HG push --submit
data > '@'
data > '#'
$HG ci -m 'hg modify @ #'
$HG rm '%'
$HG ci -m 'hg remove %'
data > '*'
data > '%#@#%*@'
$HG ci -m 'hg modify * %#@#%*@'
$HG push --submit
check_contents
cd ../src
p4 sync
# ..........................................................................
echo % clone
cd ..
$HG clone ${ENCODING:+--encoding $ENCODING} p4://$P4PORT/$P4CLIENT dst2
cd dst2
$HG up
check_contents
cd ../src
echo % merge/pull test
data >f1
p4 add f1
p4 submit -d "add f1 - repo"
p4 edit f1
data >f1
data >f2
p4 add f2
p4 submit -d "add f2, mod f1 - repo"
p4 edit f2
data >f2
data >f3
p4 add f3
p4 submit -d "add f3, mod f2 - repo"
cd ../dst
$HG pull
$HG up
data >f2
data >f4
$HG add f4
$HG ci -m "add f4, mod f2 - clone"
data >f1
data >f5
$HG add f5
$HG ci -m "add f5, mod f1 - clone"
data >f3
data >f6
$HG add f6
$HG ci -m "add f6, mod f3 - clone"
cd ../src
p4 edit f1
p4 edit f2
data >f1
data >f2
data >f7
p4 add f7
p4 submit -d "add f7, mod f1, mod f2 - repo"
p4 edit f1
p4 edit f2
data >f1
data >f2
p4 submit -d "mod f1, mod f2 - repo"
p4 edit f2
data >f2
p4 delete f1
p4 submit -d "mod f2, del f1 - repo"
p4 edit f3
data >f3
p4 submit -d "mod f3 - repo"
cd ../dst
echo % pull before merge
$HG pull
echo % merge
echo d | hg merge --config ui.merge=internal:other
$HG ci -m "merge"
$HG push
cd ..
echo % partial clone
$HG clone ${ENCODING:+--encoding $ENCODING} p4://$P4PORT/$P4CLIENT/bb dst3
cd dst3
$HG up
check_contents
echo % partial push
data >>d
data >>e
$HG ci -m "hg partial d,e"
$HG push --submit
cd ../dst2
$HG pull -u
cmp -s bb/d ../dst3/d
cmp -s bb/e ../dst3/e
echo % done
# EOF