README: move "custom branch" part to "Basic use"
[vim_extended.git] / update-vim.sh
bloba98f227a6bd8adde0fa78a69df4523dab4650b2d
1 #!/bin/sh
3 # by Markus Heidelberg, 2009
5 # Fetch official bugfix patches, apply and commit them.
7 # Author and committer name and email are extracted from the "From:" line of
8 # the "email" part of the patch file.
9 # The author and committer date is currently the date, which is written behind
10 # version.c from the "patch" part of the patch file.
12 get_author_name() {
13 sed -n 's/^From: \(.*\) <.*/\1/p' "$1"
16 get_author_email() {
17 sed -n 's/^From: .* <\(.*\)>.*/\1/p' "$1"
20 get_author_date() {
21 # TODO: UTC offset of the current time zone is used, this leads to
22 # different SHA1s dependent on the time zone
23 sed -n 's/^--- src\/version\.c \(.*\)/\1/p' "$1"
26 apply_patch() {
28 # Apply the patch
31 interdiff -q /dev/null "$1" | git apply --index -p0
34 # Prepare the commit message
37 # Summary (subject)
39 # Patch number in brackets
40 NUM=$(sed -n 's/^Patch \([0-9a-z\.]*\).*/[\1]/p' "$1")
42 # First line of the problem description
43 SUM=$(sed -n 's/^Problem:[ ]*\(.*\)/\1/p' "$1")
45 # Description (body)
47 # Problem
48 PROB=$(sed -n '/^Problem:.*/,/^Solution:.*/{s/^Solution:.*//;t;p}' "$1")
50 # Solution
51 SOL=$(sed -n '/^Solution:.*/,/^Files:.*/{s/^Files:.*//;t;p}' "$1")
53 # Original patch subject (with "extra", "after", ...)
54 SUBJ=$(sed -n '/^Patch [0-9a-z\.]*.*/ p' "$1")
57 # Convert tabs to spaces in the commit message and commit
60 printf "%s %s\n\n%s\n\n%s\n\n%s" \
61 "$NUM" "$SUM" "$PROB" "$SOL" "$SUBJ" \
62 | expand | git commit -F-
65 get_vim_version_major() {
66 sed -n 's/^#define VIM_VERSION_MAJOR[ ]\+\([0-9]*\)/\1/p' src/version.h
69 get_vim_version_minor() {
70 sed -n 's/^#define VIM_VERSION_MINOR[ ]\+\([0-9]*\)/\1/p' src/version.h
73 get_vim_version_patch() {
74 sed -n '/included_patches\[\]/,/^[ ]*\([0-9]\+\).*/{s/^[ ]*\([0-9]\+\).*/\1/;T;p}' src/version.c
77 get_vim_next_version() {
78 printf "%u.%u.%03u\n" "$(get_vim_version_major)" \
79 "$(get_vim_version_minor)" \
80 "$(expr $(get_vim_version_patch) + 1)"
83 ### main ###
85 SERVER_PATCH_DIR="http://ftp.vim.org/pub/vim/patches/$(get_vim_version_major).$(get_vim_version_minor)"
86 PATCH=$(get_vim_next_version)
88 while wget $SERVER_PATCH_DIR/$PATCH 2>/dev/null; do
89 echo "Applying patch $(basename $PATCH)"
91 export GIT_AUTHOR_NAME="$(get_author_name $PATCH)"
92 export GIT_AUTHOR_EMAIL="$(get_author_email $PATCH)"
93 export GIT_AUTHOR_DATE="$(get_author_date $PATCH)"
94 export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
95 export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
96 export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
98 apply_patch $PATCH
99 rm $PATCH
101 PATCH=$(get_vim_next_version)
102 done