forked from takaki/prcs2git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prcs2git.sh
executable file
·118 lines (97 loc) · 3.16 KB
/
prcs2git.sh
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
#!/bin/bash
# prcs2git - convert PRCS repository to Git repository
# Copyright (C) 2009 TANIGUCHI, Takaki <takaki@asis.media-as.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set -e
package=$1
domain=$2
basedir=/tmp/prcs2git
pdir=${basedir}/prcs/${package}
gdir=${basedir}/git/${package}
ddir=${basedir}/done/${package}
if [ $# -lt 1 ]; then
cat <<EOF
Usage: $(basename $0) project [email_domain]
New Git repository is exported at ${gdir}project.
If email domain is provided, then a prcs user is converted to a git author
as user@email_domain.
prcs2git - Copyright (C) 2009 TANIGUCHI Takaki <takaki@asis.media-as.org>
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions
EOF
exit 1
fi
revs=($(prcs info --sort=date ${package} | grep ${package} | grep -v '\*DELETED\*' | awk '{print $2}'))
branches=($(for i in ${revs[@]}; do
echo $i | sed -e 's/\.[0-9]\+$//'
done | sort -u ))
mkdir -p ${ddir}
if [ ! -d ${gdir} ]; then
mkdir -p ${gdir}
cd ${gdir}
git init
fi
first=1
for i in ${revs[@]}; do
if [ -f ${ddir}/${i} ]; then
continue
fi
mkdir -p ${pdir}/${i}
cd ${pdir}/${i}
prcs checkout -f -r${i} ${package}
cd ${gdir}
c_info=$(cd /; prcs info -f -r${i} -l ${package})
c_branch=$(echo $i | sed -e 's/\.[0-9]\+$//')
c_branch_rev=$(echo $i | sed -e 's/^.*\.//')
p_revs=($(echo "${c_info}" | grep Parent-Version: | awk '{print $2}' ))
c_info_lite=$(cd /; prcs info -r${i} ${package} | tr -d '\n')
date=$(echo "${c_info_lite}" | cut -d' ' -f 3-8)
auth=$(echo "${c_info_lite}" | cut -d' ' -f 10)
full_auth="${auth} <${auth}@${domain}>"
if [ ${first} = 1 ]; then
rsync --exclude=.git --delete -ac "${pdir}/${i}/." .
git add .
git commit -a --date="${date}" -m "${c_info}"
git branch -m master ${c_branch}
touch ${ddir}/${i}
rm -rf ${pdir}/${i}
first=0
continue
fi
if [ ${c_branch_rev} = "1" ]; then
p_branch=$(echo "${p_revs[0]}" | sed -e 's/\.[0-9]\+$//')
git checkout "${p_branch}"
git branch "${c_branch}"
fi
git checkout "${c_branch}"
for p in ${p_revs[@]}; do
p_branch=$(echo $p | sed -e 's/\.[0-9]\+$//')
p_branch_rev=$(echo $p | sed -e 's/^.*\.//')
git merge "${p_branch}" || true
git add -u
git add .
done
rsync --exclude=.git --delete -ac ${pdir}/${i}/. .
git add -u
git add .
if [ -n "${domain}" ]; then
git commit -a --date="${date}" --author="${full_auth}" -m "${c_info}"
else
git commit -a --date="${date}" -m "${c_info}"
fi
touch ${ddir}/${i}
rm -rf ${pdir}/${i}
done
rm -rf ${pdir}