#!/bin/bash


# NOTE: This conversion has been made and merge.
# This "one-shot" script is not required anymore,
# it is only kept here for historical interest.


# This script imports 3301 revisions of CSS 2,
# dated from 1997-07-21 to 2014-01-17,
# from a zip archive of W3C's CVS repository into a Mercurial bundle file.
#
# This bundle can be imported into a clone of CSSWG's repository
# (https://hg.csswg.org/drafts/) to add a 'css2' subdirectory
# with all its change history:
#
#     hg unbundle path/to/css2.hg-bundle
#     hg merge
#     hg commit -m 'Import CSS 2 from CVS, with change history'

# This script requires cvs2svn and hg convert
#     http://cvs2svn.tigris.org/
#     http://mercurial.selenic.com/wiki/ConvertExtension
#
# It expects to be in the same directory as a 'css2.zip' file
# containing the 'css2-src' directory of W3C's internal CVS repository,
# which itself consists of a bunch of '*,v' files.
#
# It will go through a multiple-step conversion, creating temporary files
# in the 'tmp' subdirectory, to finally produce a ~10 MB 'css2.hg-bundle' file.


set -e

cd $(dirname $0)

rm -rf tmp

mkdir -p tmp/cvs/CVSROOT

# Exclude:
#    css2-src/css2.tgz,v
#    css2-src/css2.ps,v
#    css2-src/css2.ps.gz,v
#    css2-src/css2.pdf,v
#    css2-src/css2.zip,v
#    css2-src/css2.txt,v
# But not:
#    css2-src/css2.html,v
unzip -q css2.zip 'css2-src/*' -x 'css2-src/css2.[^h]*' -d tmp/cvs

# We want the final result at http://dev.w3.org/csswg/css2/
mv tmp/cvs/css2-src tmp/cvs/css2

# Try some surgery on a broken RCS file.
# We may end up with incorrect earlier versions of bin/mkidx
# but at least cvs2svn doesn't abort in the middle of the conversion
patch -p 1 <<-'EOF'
--- a/tmp/cvs/css2/bin/mkidx,v
+++ b/tmp/cvs/css2/bin/mkidx,v
@@ -509,20 +509,19 @@
	     # class="tocline*" directs out patched html2ps to omit the bullet
	 d85 2
	 a86 3
	 	print OUTPUT "\n$indent[$j]<li class=\"tocline0\">$subs[$j]";
	 	if ($j < $#subs) {
	 	    print OUTPUT "\n$indent[$j]<ul class=\"index\">";
	 d88 1
	 d90 1
	-d109 2
	-a110 2
	+d106 1
	+a106 1
	 print OUTPUT "\n</ul>\n";
	-    
	 @
	 
	 
	 2.9
	 log
	 @Bug: lowercase & uppercase were considered different
	 @
	 text
	@@ -851,21 +850,21 @@
	 a91 7
	 $buf .= "</dl>\n";
	 
	 # Print out the full buffer
	 open(OUTPUT, "> $indexf");
	 print OUTPUT "<DIV class=\"noprint\"> ";
	 foreach $letter (@@letters) {
	     print OUTPUT " <a href=\"#$letter\">" . uc($letter) . "</a> ";
	-d93 2
	-a94 2
	+d93 1
	+a93 2
	 print OUTPUT "</DIV>";
	 print OUTPUT $buf;
	-a95 2
	+a93 2
	 
	 
	 @
	 
	 
	 1.11
	 log
	 @Updated to be like HTML
	@@ -1011,17 +1010,17 @@
	 a85 1
	 		print OUTPUT "\n<dd> $cmt";
	 d109 1
	 a109 1
	 	print OUTPUT "$pre$content$post";
	 d112 10
	 a121 1
	 print OUTPUT "</dl>\n";
	-d123 3
	+d123 1
	 @
	 
	 
	 1.5
	 log
	 @Fixed bug
	 @
	 text
EOF

# Prefix all commit messages with "[css2] "
find tmp/cvs -name '*,v' | xargs sed -i -r '/^log$/{
    N
    s/^(log\n@+)/\1\[css2\] /
}'

cvs2svn --encoding latin1 --retain-conflicting-attic-files --trunk-only \
        --tmpdir=tmp/cvs2svn --svnrepos tmp/svn tmp/cvs

cat > tmp/authormap.txt <<-'EOF'
	bbos=Bert Bos <bert@w3.org>
	ijacobs=Ian Jacobs <ij@w3.org>
	ian=Ian Jacobs <ij@w3.org>
	howcome=Håkon Wium Lie <howcome@opera.com>
	fantasai=Elika Etemad <fantasai.cvs@inkedblade.net>
	clilley=Chris Lilley <chris@w3.org>
	ihickson=Ian Hickson <ian@hixie.ch>
	lehors=Arnaud Le Hors <lehors@w3.org>
	ot=Olivier Thereaux <ot@w3.org>
	ted=Ted Guild <ted@w3.org>
	mmielke=Markus Mielke <mmielke@microsoft.com>
	dbaron=L. David Baron <dbaron@dbaron.org>
EOF

hg convert --authormap tmp/authormap.txt --datesort tmp/svn tmp/hg

hg --repository tmp/hg bundle --all css2.hg-bundle
