-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport.sh
More file actions
executable file
·542 lines (399 loc) · 14.8 KB
/
import.sh
File metadata and controls
executable file
·542 lines (399 loc) · 14.8 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
#!/bin/bash
fetch_svn()
{
echo "Fetching SVN repository to ${svn_path}"
if [[ -e "${svn_path}" ]] ; then
rm -rf "${svn_path}"
fi
svnadmin create "${svn_path}"
local hook="${svn_path}/hooks/pre-revprop-change"
echo '#!/bin/sh' > "${hook}"
echo 'exit 0' >> "${hook}"
chmod +x "${hook}"
svnsync init "file://${svn_path}" "${svn_url}"
svnsync sync "file://${svn_path}"
}
clone_svn_to_git()
{(
echo "Cloning SVN repository to Git ${git_path}"
if [[ -e "${git_path}" ]] ; then
rm -rf "${git_path}"
fi
git svn clone "file://${svn_path}" -T trunk -b branches -t tags --authors-file="${base_path}/authors.txt" --prefix=svn/ "${git_path}"
cd "${git_path}"
git config user.name "Mykola Ostrovskyy"
git config user.email "spambox03@mail.ru"
)}
delete_refs()
{
git for-each-ref --format="%(refname)" "$1" | xargs -rn 1 git update-ref -d
}
filter_branch()
{
git filter-branch "$@"
delete_refs "refs/original/"
}
reset_dates()
{
filter_branch --env-filter 'export GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}"' "$@"
}
update_branch()
{(
cd "${git_path}"
local svn_branch="$1"
local git_branch="$2"
local commits="$3"
echo "Updating branch ${svn_branch}"
if [[ "$(git rev-parse --verify --quiet "${svn_branch}")" == "" ]] ; then
echo "Source branch ${svn_branch} is not found"
return 1
fi
if [[ "$(git rev-parse --verify --quiet "${git_branch}")" == "" ]] ; then
git checkout -b "${git_branch}" "${svn_branch}"
else
git checkout "${git_branch}"
git reset --hard "${svn_branch}"
fi
local commit_range
if [[ "${commits}" != "" ]] ; then
commit_range="${git_branch}~${commits}..${git_branch}"
else
commit_range="${git_branch}"
fi
filter_branch --msg-filter "php \"${base_path}/rename.php\"" "${commit_range}"
reset_dates "${commit_range}"
)}
get_revision_commit()
{
git log --oneline "$1" | grep -P "^[0-9a-f]+ $2(:|$)" | sed -re "s/^([0-9a-f]+) .*/\1/"
}
rebase_branch()
{(
cd "${git_path}"
local branch="$1"
local commits="$2"
local target_branch="$3"
local revision="$4"
local subtree="$5"
local target_commit=$(get_revision_commit "${target_branch}" ${revision})
echo "Rebasing branch ${branch}"
if [[ "${target_commit}" == "" ]] ; then
echo "Failed to find revision ${revision} on ${target_branch}"
return 1
fi
if [[ "${subtree}" != "" ]] ; then
git rebase --keep-empty --strategy-option="subtree=${subtree}" --onto ${target_commit} "${branch}~${commits}" "${branch}" || return 1
else
git rebase --keep-empty --onto ${target_commit} "${branch}~${commits}" "${branch}" || return 1
fi
reset_dates "${branch}~${commits}..${branch}"
)}
merge_branch()
{(
cd "${git_path}"
local branch="$1"
local target_branch="$2"
local revision="$3"
local target_commit=$(get_revision_commit "${target_branch}" ${revision})
echo "Merging branch ${branch} into ${target_branch}"
if [[ "${target_commit}" == "" ]] ; then
echo "Failed to find revision ${revision} on ${target_branch}"
return 1
fi
local checkout_commit
if [[ "${4}" != "" && "${5}" != "" ]] ; then
checkout_commit=$(get_revision_commit "${4}" ${5})
if [[ "${checkout_commit}" == "" ]] ; then
echo "Failed to find revision ${5} on ${4}"
return 1
fi
else
checkout_commit=${target_commit}~1
fi
(
export GIT_MESSAGE=$(git log ${target_commit} -1 --pretty=format:%B)
export GIT_AUTHOR_DATE=$(git log ${target_commit} -1 --pretty=format:%ad)
export GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}"
git checkout ${checkout_commit}
git merge "${branch}" --commit -m "${GIT_MESSAGE}" ||
(
git apply "${base_path}/patches/${revision}.patch" &&
git commit -am "${GIT_MESSAGE}"
)
) || return 1
local merge_commit=$(git log -1 --pretty=format:%h)
git rebase --onto ${merge_commit} ${target_commit} "${target_branch}" &&
reset_dates "${merge_commit}..${target_branch}"
)}
create_temp_branch()
{(
cd "${git_path}"
local branch="$1"
local revision="$2"
local commit=$(get_revision_commit "${branch}" ${revision})
if [[ "${commit}" == "" ]] ; then
echo "Failed to find revision ${revision} on ${branch}"
return 1
fi
if [[ "$(git rev-parse --verify --quiet "temp-${revision}")" != "" ]] ; then
git branch -D "temp-${revision}"
fi
git branch "temp-${revision}" ${commit}
)}
delete_branch()
{(
cd "${git_path}"
local branch="$1"
echo "Deleting branch ${branch}"
delete_refs "refs/remotes/${branch}*"
)}
splice_branch()
{
local source_branch="$1"
local branch="$2"
local commits="$3"
local subtree="$4"
local target_branch="$5"
local target_revision="$6"
update_branch "${source_branch}" "${branch}" ${commits} &&
rebase_branch "${branch}" ${commits} "${target_branch}" ${target_revision} "${subtree}" &&
delete_branch "${source_branch}"
}
splice_tag()
{
splice_branch "$1" "$2" 1 "" "$3" "$4"
}
clean_repo()
{(
cd "${git_path}"
echo "Cleaning repository ${git_path}"
git reset --hard &&
delete_refs "refs/original/" &&
delete_refs "refs/heads/temp-*" &&
git reflog expire --expire=now --all &&
git gc --aggressive --prune=now &&
git checkout master
)}
clone_repo()
{(
local clone="$1"
echo "Cloning repository ${git_path} to ${clone}"
if [[ -e "${clone}" ]] ; then
rm -rf "${clone}"
fi
cp -R "${git_path}" "${clone}"
)}
create_tags()
{(
cd "${git_path}"
echo "Creating tags for ${plugin}"
local branch
for branch in $(git for-each-ref --format="%(refname)" "refs/heads/tags-${plugin}-*" | sed -re "s/refs\/heads\///") ; do
local tag=t.$(echo ${branch} | sed -re "s/tags-${plugin}-(.+)/\1/")
(
export GIT_MESSAGE=$(git log ${branch} -1 --pretty=format:%B | sed -re "s/^r[0-9]+: //")
export GIT_AUTHOR_DATE=$(git log ${branch} -1 --pretty=format:%ad)
export GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}"
local release=$(echo "${GIT_MESSAGE}" | grep Release | sed -re "s/Release (of )?([-0-9]+).*/\2/")
if [[ "${release}" != "" ]] ; then
tag="v.${release}"
fi
git tag -a "${tag}" -m "${GIT_MESSAGE}" "${branch}~1"
) || return 1
done
delete_refs "refs/heads/tags-${plugin}-*"
)}
tag_release_revision()
{(
cd "${git_path}"
local branch="$1"
local revision="$2"
echo "Tagging release ${revision}"
local commit=$(get_revision_commit "${branch}" ${revision})
if [[ "${commit}" == "" ]] ; then
echo "Failed to find revision ${revision} on ${branch}"
return 1
fi
export GIT_MESSAGE=$(git log ${commit} -1 --pretty=format:%B | sed -re "s/^r[0-9]+: //")
export GIT_AUTHOR_DATE=$(git log ${commit} -1 --pretty=format:%ad)
export GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}"
local release=$(echo "${GIT_MESSAGE}" | grep Release | sed -re "s/Release (of )?([-0-9]+).*/\2/")
if [[ "${release}" == "" ]] ; then
echo "Revision ${revision} is not a release"
return 1
fi
git tag -a "v.${release}" -m "${GIT_MESSAGE}" "${commit}"
)}
trim_branches()
{(
cd "${git_path}"
echo "Trimming branches for ${plugin}"
local branch
for branch in $(git branch -a | sed -re "s/^\*? +(.+)/\1/" | grep -vP "master|${plugin}-") ; do
git branch -D ${branch}
done
filter_branch --tag-name-filter cat --prune-empty --subdirectory-filter "${plugin}" -- --all
reset_dates -- --all
)}
rename_branches()
{(
cd "${git_path}"
echo "Renaming branches for ${plugin}"
local branch
for branch in $(git branch -a | sed -re "s/^\*? +(.+)/\1/" | grep -P "${plugin}-") ; do
local new_name=$(echo ${branch} | sed -re "s/${plugin}-(.+)/\1/")
git branch ${new_name} ${branch} &&
git branch -D ${branch}
done
)}
export_plugin_base()
{
create_tags
trim_branches
rename_branches
}
export_plugin_entity()
{(
export_plugin_base
tag_release_revision "master" r7
)}
export_plugin_columns()
{(
export_plugin_base
cd "${git_path}"
git checkout master &&
git merge --ff-only v3 &&
git branch -d v3
git branch -d odt-support
tag_release_revision "master" r3
tag_release_revision "master" r4
)}
export_plugin_qna()
{(
export_plugin_base
cd "${git_path}"
git branch -d custom-headers
)}
export_plugin_refnotes()
{(
cd "${git_path}"
local branches
local branch
for branch in $(git branch -a | sed -re "s/^\*? +(.+)/\1/") ; do
branches="${branches};${branch}:$(git log --format=%h ${branch} -1)"
done
local plugin="footrefs"
trim_branches
local footrefs=$(git log --format=%H "master~1" -1)
git checkout ${footrefs}
git branch -D "master"
for branch in $(echo ${branches:1} | sed -re "s/;/ /g") ; do
git branch ${branch%:*} ${branch#*:}
done
git checkout "master"
plugin="refnotes"
export_plugin_base
local refnotes=$(git log --format=%H $(get_revision_commit "master" r50) -1)
echo $refnotes $footrefs >> .git/info/grafts
filter_branch --tag-name-filter cat -- --all
rm .git/info/grafts
)}
export_plugin()
{(
local plugin="$1"
local plugin_repo="${base_path}/${plugin}"
clone_repo "${plugin_repo}"
git_path="${plugin_repo}"
case "${plugin}" in
"columns") export_plugin_columns ;;
"entity") export_plugin_entity ;;
"qna") export_plugin_qna ;;
"refnotes") export_plugin_refnotes ;;
*) export_plugin_base ;;
esac
clean_repo
)}
main()
{
local base_path=$(readlink -f $(dirname $BASH_SOURCE))
local svn_url="http://dwp-forge.googlecode.com/svn/"
local svn_path="${base_path}/dwp-forge-svn"
local git_path="${base_path}/dwp-forge-git"
fetch_svn || return 1
clone_svn_to_git || return 1
update_branch "svn/trunk" "master" &&
delete_branch "svn/trunk"
splice_branch "svn/columns3" "columns-v3" 46 "columns" "master" r76
splice_branch "svn/refnotes-inheritance" "refnotes-inheritance" 13 "refnotes" "master" r115
merge_branch "refnotes-inheritance" "master" r143
splice_branch "svn/columns-odt_support" "columns-odt-support" 5 "columns" "columns-v3" r226
merge_branch "columns-odt-support" "columns-v3" r233
splice_branch "svn/refnotes-reference_database" "refnotes-reference-database" 15 "refnotes" "master" r244
merge_branch "refnotes-reference-database" "master" r270
splice_branch "svn/qna-custom_headers" "qna-custom-headers" 8 "qna" "master" r327
merge_branch "qna-custom-headers" "master" r337
splice_branch "svn/refnotes-refdb_cache_dependency" "refnotes-refdb-cache-dependency" 4 "refnotes" "master" r343
merge_branch "refnotes-refdb-cache-dependency" "master" r352
update_branch "svn/refnotes-structured_references" "refnotes-structured-references" 55
update_branch "svn/refnotes-dual_core" "refnotes-dual-core" 9
update_branch "svn/refnotes-heavy_action" "refnotes-heavy-action" 23
create_temp_branch "refnotes-structured-references" r413
create_temp_branch "refnotes-structured-references" r421
create_temp_branch "refnotes-structured-references" r433
create_temp_branch "refnotes-structured-references" r453
rebase_branch "temp-r413" 41 "master" r361 "refnotes"
rebase_branch "refnotes-dual-core" 9 "temp-r413" r409 "refnotes"
merge_branch "refnotes-dual-core" "temp-r421" r421 "temp-r413" r413
rebase_branch "temp-r433" 6 "temp-r421" r421 "refnotes"
rebase_branch "refnotes-heavy-action" 23 "temp-r433" r426 "refnotes"
merge_branch "refnotes-heavy-action" "temp-r453" r453 "temp-r433" r433
rebase_branch "refnotes-structured-references" 6 "temp-r453" r453 "refnotes"
merge_branch "refnotes-structured-references" "master" r461
delete_branch "svn/refnotes-dual_core"
delete_branch "svn/refnotes-heavy_action"
delete_branch "svn/refnotes-structured_references"
splice_tag "svn/tags/columns-0901311636" "tags-columns-0901311636" "master" r46
splice_tag "svn/tags/columns-0903011954" "tags-columns-0903011954" "columns-v3" r85
splice_tag "svn/tags/columns-0903151954" "tags-columns-0903151954" "columns-v3" r110
splice_tag "svn/tags/columns-0904041335" "tags-columns-0904041335" "columns-v3" r137
splice_tag "svn/tags/columns-0908221657" "tags-columns-0908221657" "columns-v3" r237
splice_tag "svn/tags/columns-0908301834" "tags-columns-0908301834" "columns-v3" r250
splice_tag "svn/tags/columns-1209232308" "tags-columns-1209232308" "columns-v3" r508
splice_tag "svn/tags/columns-1210131603" "tags-columns-1210131603" "columns-v3" r511
splice_tag "svn/tags/batchedit-0810251603" "tags-batchedit-0810251603" "master" r20
splice_tag "svn/tags/batchedit-0810270018" "tags-batchedit-0810270018" "master" r29
splice_tag "svn/tags/batchedit-0812071806" "tags-batchedit-0812071806" "master" r35
splice_tag "svn/tags/batchedit-0902141955" "tags-batchedit-0902141955" "master" r68
splice_tag "svn/tags/tablewidth-0902141526" "tags-tablewidth-0902141526" "master" r62
splice_tag "svn/tags/tablewidth-1011181526" "tags-tablewidth-1011181526" "master" r399
splice_tag "svn/tags/tablewidth-1312031348" "tags-tablewidth-1312031348" "master" r518
splice_tag "svn/tags/replace-0904131936" "tags-replace-0904131936" "master" r148
splice_tag "svn/tags/changes-0909162356" "tags-changes-0909162356" "master" r290
splice_tag "svn/tags/qna-0912131824" "tags-qna-0912131824" "master" r339
splice_tag "svn/tags/qna-1502160108" "tags-qna-1502160108" "master" r523
splice_tag "svn/tags/refnotes-0903181339" "tags-refnotes-0903181339" "master" r111
splice_tag "svn/tags/refnotes-0908011250" "tags-refnotes-0908011250" "master" r222
splice_tag "svn/tags/refnotes-0909121625" "tags-refnotes-0909121625" "master" r275
splice_tag "svn/tags/refnotes-0910111658" "tags-refnotes-0910111658" "master" r308
splice_tag "svn/tags/refnotes-1004052043" "tags-refnotes-1004052043" "master" r361
splice_tag "svn/tags/refnotes-1207151516" "tags-refnotes-1207151516" "master" r504
delete_branch "svn/tags/refnotes-0908011230"
delete_branch "svn/tags/refnotes-0910111319"
delete_branch "svn/tags/refnotes-1111071939"
delete_branch "svn/tags/refnotes-1204230046"
delete_branch "svn/tags/refnotes-1204291450"
clean_repo
export_plugin "batchedit"
export_plugin "changes"
export_plugin "color"
export_plugin "columns"
export_plugin "entity"
export_plugin "margin"
export_plugin "pagelist"
export_plugin "qna"
export_plugin "refnotes"
export_plugin "replace"
export_plugin "spacer"
export_plugin "tablewidth"
}
main "$@"