Use git for version control.
[netwalk.git] / export-to-git
blobc5f97be69e52d056a1c5bf76adec0d844a4bc908
1 #!/bin/bash
3 # One-shot git importer for Netwalk.
5 # Usage: Extract all tarballs up to 0.4.10 inclusive in some temporary
6 # directory, and then run:
7 # $ export-to-git > /tmp/some_file
8 # Then, in a new subdirectory, run:
9 # $ git init && git fast-import --date-format=rfc2822 < /tmp/some_file
10 # to create the repo
12 dumpfile() {
13 echo -n "M 100644 inline "
14 if [[ $1 == "." ]]; then
15 echo $2
16 else
17 echo $1/$2
19 echo "data "$(stat -c%s $2)
20 cat $2
21 echo
24 docurdir()
26 for F in *; do
27 if [[ -f $F ]]; then
28 dumpfile $1 $F
29 elif [[ -d $F ]]; then
30 cd $F
31 if [[ $1 == "." ]]; then
32 docurdir $F
33 else
34 docurdir $1/$F
36 cd ..
37 else
38 echo WARNING! NO IDEA WHAT $F IS
40 done
43 revnews()
45 TMPFILE=$(mktemp)
47 while [ 1 ]; do
48 IFS=""
49 read LINE
50 if [ $? != 0 ]; then
51 break
53 echo $LINE >> $TMPFILE
54 if [[ $LINE =~ ^[A-Z].*200.$ ]]; then
55 tac $TMPFILE
56 rm $TMPFILE
58 done
59 if [ -f $TMPFILE ]; then
60 rm $TMPFILE
64 cp netwalk-0.3.2/HISTORY bighistory
65 echo >> bighistory
66 tac netwalk-0.4.10/NEWS | revnews >> bighistory
68 LAST=""
69 # Version numbers don't sort well
70 LIST="$(ls -d netwalk* | grep -v netwalk-0.4.10) netwalk-0.4.10"
71 for DIR in $LIST; do
72 cd $DIR
73 if [[ -f HISTORY ]]; then
74 HISTFILE="HISTORY"
75 DATE=$(grep '^[A-Z]' $HISTFILE | tail -1)
76 else
77 HISTFILE="NEWS"
78 DATE=$(grep '^[A-Z]' $HISTFILE | head -1)
80 echo "commit refs/heads/master
81 committer "Ben Lynn" <blynn@cs.stanford.edu> $DATE
82 data <<EOT"
83 if [[ $LAST == "" ]]; then
84 cat $HISTFILE
85 else
86 sed -n '/'$LAST'\.tgz/,/'$DIR'\.tgz/p' < ../bighistory | sed -n '/^$/,$p' | sed -n '/^[A-Z]/,$p'
88 echo "EOT
90 echo "deleteall"
91 docurdir .
93 LAST=$DIR
94 cd ..
95 done