summaryrefslogtreecommitdiff
path: root/growth.sh
blob: 63eaf79d1701e942e8b3a9893758741b6d505c9a (plain)
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
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
#!/bin/bash
#
# growth.sh
#
# Copyright (C) 2015 Linaro, Ltd
# Andy Green <andy.green@linaro.org>
# Licensed under GPL2.1
#
# Please run the script with no args to get comprehensive help
#
# Note on sqlite3 usage
#
# The sqlite3 db generated here is just caching analysis the script
# generated itself.  You can delete it and the script will recreate an
# empty one automatically, but you will have to regenerate the runs
# that were stored in it.
#
# Having the data cached there is helpful both is making complex queries
# that are difficult to reproduce using cut, sed. sort etc and in allowing
# quick development of new graphs and queries without the cost of generating
# the data each time.


DB=growth.sq3
SCHEMA_VER=1

BP=
DIRCOL=0
rm -f .cols.tmp
touch .cols.tmp
rm -f .first-phase

function sq3()
{
	sqlite3 $DB "$1"
	if [ $? -ne 0 ] ; then
		echo "sqlite error"
		echo $1
		exit 1
	fi
}

# number of preset columns before dir ones
OFFSET_COLS=8

# return col num of dirname in DIRCOL
# $1: dirname

# $1: basis branch, $2: starting tree

function basis_point()
{
	echo basis_point $1 $2

	BP=`diff -u <(git rev-list --first-parent $2) \
		    <(git rev-list --first-parent $1) | \
		    sed -ne 's/^ //p' | head -1`

	echo result $BP
}

# $1: basis branch, $2: empty or comparison ref, $3: basis point if known
# $4: index in sequence, $5: run_key we are attached to

function make_stat()
{
	local CB
	local BASIS
	local COMP
	local DS
	local DS_BASIS
	local STATS

	CB="$2"
	if [ -z "$3" ] ; then
		basis_point $1 $CB
	else
		BP=$3
	fi

	BASIS=`git describe $BP`
	COMP=`git describe $CB`
	DS=`git log -n 1 $CB --format=format:%ct`
	DS_BASIS=`git show $BP --format=format:%ct | head -n1`

	echo "git diff $BP..$CB --shortstat"


	F="`git diff $BP..$CB --shortstat`"
	FILES=`echo $F | cut -d' ' -f1`
	ADD=`echo $F | cut -d' ' -f4`
	REM=`echo $F | cut -d' ' -f6`

	sq3 "insert into snapshots (run_idx, ref_name, ref_date, \
			basis_name, basis_date, files_changed, \
			loc_added, loc_removed) \
		values ($5, \"$COMP\", $DS, \"$BASIS\", $DS_BASIS, \
			$FILES, $ADD, $REM);"
	SKEY=`sq3 "select seq from sqlite_sequence where \
			name=\"snapshots\""`

	git diff $BP..$CB --numstat | while read i ; do

		F="`echo $i | cut -d' '  -f3`"
		ADD=`echo $i | cut -d' '  -f1`
		REM=`echo $i | cut -d' ' -f2`

		if [ "$ADD" != "-" -a \
			-z "`echo $F | grep gitignore`" \
		] ; then

			DEPTH=`echo "$F" | sed "s|[^/]||g" | wc -c`

		sq3 "insert into dir_summary (snap_idx, run_key, dir_name, \
				dir_depth, loc_added, loc_removed) \
			values ($SKEY, $5, \"$F\", $DEPTH, $ADD, $REM);"
		fi
	done

}

# $1: stats file, $2: y axis, $3: output, $4: title

function issue_plot_time()
{
	cat >plot.tmp <<EOF
set terminal pngcairo notransparent noenhanced font "arial,10" size 660, 320 
set output '$2'
set title "$3" 
set yrange [ 0 : ] noreverse nowriteback
set lmargin  9
set rmargin  2
set autoscale xfixmin
set xdata time
set termoption dash
set timefmt "%s"
set key autotitle columnhead
plot $1
EOF

	>&2 echo "creating $3"
	gnuplot plot.tmp
}

