PageRenderTime 111ms CodeModel.GetById 78ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 1ms

/contrib/cvs/contrib/rcs2sccs.sh

https://bitbucket.org/freebsd/freebsd-head/
Shell | 156 lines | 118 code | 9 blank | 29 comment | 20 complexity | 1b7c467229cccb4a31b090a5263966df MD5 | raw file
  1#! /bin/sh
  2#
  3# Copyright (C) 1995-2005 The Free Software Foundation, Inc.
  4#
  5# This program is free software; you can redistribute it and/or modify
  6# it under the terms of the GNU General Public License as published by
  7# the Free Software Foundation; either version 2, or (at your option)
  8# any later version.
  9#
 10# This program is distributed in the hope that it will be useful,
 11# but WITHOUT ANY WARRANTY; without even the implied warranty of
 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13# GNU General Public License for more details.
 14#
 15
 16############################################################
 17# Error checking
 18#
 19if [ ! -d SCCS ] ; then
 20    mkdir SCCS
 21fi
 22
 23logfile=/tmp/rcs2sccs_$$_log
 24rm -f $logfile
 25tmpfile=/tmp/rcs2sccs_$$_tmp
 26rm -f $tmpfile
 27emptyfile=/tmp/rcs2sccs_$$_empty
 28echo -n "" > $emptyfile
 29initialfile=/tmp/rcs2sccs_$$_init
 30echo "Initial revision" > $initialfile
 31sedfile=/tmp/rcs2sccs_$$_sed
 32rm -f $sedfile
 33revfile=/tmp/rcs2sccs_$$_rev
 34rm -f $revfile
 35commentfile=/tmp/rcs2sccs_$$_comment
 36rm -f $commentfile
 37
 38# create the sed script
 39cat > $sedfile << EOF
 40s,;Id;,%Z%%M% %I% %E%,g
 41s,;SunId;,%Z%%M% %I% %E%,g
 42s,;RCSfile;,%M%,g
 43s,;Revision;,%I%,g
 44s,;Date;,%E%,g
 45s,;Id:.*;,%Z%%M% %I% %E%,g
 46s,;SunId:.*;,%Z%%M% %I% %E%,g
 47s,;RCSfile:.*;,%M%,g
 48s,;Revision:.*;,%I%,g
 49s,;Date:.*;,%E%,g
 50EOF
 51sed -e 's/;/\\$/g' $sedfile > $tmpfile
 52cp $tmpfile $sedfile
 53############################################################
 54# Loop over every RCS file in RCS dir
 55#
 56if sort -k 1,1 /dev/null 2>/dev/null
 57then sort_each_field='-k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -k 9'
 58else sort_each_field='+0 +1 +2 +3 +4 +5 +6 +7 +8'
 59fi
 60for vfile in *,v; do
 61    # get rid of the ",v" at the end of the name
 62    file=`echo $vfile | sed -e 's/,v$//'`
 63
 64    # work on each rev of that file in ascending order
 65    firsttime=1
 66    rlog $file | grep "^revision [0-9][0-9]*\." | awk '{print $2}' | sed -e 's/\./ /g' | sort -n -u $sort_each_field | sed -e 's/ /./g' > $revfile
 67    for rev in `cat $revfile`; do
 68        if [ $? != 0 ]; then
 69		echo ERROR - revision
 70		exit
 71	fi
 72        # get file into current dir and get stats
 73        date=`rlog -r$rev $file | grep "^date: " | awk '{print $2; exit}' | sed -e 's/^19\|^20//'`
 74        time=`rlog -r$rev $file | grep "^date: " | awk '{print $3; exit}' | sed -e 's/;//'`
 75        author=`rlog -r$rev $file | grep "^date: " | awk '{print $5; exit}' | sed -e 's/;//'`
 76	date="$date $time"
 77        echo ""
 78	rlog -r$rev $file | sed -e '/^branches: /d' -e '1,/^date: /d' -e '/^===========/d' -e 's/$/\\/' | awk '{if ((total += length($0) + 1) < 510) print $0}' > $commentfile
 79        echo "==> file $file, rev=$rev, date=$date, author=$author"
 80	rm -f $file
 81        co -r$rev $file >> $logfile  2>&1
 82        if [ $? != 0 ]; then
 83		echo ERROR - co
 84		exit
 85	fi
 86        echo checked out of RCS
 87
 88        # add SCCS keywords in place of RCS keywords
 89        sed -f $sedfile $file > $tmpfile
 90        if [ $? != 0 ]; then
 91		echo ERROR - sed
 92		exit
 93	fi
 94        echo performed keyword substitutions
 95	rm -f $file
 96        cp $tmpfile $file
 97
 98        # check file into SCCS
 99        if [ "$firsttime" = "1" ]; then
100            firsttime=0
101	    echo about to do sccs admin
102            echo sccs admin -n -i$file $file < $commentfile
103            sccs admin -n -i$file $file < $commentfile >> $logfile 2>&1
104            if [ $? != 0 ]; then
105		    echo ERROR - sccs admin
106		    exit
107	    fi
108            echo initial rev checked into SCCS
109        else
110	    case $rev in
111	    *.*.*.*)
112		brev=`echo $rev | sed -e 's/\.[0-9]*$//'`
113		sccs admin -fb $file 2>>$logfile
114		echo sccs get -e -p -r$brev $file
115		sccs get -e -p -r$brev $file >/dev/null 2>>$logfile
116		;;
117	    *)
118		echo sccs get -e -p $file
119		sccs get -e -p $file >/dev/null 2>> $logfile
120		;;
121	    esac
122	    if [ $? != 0 ]; then
123		    echo ERROR - sccs get
124		    exit
125	    fi
126	    sccs delta $file < $commentfile >> $logfile 2>&1
127            if [ $? != 0 ]; then
128		    echo ERROR - sccs delta -r$rev $file
129		    exit
130	    fi
131            echo checked into SCCS
132	fi
133	sed -e "s;^d D $rev ../../.. ..:..:.. [^ ][^ ]*;d D $rev $date $author;" SCCS/s.$file > $tmpfile
134	rm -f SCCS/s.$file
135	cp $tmpfile SCCS/s.$file
136	chmod 444 SCCS/s.$file
137	sccs admin -z $file
138        if [ $? != 0 ]; then
139		echo ERROR - sccs admin -z
140		exit
141	fi
142    done
143    rm -f $file
144done
145
146
147############################################################
148# Clean up
149#
150echo cleaning up...
151rm -f $tmpfile $emptyfile $initialfile $sedfile $commentfile
152echo ===================================================
153echo "       Conversion Completed Successfully"
154echo ===================================================
155
156rm -f *,v