This repository has been archived by the owner on Jul 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
git-svn-fast-import.sh
111 lines (99 loc) · 3.82 KB
/
git-svn-fast-import.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
#!/bin/sh
#
# Copyright (C) 2014-2015 by Maxim Bublis <b@codemonkey.ru>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
OPTIONS_SPEC="\
git-svn-fast-import [options] <repo>
--
h,help show the help
r,revision= set revision range
s,stdlayout set trunk,tags,branches as the relative paths, which is SVN default
incremental incremental mode
b,branch=path set repository <path> as a branch
B,branches=path set repository <path> as a root for branches
t,tag=path set repository <path> as a tag
T,tags=path set repository <path> as a root for tags
I,ignore-path=path ignore a relative repository <path>
i,ignore-abspath!=path ignore repository <path>
no-ignore-abspath=path do not ignore repository <path>
A,authors-file=file load from <file> the mapping of SVN committer names to Git commit authors
export-rev-marks=file dump SVN revision marks to <file>
export-marks=file dump Git marks into <file>
export-branches=file dump known branches into <file>
import-rev-marks=file load SVN revision marks from <file>
import-marks=file load Git marks from <file>
import-marks-if-exists=file load Git marks from <file>, if exists
import-branches=file load branches from <file>
c,checksum-cache=file use <file> as a checksum cache
force force updating modified existing branches, even if doing so would cause commits to be lost
quiet disable all non-fatal output"
eval "$(echo "$OPTIONS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)"
SVN_FAST_EXPORT_ARGS=
GIT_FAST_IMPORT_ARGS=
while [ "$#" -gt 0 ]; do
case $1 in
-s|--incremental)
SVN_FAST_EXPORT_ARGS="$SVN_FAST_EXPORT_ARGS $1"
shift
;;
-r|-t|-T|-b|-B|-i|-I|-A|--export-rev-marks|--import-rev-marks|--export-branches|--import-branches|--no-ignore-abspath)
SVN_FAST_EXPORT_ARGS="$SVN_FAST_EXPORT_ARGS $1 $2"
shift 2
;;
--force|--quiet)
GIT_FAST_IMPORT_ARGS="$GIT_FAST_IMPORT_ARGS $1"
shift
;;
--export-marks|--import-marks|--import-marks-if-exists)
GIT_FAST_IMPORT_ARGS="$GIT_FAST_IMPORT_ARGS $1=$2"
shift 2
;;
--)
shift
;;
*)
SVN_FAST_EXPORT_ARGS="$SVN_FAST_EXPORT_ARGS $1"
shift
;;
esac
done
TMP_PREFIX=/tmp/git-svn-fast-import
TMP_SUFFIX=$$
CHAN=$TMP_PREFIX.chan.$TMP_SUFFIX
# Cleanup on EXIT
on_exit() {
rm -f $CHAN
}
trap 'on_exit' EXIT
mkfifo $CHAN
git fast-import $GIT_FAST_IMPORT_ARGS --done <$CHAN &
FAST_IMPORT_PID=$!
eval "svn-fast-export $SVN_FAST_EXPORT_ARGS" >$CHAN
RET_CODE=$?
wait $FAST_IMPORT_PID
GIT_RET_CODE=$?
if test $RET_CODE -gt 0; then
exit $RET_CODE
elif test $GIT_RET_CODE -gt 0; then
exit $GIT_RET_CODE
else
exit 0
fi