vim_mainline and vim_extended are discontinued
[vim_extended.git] / update-vim.sh
blob4f1b0d58865acb60fe61615827585fd79e61ee71
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 # The date in the patch doesn't contain an UTC offset, so the current
22 # time zone would be used, which would lead to different commit SHA1s
23 # depending on the time zone, where the patch is applied. Hence we
24 # simply use +0000, though it may not match with the patch author.
25 sed -n 's/^--- src\/version\.c \(.*\)/\1 +0000/p' "$1"
28 apply_patch() {
30 # Apply the patch
33 interdiff -q /dev/null "$1" | git apply --index -p0
36 # Prepare the commit message
39 # Summary (subject)
41 # Patch number in brackets
42 NUM=$(sed -n 's/^Patch \([0-9a-z\.]*\).*/[\1]/p' "$1")
44 # First line of the problem description
45 SUM=$(sed -n 's/^Problem:[ ]*\(.*\)/\1/p' "$1")
47 # Description (body)
49 # Problem
50 PROB=$(sed -n '/^Problem:.*/,/^Solution:.*/{s/^Solution:.*//;t;p}' "$1")
52 # Solution
53 SOL=$(sed -n '/^Solution:.*/,/^Files:.*/{s/^Files:.*//;t;p}' "$1")
55 # Original patch subject (with "extra", "after", ...)
56 SUBJ=$(sed -n '/^Patch [0-9a-z\.]*.*/p' "$1")
59 # Convert tabs to spaces in the commit message and commit
62 printf "%s %s\n\n%s\n\n%s\n\n%s" \
63 "$NUM" "$SUM" "$PROB" "$SOL" "$SUBJ" \
64 | expand | git commit -F-
67 get_vim_version_major() {
68 sed -n 's/^#define VIM_VERSION_MAJOR[ ]\+\([0-9]*\)/\1/p' src/version.h
71 get_vim_version_minor() {
72 sed -n 's/^#define VIM_VERSION_MINOR[ ]\+\([0-9]*\)/\1/p' src/version.h
75 get_vim_version_patch() {
76 sed -n '/included_patches\[\]/,/^[ ]*\([0-9]\+\).*/{s/^[ ]*\([0-9]\+\).*/\1/;T;p}' src/version.c
79 get_vim_next_version() {
80 printf "%u.%u.%03u\n" "$(get_vim_version_major)" \
81 "$(get_vim_version_minor)" \
82 "$(expr $(get_vim_version_patch) + 1)"
85 ### main ###
87 SERVER_PATCH_DIR="http://ftp.vim.org/pub/vim/patches/$(get_vim_version_major).$(get_vim_version_minor)"
88 PATCH=$(get_vim_next_version)
90 while wget $SERVER_PATCH_DIR/$PATCH 2>/dev/null; do
91 echo "Applying patch $(basename $PATCH)"
93 GIT_AUTHOR_NAME="$(get_author_name $PATCH)"
94 GIT_AUTHOR_EMAIL="$(get_author_email $PATCH)"
95 GIT_AUTHOR_DATE="$(get_author_date $PATCH)"
96 GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"
97 GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
98 GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
99 export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
100 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE
102 apply_patch $PATCH
103 rm $PATCH
105 PATCH=$(get_vim_next_version)
106 done