# $1: stats file, $2: y axis, $3: output, $4: title, $5: dimensions

function issue_plot_file_dist()
{
	cat >plot.tmp <<EOF
set terminal pngcairo notransparent noenhanced font "arial,10" size $5
set output '$3'
set title "$4" 
set yrange [ $2 ] noreverse nowriteback
set lmargin  9
set rmargin  2
set autoscale xfixmin
#set xdata time
set termoption dash
set timefmt "%s"
set key autotitle columnhead
set style fill transparent solid 0.5 noborder
set xtics rotate
set style data histogram
#set logscale y
set label "$6" at graph 0.96,0.8 right

plot $1
#set yrange [ $2 ] reverse
#plot $7

EOF

	>&2 echo "creating $3"
	gnuplot plot.tmp

	if [ $? -ne 0 ] ; then
		>&2 echo "Deleting failed plot $3"
		rm -f $3
	fi
}


# create schema

# one of these for each comparison run

sq3 "create table if not exists runs (\
	run_key integer primary key autoincrement, \
	basis_hash varchar(50), \
	comp_hash varchar(50), \
	tags integer, \
	schema_ver integer \
);"

# one of these for each snapshot compared

sq3 "create table if not exists snapshots (\
	snap_idx integer primary key autoincrement, \
	run_idx integer, \
	ref_name varchar(50), \
	ref_date integer, \
	basis_name varchar(50), \
	basis_date integer, \
	files_changed integer, \
	loc_added integer, \
	loc_removed integer \
);"

# one of these for each dir changed in the snapshot
# we have run_key here as well since it simplifies finding all paths

sq3 "create table if not exists dir_summary (\
	key integer primary key autoincrement, \
	snap_idx integer, \
	run_key integer, \
	dir_name varchar(150), \
	dir_depth integer, \
	loc_added integer, \
	loc_removed integer \
);"

if [ -z "$1" ] ; then
	>&2 echo ""
	>&2 echo "Usage: $0 <basis branch> --tags <tag regexp>"
	>&2 echo "       $0 --plot <run #> [ subdir ]"
	>&2 echo "       $0 --plot <run # a> < - | subdir > <run # b>"
	>&2 echo ""
	>&2 echo "$0 can be run in two modes, either create a 'run' in"
	>&2 echo "the sqlite3 db cache, or create graphs about one or"
	>&2 echo "comparing two runs already in the db cache"
	>&2 echo ""
	>&2 echo "Creating a 'run' from one or more tags"
	>&2 echo "--------------------------------------"
	>&2 echo ""
	>&2 echo "A 'run' is created by studying one or more tags against"
	>&2 echo "a 'basis branch' to isolate the patches on top of the"
	>&2 echo "tag's basis point.  So if you have a kernel branch that"
	>&2 echo "is tracking mainline, the various tags you have on that"
	>&2 echo "kernel branch may be based on different mainline versions."
	>&2 echo "$0 can autodiscover for each tag where the basis point is"
	>&2 echo "if you just give him the basis branch name, eg, 'mainline'."
	>&2 echo ""
	>&2 echo " \$ $0 mainline --tags mybranch-tagname-regexp"
	>&2 echo ""
	>&2 echo "Notice that the tag name to analyze on one 'run' is a regexp."
	>&2 echo "It's fine to have many tags analyzed in one 'run'."
	>&2 echo ""
	>&2 echo "When the run starts, the run number is reported and you"
	>&2 echo "should make a note of it and which tag(s) it contains"
	>&2 echo ""
	>&2 echo "Plotting graphs from one or two runs"
	>&2 echo "------------------------------------"
	>&2 echo ""
	>&2 echo "After the analysis for the tags you are interested in has"
	>&2 echo "been captured into 'runs' in the sqlite3 db cache, you can"
	>&2 echo "run the script to produce png and gif graphs showing or"
	>&2 echo "comparing the data from different runs."
	>&2 echo ""
	>&2 echo "There's no requirement at all that the different runs have"
	>&2 echo "anything in common in their history, basis or content,"
	>&2 echo "giving a lot of flexibility in the comparisons."
	>&2 echo ""
	>&2 echo "To produce graphs about one run itself:"
	>&2 echo ""
	>&2 echo " \$ $0 --plot <run #> [ subdir ]"
	>&2 echo ""
	>&2 echo "If subdir is missing, the whole tree is analysed, if given"
	>&2 echo "the analysis is restricted to the subdirectory given."
	>&2 echo ""
	>&2 echo "To produce graphs comparing two runs:"
	>&2 echo ""
	>&2 echo " \$ $0 --plot <run # a> < - | subdir > <run # b>"
	>&2 echo ""
	>&2 echo "If there is no subdir restriction, - must be given."
	>&2 echo ""
	>&2 echo "When comparing two runs like this, <run # a> may contain"
	>&2 echo "many tags but <run # b> must contain only one tag."
	>&2 echo ""
	>&2 echo "Graphs will be produced with the union of information"
	>&2 echo "from run a and run b, showing run a in blue and run b in red."

	exit 1
