forked from JohnAlbin/git-svn-migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch-svn-authors.sh
executable file
·150 lines (135 loc) · 4.04 KB
/
fetch-svn-authors.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
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
#!/bin/sh
# Copyright 2010 John Albin Wilkins.
# Available under the GPL v2 license. See LICENSE.txt.
script=`basename $0`;
usage=$(cat <<EOF_USAGE
USAGE: $script --url-file=<filename> --destination=<filename>
\n
\nFor more info, see: $script --help
EOF_USAGE
);
help=$(cat <<EOF_HELP
NAME
\n\t$script - Retrieves Subversion usernames from a list of
\n\tURLs for use in a git-svn-migrate (or git-svn) conversion.
\n
\nSYNOPSIS
\n\t$script [options]
\n
\nDESCRIPTION
\n\tThe $script utility creates a list of Subversion committers
\n\tfrom a list of Subversion URLs from thto Git using the
\n\tspecified authors list. The url-file parameter is required.
\n\tIf the destination parameter is not specified the authors
\n\twill be displayed in standard output.
\n
\n\tThe following options are available:
\n
\n\t-u=<filename>, -u <filename>,
\n\t--url-file=<filename>, --url-file <filename>
\n\t\tSpecify the file containing the Subversion repository list.
\n
\n\t-a=<filename>, -a <filename>,
\n\t--authors-file=[filename], --authors-file [filename]
\n\t\tSpecify the file containing the authors transformation data.
\n
\n\t-d=<folder>, -d <folder,
\n\t--destination=<folder>, --destination <folder>
\n\t\tThe directory where the new Git repositories should be
\n\t\tsaved. Defaults to the current directory.
\n
\nBASIC EXAMPLES
\n\t# Use the long parameter names
\n\t$script --url-file=my-repository-list.txt --destination=authors-file.txt
\n
\n\t# Use short parameter names and redirect standard output
\n\t$script -u my-repository-list.txt > authors-file.txt
\n
\nSEE ALSO
\n\tgit-svn-migrate.sh
EOF_HELP
);
# Set defaults for any optional parameters or arguments.
destination='';
# Process parameters.
until [[ -z "$1" ]]; do
option=$1;
# Strip off leading '--' or '-'.
if [[ ${option:0:1} == '-' ]]; then
if [[ ${option:0:2} == '--' ]]; then
tmp=${option:2};
else
tmp=${option:1};
fi
else
# Any argument given is assumed to be the destination folder.
tmp="destination=$option";
fi
parameter=${tmp%%=*}; # Extract option's name.
value=${tmp##*=}; # Extract option's value.
case $parameter in
# Some parameters don't require a value.
#no-minimize-url ) ;;
# If a value is expected, but not specified inside the parameter, grab the next param.
* )
if [[ $value == $tmp ]]; then
if [[ ${2:0:1} == '-' ]]; then
# The next parameter is a new option, so unset the value.
value='';
else
value=$2;
shift;
fi
fi
;;
esac
case $parameter in
u ) url_file=$value;;
url-file ) url_file=$value;;
d ) destination=$value;;
destination ) destination=$value;;
h ) echo $help | less >&2; exit;;
help ) echo $help | less >&2; exit;;
* ) echo "Unknown option: $option\n$usage" >&2; exit 1;;
esac
# Remove the processed parameter.
shift;
done
# Check for required parameters.
if [[ $url_file == '' ]]; then
echo $usage >&2;
exit 1;
fi
# Check for valid file.
if [[ ! -f $url_file ]]; then
echo "Specified URL file \"$url_file\" does not exist or is not a file." >&2;
echo $usage >&2;
exit 1;
fi
# Process each URL in the repository list.
tmp_file="tmp-authors-transform.txt";
while read line
do
# Check for 2-field format: Name [tab] URL
name=`echo $line | awk '{print $1}'`;
url=`echo $line | awk '{print $2}'`;
# Check for simple 1-field format: URL
if [[ $url == '' ]]; then
url=$name;
name=`basename $url`;
fi
# Process the log of each Subversion URL.
echo "Processing \"$name\" repository at $url..." >&2;
/bin/echo -n " " >&2;
svn log -q $url | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u >> $tmp_file;
echo "Done." >&2;
done < $url_file
# Process temp file one last time to show results.
if [[ $destination == '' ]]; then
# Display on standard output.
cat $tmp_file | sort -u;
else
# Output to the specified destination file.
cat $tmp_file | sort -u > $destination;
fi
unlink $tmp_file;