-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathimportFromSvn.sh
More file actions
executable file
·188 lines (167 loc) · 6.14 KB
/
importFromSvn.sh
File metadata and controls
executable file
·188 lines (167 loc) · 6.14 KB
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
#!/bin/sh
#
# 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/>.
#
# Description:
# ============
# This tool is a very simple tool for automatically propping code
# from subversion to git. Doing so allows people to choose their
# choice of an either centralized or distributed model to work with
# Ingres code. Particularly, git allows local branching, local commit
# and thus lends itself well to experimental work and working offline.
#
# This tool keeps a manifest of revisions it has successfully merged
# and thus preserves state through comitting this file in the repository.
#
# This tool could be modified to be generic fairly easily.
#
# History:
# ========
# Jun-06-2010 (Andrew Ross)
# Initial version.
# Aug-26-2010 (Andrew Ross)
# Updates to handle binaries better. Copy the changes over top rather
# than apply patches.
# Sped up the tool by only downloading files we care about.
# Added proper support for deleted files.
# Oct-16-2010 (Andrew Ross)
# Forked to handle the tests.
# TODO:
# Generic improvements:
# =====================
# Urgent
# ------
# - use svn log on the URL to get the revision numbers of changes
# that affected it. This is *much* more efficient.
# - Add error handling function with msg & return params
# - put the stuff we want to exclude into a file instead
# Minor
# -----
# - getopts for option handling
# - config file for defaults
# - add help/usage
# - consider syslog for logging
URL="http://code.ingres.com/ingres/main/src/tst"
SVNLatest=`svn info ${URL} | grep "Last Changed Rev:" | awk '{print $4}'`
RevLog="svn_import/imported_revisions.txt"
GitLatest=`tail -1 ${RevLog}`
NOW=`date +"%h%d-%Y-%H%M"`
OriginalDir=`pwd`
echo "Now: ${NOW} svn: rev >${SVNLatest}< git: rev >${GitLatest}<"
if [ "${SVNLatest}" == "${GitLatest}" ]
then
echo "git and svn are in sync"
else
echo "git and svn are NOT in sync"
if [ ${GitLatest} -gt ${SVNLatest} ]
then
echo "Error: Git is being reported as ahead of svn"
exit 1
else
echo "Stepping through svn updates to update git"
CurrentRev=${GitLatest}
while [ ${CurrentRev} -lt ${SVNLatest} ]
do
PreviousRev=${CurrentRev}
CurrentRev=`expr ${CurrentRev} + 1`
echo " "
echo "Processing revision: ${CurrentRev}"
echo "================================"
echo "Pulling patch: ${CurrentRev} from svn"
ChangeList="${CurrentRev}.import_txt"
TempList="${CurrentRev}.import_tmp"
CommitMessage="${CurrentRev}.import_msg"
# Get a list of affected files for this revision
# we're going to update each one in turn by downloading from svn
# then delete any files that have been deleted
svn log -vq -r${PreviousRev}:${CurrentRev} ${URL} > ${TempList}
# make sure we've got the list... we can't do anything without it
if [ $? != 0 ]
then
echo "ERROR: pulling patch failed for ${CurrentRev}"
echo "Cannot continue. Exiting"
exit 1
fi
# Format the output so that we can process it
cat ${TempList} | egrep '^ {3}[ADMR] ' | sort -u > ${ChangeList}
# First, process all the files that were added or modified
cat ${ChangeList} | grep -v "^D" | awk '{print $2}' |\
while read File
do
echo " Updating: ${File}"
TargetDir=`dirname ${File}`
Target="${URL}/${File}"
JustFileName=`basename ${File}`
# check if the directory involved exists, if not, add it
if [ ! -d ${TargetDir} ]
then
mkdir -p ${TargetDir}
fi
cd ${TargetDir}
if [ $? != 0 ]
then
echo "ERROR: I can't get into directory: ${TargetDir}"
echo "Cannot continue. Exiting"
exit 1
fi
# Get the file from subversion and overwrite the local copy
svn export -r ${CurrentRev} ${Target}
# make sure this worked...
if [ $? != 0 ]
then
echo "ERROR: pulling file failed for revision: ${CurrentRev} and file: ${Target}"
echo "Please re-run the import for this revision and it should recover."
echo "Cannot continue. Exiting"
exit 1
fi
git add ${JustFileName}
cd ${OriginalDir}
done # Looping for each changed file
# Then, delete all the files that were deleted
# This is a local-only operation at this point so it's best to do last
# after we know the updates worked successfully
cat ${ChangeList} | grep "^D" |\
while read DeletedFile
do
echo " Deleting: ${DeletedFile}"
git rm ${DeletedFile}
#TODO: double check that it actually removed
# complain and exit if we didn't find it to avoid a bigger mess
done
# Grab the commit message
svn log -r${PreviousRev}:${CurrentRev} ${URL} > ${CommitMessage}
# make sure this worked...
if [ $? != 0 ]
then
echo "ERROR: pulling commit message for revision: ${CurrentRev} failed"
echo "Please re-run the import for this revision and it should recover."
echo "Cannot continue. Exiting"
exit 1
fi
git status | grep "nothing to commit"
if [ $? != 0 ]
then
echo "No change to tests"
else
# Add the revision number to the log
echo "${CurrentRev}" >> ${RevLog}
git add ${RevLog}
# Commit, with the same commit message
git commit -F ${CommitMessage}
fi
done # Looping for each revision
fi
fi
echo "Done! Successuful. Until next time you need to update."
exit 0