fi

LEVELS=1,2
FILTER=$3
if [ "$FILTER" = "-" ] ; then
	FILTER=
fi

FILTERLEN=${#FILTER}
F_DEPTH=`echo "$FILTER" | sed "s|[^/]||g" | wc -c`

if [ ! -z "$FILTER" ] ; then
	if [ $F_DEPTH == 1 ] ; then
		LEVELS=1,2,3
	else if [ $F_DEPTH == 2 ] ; then
		LEVELS=1,2,3,4
		else if [ $F_DEPTH == 3 ] ; then
			LEVELS=1,2,3,4,5
			else
				LEVELS=1,2,3,4,5,6
			fi
		fi
	fi
fi

#
# plot mode
#

if [ "$1" = "--plot" ] ; then

	PLOT_RUN=$2
	COMP_RUN=$4

	R=`sq3 "select comp_hash,basis_hash from runs where run_key=$PLOT_RUN"|\
		tr '|' '-'`

	#
	# get a list of snapshot idxs for both runs combined
	#

	if [ ! -z "$COMP_RUN" ] ; then
		RUN_IDX_COMP="(run_idx=$PLOT_RUN or run_idx=$COMP_RUN)"
		RUN_KEY_COMP="(run_key=$PLOT_RUN or run_key=$COMP_RUN)"
		CR=`sq3 "select comp_hash,basis_hash from runs where \
			run_key=$COMP_RUN" | tr '|' '-'`
		R="$R"-VS-$CR
	else
		RUN_IDX_COMP="run_idx=$PLOT_RUN"
		RUN_KEY_COMP="run_key=$PLOT_RUN"
	fi
echo $R
	# our snapshots
	SN=`sq3 "select snap_idx from snapshots where run_idx=$PLOT_RUN"`

	# there's a comparison snapshot?
	SNC=
	if [ ! -z "$COMP_RUN" ] ; then
		SNC=`sq3 "select snap_idx from snapshots where run_idx=$COMP_RUN"`
		COUNT=
		for i in $SNC ; do
			if [ ! -z "$COUNT" ] ; then
				>&2 echo "Must be single comparison snapshot"
				exit 1
			fi
			COUNT=x
		done
	fi

	rm -f .plot.tmp .plot.cols .plot.cols1 .plot.dist

	#
	# using both runs if two given,
	# create the column header row, and fill .plot.cols with the
	# list of files / dirs changed in this view of the diff
	# 

	echo -n "basis_name basis_date ref_name ref_date files add del " \
								> .plot.tmp
	sq3 "select dir_name from dir_summary where \
		$RUN_KEY_COMP and \
		substr(dir_name, 1, $FILTERLEN)=\"$FILTER\" \
		order by loc_added,loc_removed asc" | \
		cut -d'/' -f$LEVELS | while read i ; do
		if [ ! -z "`echo "$i" | grep ^Documentation/`" ] ; then
			echo "Documentation" >> .plot.cols1
		else
			if [ "$i" != "." ] ; then
				# don't allow individual files
				if [ ! -d "$i" ] ; then
					dirname $i >> .plot.cols1
				else
					echo $i >> .plot.cols1
				fi
			fi
		fi
	done

	#
	# put the column titles in place and write out the
	# filtered list of files/dirs we will care about
	#
	cat .plot.cols1 | sort | uniq | while read i ; do
		echo -n "$i " >> .plot.tmp
		echo $i >> .plot.cols
	done
	echo >> .plot.tmp

	#
	# find out how many snapshots created by the run he's using
	# it doesn't include any comparison snapshot
	#
	N=0
	for i in $SN ; do
		N=$(( $N + 1 ))
	done

	# how many files were changed
	CHANGEDFILES=`wc -l .plot.cols | cut -d' ' -f1`

	>&2 echo "Studying $N snapshots"
	>&2 echo "Total $CHANGEDFILES files changed"

	#
	# For each snapshot, go through the list of changed files/dirs and
	# find out how much changed there in that snapshot
	#
	T=1
	for i in $SN ; do
		L=`sq3 "select basis_name, basis_date, ref_name, \
			ref_date, files_changed, loc_added, loc_removed\
			from snapshots where snap_idx=$i" | tr '|' ' '`
		echo -n $L >> .plot.tmp

		>&2 echo -n -e "Snapshot $T/$N: `echo $L | cut -d' ' -f3`      \r"
		T=$(( $T + 1 ))

		cat .plot.cols | while read j ; do
			JLEN=${#j}

			# are we going to deal with his subdirs?
			if [ -z "`cat .plot.cols | grep "$j/"`" ] ; then

				# everything inside this dir
				A=`sq3 "select sum(loc_added) \
					from dir_summary where \
					 snap_idx=$i and \
					 substr(dir_name, 1, $JLEN)=\"$j\"\
					" | head -n1`

			else
				# it's truncated, so only files in this dir
				# eg arch, but arch/arm is handled elsewhere

				DEP=$(( `echo "$j" | sed "s|[^/]||g" | \
					wc -c` + 1 ))
				A=`sq3 "select sum(loc_added) \
					from dir_summary where\
				 	snap_idx=$i and \
					substr(dir_name, 1, $JLEN)=\"$j\" and \
					dir_depth=$DEP" | head -n1`
			fi

			if [ -z "$A" ] ; then
				echo -n "0 " >> .plot.tmp
			else
				echo -n "$A " >> .plot.tmp
			fi
		done
		echo >> .plot.tmp
	done

	>&2 echo

	#
	# for plots related to changes over time, we can do them now
	#

	issue_plot_time "'.plot.tmp' using \
		4:6 notitle  with filledcurve y1=0 lc rgb \"#0000ff\"" \
		"growth-$R-LOC.png" "$R growth in LOC"

	issue_plot_time "'.plot.tmp' using \
		4:( (\$4-\$2)/(24 * 3600) ) notitle \
		with filledcurve y1=0 lc rgb \"#0000ff\"" \
		   "growth-$R-basis-age.png" "$R growth basis age (days)"

	rm -f .plot.tmp1

	#
	# for each file / dir that has changes in any snapshot, for each
	# snapshot calculate its changes and create a unified plot data file
	#
	echo 0 > .biggest
	echo 0 > .next-biggest
	echo 10000000 > .smallest

	T=1
	cat .plot.cols | while read j ; do

		>&2 echo -n -e "File $T/$CHANGEDFILES    \r"
		T=$(( $T + 1 ))

		echo -n "$j " >> .plot.tmp1

		BIGGEST=`cat .biggest`
		NEXT_BIGGEST=`cat .next-biggest`

		SMALLEST=`cat .smallest`

		JLEN=${#j}

		for i in $SN $SNC ; do
			if [ -z "`cat .plot.cols | grep "$j/"`" ] ; then
				# everything inside the dir
			A=`sq3 "select sum(loc_added) \
				from dir_summary where\
                         	snap_idx=$i and \
				substr(dir_name, 1, $JLEN)=\"$j\" \
				"|head -n1`

			D=`sq3 "select sum(loc_removed) \
				from dir_summary where\
				snap_idx=$i and \
				substr(dir_name, 1, $JLEN)=\"$j\" \
				"|head -n1`
			else
				# it's truncated, so only files in this dir
				# eg arch, but arch/arm is handled elsewhere
				DEP=$(( `echo "$j" | sed "s|[^/]||g" | \
					wc -c` + 1 ))

				A=`sq3 "select sum(loc_added) \
					from dir_summary where \
				 	snap_idx=$i and \
					substr(dir_name, 1, $JLEN)=\"$j\"\
					and dir_depth=$DEP" | head -n1`

				D=`sq3 "select sum(loc_removed) \
					from dir_summary where \
				 	snap_idx=$i and \
					substr(dir_name, 1, $JLEN)=\"$j\" \
					and dir_depth=$DEP" | head -n1`
			fi

			if [ ! -z "$A" -a ! -z "$D" ] ; then
				V=$(( $A - $D ))
				echo -n "$V " >> .plot.tmp1

				if [ $V -gt $BIGGEST ] ; then
					BIGGEST=$V
					echo $V > .biggest
				fi
				if [ $V -lt $SMALLEST ] ; then
					SMALLEST=$V
					echo $V > .smallest
				fi

			else
				echo -n "0 " >> .plot.tmp1
			fi
		done

		echo >> .plot.tmp1
		F=0
	done

	>&2 echo

	SMALLEST=`cat .smallest`

	FIXEDCOLS=2
#	if [ ! -z "$COMP_RUN" ] ; then
#		FIXEDCOLS=3
#	fi

	#
	# add in the title row
	#
	echo -n "idx dir " > .plot.tmp
	for i in $SN $SNC ; do
		V="`sq3 "select ref_name \
			from snapshots where snap_idx=$i"`"

		echo -n "$V " >> .plot.tmp
	done
	echo >> .plot.tmp

	#
	# the second row is the basis names
	#
	echo -n "idx basis " >> .plot.tmp
	for i in $SN $SNC ; do
		A=`sq3 "select basis_name from snapshots where snap_idx=$i"`
		echo -n "$A " >> .plot.tmp
	done
	echo >> .plot.tmp

	#
	# output the files in LOC-sorted order

	C=0
	sort -k$(( $N + 1 )) -nr .plot.tmp1 | while read i ; do
		echo "$C $i" >> .plot.tmp
		C=$(( $C + 1 ))
	done

	WIDTH=$(( 16 * `cat .plot.cols | wc -l` ))
	if [ $WIDTH -lt 640 ] ; then
		WIDTH=640
	fi

	# determine the best scale, considering first col may be an outlier

	BROW=0
	function biggest_row {
		BROW=`cat .plot.tmp | head -n+$1 | \
		tail -n1 | cut -d' ' -f3- | tr ' ' '\n' | \
		sort -h | tail -n1`
	}

	biggest_row 4

	NEXT_BIGGEST=$BIGGEST
	echo $NEXT_BIGGEST >.next-biggest

	# plot each snapshot in turn

	C=1
	while [ $C -le $N ]; do

		echo $C $N

		BIGGEST=`cat .biggest`
		NEXT_BIGGEST=`cat .next-biggest`
		SMALLEST=`cat .smallest`

		TOT=`cat .plot.tmp |tail -n+3 | \
			cut -d' ' -f$(( $C + $FIXEDCOLS )) |paste -sd+ | bc`
		_FILTER=`echo "$FILTER" | sed "s|/|_|g"`
		if [ ! -z "$_FILTER" ] ; then
			_FILTER=$_FILTER-
		fi

		PL="'.plot.tmp' using \
			1:$(( $C + $FIXEDCOLS )):xtic(2) \
                        w boxes lc rgb \"#0000ff\" "
		PLR="'.plot.tmp' using \
			1:(-\$$(( $C + $FIXEDCOLS ))):xtic(2) \
                        w boxes lc rgb \"#0000ff\" "

		Q="`cat .plot.tmp | head -n1 | \
				cut -d' ' -f$(( $C + $FIXEDCOLS ))`"
		B="`cat .plot.tmp | head -n2 | tail -n1 |\
				cut -d' ' -f$(( $C + $FIXEDCOLS ))`"

		_TOT="Total LOC $Q ($B): `printf %7d $TOT`"

		echo $_TOT

		if [ ! -z "$SNC" ] ; then
			PL="'.plot.tmp' using \
				1:$(( $N + $FIXEDCOLS + 1 )):xtic(2) \
                        	w boxes lc rgb \"#ff0000\",$PL"
			PLR="'.plot.tmp' using \
				1:(-\$$(( $N + $FIXEDCOLS + 1 ))):xtic(2) \
	                        w boxes lc rgb \"#0000ff\",$PLR"


			TOTC="`cat .plot.tmp |tail -n+3 | \
				cut -d' ' -f$(( $N + $FIXEDCOLS + 1 )) |\
				paste -sd+ | bc`"
			Q="`cat .plot.tmp | head -n1 | \
				cut -d' ' -f$(( $N + $FIXEDCOLS + 1 ))`" \
			B="`cat .plot.tmp | head -n2 | tail -n1 |\
				cut -d' ' -f$(( $N + $FIXEDCOLS + 1 ))`"

			echo $TOT $TOTC

			_TOT="Total LOC $Q ($B): `printf %7d $TOTC`\n$_TOT\n\
				(`printf %3d $(( $TOT * 100 / $TOTC ))`%)"
		fi

		issue_plot_file_dist \
			"$PL" "$SMALLEST : $NEXT_BIGGEST" \
			"growth-$R-dist-$_FILTER`printf %04d $C`.png" \
			"$R patch distribution (LOC) $3" \
			$WIDTH,1024 "$_TOT" "$BROW"
		C=$(( $C + 1 ))
	done

	>&2 echo "Converting gif"
	convert -delay 50 -loop 0 growth-$R-dist-$_FILTER????.png growth-$R-dist-$_FILTER.gif

	exit 0
fi

#
# Tagged rebase tree mode
#

if [ "$2" = "--tags" ] ; then
	if [ -z "$3" ] ; then
		>&2 echo "Need tag regexp filter with --tags"
		exit 1
	fi

	sq3 "insert into runs ( \
			run_key, basis_hash, comp_hash, schema_ver) \
			values (NULL, \"$1\", \"$3\", \"$SCHEMA_VER\"); \
		"
	RUNKEY=`sq3 "select seq from sqlite_sequence where \
			name=\"runs\""`

	>&2 echo "tags mode -- run $RUNKEY"
	index=0
	for i in `git tag | grep "$3"` ; do
		>&2 echo $i
		make_stat $1 $i "" $index $RUNKEY
		index=$(( $index + 1 ))
	done

	exit 0
fi

exit 0

# ---> untested

#
# History tree mode
#

if [ ! -z "$2" ] ; then
	COMP=$2
else
	COMP=`git rev-parse --abbrev-ref HEAD`
fi

basis_point $1 $COMP

git log $BP.. --oneline | \
	cut -d' ' -f1 | \
	tac > .patches.tmp

TODO=`wc -l .patches.tmp | cut -d' ' -f 1`
C=1

cat .patches.tmp | while read i ; do
	>&2 echo "Patch $C/$TODO"
	make_stat $1 $i $BP
	C=$(( $C + 1 ))
done

exit 0